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