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,614 +0,0 @@
1
- # encoding: UTF-8
2
- require 'spec_helper'
3
-
4
- class MyFormBuilder
5
- include Datagrid::FormBuilder
6
- end
7
-
8
- class MyTemplate
9
- include ActionView::Helpers::FormHelper
10
- end
11
-
12
-
13
- describe Datagrid::FormBuilder do
14
-
15
- let(:template) do
16
- ActionView::Base.new.tap do |v|
17
- v.view_paths << File.expand_path("../../../app/views", __FILE__)
18
- v.view_paths << File.expand_path("../../support/test_partials", __FILE__)
19
- end
20
- end
21
- let(:view) { ActionView::Helpers::FormBuilder.new(:report, _grid, template, view_options)}
22
- let(:view_options) { {} }
23
-
24
-
25
- describe ".datagrid_filter" do
26
-
27
- it "should work for every filter type" do
28
- Datagrid::Filters::FILTER_TYPES.each do |type, klass|
29
- expect(Datagrid::FormBuilder.instance_methods.map(&:to_sym)).to include(klass.form_builder_helper_name)
30
- end
31
- end
32
-
33
- subject do
34
- view.datagrid_filter(_filter, _filter_options, &_filter_block)
35
- end
36
-
37
- let(:_filter_options) { {} }
38
- let(:_filter_block) { nil }
39
- context "with default filter type" do
40
- let(:_grid) {
41
- test_report do
42
- scope {Entry}
43
- filter(:name)
44
- end
45
- }
46
- let(:_filter) { :name }
47
- it { should equal_to_dom(
48
- '<input class="name default_filter" type="text" name="report[name]" id="report_name"/>'
49
- )}
50
- end
51
- context "with integer filter type" do
52
- let(:_filter) { :group_id }
53
- let(:_grid) {
54
- test_report do
55
- scope {Entry}
56
- filter(:group_id, :integer)
57
- end
58
- }
59
- it { should equal_to_dom(
60
- '<input class="group_id integer_filter" type="text" name="report[group_id]" id="report_group_id"/>'
61
- )}
62
-
63
- context "when partials option is passed for filter that don't support range" do
64
- let(:view_options) { {partials: 'anything' } }
65
- it { should equal_to_dom(
66
- '<input class="group_id integer_filter" type="text" name="report[group_id]" id="report_group_id"/>'
67
- )}
68
- end
69
- end
70
-
71
- context "with date filter type" do
72
- let(:_filter) { :created_at }
73
- let(:_grid) {
74
- test_report do
75
- scope {Entry}
76
- filter(:created_at, :date)
77
- end
78
- }
79
- it { should equal_to_dom(
80
- '<input class="created_at date_filter" type="text" name="report[created_at]" id="report_created_at"/>'
81
- )}
82
- context "when special date format specified" do
83
- around(:each) do |example|
84
- _grid.created_at = Date.parse('2012-01-02')
85
- with_date_format do
86
- example.run
87
- end
88
- end
89
- it { should equal_to_dom(
90
- '<input value="01/02/2012" class="created_at date_filter" type="text" name="report[created_at]" id="report_created_at"/>'
91
- )}
92
- end
93
- end
94
-
95
- context "with integer filter type and range option" do
96
- let(:_filter) { :group_id }
97
- let(:_grid) {
98
- test_report(:group_id => _range) do
99
- scope {Entry}
100
- filter(:group_id, :integer, :range => true)
101
- end
102
- }
103
- context "when datagrid_filter options has id" do
104
- let(:_filter_options) { {:id => "hello"} }
105
- let(:_range) { [1,2]}
106
- it { should equal_to_dom(
107
- '<input id="from_hello" class="group_id integer_filter from" multiple value="1" type="text" name="report[group_id][]"/>' +
108
- '<span class="separator integer"> - </span>' +
109
- '<input id="to_hello" class="group_id integer_filter to" multiple value="2" type="text" name="report[group_id][]"/>'
110
- )}
111
- end
112
- context "with only left bound" do
113
-
114
- let(:_range) { [10, nil]}
115
- it { should equal_to_dom(
116
- '<input class="group_id integer_filter from" multiple value="10" type="text" name="report[group_id][]"/>' +
117
- '<span class="separator integer"> - </span>' +
118
- '<input class="group_id integer_filter to" multiple type="text" name="report[group_id][]"/>'
119
- )}
120
- it { should be_html_safe }
121
- end
122
- context "with only right bound" do
123
- let(:_range) { [nil, 10]}
124
- it { should equal_to_dom(
125
- '<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"/>' +
126
- '<span class="separator integer"> - </span>' +
127
- '<input class="group_id integer_filter to" multiple value="10" type="text" name="report[group_id][]"/>'
128
- )}
129
- it { should be_html_safe }
130
- end
131
-
132
- context "with invalid range value" do
133
- let(:_range) { 2..1 }
134
- it { should equal_to_dom(
135
- '<input class="group_id integer_filter from" multiple value="1" type="text" name="report[group_id][]"/>' +
136
- '<span class="separator integer"> - </span>' +
137
- '<input class="group_id integer_filter to" multiple value="2" type="text" name="report[group_id][]"/>'
138
- )}
139
- end
140
-
141
- context "with custom partials option and template exists" do
142
- let(:view_options) { { :partials => 'custom_range' } }
143
- let(:_range) { nil }
144
- it { should equal_to_dom(
145
- "custom_range_partial"
146
- ) }
147
- end
148
-
149
- context "when custom partial doesn't exist" do
150
- let(:view_options) { { :partials => 'not_existed' } }
151
- let(:_range) { nil }
152
- it { should equal_to_dom(
153
- '<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"><span class="separator integer"> - </span><input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
154
- ) }
155
-
156
- end
157
- end
158
-
159
- context "with float filter type and range option" do
160
- let(:_filter) { :rating }
161
- let(:_grid) {
162
- test_report(:rating => _range) do
163
- scope {Group}
164
- filter(:rating, :float, :range => true)
165
- end
166
- }
167
- let(:_range) { [1.5,2.5]}
168
- it { should equal_to_dom(
169
- '<input class="rating float_filter from" multiple value="1.5" type="text" name="report[rating][]"/>' +
170
- '<span class="separator float"> - </span>' +
171
- '<input class="rating float_filter to" multiple value="2.5" type="text" name="report[rating][]"/>'
172
- )}
173
- end
174
-
175
- context "with date filter type and range option" do
176
- let(:_filter) { :created_at }
177
- let(:_grid) {
178
- test_report(:created_at => _range) do
179
- scope {Entry}
180
- filter(:created_at, :date, :range => true)
181
- end
182
- }
183
- context "with only left bound" do
184
-
185
- let(:_range) { ["2012-01-03", nil]}
186
- it { should equal_to_dom(
187
- '<input class="created_at date_filter from" multiple value="2012-01-03" type="text" name="report[created_at][]"/>' +
188
- '<span class="separator date"> - </span>' +
189
- '<input class="created_at date_filter to" multiple type="text" name="report[created_at][]"/>'
190
- )}
191
- it { should be_html_safe }
192
- end
193
- context "when special date format specified" do
194
- around(:each) do |example|
195
- with_date_format do
196
- example.run
197
- end
198
- end
199
- let(:_range) { ["2013/01/01", '2013/02/02']}
200
- it { should equal_to_dom(
201
- '<input class="created_at date_filter from" multiple value="01/01/2013" type="text" name="report[created_at][]"/>' +
202
- '<span class="separator date"> - </span>' +
203
- '<input class="created_at date_filter to" multiple value="02/02/2013" type="text" name="report[created_at][]"/>'
204
- )}
205
- end
206
- context "with only right bound" do
207
-
208
- let(:_range) { [nil, "2012-01-03"]}
209
- it { should equal_to_dom(
210
- '<input class="created_at date_filter from" multiple type="text" name="report[created_at][]"/>' +
211
- '<span class="separator date"> - </span>' +
212
- '<input class="created_at date_filter to" multiple value="2012-01-03" type="text" name="report[created_at][]"/>'
213
- )}
214
- it { should be_html_safe }
215
- end
216
-
217
- context "with invalid range value" do
218
- let(:_range) { Date.parse('2012-01-02')..Date.parse('2012-01-01') }
219
- it { should equal_to_dom(
220
- '<input class="created_at date_filter from" multiple value="2012-01-01" type="text" name="report[created_at][]"/>' +
221
- '<span class="separator date"> - </span>' +
222
- '<input class="created_at date_filter to" multiple value="2012-01-02" type="text" name="report[created_at][]"/>'
223
- )}
224
- end
225
- context "with blank range value" do
226
- around(:each) do |example|
227
- with_date_format do
228
- example.run
229
- end
230
- end
231
- let(:_range) { [nil, nil] }
232
- it { should equal_to_dom(
233
- '<input class="created_at date_filter from" multiple type="text" name="report[created_at][]"/>' +
234
- '<span class="separator date"> - </span>' +
235
- '<input class="created_at date_filter to" multiple type="text" name="report[created_at][]"/>'
236
- )}
237
- end
238
- end
239
- context "with enum filter type" do
240
- let(:_filter) { :category }
241
- let(:_grid) {
242
- test_report do
243
- scope {Entry}
244
- filter(:category, :enum, :select => ["first", "second"])
245
- filter(:category_without_include_blank, :enum, :select => ["first", "second"], :include_blank => false)
246
- filter(:category_with_prompt, :enum, :select => ["first", "second"], :prompt => "My Prompt")
247
- end
248
- }
249
- it { should equal_to_dom(
250
- '<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
251
- <option value="first">first</option>
252
- <option value="second">second</option></select>'
253
- )}
254
-
255
- context "when block is given" do
256
- before(:each) do
257
- skip("not supported by rails < 4.1") if Rails.version < '4.1'
258
- end
259
- let(:_filter_block ) do
260
- proc do
261
- template.content_tag(:option, 'block option', :value => 'block_value')
262
- end
263
- end
264
- it { should equal_to_dom(
265
- '<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
266
- <option value="block_value">block option</option></select>'
267
- )}
268
- end
269
- context "when first option is selected" do
270
- before(:each) do
271
- _grid.category = "first"
272
- end
273
- it { should equal_to_dom(
274
- '<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
275
- <option selected value="first">first</option>
276
- <option value="second">second</option></select>'
277
- )}
278
- end
279
- context "with include_blank option set to false" do
280
- let(:_filter) { :category_without_include_blank }
281
- it { should equal_to_dom(
282
- '<select class="category_without_include_blank enum_filter" name="report[category_without_include_blank]" id="report_category_without_include_blank">
283
- <option value="first">first</option>
284
- <option value="second">second</option></select>'
285
- )}
286
- end
287
- context "with dynamic include_blank option" do
288
- let(:_grid) do
289
- test_report do
290
- scope {Entry}
291
- filter(:category, :enum, :select => ["first", "second"], :include_blank => proc { "Choose plz" })
292
- end
293
- end
294
- let(:_filter) { :category }
295
- it { should equal_to_dom(
296
- '<select class="category enum_filter" name="report[category]" id="report_category">
297
- <option value="">Choose plz</option>
298
- <option value="first">first</option>
299
- <option value="second">second</option></select>'
300
- )}
301
- end
302
-
303
- context "with prompt option" do
304
- let(:_filter) { :category_with_prompt }
305
- it { should equal_to_dom(
306
- '<select class="category_with_prompt enum_filter" name="report[category_with_prompt]" id="report_category_with_prompt"><option value="">My Prompt</option>
307
- <option value="first">first</option>
308
- <option value="second">second</option></select>'
309
- )}
310
- end
311
- context "with checkboxes option" do
312
- let(:_grid) do
313
- test_report do
314
- scope {Entry}
315
- filter(:category, :enum, :select => ["first", "second"], :checkboxes => true)
316
- end
317
- end
318
- let(:_filter) { :category }
319
- if Rails.version >= "4.1"
320
- it { should equal_to_dom(
321
- '
322
- <label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" type="checkbox" value="first" name="report[category][]" />first</label>
323
- <label class="category enum_filter checkboxes" for="report_category_second"><input id="report_category_second" type="checkbox" value="second" name="report[category][]" />second</label>
324
- '
325
- )}
326
- else
327
- it { should equal_to_dom(
328
- '
329
- <label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" name="report[category][]" type="checkbox" value="first" />first</label>
330
- <label class="category enum_filter checkboxes" for="report_category_second"><input id="report_category_second" name="report[category][]" type="checkbox" value="second" />second</label>
331
- '
332
- )}
333
-
334
-
335
- end
336
-
337
- context "when partials option passed and partial exists" do
338
- let(:view_options) { {partials: 'custom_checkboxes'} }
339
- it { should equal_to_dom('custom_enum_checkboxes') }
340
- end
341
- end
342
- end
343
-
344
- context "with boolean filter type" do
345
- let(:_filter) { :disabled }
346
- let(:_grid) do
347
- test_report do
348
- scope {Entry}
349
- filter(:disabled, :boolean, default: true)
350
- end
351
- end
352
- it { should equal_to_dom(
353
- # hidden is important when default is set to true
354
- '<input name="report[disabled]" type="hidden" value="0"><input class="disabled boolean_filter" type="checkbox" value="1" checked name="report[disabled]" id="report_disabled">'
355
- )}
356
- end
357
- context "with xboolean filter type" do
358
- let(:_filter) { :disabled }
359
- let(:_grid) do
360
- test_report do
361
- scope {Entry}
362
- filter(:disabled, :xboolean)
363
- end
364
- end
365
- it { should equal_to_dom(
366
- '<select class="disabled extended_boolean_filter" name="report[disabled]" id="report_disabled"><option value=""></option>
367
- <option value="YES">Yes</option>
368
- <option value="NO">No</option></select>'
369
- )}
370
- end
371
- context "with string filter" do
372
- let(:_grid) do
373
- test_report do
374
- scope {Entry}
375
- filter(:name, :string)
376
- end
377
- end
378
-
379
- let(:_filter) { :name }
380
-
381
- it {should equal_to_dom('<input class="name string_filter" type="text" name="report[name]" id="report_name">')}
382
-
383
- context "when multiple option is set" do
384
- let(:_grid) do
385
- test_report(:name => "one,two") do
386
- scope {Entry}
387
- filter(:name, :string, :multiple => true)
388
- end
389
- end
390
-
391
- let(:_filter) { :name }
392
-
393
- it {should equal_to_dom('<input value="one,two" class="name string_filter" type="text" name="report[name]" id="report_name">')}
394
- end
395
- end
396
-
397
- context "with non multiple filter" do
398
- let(:_grid) do
399
- test_report do
400
- scope {Entry}
401
- filter(
402
- :name, :enum,
403
- :include_blank => false,
404
- :multiple => false,
405
- :select => []
406
- )
407
- end
408
- end
409
- let(:_filter) { :name }
410
- it {should equal_to_dom('<select class="name enum_filter" name="report[name]" id="report_name"></select>')}
411
- end
412
- context "with float filter type" do
413
- let(:_grid) {
414
- test_report do
415
- scope {Entry}
416
- filter(:group_id, :float)
417
- end
418
- }
419
- let(:_filter) { :group_id }
420
- it { should equal_to_dom(
421
- '<input class="group_id float_filter" type="text" name="report[group_id]" id="report_group_id"/>'
422
- )}
423
-
424
- end
425
-
426
- context "with enum multiple filter" do
427
- let(:_grid) do
428
- test_report do
429
- scope {Entry}
430
- filter(:group_id, :enum, :select => ['hello'], :multiple => true)
431
- end
432
- end
433
- let(:_filter) { :group_id }
434
- let(:expected_html) do
435
- <<-HTML
436
- <select class="group_id enum_filter" multiple name="report[group_id][]" id="report_group_id">
437
- <option value="hello">hello</option></select>
438
- HTML
439
- end
440
-
441
- it { should equal_to_dom(expected_html) }
442
- end
443
-
444
- context "with column names filter" do
445
- let(:_grid) do
446
- test_report(:column_names => [:id, :name]) do
447
- scope {Entry}
448
-
449
- column_names_filter
450
-
451
- column(:id)
452
- column(:name)
453
- column(:category)
454
- end
455
- end
456
- let(:_filter) { :column_names }
457
- let(:expected_html) do
458
- <<-HTML
459
- <select class="column_names enum_filter" multiple name="report[column_names][]" id="report_column_names"><option selected value="id">Id</option>
460
- <option selected value="name">Name</option>
461
- <option value="category">Category</option></select>
462
- HTML
463
- end
464
-
465
- it { should equal_to_dom(expected_html) }
466
- end
467
- context "with column_names_filter default given as symbols" do
468
- let(:_grid) do
469
- test_report() do
470
- scope {Entry}
471
-
472
- column_names_filter(:default => [:id, :name], :checkboxes => true)
473
-
474
- column(:id)
475
- column(:name)
476
- column(:category)
477
- end
478
- end
479
- let(:_filter) { :column_names }
480
- let(:expected_html) do
481
- <<DOM
482
- <label class="column_names enum_filter checkboxes" for="report_column_names_id"><input id="report_column_names_id" type="checkbox" value="id" checked name="report[column_names][]">Id</label>
483
- <label class="column_names enum_filter checkboxes" for="report_column_names_name"><input id="report_column_names_name" type="checkbox" value="name" checked name="report[column_names][]">Name</label>
484
- <label class="column_names enum_filter checkboxes" for="report_column_names_category"><input id="report_column_names_category" type="checkbox" value="category" name="report[column_names][]">Category</label>
485
- DOM
486
- end
487
-
488
- it do
489
- should equal_to_dom(expected_html)
490
- end
491
- end
492
-
493
- context "with dynamic filter" do
494
- let(:filter_options) do
495
- {}
496
- end
497
-
498
- let(:_grid) do
499
- options = filter_options
500
- test_report do
501
- scope {Entry}
502
- filter(:condition, :dynamic, options)
503
- end
504
- end
505
- let(:_filter) { :condition }
506
- context "with no options" do
507
- let(:expected_html) do
508
- <<-HTML
509
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">Id</option>
510
- <option value="group_id">Group</option>
511
- <option value="name">Name</option>
512
- <option value="category">Category</option>
513
- <option value="access_level">Access level</option>
514
- <option value="pet">Pet</option>
515
- <option value="disabled">Disabled</option>
516
- <option value="confirmed">Confirmed</option>
517
- <option value="shipping_date">Shipping date</option>
518
- <option value="created_at">Created at</option>
519
- <option value="updated_at">Updated at</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
520
- <option value="=~">&asymp;</option>
521
- <option value="&gt;=">&ge;</option>
522
- <option value="&lt;=">&le;</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
523
- HTML
524
- end
525
- it {should equal_to_dom(expected_html)}
526
-
527
- end
528
- context "when default option passed" do
529
- let(:filter_options) do
530
- {:select => [:id, :name], :default => [:id, '>=', 1]}
531
- end
532
- let(:expected_html) do
533
- <<-HTML
534
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option selected value="id">id</option>
535
- <option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
536
- <option value="=~">&asymp;</option>
537
- <option selected value="&gt;=">&ge;</option>
538
- <option value="&lt;=">&le;</option></select><input class="condition dynamic_filter value" name="report[condition][]" value="1" type="text" id="report_condition">
539
- HTML
540
- end
541
- it {should equal_to_dom(expected_html)}
542
-
543
- end
544
-
545
- context "when operations and options are defined" do
546
- let(:filter_options) do
547
- {:operations => %w(>= <=), :select => [:id, :name]}
548
- end
549
- let(:expected_html) do
550
- <<-HTML
551
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option><option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="&gt;=">≥</option>
552
- <option value="&lt;=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
553
- HTML
554
- end
555
- it {should equal_to_dom(expected_html)}
556
- end
557
-
558
- context "when the field is predefined" do
559
- let(:filter_options) do
560
- {:operations => %w(>= <=), :select => [:id]}
561
- end
562
- let(:expected_html) do
563
- <<-HTML
564
- <input class="condition dynamic_filter field" name="report[condition][]" value="id" type="hidden" id="report_condition"><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="&gt;=">≥</option>
565
- <option value="&lt;=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
566
- HTML
567
- end
568
- it {should equal_to_dom(expected_html)}
569
- end
570
- context "when operation is predefined" do
571
- let(:filter_options) do
572
- {:operations => %w(=), :select => [:id, :name]}
573
- end
574
- let(:expected_html) do
575
- <<-HTML
576
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">id</option><option value="name">name</option></select><input class="condition dynamic_filter operation" name="report[condition][]" value="=" type="hidden" id="report_condition"><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
577
- HTML
578
- end
579
- it {should equal_to_dom(expected_html)}
580
- end
581
-
582
- end
583
- end
584
-
585
-
586
- describe ".datagrid_label" do
587
- let(:_grid) do
588
- test_report do
589
- scope {Entry}
590
- filter(:name, :string)
591
- end
592
- end
593
- it "should generate label for filter" do
594
- expect(view.datagrid_label(:name)).to equal_to_dom(
595
- '<label for="report_name">Name</label>'
596
- )
597
- end
598
- it "should pass options through to the helper" do
599
- expect(view.datagrid_label(:name, :class => 'foo')).to equal_to_dom(
600
- '<label class="foo" for="report_name">Name</label>'
601
- )
602
- end
603
- it "should support block" do
604
- expect(view.datagrid_label(:name, :class => 'foo') { 'The Name' }).to equal_to_dom(
605
- '<label class="foo" for="report_name">The Name</label>'
606
- )
607
- end
608
- it "should support explicit label" do
609
- expect(view.datagrid_label(:name, "The Name")).to equal_to_dom(
610
- '<label for="report_name">The Name</label>'
611
- )
612
- end
613
- end
614
- end