datagrid 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/datagrid.gemspec +26 -164
  4. data/lib/datagrid/columns.rb +5 -10
  5. data/lib/datagrid/filters.rb +3 -6
  6. data/lib/datagrid/filters/base_filter.rb +8 -0
  7. data/lib/datagrid/form_builder.rb +14 -13
  8. data/lib/datagrid/version.rb +3 -0
  9. metadata +10 -196
  10. data/.document +0 -5
  11. data/.rspec +0 -1
  12. data/.travis.yml +0 -23
  13. data/Gemfile +0 -33
  14. data/Rakefile +0 -43
  15. data/VERSION +0 -1
  16. data/spec/datagrid/active_model_spec.rb +0 -33
  17. data/spec/datagrid/column_names_attribute_spec.rb +0 -86
  18. data/spec/datagrid/columns/column_spec.rb +0 -19
  19. data/spec/datagrid/columns_spec.rb +0 -592
  20. data/spec/datagrid/core_spec.rb +0 -210
  21. data/spec/datagrid/drivers/active_record_spec.rb +0 -79
  22. data/spec/datagrid/drivers/array_spec.rb +0 -106
  23. data/spec/datagrid/drivers/mongo_mapper_spec.rb +0 -101
  24. data/spec/datagrid/drivers/mongoid_spec.rb +0 -109
  25. data/spec/datagrid/drivers/sequel_spec.rb +0 -111
  26. data/spec/datagrid/filters/base_filter_spec.rb +0 -19
  27. data/spec/datagrid/filters/boolean_enum_filter_spec.rb +0 -5
  28. data/spec/datagrid/filters/composite_filters_spec.rb +0 -65
  29. data/spec/datagrid/filters/date_filter_spec.rb +0 -198
  30. data/spec/datagrid/filters/date_time_filter_spec.rb +0 -157
  31. data/spec/datagrid/filters/dynamic_filter_spec.rb +0 -175
  32. data/spec/datagrid/filters/enum_filter_spec.rb +0 -51
  33. data/spec/datagrid/filters/extended_boolean_filter_spec.rb +0 -46
  34. data/spec/datagrid/filters/float_filter_spec.rb +0 -15
  35. data/spec/datagrid/filters/integer_filter_spec.rb +0 -144
  36. data/spec/datagrid/filters/string_filter_spec.rb +0 -35
  37. data/spec/datagrid/filters_spec.rb +0 -332
  38. data/spec/datagrid/form_builder_spec.rb +0 -611
  39. data/spec/datagrid/helper_spec.rb +0 -683
  40. data/spec/datagrid/ordering_spec.rb +0 -150
  41. data/spec/datagrid/scaffold_spec.rb +0 -45
  42. data/spec/datagrid/stylesheet_spec.rb +0 -12
  43. data/spec/datagrid/utils_spec.rb +0 -19
  44. data/spec/datagrid_spec.rb +0 -94
  45. data/spec/spec_helper.rb +0 -123
  46. data/spec/support/active_record.rb +0 -38
  47. data/spec/support/configuration.rb +0 -28
  48. data/spec/support/i18n_helpers.rb +0 -6
  49. data/spec/support/matchers.rb +0 -101
  50. data/spec/support/mongo_mapper.rb +0 -32
  51. data/spec/support/mongoid.rb +0 -36
  52. data/spec/support/sequel.rb +0 -39
  53. data/spec/support/simple_report.rb +0 -64
  54. data/spec/support/test_partials/_actions.html.erb +0 -1
  55. data/spec/support/test_partials/client/datagrid/_form.html.erb +0 -13
  56. data/spec/support/test_partials/client/datagrid/_head.html.erb +0 -9
  57. data/spec/support/test_partials/client/datagrid/_order_for.html.erb +0 -11
  58. data/spec/support/test_partials/client/datagrid/_row.html.erb +0 -6
  59. data/spec/support/test_partials/client/datagrid/_table.html.erb +0 -19
  60. data/spec/support/test_partials/custom_checkboxes/_enum_checkboxes.html.erb +0 -1
  61. data/spec/support/test_partials/custom_form/_form.html.erb +0 -7
  62. data/spec/support/test_partials/custom_range/_range_filter.html.erb +0 -1
@@ -1,144 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters::IntegerFilter do
4
-
5
- let(:entry1) { Entry.create!(:group_id => 1) }
6
- let(:entry2) { Entry.create!(:group_id => 2) }
7
- let(:entry3) { Entry.create!(:group_id => 3) }
8
- let(:entry4) { Entry.create!(:group_id => 4) }
9
- let(:entry5) { Entry.create!(:group_id => 5) }
10
- let(:entry7) { Entry.create!(:group_id => 7) }
11
-
12
- it "should support integer range argument" do
13
- report = test_report(:group_id => 3..5) do
14
- scope { Entry }
15
- filter(:group_id, :integer)
16
- end
17
- expect(report.assets).not_to include(entry1)
18
- expect(report.assets).to include(entry4)
19
- expect(report.assets).not_to include(entry7)
20
- end
21
-
22
- it "should support integer range given as array argument" do
23
- report = test_report(:group_id => [3.to_s, 5.to_s]) do
24
- scope { Entry }
25
- filter(:group_id, :integer, :range => true)
26
- end
27
- expect(report.assets).not_to include(entry7)
28
- expect(report.assets).to include(entry4)
29
- expect(report.assets).not_to include(entry1)
30
- end
31
-
32
- it "should support minimum integer argument" do
33
- report = test_report(:group_id => [5.to_s, nil]) do
34
- scope { Entry }
35
- filter(:group_id, :integer, :range => true)
36
- end
37
- expect(report.assets).not_to include(entry1)
38
- expect(report.assets).not_to include(entry4)
39
- expect(report.assets).to include(entry7)
40
- end
41
-
42
- it "should support maximum integer argument" do
43
- report = test_report(:group_id => [nil, 5.to_s]) do
44
- scope { Entry }
45
- filter(:group_id, :integer, :range => true)
46
- end
47
- expect(report.assets).to include(entry1)
48
- expect(report.assets).to include(entry4)
49
- expect(report.assets).not_to include(entry7)
50
- end
51
-
52
- it "should find something in one integer interval" do
53
-
54
- report = test_report(:group_id => (4..4)) do
55
- scope { Entry }
56
- filter(:group_id, :integer, :range => true)
57
- end
58
- expect(report.assets).not_to include(entry7)
59
- expect(report.assets).to include(entry4)
60
- expect(report.assets).not_to include(entry1)
61
- end
62
-
63
- it "should support invalid range" do
64
-
65
- report = test_report(:group_id => (7..1)) do
66
- scope { Entry }
67
- filter(:group_id, :integer, :range => true)
68
- end
69
- expect(report.group_id).to eq([1,7])
70
- expect(report.assets).to include(entry7)
71
- expect(report.assets).to include(entry4)
72
- expect(report.assets).to include(entry1)
73
- end
74
-
75
-
76
- it "should support block" do
77
- report = test_report(:group_id => 5) do
78
- scope { Entry }
79
- filter(:group_id, :integer, :range => true) do |value|
80
- where("group_id >= ?", value)
81
- end
82
- end
83
- expect(report.assets).not_to include(entry1)
84
- expect(report.assets).to include(entry5)
85
- end
86
-
87
-
88
- it "should not prefix table name if column is joined" do
89
- report = test_report(:rating => [4,nil]) do
90
- scope { Entry.joins(:group) }
91
- filter(:rating, :integer, :range => true)
92
- end
93
- expect(report.rating).to eq([4,nil])
94
- expect(report.assets).not_to include(Entry.create!(:group => Group.create!(:rating => 3)))
95
- expect(report.assets).to include(Entry.create!(:group => Group.create!(:rating => 5)))
96
- end
97
-
98
- it "should support multiple values" do
99
- report = test_report(:group_id => "1,2") do
100
- scope {Entry}
101
- filter(:group_id, :integer, :multiple => true)
102
- end
103
- expect(report.group_id).to eq([1,2])
104
- expect(report.assets).to include(entry1)
105
- expect(report.assets).to include(entry2)
106
- expect(report.assets).not_to include(entry3)
107
- end
108
- it "should support custom separator multiple values" do
109
- report = test_report(:group_id => "1|2") do
110
- scope {Entry}
111
- filter(:group_id, :integer, :multiple => '|')
112
- end
113
- expect(report.group_id).to eq([1,2])
114
- expect(report.assets).to include(entry1)
115
- expect(report.assets).to include(entry2)
116
- expect(report.assets).not_to include(entry3)
117
- end
118
-
119
- it "should support multiple with allow_blank allow_nil options" do
120
- report = test_report do
121
- scope {Entry}
122
- filter(:group_id, :integer, :multiple => true, :allow_nil => false, :allow_blank => true )
123
- end
124
- report.group_id = []
125
- expect(report.assets).to_not include(entry1)
126
- expect(report.assets).to_not include(entry2)
127
- report.group_id = [1]
128
- expect(report.assets).to include(entry1)
129
- expect(report.assets).to_not include(entry2)
130
- report.group_id = nil
131
- expect(report.assets).to include(entry1)
132
- expect(report.assets).to include(entry2)
133
- end
134
-
135
- it "normalizes AR object to ID" do
136
- group = Group.create!
137
- report = test_report(group_id: group) do
138
- scope {Entry}
139
- filter(:group_id, :integer)
140
- end
141
-
142
- expect(report.group_id).to eq(group.id)
143
- end
144
- end
@@ -1,35 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Datagrid::Filters::StringFilter do
4
-
5
- it "should support multiple values" do
6
- report = test_report(:name => "one,two") do
7
- scope {Entry}
8
- filter(:name, :string, :multiple => true)
9
- end
10
- expect(report.assets).to include(Entry.create!( :name => "one"))
11
- expect(report.assets).to include(Entry.create!( :name => "two"))
12
- expect(report.assets).not_to include(Entry.create!( :name => "three"))
13
- end
14
- it "should support custom separator multiple values" do
15
- report = test_report(:name => "one,1|two,2") do
16
- scope {Entry}
17
- filter(:name, :string, :multiple => '|')
18
- end
19
- expect(report.assets).to include(Entry.create!( :name => "one,1"))
20
- expect(report.assets).to include(Entry.create!( :name => "two,2"))
21
- expect(report.assets).not_to include(Entry.create!( :name => "one"))
22
- expect(report.assets).not_to include(Entry.create!( :name => "two"))
23
- end
24
-
25
- it "supports range" do
26
- report = test_report(:name => ['ab', 'lm']) do
27
- scope {Entry}
28
- filter(:name, :string, range: true)
29
- end
30
- expect(report.assets).to include(Entry.create!( :name => "ac"))
31
- expect(report.assets).to include(Entry.create!( :name => "kl"))
32
- expect(report.assets).not_to include(Entry.create!( :name => "aa"))
33
- expect(report.assets).not_to include(Entry.create!( :name => "mn"))
34
- end
35
- end
@@ -1,332 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Datagrid::Filters do
4
-
5
- it "should support default option as proc" do
6
- expect(test_report do
7
- scope {Entry}
8
- filter(:created_at, :date, :default => proc { Date.today } )
9
- end.created_at).to eq(Date.today)
10
- end
11
-
12
- it "should stack with other filters" do
13
- Entry.create(:name => "ZZ", :category => "first")
14
- report = test_report(:name => "Pop", :category => "first") do
15
- scope { Entry }
16
- filter(:name)
17
- filter(:category, :enum, :select => ["first", "second"])
18
- end
19
- expect(report.assets).to be_empty
20
- end
21
-
22
- it "should not support array argument for not multiple filter" do
23
- report = test_report do
24
- scope {Entry}
25
- filter(:group_id, :integer)
26
- end
27
- expect {
28
- report.group_id = [1,2]
29
- }.to raise_error(Datagrid::ArgumentError)
30
- end
31
-
32
- it "should filter block with 2 arguments" do
33
- report = test_report do
34
- scope {Entry}
35
- filter(:group_id, :integer) do |value, scope|
36
- scope.where(:group_id => value)
37
- end
38
- end
39
- expect {
40
- report.group_id = [1,2]
41
- }.to raise_error(Datagrid::ArgumentError)
42
- end
43
-
44
-
45
- it "should initialize when report Scope table not exists" do
46
- class ModelWithoutTable < ActiveRecord::Base; end
47
- expect(ModelWithoutTable).not_to be_table_exists
48
- class TheReport
49
- include Datagrid
50
-
51
- scope {ModelWithoutTable}
52
-
53
- filter(:name)
54
- filter(:limit)
55
- end
56
- expect(TheReport.new(:name => 'hello')).not_to be_nil
57
- end
58
-
59
- it "should support inheritence" do
60
- parent = Class.new do
61
- include Datagrid
62
- scope {Entry}
63
- filter(:name)
64
- end
65
- child = Class.new(parent) do
66
- filter(:group_id)
67
- end
68
- expect(parent.filters.size).to eq(1)
69
- expect(child.filters.size).to eq(2)
70
- end
71
-
72
- describe "allow_blank and allow_nil options" do
73
-
74
- def check_performed(value, result, options)
75
- $FILTER_PERFORMED = false
76
- report = test_report(:name => value) do
77
- scope {Entry}
78
- filter(:name, options) do |_|
79
- $FILTER_PERFORMED = true
80
- self
81
- end
82
- end
83
- expect(report.name).to eq(value)
84
- report.assets
85
- expect($FILTER_PERFORMED).to eq(result)
86
- end
87
-
88
- it "should support allow_blank argument" do
89
- [nil, "", " "].each do |value|
90
- check_performed(value, true, :allow_blank => true)
91
- end
92
- end
93
-
94
- it "should support allow_nil argument" do
95
- check_performed(nil, true, :allow_nil => true)
96
- end
97
-
98
- it "should support combination on allow_nil and allow_blank" do
99
- check_performed(nil, false, :allow_nil => false, :allow_blank => true)
100
- check_performed("", true, :allow_nil => false, :allow_blank => true)
101
- check_performed(nil, true, :allow_nil => true, :allow_blank => false)
102
- end
103
- end
104
-
105
- describe "default filter as scope" do
106
- it "should create default filter if scope respond to filter name method" do
107
- Entry.create!
108
- Entry.create!
109
- grid = test_report(:limit => 1) do
110
- scope {Entry}
111
- filter(:limit)
112
- end
113
- expect(grid.assets.to_a.size).to eq(1)
114
- end
115
-
116
- end
117
- describe "default filter as scope" do
118
- it "should create default filter if scope respond to filter name method" do
119
- Entry.create!
120
- grid = test_report(:custom => 'skip') do
121
- scope {Entry}
122
- filter(:custom) do |value|
123
- if value != 'skip'
124
- where(:custom => value)
125
- end
126
- end
127
- end
128
- expect(grid.assets).not_to be_empty
129
- end
130
-
131
- end
132
-
133
- describe "positioning filter before another" do
134
- it "should insert the filter before the specified element" do
135
- grid = test_report do
136
- scope {Entry}
137
- filter(:limit)
138
- filter(:name, :before => :limit)
139
- end
140
- expect(grid.filters.index {|f| f.name == :name}).to eq(0)
141
- end
142
- end
143
-
144
- describe "positioning filter after another" do
145
- it "should insert the filter before the specified element" do
146
- grid = test_report do
147
- scope {Entry}
148
- filter(:limit)
149
- filter(:name)
150
- filter(:group_id, :after => :limit)
151
- end
152
- expect(grid.filters.index {|f| f.name == :group_id}).to eq(1)
153
- end
154
- end
155
-
156
- it "should support dummy filter" do
157
- grid = test_report do
158
- scope { Entry }
159
- filter(:period, :date, :dummy => true, :default => proc { Date.today })
160
- end
161
- Entry.create!(:created_at => 3.days.ago)
162
- expect(grid.assets).not_to be_empty
163
- end
164
-
165
- describe "#filter_by" do
166
- it "should allow partial filtering" do
167
- grid = test_report do
168
- scope {Entry}
169
- filter(:id)
170
- filter(:name)
171
- end
172
- Entry.create!(:name => 'hello')
173
- grid.attributes = {:id => -1, :name => 'hello'}
174
- expect(grid.assets).to be_empty
175
- expect(grid.filter_by(:name)).not_to be_empty
176
- end
177
- end
178
-
179
- it "supports dynamic header" do
180
- grid = test_report do
181
- scope {Entry}
182
- filter(:id, :integer, header: proc { rand(10**9) })
183
- end
184
-
185
- filter = grid.filter_by_name(:id)
186
- expect(filter.header).to_not eq(filter.header)
187
- end
188
-
189
-
190
- describe "#filter_by_name" do
191
- it "should return filter object" do
192
- r = test_report do
193
- scope {Entry}
194
- filter(:id, :integer)
195
- end
196
-
197
- object = r.filter_by_name(:id)
198
- expect(object.type).to eq(:integer)
199
- end
200
- end
201
-
202
- describe "tranlations" do
203
-
204
- module ::Ns46
205
- class TranslatedReport
206
- include Datagrid
207
- scope { Entry }
208
- filter(:name)
209
- end
210
-
211
- class InheritedReport < TranslatedReport
212
- end
213
- end
214
-
215
- it "translates filter with namespace" do
216
- grid = Ns46::TranslatedReport.new
217
- store_translations(:en, datagrid: {:"ns46/translated_report" => {filters: {name: "Navn"}}}) do
218
- expect(grid.filters.map(&:header)).to eq(["Navn"])
219
- end
220
- end
221
-
222
- it "translates filter using defaults namespace" do
223
- grid = Ns46::TranslatedReport.new
224
- store_translations(:en, datagrid: {defaults: {filters: {name: "Navn"}}}) do
225
- expect(grid.filters.map(&:header)).to eq(["Navn"])
226
- end
227
- end
228
-
229
- it "translates filter using parent report" do
230
- grid = Ns46::InheritedReport.new
231
- store_translations(:en, datagrid: {:"ns46/translated_report" => {filters: {name: "Navn"}}}) do
232
- expect(grid.filters.map(&:header)).to eq(["Navn"])
233
- end
234
- end
235
- end
236
-
237
-
238
- describe "#select_options" do
239
- it "should return select options" do
240
- grid = test_report do
241
- scope {Entry}
242
- filter(:id, :enum, select: [1,2,3])
243
- end
244
- expect(grid.select_options(:id)).to eq([1,2,3])
245
- end
246
-
247
- it "should raise ArgumentError for filter without options" do
248
- grid = test_report do
249
- scope {Entry}
250
- filter(:id, :integer)
251
- end
252
- expect {
253
- grid.select_options(:id)
254
- }.to raise_error(Datagrid::ArgumentError)
255
- end
256
- end
257
-
258
- describe "#inspect" do
259
- it "should list all fitlers with types" do
260
-
261
- module ::NsInspect
262
- class TestGrid
263
- include Datagrid
264
- scope {Entry}
265
- filter(:id, :integer)
266
- filter(:name, :string)
267
- filter(:current_user)
268
- end
269
- end
270
-
271
- expect(NsInspect::TestGrid.inspect).to eq(
272
- "NsInspect::TestGrid(id: integer, name: string, current_user: default)"
273
- )
274
- end
275
-
276
- it "dislays no filters" do
277
- class TestGrid8728
278
- include Datagrid
279
- scope {Entry}
280
- end
281
-
282
- expect(TestGrid8728.inspect).to eq("TestGrid8728(no filters)")
283
- end
284
- end
285
-
286
-
287
- describe ":if :unless options" do
288
- it "supports :if option" do
289
- klass = test_report_class do
290
- scope {Entry}
291
- filter(:admin_mode, :boolean, dummy: true)
292
- filter(:id, :integer, if: :admin_mode)
293
- filter(:name, :integer, unless: :admin_mode)
294
- end
295
-
296
- admin_filters = klass.new(admin_mode: true).filters.map(&:name)
297
- non_admin_filters = klass.new(admin_mode: false).filters.map(&:name)
298
- expect(admin_filters).to include(:id)
299
- expect(admin_filters).to_not include(:name)
300
- expect(non_admin_filters).to_not include(:id)
301
- expect(non_admin_filters).to include(:name)
302
- end
303
-
304
- context 'with delegation to attribute' do
305
- let(:role) { OpenStruct.new('admin?' => admin) }
306
- let(:klass) do
307
- test_report_class do
308
- attr_accessor :role
309
- delegate :admin?, to: :role
310
-
311
- scope { Entry }
312
-
313
- filter(:id, :integer, if: :admin?)
314
- end
315
- end
316
-
317
- subject { klass.new(role: role).filters.map(&:name) }
318
-
319
- context 'when condition is true' do
320
- let(:admin) { true }
321
-
322
- it { is_expected.to include(:id) }
323
- end
324
-
325
- context 'when condition is false' do
326
- let(:admin) { false }
327
-
328
- it { is_expected.to_not include(:id) }
329
- end
330
- end
331
- end
332
- end