datagrid 1.5.9 → 1.6.3

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