datagrid 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/datagrid.gemspec +26 -164
- data/lib/datagrid/columns.rb +5 -10
- data/lib/datagrid/filters.rb +3 -6
- data/lib/datagrid/filters/base_filter.rb +8 -0
- data/lib/datagrid/form_builder.rb +14 -13
- data/lib/datagrid/version.rb +3 -0
- metadata +10 -196
- data/.document +0 -5
- data/.rspec +0 -1
- data/.travis.yml +0 -23
- data/Gemfile +0 -33
- data/Rakefile +0 -43
- data/VERSION +0 -1
- data/spec/datagrid/active_model_spec.rb +0 -33
- data/spec/datagrid/column_names_attribute_spec.rb +0 -86
- data/spec/datagrid/columns/column_spec.rb +0 -19
- data/spec/datagrid/columns_spec.rb +0 -592
- data/spec/datagrid/core_spec.rb +0 -210
- data/spec/datagrid/drivers/active_record_spec.rb +0 -79
- data/spec/datagrid/drivers/array_spec.rb +0 -106
- data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
- data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
- data/spec/datagrid/drivers/sequel_spec.rb +0 -111
- data/spec/datagrid/filters/base_filter_spec.rb +0 -19
- data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
- data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
- data/spec/datagrid/filters/date_filter_spec.rb +0 -198
- data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
- data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
- data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
- data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
- data/spec/datagrid/filters/float_filter_spec.rb +0 -15
- data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
- data/spec/datagrid/filters/string_filter_spec.rb +0 -35
- data/spec/datagrid/filters_spec.rb +0 -332
- data/spec/datagrid/form_builder_spec.rb +0 -611
- data/spec/datagrid/helper_spec.rb +0 -683
- data/spec/datagrid/ordering_spec.rb +0 -150
- data/spec/datagrid/scaffold_spec.rb +0 -45
- data/spec/datagrid/stylesheet_spec.rb +0 -12
- data/spec/datagrid/utils_spec.rb +0 -19
- data/spec/datagrid_spec.rb +0 -94
- data/spec/spec_helper.rb +0 -123
- data/spec/support/active_record.rb +0 -38
- data/spec/support/configuration.rb +0 -28
- data/spec/support/i18n_helpers.rb +0 -6
- data/spec/support/matchers.rb +0 -101
- data/spec/support/mongo_mapper.rb +0 -32
- data/spec/support/mongoid.rb +0 -36
- data/spec/support/sequel.rb +0 -39
- data/spec/support/simple_report.rb +0 -64
- data/spec/support/test_partials/_actions.html.erb +0 -1
- data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
- data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
- data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
- data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
- data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
- data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
- data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
- data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
@@ -1,683 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require "active_support/core_ext/hash"
|
3
|
-
require "active_support/core_ext/object"
|
4
|
-
require "action_controller"
|
5
|
-
|
6
|
-
require 'datagrid/renderer'
|
7
|
-
|
8
|
-
describe Datagrid::Helper do
|
9
|
-
subject do
|
10
|
-
action_view_template
|
11
|
-
end
|
12
|
-
|
13
|
-
before(:each) do
|
14
|
-
allow(subject).to receive(:params).and_return({})
|
15
|
-
allow(subject).to receive(:request) do
|
16
|
-
Struct.new(:path, :query_parameters).new("/location", {})
|
17
|
-
end
|
18
|
-
allow(subject).to receive(:url_for) do |options|
|
19
|
-
options.is_a?(String) ? options : ["/location", options.to_param.presence].compact.join('?')
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
let(:group) { Group.create!(:name => "Pop") }
|
25
|
-
let!(:entry) { Entry.create!(
|
26
|
-
:group => group, :name => "Star", :disabled => false, :confirmed => false, :category => "first"
|
27
|
-
) }
|
28
|
-
let(:grid) { SimpleReport.new }
|
29
|
-
|
30
|
-
context "when grid has no records" do
|
31
|
-
let(:grid) do
|
32
|
-
test_report do
|
33
|
-
scope { Entry.where("1 != 1") }
|
34
|
-
column(:id)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should show an empty table with dashes" do
|
39
|
-
datagrid_table = subject.datagrid_table(grid)
|
40
|
-
|
41
|
-
expect(datagrid_table).to match_css_pattern(
|
42
|
-
"table.datagrid tr td.noresults" => 1
|
43
|
-
)
|
44
|
-
expect(datagrid_table).to include(I18n.t("datagrid.no_results"))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe ".datagrid_table" do
|
49
|
-
it "should have grid class as html class on table" do
|
50
|
-
expect(subject.datagrid_table(grid)).to match_css_pattern(
|
51
|
-
"table.datagrid.simple_report" => 1
|
52
|
-
)
|
53
|
-
end
|
54
|
-
it "should have namespaced grid class as html class on table" do
|
55
|
-
module ::Ns23
|
56
|
-
class TestGrid
|
57
|
-
include Datagrid
|
58
|
-
scope { Entry }
|
59
|
-
column(:id)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
expect(subject.datagrid_table(::Ns23::TestGrid.new)).to match_css_pattern(
|
63
|
-
"table.datagrid.ns23_test_grid" => 1
|
64
|
-
)
|
65
|
-
end
|
66
|
-
it "should return data table html" do
|
67
|
-
datagrid_table = subject.datagrid_table(grid)
|
68
|
-
|
69
|
-
expect(datagrid_table).to match_css_pattern({
|
70
|
-
"table.datagrid tr th.group div.order" => 1,
|
71
|
-
"table.datagrid tr th.group" => /Group.*/,
|
72
|
-
"table.datagrid tr th.name div.order" => 1,
|
73
|
-
"table.datagrid tr th.name" => /Name.*/,
|
74
|
-
"table.datagrid tr td.group" => "Pop",
|
75
|
-
"table.datagrid tr td.name" => "Star"
|
76
|
-
})
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should support giving assets explicitly" do
|
80
|
-
Entry.create!(entry.attributes.except("id"))
|
81
|
-
datagrid_table = subject.datagrid_table(grid, [entry])
|
82
|
-
|
83
|
-
expect(datagrid_table).to match_css_pattern({
|
84
|
-
"table.datagrid tr th.group div.order" => 1,
|
85
|
-
"table.datagrid tr th.group" => /Group.*/,
|
86
|
-
"table.datagrid tr th.name div.order" => 1,
|
87
|
-
"table.datagrid tr th.name" => /Name.*/,
|
88
|
-
"table.datagrid tr td.group" => "Pop",
|
89
|
-
"table.datagrid tr td.name" => "Star"
|
90
|
-
})
|
91
|
-
end
|
92
|
-
|
93
|
-
it "should support no order given" do
|
94
|
-
expect(subject.datagrid_table(grid, [entry], :order => false)).to match_css_pattern("table.datagrid th .order" => 0)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "should support columns option" do
|
98
|
-
expect(subject.datagrid_table(grid, [entry], :columns => [:name])).to match_css_pattern(
|
99
|
-
"table.datagrid th.name" => 1,
|
100
|
-
"table.datagrid td.name" => 1,
|
101
|
-
"table.datagrid th.group" => 0,
|
102
|
-
"table.datagrid td.group" => 0
|
103
|
-
)
|
104
|
-
end
|
105
|
-
|
106
|
-
context "with column_names attribute" do
|
107
|
-
let(:grid) do
|
108
|
-
test_report(:column_names => "name") do
|
109
|
-
scope { Entry }
|
110
|
-
column(:name)
|
111
|
-
column(:category)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "should output only given column names" do
|
116
|
-
expect(subject.datagrid_table(grid, [entry])).to match_css_pattern(
|
117
|
-
"table.datagrid th.name" => 1,
|
118
|
-
"table.datagrid td.name" => 1,
|
119
|
-
"table.datagrid th.category" => 0,
|
120
|
-
"table.datagrid td.category" => 0
|
121
|
-
)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "when grid has no columns" do
|
126
|
-
let(:grid) do
|
127
|
-
test_report do
|
128
|
-
scope {Entry}
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should render no_columns message" do
|
133
|
-
expect(subject.datagrid_table(grid, [entry])).to equal_to_dom("No columns selected")
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context 'with partials attribute' do
|
138
|
-
let(:grid) do
|
139
|
-
test_report do
|
140
|
-
scope { Entry }
|
141
|
-
column(:name)
|
142
|
-
column(:category)
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
it 'renders namespaced table partial' do
|
147
|
-
rendered_partial = subject.datagrid_table(grid, [entry], {
|
148
|
-
:partials => 'client/datagrid'
|
149
|
-
})
|
150
|
-
expect(rendered_partial).to include 'Namespaced table partial.'
|
151
|
-
expect(rendered_partial).to include 'Namespaced row partial.'
|
152
|
-
expect(rendered_partial).to include 'Namespaced head partial.'
|
153
|
-
expect(rendered_partial).to include 'Namespaced order_for partial.'
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
context "when scope is enumerator" do
|
158
|
-
let(:grid) do
|
159
|
-
test_report do
|
160
|
-
scope { ['a', 'b'].to_enum }
|
161
|
-
column(:name) do |value|
|
162
|
-
value
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
it "should render table" do
|
167
|
-
expect(subject.datagrid_table(grid)).to match_css_pattern(
|
168
|
-
"table.datagrid th.name" => 1,
|
169
|
-
"table.datagrid td.name" => 2,
|
170
|
-
)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
context "when scope is lazy enumerator" do
|
174
|
-
before(:each) do
|
175
|
-
pending("not supported by ruby < 2.0") if RUBY_VERSION < '2.0'
|
176
|
-
end
|
177
|
-
let(:grid) do
|
178
|
-
test_report do
|
179
|
-
scope { ['a', 'b'].lazy }
|
180
|
-
column(:name) do |value|
|
181
|
-
value
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
it "should render table" do
|
186
|
-
expect(subject.datagrid_table(grid)).to match_css_pattern(
|
187
|
-
"table.datagrid th.name" => 1,
|
188
|
-
"table.datagrid td.name" => 2,
|
189
|
-
)
|
190
|
-
end
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
describe ".datagrid_rows" do
|
195
|
-
it "should support urls" do
|
196
|
-
rp = test_report do
|
197
|
-
scope { Entry }
|
198
|
-
column(:name, :url => lambda {|model| model.name})
|
199
|
-
end
|
200
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
201
|
-
"tr td.name a[href=Star]" => "Star"
|
202
|
-
)
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should support conditional urls" do
|
206
|
-
rp = test_report do
|
207
|
-
scope { Entry }
|
208
|
-
column(:name, :url => lambda {|model| false})
|
209
|
-
end
|
210
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
211
|
-
"tr td.name" => "Star"
|
212
|
-
)
|
213
|
-
end
|
214
|
-
|
215
|
-
it "should add ordering classes to column" do
|
216
|
-
rp = test_report(:order => :name) do
|
217
|
-
scope { Entry }
|
218
|
-
column(:name)
|
219
|
-
end
|
220
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
221
|
-
"tr td.name.ordered.asc" => "Star"
|
222
|
-
)
|
223
|
-
end
|
224
|
-
it "should add ordering classes to column" do
|
225
|
-
rp = test_report(:order => :name) do
|
226
|
-
scope { Entry }
|
227
|
-
column(:name)
|
228
|
-
end
|
229
|
-
expect(
|
230
|
-
subject.datagrid_rows(rp) do |row|
|
231
|
-
subject.content_tag(:strong, row.name)
|
232
|
-
end
|
233
|
-
).to match_css_pattern(
|
234
|
-
"strong" => "Star"
|
235
|
-
)
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should add ordering classes to column" do
|
239
|
-
rp = test_report(:order => :name, :descending => true) do
|
240
|
-
scope { Entry }
|
241
|
-
column(:name)
|
242
|
-
end
|
243
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
244
|
-
"tr td.name.ordered.desc" => "Star"
|
245
|
-
)
|
246
|
-
end
|
247
|
-
|
248
|
-
it "should render columns with &:symbol block" do
|
249
|
-
rp = test_report do
|
250
|
-
scope { Entry }
|
251
|
-
column(:name, &:name)
|
252
|
-
end
|
253
|
-
|
254
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
255
|
-
"tr td.name" => "Star"
|
256
|
-
)
|
257
|
-
end
|
258
|
-
|
259
|
-
it "should render html columns" do
|
260
|
-
rp = test_report do
|
261
|
-
scope { Entry }
|
262
|
-
column(:name, :html => true) do |model|
|
263
|
-
content_tag(:span, model.name)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
267
|
-
"tr td.name span" => "Star"
|
268
|
-
)
|
269
|
-
end
|
270
|
-
|
271
|
-
it "should render :html columns with &:symbol block" do
|
272
|
-
rp = test_report do
|
273
|
-
scope { Entry }
|
274
|
-
column(:name, :html => true, &:name)
|
275
|
-
end
|
276
|
-
|
277
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
278
|
-
"tr td.name" => "Star"
|
279
|
-
)
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should render format columns with &:symbol block" do
|
283
|
-
rp = test_report do
|
284
|
-
scope { Entry }
|
285
|
-
column(:name) do |record|
|
286
|
-
format(record, &:name)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
291
|
-
"tr td.name" => "Star"
|
292
|
-
)
|
293
|
-
end
|
294
|
-
|
295
|
-
it "should render :html columns with &:symbol block with a data attribute" do
|
296
|
-
rp = test_report do
|
297
|
-
scope { Entry }
|
298
|
-
column(:name, :html => true, data: 'DATA', &:name)
|
299
|
-
end
|
300
|
-
|
301
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
302
|
-
"tr td.name" => "Star"
|
303
|
-
)
|
304
|
-
end
|
305
|
-
|
306
|
-
it "should render argument-based html columns" do
|
307
|
-
rp = test_report do
|
308
|
-
scope { Entry }
|
309
|
-
column(:name, :html => lambda {|data| content_tag :h1, data})
|
310
|
-
end
|
311
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
312
|
-
"tr td.name h1" => "Star"
|
313
|
-
)
|
314
|
-
end
|
315
|
-
|
316
|
-
it "should render argument-based html columns with custom data" do
|
317
|
-
rp = test_report do
|
318
|
-
scope { Entry }
|
319
|
-
column(:name, :html => lambda {|data| content_tag :em, data}) do
|
320
|
-
self.name.upcase
|
321
|
-
end
|
322
|
-
end
|
323
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
324
|
-
"tr td.name em" => "STAR"
|
325
|
-
)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "should render html columns with double arguments for column" do
|
329
|
-
rp = test_report do
|
330
|
-
scope { Entry }
|
331
|
-
column(:name, :html => true) do |model, grid|
|
332
|
-
content_tag(:span, "#{model.name}-#{grid.assets.klass}" )
|
333
|
-
end
|
334
|
-
end
|
335
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
336
|
-
"tr td.name span" => "Star-Entry"
|
337
|
-
)
|
338
|
-
end
|
339
|
-
|
340
|
-
it "should render argument-based html blocks with double arguments" do
|
341
|
-
rp = test_report do
|
342
|
-
scope { Entry }
|
343
|
-
column(:name, :html => lambda { |data, model|
|
344
|
-
content_tag :h1, "#{data}-#{model.name.downcase}"
|
345
|
-
})
|
346
|
-
end
|
347
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
348
|
-
"tr td.name h1" => "Star-star"
|
349
|
-
)
|
350
|
-
end
|
351
|
-
|
352
|
-
it "should render argument-based html blocks with triple arguments" do
|
353
|
-
rp = test_report do
|
354
|
-
scope { Entry }
|
355
|
-
column(:name, :html => lambda { |data, model, grid|
|
356
|
-
content_tag :h1, "#{data}-#{model.name.downcase}-#{grid.assets.klass}"
|
357
|
-
})
|
358
|
-
end
|
359
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
360
|
-
"tr td.name h1" => "Star-star-Entry"
|
361
|
-
)
|
362
|
-
end
|
363
|
-
|
364
|
-
it "should render argument-based html blocks with double arguments and custom data" do
|
365
|
-
rp = test_report do
|
366
|
-
scope { Entry }
|
367
|
-
column(:name, :html => lambda { |data, model|
|
368
|
-
content_tag :h1, "#{data}-#{model.name}"
|
369
|
-
}) do
|
370
|
-
self.name.upcase
|
371
|
-
end
|
372
|
-
end
|
373
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
374
|
-
"tr td.name h1" => "STAR-Star"
|
375
|
-
)
|
376
|
-
end
|
377
|
-
|
378
|
-
it "should render argument-based html blocks with triple arguments and custom data" do
|
379
|
-
rp = test_report do
|
380
|
-
scope { Entry }
|
381
|
-
column(:name, :html => lambda { |data, model, grid|
|
382
|
-
content_tag :h1, "#{data}-#{model.name}-#{grid.assets.klass}"
|
383
|
-
}) do
|
384
|
-
self.name.upcase
|
385
|
-
end
|
386
|
-
end
|
387
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
388
|
-
"tr td.name h1" => "STAR-Star-Entry"
|
389
|
-
)
|
390
|
-
end
|
391
|
-
|
392
|
-
it "should support columns option" do
|
393
|
-
rp = test_report do
|
394
|
-
scope { Entry }
|
395
|
-
column(:name)
|
396
|
-
column(:category)
|
397
|
-
end
|
398
|
-
expect(subject.datagrid_rows(rp, [entry], :columns => [:name])).to match_css_pattern(
|
399
|
-
"tr td.name" => "Star"
|
400
|
-
)
|
401
|
-
expect(subject.datagrid_rows(rp, [entry], :columns => [:name])).to match_css_pattern(
|
402
|
-
"tr td.category" => 0
|
403
|
-
)
|
404
|
-
end
|
405
|
-
|
406
|
-
it "should allow CSS classes to be specified for a column" do
|
407
|
-
rp = test_report do
|
408
|
-
scope { Entry }
|
409
|
-
column(:name, :class => 'my_class')
|
410
|
-
end
|
411
|
-
|
412
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
413
|
-
"tr td.name.my_class" => "Star"
|
414
|
-
)
|
415
|
-
end
|
416
|
-
|
417
|
-
context "when grid has complicated columns" do
|
418
|
-
let(:grid) do
|
419
|
-
test_report(:name => 'Hello') do
|
420
|
-
scope {Entry}
|
421
|
-
filter(:name)
|
422
|
-
column(:name) do |model, grid|
|
423
|
-
"'#{model.name}' filtered by '#{grid.name}'"
|
424
|
-
end
|
425
|
-
end
|
426
|
-
end
|
427
|
-
it "should ignore them" do
|
428
|
-
expect(subject.datagrid_rows(grid, [entry])).to match_css_pattern(
|
429
|
-
"td.name" => 1
|
430
|
-
)
|
431
|
-
end
|
432
|
-
end
|
433
|
-
|
434
|
-
it "should escape html" do
|
435
|
-
entry.update!(:name => "<div>hello</div>")
|
436
|
-
expect(subject.datagrid_rows(grid, [entry], :columns => [:name])).to equal_to_dom(<<-HTML)
|
437
|
-
<tr><td class="name"><div>hello</div></td></tr>
|
438
|
-
HTML
|
439
|
-
end
|
440
|
-
|
441
|
-
it "should not escape safe html" do
|
442
|
-
entry.update!(:name => "<div>hello</div>")
|
443
|
-
grid.column(:safe_name) do |model|
|
444
|
-
model.name.html_safe
|
445
|
-
end
|
446
|
-
expect(subject.datagrid_rows(grid, [entry], :columns => [:safe_name])).to equal_to_dom(<<-HTML)
|
447
|
-
<tr><td class="safe_name"><div>hello</div></td></tr>
|
448
|
-
HTML
|
449
|
-
|
450
|
-
end
|
451
|
-
|
452
|
-
end
|
453
|
-
|
454
|
-
describe ".datagrid_order_for" do
|
455
|
-
it "should render ordering layout" do
|
456
|
-
class OrderedGrid
|
457
|
-
include Datagrid
|
458
|
-
scope { Entry }
|
459
|
-
column(:category)
|
460
|
-
end
|
461
|
-
object = OrderedGrid.new(:descending => true, :order => :category)
|
462
|
-
expect(subject.datagrid_order_for(object, object.column_by_name(:category))).to equal_to_dom(<<-HTML)
|
463
|
-
<div class="order">
|
464
|
-
<a class="asc" href="/location?ordered_grid%5Bdescending%5D=false&ordered_grid%5Border%5D=category">↑</a>
|
465
|
-
<a class="desc" href="/location?ordered_grid%5Bdescending%5D=true&ordered_grid%5Border%5D=category">↓</a>
|
466
|
-
</div>
|
467
|
-
HTML
|
468
|
-
end
|
469
|
-
|
470
|
-
end
|
471
|
-
describe ".datagrid_form_for" do
|
472
|
-
it 'returns namespaced partial if partials options is passed' do
|
473
|
-
rendered_form = subject.datagrid_form_for(grid, {
|
474
|
-
:url => '',
|
475
|
-
:partials => 'client/datagrid'
|
476
|
-
})
|
477
|
-
expect(rendered_form).to include 'Namespaced form partial.'
|
478
|
-
end
|
479
|
-
it "should render form and filter inputs" do
|
480
|
-
class FormForGrid
|
481
|
-
include Datagrid
|
482
|
-
scope { Entry }
|
483
|
-
filter(:category)
|
484
|
-
end
|
485
|
-
object = FormForGrid.new(:category => "hello")
|
486
|
-
expect(subject.datagrid_form_for(object, :url => "/grid")).to match_css_pattern(
|
487
|
-
"form.datagrid-form.form_for_grid[action='/grid']" => 1,
|
488
|
-
"form input[name=utf8]" => 1,
|
489
|
-
"form .filter label" => "Category",
|
490
|
-
"form .filter input.category.default_filter[name='form_for_grid[category]'][value=hello]" => 1,
|
491
|
-
"form input[name=commit][value=Search]" => 1,
|
492
|
-
"form a.datagrid-reset[href='/location']" => 1
|
493
|
-
)
|
494
|
-
end
|
495
|
-
it "should support html classes for grid class with namespace" do
|
496
|
-
module ::Ns22
|
497
|
-
class TestGrid
|
498
|
-
include Datagrid
|
499
|
-
scope { Entry }
|
500
|
-
filter(:id)
|
501
|
-
end
|
502
|
-
end
|
503
|
-
expect(subject.datagrid_form_for(::Ns22::TestGrid.new, :url => "grid")).to match_css_pattern(
|
504
|
-
"form.datagrid-form.ns22_test_grid" => 1,
|
505
|
-
"form.datagrid-form label[for=ns22_test_grid_id]" => 1,
|
506
|
-
"form.datagrid-form input#ns22_test_grid_id[name='ns22_test_grid[id]']" => 1,
|
507
|
-
)
|
508
|
-
end
|
509
|
-
|
510
|
-
it "should have overridable param_name method" do
|
511
|
-
class ParamNameGrid81
|
512
|
-
include Datagrid
|
513
|
-
scope { Entry }
|
514
|
-
filter(:id)
|
515
|
-
def param_name
|
516
|
-
'g'
|
517
|
-
end
|
518
|
-
end
|
519
|
-
expect(subject.datagrid_form_for(::ParamNameGrid81.new, :url => "/grid")).to match_css_pattern(
|
520
|
-
"form.datagrid-form input[name='g[id]']" => 1,
|
521
|
-
)
|
522
|
-
end
|
523
|
-
|
524
|
-
it "takes default partials if custom doesn't exist" do
|
525
|
-
class PartialDefaultGrid
|
526
|
-
include Datagrid
|
527
|
-
scope {Entry}
|
528
|
-
filter(:id, :integer, :range => true)
|
529
|
-
filter(:group_id, :enum, :multiple => true, :checkboxes => true, :select => [1,2])
|
530
|
-
def param_name
|
531
|
-
'g'
|
532
|
-
end
|
533
|
-
end
|
534
|
-
rendered_form = subject.datagrid_form_for(PartialDefaultGrid.new, {
|
535
|
-
:url => '',
|
536
|
-
:partials => 'custom_form'
|
537
|
-
})
|
538
|
-
expect(rendered_form).to include 'form_partial_test'
|
539
|
-
expect(rendered_form).to match_css_pattern([
|
540
|
-
'input.integer_filter.from',
|
541
|
-
'input.integer_filter.to',
|
542
|
-
".enum_filter input[value='1']",
|
543
|
-
".enum_filter input[value='2']",
|
544
|
-
])
|
545
|
-
end
|
546
|
-
end
|
547
|
-
|
548
|
-
|
549
|
-
describe ".datagrid_row" do
|
550
|
-
let(:grid) do
|
551
|
-
test_report do
|
552
|
-
scope { Entry }
|
553
|
-
column(:name)
|
554
|
-
column(:category)
|
555
|
-
end
|
556
|
-
end
|
557
|
-
|
558
|
-
let(:entry) do
|
559
|
-
Entry.create!(:name => "Hello", :category => "greetings")
|
560
|
-
end
|
561
|
-
|
562
|
-
it "should provide access to row data" do
|
563
|
-
r = subject.datagrid_row(grid, entry)
|
564
|
-
expect(r.name).to eq("Hello")
|
565
|
-
expect(r.category).to eq("greetings")
|
566
|
-
end
|
567
|
-
it "should provide an interator" do
|
568
|
-
r = subject.datagrid_row(grid, entry)
|
569
|
-
expect(r.map {|z| z.upcase}).to eq(["HELLO", "GREETINGS"])
|
570
|
-
expect(r.name).to eq("Hello")
|
571
|
-
expect(r.category).to eq("greetings")
|
572
|
-
end
|
573
|
-
|
574
|
-
it "should yield block" do
|
575
|
-
subject.datagrid_row(grid, entry) do |row|
|
576
|
-
expect(row.name).to eq("Hello")
|
577
|
-
expect(row.category).to eq("greetings")
|
578
|
-
end
|
579
|
-
end
|
580
|
-
|
581
|
-
it "should output data from block" do
|
582
|
-
name = subject.datagrid_row(grid, entry) do |row|
|
583
|
-
subject.concat(row.name)
|
584
|
-
subject.concat(",")
|
585
|
-
subject.concat(row.category)
|
586
|
-
end
|
587
|
-
expect(name).to eq("Hello,greetings")
|
588
|
-
end
|
589
|
-
|
590
|
-
it "should give access to grid and asset" do
|
591
|
-
r = subject.datagrid_row(grid, entry)
|
592
|
-
expect(r.grid).to eq(grid)
|
593
|
-
expect(r.asset).to eq(entry)
|
594
|
-
end
|
595
|
-
|
596
|
-
it "should use cache" do
|
597
|
-
grid = test_report do
|
598
|
-
scope {Entry}
|
599
|
-
self.cached = true
|
600
|
-
column(:random1, html: true) {rand(10**9)}
|
601
|
-
column(:random2) {|model| format(rand(10**9)) {|value| value}}
|
602
|
-
end
|
603
|
-
|
604
|
-
entry = Entry.create!
|
605
|
-
|
606
|
-
data_row = grid.data_row(entry)
|
607
|
-
html_row = subject.datagrid_row(grid, entry)
|
608
|
-
expect(html_row.random1).to eq(html_row.random1)
|
609
|
-
expect(html_row.random2).to_not eq(html_row.random1)
|
610
|
-
expect(data_row.random2).to eq(html_row.random2)
|
611
|
-
expect(data_row.random2).to_not eq(html_row.random1)
|
612
|
-
grid.cached = false
|
613
|
-
expect(html_row.random2).to_not eq(html_row.random2)
|
614
|
-
expect(html_row.random2).to_not eq(html_row.random1)
|
615
|
-
expect(data_row.random2).to_not eq(html_row.random2)
|
616
|
-
expect(data_row.random2).to_not eq(html_row.random1)
|
617
|
-
end
|
618
|
-
|
619
|
-
end
|
620
|
-
|
621
|
-
describe ".datagrid_value" do
|
622
|
-
it "should format value by column name" do
|
623
|
-
report = test_report do
|
624
|
-
scope {Entry}
|
625
|
-
column(:name) do |e|
|
626
|
-
"<b>#{e.name}</b>"
|
627
|
-
end
|
628
|
-
end
|
629
|
-
|
630
|
-
expect(subject.datagrid_value(report, :name, entry)).to eq("<b>Star</b>")
|
631
|
-
end
|
632
|
-
it "should support format in column" do
|
633
|
-
report = test_report do
|
634
|
-
scope {Entry}
|
635
|
-
column(:name) do |e|
|
636
|
-
format(e.name) do |value|
|
637
|
-
link_to value, "/profile"
|
638
|
-
end
|
639
|
-
end
|
640
|
-
end
|
641
|
-
expect(subject.datagrid_value(report, :name, entry)).to be_html_safe
|
642
|
-
expect(subject.datagrid_value(report, :name, entry)).to eq("<a href=\"/profile\">Star</a>")
|
643
|
-
end
|
644
|
-
|
645
|
-
it "applies decorator" do
|
646
|
-
report = test_report do
|
647
|
-
scope {Entry}
|
648
|
-
decorate do |model|
|
649
|
-
Class.new(Struct.new(:model)) do
|
650
|
-
def name
|
651
|
-
model.name.upcase
|
652
|
-
end
|
653
|
-
end
|
654
|
-
end
|
655
|
-
column(:name, html: true)
|
656
|
-
end
|
657
|
-
entry = Entry.create!(name: 'hello')
|
658
|
-
expect(subject.datagrid_value(report, :name, entry)).to eq("HELLO")
|
659
|
-
end
|
660
|
-
end
|
661
|
-
|
662
|
-
describe ".datagrid_header" do
|
663
|
-
|
664
|
-
it "should support order_by_value colums" do
|
665
|
-
grid = test_report(:order => "category") do
|
666
|
-
scope { Entry }
|
667
|
-
column(:category, :order => false, :order_by_value => true)
|
668
|
-
|
669
|
-
def param_name
|
670
|
-
'grid'
|
671
|
-
end
|
672
|
-
end
|
673
|
-
expect(subject.datagrid_header(grid)).to equal_to_dom(<<HTML)
|
674
|
-
<tr><th class="category ordered asc">Category<div class="order">
|
675
|
-
<a class="asc" href="/location?grid%5Bdescending%5D=false&grid%5Border%5D=category">↑</a><a class="desc" href="/location?grid%5Bdescending%5D=true&grid%5Border%5D=category">↓</a>
|
676
|
-
</div>
|
677
|
-
</th></tr>
|
678
|
-
HTML
|
679
|
-
end
|
680
|
-
end
|
681
|
-
|
682
|
-
end
|
683
|
-
|