datagrid 1.4.4 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -171,6 +171,15 @@ describe Datagrid::Filters::DateFilter do
171
171
  expect(report.created_at).to eq([Date.new(2012, 01, 01), Date.new(2013, 01, 01)])
172
172
  end
173
173
 
174
+ it "should nullify blank range" do
175
+ report = test_report(:created_at => [nil, nil]) do
176
+ scope {Entry}
177
+ filter(:created_at, :date, :range => true)
178
+ end
179
+
180
+ expect(report.created_at).to eq(nil)
181
+ end
182
+
174
183
  it "should properly format date in filter_value_as_string" do
175
184
  with_date_format do
176
185
  report = test_report(:created_at => "2012-01-02") do
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require "spec_helper"
2
2
 
3
3
 
4
4
  describe Datagrid::Filters::DynamicFilter do
@@ -139,6 +139,32 @@ describe Datagrid::Filters::DynamicFilter do
139
139
  expect(grid.assets).to_not include(Entry.create!(disabled: false, group_id: 2))
140
140
  end
141
141
 
142
+ it "should support custom operations" do
143
+ entry = Entry.create!(name: 'hello')
144
+
145
+ grid = test_report do
146
+ scope {Entry}
147
+ filter(
148
+ :condition, :dynamic, operations: ["=", "!="]
149
+ ) do |(field, operation, value), scope|
150
+ if operation == "!="
151
+ scope.where("#{field} != ?", value)
152
+ else
153
+ default_filter
154
+ end
155
+ end
156
+ end
157
+
158
+ grid.condition = ["name", "=", "hello"]
159
+ expect(grid.assets).to include(entry)
160
+ grid.condition = ["name", "!=", "hello"]
161
+ expect(grid.assets).to_not include(entry)
162
+ grid.condition = ["name", "=", "hello1"]
163
+ expect(grid.assets).to_not include(entry)
164
+ grid.condition = ["name", "!=", "hello1"]
165
+ expect(grid.assets).to include(entry)
166
+ end
167
+
142
168
  it "should raise if unknown operation" do
143
169
  report.condition = [:shipping_date, "<>", '1996-08-05']
144
170
  expect{
@@ -112,7 +112,7 @@ describe Datagrid::Filters do
112
112
  end
113
113
  expect(grid.assets.to_a.size).to eq(1)
114
114
  end
115
-
115
+
116
116
  end
117
117
  describe "default filter as scope" do
118
118
  it "should create default filter if scope respond to filter name method" do
@@ -176,23 +176,6 @@ describe Datagrid::Filters do
176
176
  end
177
177
  end
178
178
 
179
- it "should support instance filter rejection" do
180
- grid = test_report(:name => 'hello') do
181
- scope { Entry }
182
- filter(:id)
183
- filter(:name)
184
- end
185
-
186
- Entry.create!(:name => 'hello1')
187
- expect(grid.assets).to be_empty
188
- grid.filters.reject! {|f| f.name == :name }
189
- expect(grid.filters.map(&:name)).to eq([:id])
190
- expect(grid.assets).to_not be_empty
191
- expect(grid.class.filters.map(&:name)).to eq([:id, :name])
192
-
193
- end
194
-
195
-
196
179
  it "supports dynamic header" do
197
180
  grid = test_report do
198
181
  scope {Entry}
@@ -217,7 +200,7 @@ describe Datagrid::Filters do
217
200
  end
218
201
 
219
202
  describe "tranlations" do
220
-
203
+
221
204
  module ::Ns46
222
205
  class TranslatedReport
223
206
  include Datagrid
@@ -263,4 +246,51 @@ describe Datagrid::Filters do
263
246
  }.to raise_error(Datagrid::ArgumentError)
264
247
  end
265
248
  end
249
+
250
+ describe "#inspect" do
251
+ it "should list all fitlers with types" do
252
+
253
+ module ::NsInspect
254
+ class TestGrid
255
+ include Datagrid
256
+ scope {Entry}
257
+ filter(:id, :integer)
258
+ filter(:name, :string)
259
+ filter(:current_user)
260
+ end
261
+ end
262
+
263
+ expect(NsInspect::TestGrid.inspect).to eq(
264
+ "NsInspect::TestGrid(id: integer, name: string, current_user: default)"
265
+ )
266
+ end
267
+
268
+ it "dislays no filters" do
269
+ class TestGrid8728
270
+ include Datagrid
271
+ scope {Entry}
272
+ end
273
+
274
+ expect(TestGrid8728.inspect).to eq("TestGrid8728(no filters)")
275
+ end
276
+ end
277
+
278
+
279
+ describe ":if :unless options" do
280
+ it "supports :if option" do
281
+ klass = test_report_class do
282
+ scope {Entry}
283
+ filter(:admin_mode, :boolean, dummy: true)
284
+ filter(:id, :integer, if: :admin_mode)
285
+ filter(:name, :integer, unless: :admin_mode)
286
+ end
287
+
288
+ admin_filters = klass.new(admin_mode: true).filters.map(&:name)
289
+ non_admin_filters = klass.new(admin_mode: false).filters.map(&:name)
290
+ expect(admin_filters).to include(:id)
291
+ expect(admin_filters).to_not include(:name)
292
+ expect(non_admin_filters).to_not include(:id)
293
+ expect(non_admin_filters).to include(:name)
294
+ end
295
+ end
266
296
  end
@@ -221,6 +221,19 @@ describe Datagrid::Helper do
221
221
  "tr td.name.ordered.asc" => "Star"
222
222
  )
223
223
  end
224
+ it "should add ordering classes to column" do
225
+ rp = test_report(:order => :name) do
226
+ scope { Entry }
227
+ column(:name)
228
+ end
229
+ expect(
230
+ subject.datagrid_rows(rp) do |row|
231
+ subject.content_tag(:strong, row.name)
232
+ end
233
+ ).to match_css_pattern(
234
+ "strong" => "Star"
235
+ )
236
+ end
224
237
 
225
238
  it "should add ordering classes to column" do
226
239
  rp = test_report(:order => :name, :descending => true) do
@@ -505,6 +518,12 @@ describe Datagrid::Helper do
505
518
  expect(r.name).to eq("Hello")
506
519
  expect(r.category).to eq("greetings")
507
520
  end
521
+ it "should provide an interator" do
522
+ r = subject.datagrid_row(grid, entry)
523
+ expect(r.map {|z| z.upcase}).to eq(["HELLO", "GREETINGS"])
524
+ expect(r.name).to eq("Hello")
525
+ expect(r.category).to eq("greetings")
526
+ end
508
527
 
509
528
  it "should yield block" do
510
529
  subject.datagrid_row(grid, entry) do |row|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.4
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bogdan Gusiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,188 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.22.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: jeweler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: debugger
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sqlite3
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sequel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: mongoid
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.1.7
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.1.7
153
+ - !ruby/object:Gem::Dependency
154
+ name: mongo_mapper
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 0.13.0
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 0.13.0
167
+ - !ruby/object:Gem::Dependency
168
+ name: bson
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: bson_ext
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: rails
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: 3.2.22.2
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: 3.2.22.2
27
209
  - !ruby/object:Gem::Dependency
28
210
  name: bundler
29
211
  requirement: !ruby/object:Gem::Requirement
@@ -67,7 +249,7 @@ dependencies:
67
249
  - !ruby/object:Gem::Version
68
250
  version: '0'
69
251
  - !ruby/object:Gem::Dependency
70
- name: byebug
252
+ name: pry-byebug
71
253
  requirement: !ruby/object:Gem::Requirement
72
254
  requirements:
73
255
  - - ">="
@@ -319,7 +501,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
319
501
  requirements:
320
502
  - - ">="
321
503
  - !ruby/object:Gem::Version
322
- version: '0'
504
+ version: '2.0'
323
505
  required_rubygems_version: !ruby/object:Gem::Requirement
324
506
  requirements:
325
507
  - - ">="
@@ -327,7 +509,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
327
509
  version: '0'
328
510
  requirements: []
329
511
  rubyforge_project:
330
- rubygems_version: 2.5.1
512
+ rubygems_version: 2.6.7
331
513
  signing_key:
332
514
  specification_version: 4
333
515
  summary: Ruby gem to create datagrids