datagrid 1.5.8 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +8 -0
  3. data/Readme.markdown +2 -1
  4. data/app/views/datagrid/_table.html.erb +1 -1
  5. data/datagrid.gemspec +29 -166
  6. data/lib/datagrid/columns.rb +11 -14
  7. data/lib/datagrid/columns/column.rb +0 -5
  8. data/lib/datagrid/core.rb +13 -1
  9. data/lib/datagrid/drivers/active_record.rb +2 -1
  10. data/lib/datagrid/drivers/mongoid.rb +5 -1
  11. data/lib/datagrid/filters.rb +4 -7
  12. data/lib/datagrid/filters/base_filter.rb +11 -16
  13. data/lib/datagrid/filters/dynamic_filter.rb +15 -5
  14. data/lib/datagrid/filters/select_options.rb +1 -4
  15. data/lib/datagrid/form_builder.rb +17 -43
  16. data/lib/datagrid/helper.rb +1 -1
  17. data/lib/datagrid/locale/en.yml +6 -6
  18. data/lib/datagrid/renderer.rb +1 -2
  19. data/lib/datagrid/utils.rb +2 -6
  20. data/lib/datagrid/version.rb +3 -0
  21. metadata +15 -201
  22. data/.document +0 -5
  23. data/.rspec +0 -1
  24. data/.travis.yml +0 -20
  25. data/Gemfile +0 -29
  26. data/Rakefile +0 -43
  27. data/VERSION +0 -1
  28. data/spec/datagrid/active_model_spec.rb +0 -33
  29. data/spec/datagrid/column_names_attribute_spec.rb +0 -86
  30. data/spec/datagrid/columns/column_spec.rb +0 -19
  31. data/spec/datagrid/columns_spec.rb +0 -592
  32. data/spec/datagrid/core_spec.rb +0 -196
  33. data/spec/datagrid/drivers/active_record_spec.rb +0 -79
  34. data/spec/datagrid/drivers/array_spec.rb +0 -106
  35. data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
  36. data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
  37. data/spec/datagrid/drivers/sequel_spec.rb +0 -111
  38. data/spec/datagrid/filters/base_filter_spec.rb +0 -19
  39. data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
  40. data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
  41. data/spec/datagrid/filters/date_filter_spec.rb +0 -195
  42. data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
  43. data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
  44. data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
  45. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
  46. data/spec/datagrid/filters/float_filter_spec.rb +0 -15
  47. data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
  48. data/spec/datagrid/filters/string_filter_spec.rb +0 -35
  49. data/spec/datagrid/filters_spec.rb +0 -332
  50. data/spec/datagrid/form_builder_spec.rb +0 -641
  51. data/spec/datagrid/helper_spec.rb +0 -640
  52. data/spec/datagrid/ordering_spec.rb +0 -150
  53. data/spec/datagrid/scaffold_spec.rb +0 -45
  54. data/spec/datagrid/stylesheet_spec.rb +0 -12
  55. data/spec/datagrid/utils_spec.rb +0 -19
  56. data/spec/datagrid_spec.rb +0 -83
  57. data/spec/spec_helper.rb +0 -114
  58. data/spec/support/active_record.rb +0 -37
  59. data/spec/support/configuration.rb +0 -28
  60. data/spec/support/i18n_helpers.rb +0 -6
  61. data/spec/support/matchers.rb +0 -101
  62. data/spec/support/mongo_mapper.rb +0 -32
  63. data/spec/support/mongoid.rb +0 -36
  64. data/spec/support/sequel.rb +0 -39
  65. data/spec/support/simple_report.rb +0 -64
  66. data/spec/support/test_partials/_actions.html.erb +0 -1
  67. data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
  68. data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
  69. data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
  70. data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
  71. data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
  72. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
  73. data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
  74. data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
@@ -1,641 +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
-
158
- context "when deprecated format translation specified" do
159
- let(:_range) { nil }
160
- around(:each) do |example|
161
- store_translations(:en, datagrid: {filters: {integer: {range_format: "from %{from_input} to %{to_input}"}}}) do
162
- silence_warnings do
163
- example.run
164
- end
165
- end
166
- end
167
- it { should equal_to_dom(
168
- 'from <input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"> to <input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
169
- )}
170
- end
171
- context "when deprecated separator is specified" do
172
- let(:_range) { nil }
173
- around(:each) do |example|
174
- store_translations(:en, datagrid: {filters: {integer: {range_separator: " | "}}}) do
175
- silence_warnings do
176
- example.run
177
- end
178
- end
179
- end
180
- it { should equal_to_dom(
181
- '<input class="group_id integer_filter from" multiple type="text" name="report[group_id][]"> | <input class="group_id integer_filter to" multiple type="text" name="report[group_id][]">'
182
- )}
183
- end
184
- end
185
- context "with float filter type and range option" do
186
- let(:_filter) { :rating }
187
- let(:_grid) {
188
- test_report(:rating => _range) do
189
- scope {Group}
190
- filter(:rating, :float, :range => true)
191
- end
192
- }
193
- let(:_range) { [1.5,2.5]}
194
- it { should equal_to_dom(
195
- '<input class="rating float_filter from" multiple value="1.5" type="text" name="report[rating][]"/>' +
196
- '<span class="separator float"> - </span>' +
197
- '<input class="rating float_filter to" multiple value="2.5" type="text" name="report[rating][]"/>'
198
- )}
199
- end
200
-
201
-
202
- context "with date filter type and range option" do
203
- let(:_filter) { :created_at }
204
- let(:_grid) {
205
- test_report(:created_at => _range) do
206
- scope {Entry}
207
- filter(:created_at, :date, :range => true)
208
- end
209
- }
210
- context "with only left bound" do
211
-
212
- let(:_range) { ["2012-01-03", nil]}
213
- it { should equal_to_dom(
214
- '<input class="created_at date_filter from" multiple value="2012-01-03" type="text" name="report[created_at][]"/>' +
215
- '<span class="separator date"> - </span>' +
216
- '<input class="created_at date_filter to" multiple type="text" name="report[created_at][]"/>'
217
- )}
218
- it { should be_html_safe }
219
- end
220
- context "when special date format specified" do
221
- around(:each) do |example|
222
- with_date_format do
223
- example.run
224
- end
225
- end
226
- let(:_range) { ["2013/01/01", '2013/02/02']}
227
- it { should equal_to_dom(
228
- '<input class="created_at date_filter from" multiple value="01/01/2013" type="text" name="report[created_at][]"/>' +
229
- '<span class="separator date"> - </span>' +
230
- '<input class="created_at date_filter to" multiple value="02/02/2013" type="text" name="report[created_at][]"/>'
231
- )}
232
- end
233
- context "with only right bound" do
234
-
235
- let(:_range) { [nil, "2012-01-03"]}
236
- it { should equal_to_dom(
237
- '<input class="created_at date_filter from" multiple type="text" name="report[created_at][]"/>' +
238
- '<span class="separator date"> - </span>' +
239
- '<input class="created_at date_filter to" multiple value="2012-01-03" type="text" name="report[created_at][]"/>'
240
- )}
241
- it { should be_html_safe }
242
- end
243
-
244
- context "with invalid range value" do
245
- let(:_range) { Date.parse('2012-01-02')..Date.parse('2012-01-01') }
246
- it { should equal_to_dom(
247
- '<input class="created_at date_filter from" multiple value="2012-01-01" type="text" name="report[created_at][]"/>' +
248
- '<span class="separator date"> - </span>' +
249
- '<input class="created_at date_filter to" multiple value="2012-01-02" type="text" name="report[created_at][]"/>'
250
- )}
251
- end
252
- context "with blank range value" do
253
- around(:each) do |example|
254
- with_date_format do
255
- example.run
256
- end
257
- end
258
- let(:_range) { [nil, nil] }
259
- it { should equal_to_dom(
260
- '<input class="created_at date_filter from" multiple type="text" name="report[created_at][]"/>' +
261
- '<span class="separator date"> - </span>' +
262
- '<input class="created_at date_filter to" multiple type="text" name="report[created_at][]"/>'
263
- )}
264
- end
265
- end
266
- context "with enum filter type" do
267
- let(:_filter) { :category }
268
- let(:_grid) {
269
- test_report do
270
- scope {Entry}
271
- filter(:category, :enum, :select => ["first", "second"])
272
- filter(:category_without_include_blank, :enum, :select => ["first", "second"], :include_blank => false)
273
- filter(:category_with_prompt, :enum, :select => ["first", "second"], :prompt => "My Prompt")
274
- end
275
- }
276
- it { should equal_to_dom(
277
- '<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
278
- <option value="first">first</option>
279
- <option value="second">second</option></select>'
280
- )}
281
-
282
- context "when block is given" do
283
- before(:each) do
284
- skip("not supported by rails < 4.1") if Rails.version < '4.1'
285
- end
286
- let(:_filter_block ) do
287
- proc do
288
- template.content_tag(:option, 'block option', :value => 'block_value')
289
- end
290
- end
291
- it { should equal_to_dom(
292
- '<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
293
- <option value="block_value">block option</option></select>'
294
- )}
295
- end
296
- context "when first option is selected" do
297
- before(:each) do
298
- _grid.category = "first"
299
- end
300
- it { should equal_to_dom(
301
- '<select class="category enum_filter" name="report[category]" id="report_category"><option value=""></option>
302
- <option selected value="first">first</option>
303
- <option value="second">second</option></select>'
304
- )}
305
- end
306
- context "with include_blank option set to false" do
307
- let(:_filter) { :category_without_include_blank }
308
- it { should equal_to_dom(
309
- '<select class="category_without_include_blank enum_filter" name="report[category_without_include_blank]" id="report_category_without_include_blank">
310
- <option value="first">first</option>
311
- <option value="second">second</option></select>'
312
- )}
313
- end
314
- context "with dynamic include_blank option" do
315
- let(:_grid) do
316
- test_report do
317
- scope {Entry}
318
- filter(:category, :enum, :select => ["first", "second"], :include_blank => proc { "Choose plz" })
319
- end
320
- end
321
- let(:_filter) { :category }
322
- it { should equal_to_dom(
323
- '<select class="category enum_filter" name="report[category]" id="report_category">
324
- <option value="">Choose plz</option>
325
- <option value="first">first</option>
326
- <option value="second">second</option></select>'
327
- )}
328
- end
329
-
330
- context "with prompt option" do
331
- let(:_filter) { :category_with_prompt }
332
- it { should equal_to_dom(
333
- '<select class="category_with_prompt enum_filter" name="report[category_with_prompt]" id="report_category_with_prompt"><option value="">My Prompt</option>
334
- <option value="first">first</option>
335
- <option value="second">second</option></select>'
336
- )}
337
- end
338
- context "with checkboxes option" do
339
- let(:_grid) do
340
- test_report do
341
- scope {Entry}
342
- filter(:category, :enum, :select => ["first", "second"], :checkboxes => true)
343
- end
344
- end
345
- let(:_filter) { :category }
346
- if Rails.version >= "4.1"
347
- it { should equal_to_dom(
348
- '
349
- <label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" type="checkbox" value="first" name="report[category][]" />first</label>
350
- <label class="category enum_filter checkboxes" for="report_category_second"><input id="report_category_second" type="checkbox" value="second" name="report[category][]" />second</label>
351
- '
352
- )}
353
- else
354
- it { should equal_to_dom(
355
- '
356
- <label class="category enum_filter checkboxes" for="report_category_first"><input id="report_category_first" name="report[category][]" type="checkbox" value="first" />first</label>
357
- <label class="category enum_filter checkboxes" for="report_category_second"><input id="report_category_second" name="report[category][]" type="checkbox" value="second" />second</label>
358
- '
359
- )}
360
-
361
-
362
- end
363
-
364
- context "when partials option passed and partial exists" do
365
- let(:view_options) { {partials: 'custom_checkboxes'} }
366
- it { should equal_to_dom('custom_enum_checkboxes') }
367
- end
368
- end
369
- end
370
-
371
- context "with boolean filter type" do
372
- let(:_filter) { :disabled }
373
- let(:_grid) do
374
- test_report do
375
- scope {Entry}
376
- filter(:disabled, :boolean, default: true)
377
- end
378
- end
379
- it { should equal_to_dom(
380
- # hidden is important when default is set to true
381
- '<input name="report[disabled]" type="hidden" value="0"><input class="disabled boolean_filter" type="checkbox" value="1" checked name="report[disabled]" id="report_disabled">'
382
- )}
383
- end
384
- context "with xboolean filter type" do
385
- let(:_filter) { :disabled }
386
- let(:_grid) do
387
- test_report do
388
- scope {Entry}
389
- filter(:disabled, :xboolean)
390
- end
391
- end
392
- it { should equal_to_dom(
393
- '<select class="disabled extended_boolean_filter" name="report[disabled]" id="report_disabled"><option value=""></option>
394
- <option value="YES">Yes</option>
395
- <option value="NO">No</option></select>'
396
- )}
397
- end
398
- context "with string filter" do
399
- let(:_grid) do
400
- test_report do
401
- scope {Entry}
402
- filter(:name, :string)
403
- end
404
- end
405
-
406
- let(:_filter) { :name }
407
-
408
- it {should equal_to_dom('<input class="name string_filter" type="text" name="report[name]" id="report_name">')}
409
-
410
- context "when multiple option is set" do
411
- let(:_grid) do
412
- test_report(:name => "one,two") do
413
- scope {Entry}
414
- filter(:name, :string, :multiple => true)
415
- end
416
- end
417
-
418
- let(:_filter) { :name }
419
-
420
- it {should equal_to_dom('<input value="one,two" class="name string_filter" type="text" name="report[name]" id="report_name">')}
421
- end
422
- end
423
-
424
- context "with non multiple filter" do
425
- let(:_grid) do
426
- test_report do
427
- scope {Entry}
428
- filter(
429
- :name, :enum,
430
- :include_blank => false,
431
- :multiple => false,
432
- :select => []
433
- )
434
- end
435
- end
436
- let(:_filter) { :name }
437
- it {should equal_to_dom('<select class="name enum_filter" name="report[name]" id="report_name"></select>')}
438
- end
439
- context "with float filter type" do
440
- let(:_grid) {
441
- test_report do
442
- scope {Entry}
443
- filter(:group_id, :float)
444
- end
445
- }
446
- let(:_filter) { :group_id }
447
- it { should equal_to_dom(
448
- '<input class="group_id float_filter" type="text" name="report[group_id]" id="report_group_id"/>'
449
- )}
450
-
451
- end
452
-
453
- context "with enum multiple filter" do
454
- let(:_grid) do
455
- test_report do
456
- scope {Entry}
457
- filter(:group_id, :enum, :select => ['hello'], :multiple => true)
458
- end
459
- end
460
- let(:_filter) { :group_id }
461
- let(:expected_html) do
462
- <<-HTML
463
- <select class="group_id enum_filter" multiple name="report[group_id][]" id="report_group_id">
464
- <option value="hello">hello</option></select>
465
- HTML
466
- end
467
-
468
- it { should equal_to_dom(expected_html) }
469
- end
470
-
471
- context "with column names filter" do
472
- let(:_grid) do
473
- test_report(:column_names => [:id, :name]) do
474
- scope {Entry}
475
-
476
- column_names_filter
477
-
478
- column(:id)
479
- column(:name)
480
- column(:category)
481
- end
482
- end
483
- let(:_filter) { :column_names }
484
- let(:expected_html) do
485
- <<-HTML
486
- <select class="column_names enum_filter" multiple name="report[column_names][]" id="report_column_names"><option selected value="id">Id</option>
487
- <option selected value="name">Name</option>
488
- <option value="category">Category</option></select>
489
- HTML
490
- end
491
-
492
- it { should equal_to_dom(expected_html) }
493
- end
494
- context "with column_names_filter default given as symbols" do
495
- let(:_grid) do
496
- test_report() do
497
- scope {Entry}
498
-
499
- column_names_filter(:default => [:id, :name], :checkboxes => true)
500
-
501
- column(:id)
502
- column(:name)
503
- column(:category)
504
- end
505
- end
506
- let(:_filter) { :column_names }
507
- let(:expected_html) do
508
- <<DOM
509
- <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>
510
- <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>
511
- <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>
512
- DOM
513
- end
514
-
515
- it do
516
- should equal_to_dom(expected_html)
517
- end
518
- end
519
-
520
- context "with dynamic filter" do
521
- let(:filter_options) do
522
- {}
523
- end
524
-
525
- let(:_grid) do
526
- options = filter_options
527
- test_report do
528
- scope {Entry}
529
- filter(:condition, :dynamic, options)
530
- end
531
- end
532
- let(:_filter) { :condition }
533
- context "with no options" do
534
- let(:expected_html) do
535
- <<-HTML
536
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option value="id">Id</option>
537
- <option value="group_id">Group</option>
538
- <option value="name">Name</option>
539
- <option value="category">Category</option>
540
- <option value="access_level">Access level</option>
541
- <option value="pet">Pet</option>
542
- <option value="disabled">Disabled</option>
543
- <option value="confirmed">Confirmed</option>
544
- <option value="shipping_date">Shipping date</option>
545
- <option value="created_at">Created at</option>
546
- <option value="updated_at">Updated at</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
547
- <option value="=~">&asymp;</option>
548
- <option value="&gt;=">&ge;</option>
549
- <option value="&lt;=">&le;</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
550
- HTML
551
- end
552
- it {should equal_to_dom(expected_html)}
553
-
554
- end
555
- context "when default option passed" do
556
- let(:filter_options) do
557
- {:select => [:id, :name], :default => [:id, '>=', 1]}
558
- end
559
- let(:expected_html) do
560
- <<-HTML
561
- <select class="condition dynamic_filter field" name="report[condition][]" id="report_condition"><option selected value="id">id</option>
562
- <option value="name">name</option></select><select class="condition dynamic_filter operation" name="report[condition][]" id="report_condition"><option value="=">=</option>
563
- <option value="=~">&asymp;</option>
564
- <option selected value="&gt;=">&ge;</option>
565
- <option value="&lt;=">&le;</option></select><input class="condition dynamic_filter value" name="report[condition][]" value="1" type="text" id="report_condition">
566
- HTML
567
- end
568
- it {should equal_to_dom(expected_html)}
569
-
570
- end
571
-
572
- context "when operations and options are defined" do
573
- let(:filter_options) do
574
- {:operations => %w(>= <=), :select => [:id, :name]}
575
- end
576
- let(:expected_html) do
577
- <<-HTML
578
- <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>
579
- <option value="&lt;=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
580
- HTML
581
- end
582
- it {should equal_to_dom(expected_html)}
583
- end
584
-
585
- context "when the field is predefined" do
586
- let(:filter_options) do
587
- {:operations => %w(>= <=), :select => [:id]}
588
- end
589
- let(:expected_html) do
590
- <<-HTML
591
- <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>
592
- <option value="&lt;=">≤</option></select><input class="condition dynamic_filter value" name="report[condition][]" type="text" id="report_condition">
593
- HTML
594
- end
595
- it {should equal_to_dom(expected_html)}
596
- end
597
- context "when operation is predefined" do
598
- let(:filter_options) do
599
- {:operations => %w(=), :select => [:id, :name]}
600
- end
601
- let(:expected_html) do
602
- <<-HTML
603
- <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">
604
- HTML
605
- end
606
- it {should equal_to_dom(expected_html)}
607
- end
608
-
609
- end
610
- end
611
-
612
-
613
- describe ".datagrid_label" do
614
- let(:_grid) do
615
- test_report do
616
- scope {Entry}
617
- filter(:name, :string)
618
- end
619
- end
620
- it "should generate label for filter" do
621
- expect(view.datagrid_label(:name)).to equal_to_dom(
622
- '<label for="report_name">Name</label>'
623
- )
624
- end
625
- it "should pass options through to the helper" do
626
- expect(view.datagrid_label(:name, :class => 'foo')).to equal_to_dom(
627
- '<label class="foo" for="report_name">Name</label>'
628
- )
629
- end
630
- it "should support block" do
631
- expect(view.datagrid_label(:name, :class => 'foo') { 'The Name' }).to equal_to_dom(
632
- '<label class="foo" for="report_name">The Name</label>'
633
- )
634
- end
635
- it "should support explicit label" do
636
- expect(view.datagrid_label(:name, "The Name")).to equal_to_dom(
637
- '<label for="report_name">The Name</label>'
638
- )
639
- end
640
- end
641
- end