datagrid 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.markdown +2 -2
- data/VERSION +1 -1
- data/app/views/datagrid/_table.html.erb +3 -3
- data/datagrid.gemspec +3 -3
- data/lib/datagrid/columns.rb +1 -1
- data/lib/datagrid/drivers/array.rb +1 -1
- data/lib/datagrid/renderer.rb +8 -7
- data/spec/datagrid/columns_spec.rb +13 -0
- data/spec/datagrid/drivers/array_spec.rb +13 -0
- data/spec/datagrid/helper_spec.rb +262 -227
- data/spec/support/matchers.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ddccc0241fe7be8d5b6cce9fc48cdf20a5d9d29
|
4
|
+
data.tar.gz: d6f33446081c20970effc047a14a1b147dd17e55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5120028296554128bae6a4614a1ac7a021a6c14cb4c107f55d01efb2b11493fe96db1cf9db1e589a6e9318e966ca7ba09aa628d7ba2467594d08d1a6daa333da
|
7
|
+
data.tar.gz: 4b23c861a07ded0fb42a89a6a5142e6e17372d55581e8f3b527a95060f8c397eeb5b17266c5a527341c3f070db7a4c359869fb1eb04f4202fc26969eafea5551
|
data/Readme.markdown
CHANGED
@@ -21,10 +21,10 @@ Ruby library that helps you to build and represent table-like data with:
|
|
21
21
|
|
22
22
|
### Live Demo
|
23
23
|
|
24
|
-
[Datagrid DEMO application](http://datagrid.
|
24
|
+
[Datagrid DEMO application](http://datagrid.herokuapp.com) is available live!
|
25
25
|
[Demo source code](https://github.com/bogdan/datagrid-demo).
|
26
26
|
|
27
|
-
<img src="http://datagrid.
|
27
|
+
<img src="http://datagrid.herokuapp.com/datagrid_demo_screenshot.png" style="margin: 7px; border: 1px solid black">
|
28
28
|
|
29
29
|
### Example
|
30
30
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.3.
|
1
|
+
1.3.1
|
@@ -9,10 +9,10 @@ Local variables:
|
|
9
9
|
<%= datagrid_header(grid, options) %>
|
10
10
|
</thead>
|
11
11
|
<tbody>
|
12
|
-
<% if assets.
|
13
|
-
|
12
|
+
<% if assets.any? %>
|
13
|
+
<%= datagrid_rows(grid, assets, options) %>
|
14
14
|
<% else %>
|
15
|
-
|
15
|
+
<tr><td class="noresults" colspan="100%"><%= I18n.t('datagrid.no_results').html_safe %></td></tr>
|
16
16
|
<% end %>
|
17
17
|
</tbody>
|
18
18
|
<% end %>
|
data/datagrid.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: datagrid 1.3.
|
5
|
+
# stub: datagrid 1.3.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "datagrid"
|
9
|
-
s.version = "1.3.
|
9
|
+
s.version = "1.3.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Bogdan Gusiev"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-08-21"
|
15
15
|
s.description = "This allows you to easily build datagrid aka data tables with sortable columns and filters"
|
16
16
|
s.email = "agresso@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/datagrid/columns.rb
CHANGED
@@ -415,8 +415,8 @@ module Datagrid
|
|
415
415
|
|
416
416
|
def initialize(*) #:nodoc:
|
417
417
|
self.columns_array = self.class.columns_array.clone
|
418
|
-
instance_eval(&dynamic_block) if dynamic_block
|
419
418
|
super
|
419
|
+
instance_eval(&dynamic_block) if dynamic_block
|
420
420
|
end
|
421
421
|
|
422
422
|
# Returns all columns available for current grid configuration
|
@@ -3,7 +3,7 @@ module Datagrid
|
|
3
3
|
class Array < AbstractDriver #:nodoc:
|
4
4
|
|
5
5
|
def self.match?(scope)
|
6
|
-
!Datagrid::Drivers::ActiveRecord.match?(scope) && scope.is_a?(::Array)
|
6
|
+
!Datagrid::Drivers::ActiveRecord.match?(scope) && (scope.is_a?(::Array) || scope.is_a?(Enumerator))
|
7
7
|
end
|
8
8
|
|
9
9
|
def to_scope(scope)
|
data/lib/datagrid/renderer.rb
CHANGED
@@ -65,13 +65,14 @@ module Datagrid
|
|
65
65
|
|
66
66
|
def rows(grid, assets, options = {})
|
67
67
|
result = assets.map do |asset|
|
68
|
-
_render_partial(
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
_render_partial(
|
69
|
+
'row', options[:partials],
|
70
|
+
{
|
71
|
+
:grid => grid,
|
72
|
+
:options => options,
|
73
|
+
:asset => asset
|
74
|
+
})
|
75
|
+
end.to_a.join
|
75
76
|
|
76
77
|
_safe(result)
|
77
78
|
end
|
@@ -386,6 +386,19 @@ describe Datagrid::Columns do
|
|
386
386
|
expect(grid.column_by_name(:id)).not_to be_nil
|
387
387
|
expect(grid.column_by_name(:name)).not_to be_nil
|
388
388
|
end
|
389
|
+
|
390
|
+
it "has access to attributes" do
|
391
|
+
grid = test_report(:attribute_name => 'value') do
|
392
|
+
scope {Entry}
|
393
|
+
datagrid_attribute :attribute_name
|
394
|
+
dynamic {
|
395
|
+
value = attribute_name
|
396
|
+
column(:name) { value }
|
397
|
+
}
|
398
|
+
end
|
399
|
+
|
400
|
+
expect(grid.data_value(:name, Entry.create!)).to eq('value')
|
401
|
+
end
|
389
402
|
end
|
390
403
|
|
391
404
|
describe ".data_value" do
|
@@ -89,5 +89,18 @@ describe Datagrid::Drivers::Array do
|
|
89
89
|
it {should == [third, first, second]}
|
90
90
|
end
|
91
91
|
end
|
92
|
+
|
92
93
|
end
|
94
|
+
describe "when using enumerator scope" do
|
95
|
+
|
96
|
+
it "should work fine" do
|
97
|
+
grid = test_report(to_enum: true) do
|
98
|
+
scope {[]}
|
99
|
+
filter(:to_enum, :boolean) do |_, scope|
|
100
|
+
scope.to_enum
|
101
|
+
end
|
102
|
+
end
|
103
|
+
grid.assets.should_not be_any
|
104
|
+
end
|
105
|
+
end
|
93
106
|
end
|
@@ -75,7 +75,7 @@ describe Datagrid::Helper do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "should support giving assets explicitly" do
|
78
|
-
|
78
|
+
Entry.create!(entry.attributes)
|
79
79
|
datagrid_table = subject.datagrid_table(grid, [entry])
|
80
80
|
|
81
81
|
expect(datagrid_table).to match_css_pattern({
|
@@ -148,293 +148,328 @@ describe Datagrid::Helper do
|
|
148
148
|
end
|
149
149
|
end
|
150
150
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
151
|
+
context "when scope is enumerator" do
|
152
|
+
let(:grid) do
|
153
|
+
test_report do
|
154
|
+
scope { ['a', 'b'].to_enum }
|
155
|
+
column(:name) do |value|
|
156
|
+
value
|
157
|
+
end
|
157
158
|
end
|
158
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
159
|
-
"tr td.name a[href=Star]" => "Star"
|
160
|
-
)
|
161
159
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
column(:name, :url => lambda {|model| false})
|
167
|
-
end
|
168
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
169
|
-
"tr td.name" => "Star"
|
170
|
-
)
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should add ordering classes to column" do
|
174
|
-
rp = test_report(:order => :name) do
|
175
|
-
scope { Entry }
|
176
|
-
column(:name)
|
177
|
-
end
|
178
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
179
|
-
"tr td.name.ordered.asc" => "Star"
|
160
|
+
it "should render table" do
|
161
|
+
expect(subject.datagrid_table(grid)).to match_css_pattern(
|
162
|
+
"table.datagrid th.name" => 1,
|
163
|
+
"table.datagrid td.name" => 2,
|
180
164
|
)
|
181
165
|
end
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
column(:name)
|
187
|
-
end
|
188
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
189
|
-
"tr td.name.ordered.desc" => "Star"
|
190
|
-
)
|
166
|
+
end
|
167
|
+
context "when scope is lazy enumerator" do
|
168
|
+
before(:each) do
|
169
|
+
pending("not supported by ruby < 2.0") if RUBY_VERSION < '2.0'
|
191
170
|
end
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
content_tag(:span, model.name)
|
171
|
+
let(:grid) do
|
172
|
+
test_report do
|
173
|
+
scope { ['a', 'b'].lazy }
|
174
|
+
column(:name) do |value|
|
175
|
+
value
|
198
176
|
end
|
199
177
|
end
|
200
|
-
|
201
|
-
|
178
|
+
end
|
179
|
+
it "should render table" do
|
180
|
+
expect(subject.datagrid_table(grid)).to match_css_pattern(
|
181
|
+
"table.datagrid th.name" => 1,
|
182
|
+
"table.datagrid td.name" => 2,
|
202
183
|
)
|
203
184
|
end
|
185
|
+
end
|
186
|
+
end
|
204
187
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
211
|
-
"tr td.name h1" => "Star"
|
212
|
-
)
|
188
|
+
describe ".datagrid_rows" do
|
189
|
+
it "should support urls" do
|
190
|
+
rp = test_report do
|
191
|
+
scope { Entry }
|
192
|
+
column(:name, :url => lambda {|model| model.name})
|
213
193
|
end
|
194
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
195
|
+
"tr td.name a[href=Star]" => "Star"
|
196
|
+
)
|
197
|
+
end
|
214
198
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
self.name.upcase
|
220
|
-
end
|
221
|
-
end
|
222
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
223
|
-
"tr td.name em" => "STAR"
|
224
|
-
)
|
199
|
+
it "should support conditional urls" do
|
200
|
+
rp = test_report do
|
201
|
+
scope { Entry }
|
202
|
+
column(:name, :url => lambda {|model| false})
|
225
203
|
end
|
204
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
205
|
+
"tr td.name" => "Star"
|
206
|
+
)
|
207
|
+
end
|
226
208
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
content_tag(:span, "#{model.name}-#{grid.assets.klass}" )
|
232
|
-
end
|
233
|
-
end
|
234
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
235
|
-
"tr td.name span" => "Star-Entry"
|
236
|
-
)
|
209
|
+
it "should add ordering classes to column" do
|
210
|
+
rp = test_report(:order => :name) do
|
211
|
+
scope { Entry }
|
212
|
+
column(:name)
|
237
213
|
end
|
214
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
215
|
+
"tr td.name.ordered.asc" => "Star"
|
216
|
+
)
|
217
|
+
end
|
238
218
|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
content_tag :h1, "#{data}-#{model.name.downcase}"
|
244
|
-
})
|
245
|
-
end
|
246
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
247
|
-
"tr td.name h1" => "Star-star"
|
248
|
-
)
|
219
|
+
it "should add ordering classes to column" do
|
220
|
+
rp = test_report(:order => :name, :descending => true) do
|
221
|
+
scope { Entry }
|
222
|
+
column(:name)
|
249
223
|
end
|
224
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
225
|
+
"tr td.name.ordered.desc" => "Star"
|
226
|
+
)
|
227
|
+
end
|
250
228
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
})
|
229
|
+
it "should render html columns" do
|
230
|
+
rp = test_report do
|
231
|
+
scope { Entry }
|
232
|
+
column(:name, :html => true) do |model|
|
233
|
+
content_tag(:span, model.name)
|
257
234
|
end
|
258
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
259
|
-
"tr td.name h1" => "Star-star-Entry"
|
260
|
-
)
|
261
235
|
end
|
236
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
237
|
+
"tr td.name span" => "Star"
|
238
|
+
)
|
239
|
+
end
|
262
240
|
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
content_tag :h1, "#{data}-#{model.name}"
|
268
|
-
}) do
|
269
|
-
self.name.upcase
|
270
|
-
end
|
271
|
-
end
|
272
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
273
|
-
"tr td.name h1" => "STAR-Star"
|
274
|
-
)
|
241
|
+
it "should render argument-based html columns" do
|
242
|
+
rp = test_report do
|
243
|
+
scope { Entry }
|
244
|
+
column(:name, :html => lambda {|data| content_tag :h1, data})
|
275
245
|
end
|
246
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
247
|
+
"tr td.name h1" => "Star"
|
248
|
+
)
|
249
|
+
end
|
276
250
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
}) do
|
283
|
-
self.name.upcase
|
284
|
-
end
|
251
|
+
it "should render argument-based html columns with custom data" do
|
252
|
+
rp = test_report do
|
253
|
+
scope { Entry }
|
254
|
+
column(:name, :html => lambda {|data| content_tag :em, data}) do
|
255
|
+
self.name.upcase
|
285
256
|
end
|
286
|
-
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
287
|
-
"tr td.name h1" => "STAR-Star-Entry"
|
288
|
-
)
|
289
257
|
end
|
258
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
259
|
+
"tr td.name em" => "STAR"
|
260
|
+
)
|
261
|
+
end
|
290
262
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
263
|
+
it "should render html columns with double arguments for column" do
|
264
|
+
rp = test_report do
|
265
|
+
scope { Entry }
|
266
|
+
column(:name, :html => true) do |model, grid|
|
267
|
+
content_tag(:span, "#{model.name}-#{grid.assets.klass}" )
|
296
268
|
end
|
297
|
-
expect(subject.datagrid_rows(rp, [entry], :columns => [:name])).to match_css_pattern(
|
298
|
-
"tr td.name" => "Star"
|
299
|
-
)
|
300
|
-
expect(subject.datagrid_rows(rp, [entry], :columns => [:name])).to match_css_pattern(
|
301
|
-
"tr td.category" => 0
|
302
|
-
)
|
303
269
|
end
|
270
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
271
|
+
"tr td.name span" => "Star-Entry"
|
272
|
+
)
|
273
|
+
end
|
304
274
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
275
|
+
it "should render argument-based html blocks with double arguments" do
|
276
|
+
rp = test_report do
|
277
|
+
scope { Entry }
|
278
|
+
column(:name, :html => lambda { |data, model|
|
279
|
+
content_tag :h1, "#{data}-#{model.name.downcase}"
|
280
|
+
})
|
281
|
+
end
|
282
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
283
|
+
"tr td.name h1" => "Star-star"
|
284
|
+
)
|
285
|
+
end
|
310
286
|
|
311
|
-
|
312
|
-
|
313
|
-
|
287
|
+
it "should render argument-based html blocks with triple arguments" do
|
288
|
+
rp = test_report do
|
289
|
+
scope { Entry }
|
290
|
+
column(:name, :html => lambda { |data, model, grid|
|
291
|
+
content_tag :h1, "#{data}-#{model.name.downcase}-#{grid.assets.klass}"
|
292
|
+
})
|
314
293
|
end
|
294
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
295
|
+
"tr td.name h1" => "Star-star-Entry"
|
296
|
+
)
|
297
|
+
end
|
315
298
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
end
|
324
|
-
end
|
325
|
-
end
|
326
|
-
it "should ignore them" do
|
327
|
-
expect(subject.datagrid_rows(grid, [entry])).to match_css_pattern(
|
328
|
-
"td.name" => 1
|
329
|
-
)
|
299
|
+
it "should render argument-based html blocks with double arguments and custom data" do
|
300
|
+
rp = test_report do
|
301
|
+
scope { Entry }
|
302
|
+
column(:name, :html => lambda { |data, model|
|
303
|
+
content_tag :h1, "#{data}-#{model.name}"
|
304
|
+
}) do
|
305
|
+
self.name.upcase
|
330
306
|
end
|
331
307
|
end
|
308
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
309
|
+
"tr td.name h1" => "STAR-Star"
|
310
|
+
)
|
332
311
|
end
|
333
312
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
313
|
+
it "should render argument-based html blocks with triple arguments and custom data" do
|
314
|
+
rp = test_report do
|
315
|
+
scope { Entry }
|
316
|
+
column(:name, :html => lambda { |data, model, grid|
|
317
|
+
content_tag :h1, "#{data}-#{model.name}-#{grid.assets.klass}"
|
318
|
+
}) do
|
319
|
+
self.name.upcase
|
340
320
|
end
|
341
|
-
grid = OrderedGrid.new(:descending => true, :order => :category)
|
342
|
-
expect(subject.datagrid_order_for(grid, grid.column_by_name(:category))).to equal_to_dom(<<-HTML)
|
343
|
-
<div class="order">
|
344
|
-
<a href="/location?ordered_grid%5Bdescending%5D=false&ordered_grid%5Border%5D=category" class="asc">↑</a>
|
345
|
-
<a href="/location?ordered_grid%5Bdescending%5D=true&ordered_grid%5Border%5D=category" class="desc">↓</a>
|
346
|
-
</div>
|
347
|
-
HTML
|
348
321
|
end
|
322
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
323
|
+
"tr td.name h1" => "STAR-Star-Entry"
|
324
|
+
)
|
349
325
|
end
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
expect(rendered_form).to include 'Namespaced form partial.'
|
326
|
+
|
327
|
+
it "should support columns option" do
|
328
|
+
rp = test_report do
|
329
|
+
scope { Entry }
|
330
|
+
column(:name)
|
331
|
+
column(:category)
|
357
332
|
end
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
"form input[name=commit][value=Search]" => 1,
|
371
|
-
"form a.datagrid-reset[href='/location']" => 1
|
372
|
-
)
|
333
|
+
expect(subject.datagrid_rows(rp, [entry], :columns => [:name])).to match_css_pattern(
|
334
|
+
"tr td.name" => "Star"
|
335
|
+
)
|
336
|
+
expect(subject.datagrid_rows(rp, [entry], :columns => [:name])).to match_css_pattern(
|
337
|
+
"tr td.category" => 0
|
338
|
+
)
|
339
|
+
end
|
340
|
+
|
341
|
+
it "should allow CSS classes to be specified for a column" do
|
342
|
+
rp = test_report do
|
343
|
+
scope { Entry }
|
344
|
+
column(:name, :class => 'my_class')
|
373
345
|
end
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
346
|
+
|
347
|
+
expect(subject.datagrid_rows(rp, [entry])).to match_css_pattern(
|
348
|
+
"tr td.name.my_class" => "Star"
|
349
|
+
)
|
350
|
+
end
|
351
|
+
|
352
|
+
context "when grid has complicated columns" do
|
353
|
+
let(:grid) do
|
354
|
+
test_report(:name => 'Hello') do
|
355
|
+
scope {Entry}
|
356
|
+
filter(:name)
|
357
|
+
column(:name) do |model, grid|
|
358
|
+
"'#{model.name}' filtered by '#{grid.name}'"
|
380
359
|
end
|
381
360
|
end
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
"
|
361
|
+
end
|
362
|
+
it "should ignore them" do
|
363
|
+
expect(subject.datagrid_rows(grid, [entry])).to match_css_pattern(
|
364
|
+
"td.name" => 1
|
386
365
|
)
|
387
366
|
end
|
367
|
+
end
|
368
|
+
end
|
388
369
|
|
389
|
-
|
390
|
-
|
370
|
+
describe ".datagrid_order_for" do
|
371
|
+
it "should render ordering layout" do
|
372
|
+
class OrderedGrid
|
373
|
+
include Datagrid
|
374
|
+
scope { Entry }
|
375
|
+
column(:category)
|
376
|
+
end
|
377
|
+
grid = OrderedGrid.new(:descending => true, :order => :category)
|
378
|
+
expect(subject.datagrid_order_for(grid, grid.column_by_name(:category))).to equal_to_dom(<<-HTML)
|
379
|
+
<div class="order">
|
380
|
+
<a href="/location?ordered_grid%5Bdescending%5D=false&ordered_grid%5Border%5D=category" class="asc">↑</a>
|
381
|
+
<a href="/location?ordered_grid%5Bdescending%5D=true&ordered_grid%5Border%5D=category" class="desc">↓</a>
|
382
|
+
</div>
|
383
|
+
HTML
|
384
|
+
end
|
385
|
+
end
|
386
|
+
describe ".datagrid_form_for" do
|
387
|
+
it 'returns namespaced partial if partials options is passed' do
|
388
|
+
rendered_form = subject.datagrid_form_for(grid, {
|
389
|
+
:url => '',
|
390
|
+
:partials => 'client/datagrid'
|
391
|
+
})
|
392
|
+
expect(rendered_form).to include 'Namespaced form partial.'
|
393
|
+
end
|
394
|
+
it "should render form and filter inputs" do
|
395
|
+
class FormForGrid
|
396
|
+
include Datagrid
|
397
|
+
scope { Entry }
|
398
|
+
filter(:category)
|
399
|
+
end
|
400
|
+
grid = FormForGrid.new(:category => "hello")
|
401
|
+
expect(subject.datagrid_form_for(grid, :url => "/grid")).to match_css_pattern(
|
402
|
+
"form.datagrid-form.form_for_grid[action='/grid']" => 1,
|
403
|
+
"form input[name=utf8]" => 1,
|
404
|
+
"form .filter label" => "Category",
|
405
|
+
"form .filter input.category.default_filter[name='form_for_grid[category]'][value=hello]" => 1,
|
406
|
+
"form input[name=commit][value=Search]" => 1,
|
407
|
+
"form a.datagrid-reset[href='/location']" => 1
|
408
|
+
)
|
409
|
+
end
|
410
|
+
it "should support html classes for grid class with namespace" do
|
411
|
+
module ::Ns22
|
412
|
+
class TestGrid
|
391
413
|
include Datagrid
|
392
414
|
scope { Entry }
|
393
415
|
filter(:id)
|
394
|
-
def param_name
|
395
|
-
'g'
|
396
|
-
end
|
397
416
|
end
|
398
|
-
expect(subject.datagrid_form_for(::ParamNameGrid81.new, :url => "/grid")).to match_css_pattern(
|
399
|
-
"form.datagrid-form input[name='g[id]']" => 1,
|
400
|
-
)
|
401
417
|
end
|
418
|
+
expect(subject.datagrid_form_for(::Ns22::TestGrid.new, :url => "grid")).to match_css_pattern(
|
419
|
+
"form.datagrid-form.ns22_test_grid" => 1,
|
420
|
+
"form.datagrid-form label[for=ns22_test_grid_id]" => 1,
|
421
|
+
"form.datagrid-form input#ns22_test_grid_id[name='ns22_test_grid[id]']" => 1,
|
422
|
+
)
|
402
423
|
end
|
403
424
|
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
425
|
+
it "should have overridable param_name method" do
|
426
|
+
class ParamNameGrid81
|
427
|
+
include Datagrid
|
428
|
+
scope { Entry }
|
429
|
+
filter(:id)
|
430
|
+
def param_name
|
431
|
+
'g'
|
411
432
|
end
|
412
433
|
end
|
434
|
+
expect(subject.datagrid_form_for(::ParamNameGrid81.new, :url => "/grid")).to match_css_pattern(
|
435
|
+
"form.datagrid-form input[name='g[id]']" => 1,
|
436
|
+
)
|
437
|
+
end
|
438
|
+
end
|
413
439
|
|
414
|
-
let(:entry) do
|
415
|
-
Entry.create!(:name => "Hello", :category => "greetings")
|
416
|
-
end
|
417
440
|
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
441
|
+
describe ".datagrid_row" do
|
442
|
+
let(:grid) do
|
443
|
+
test_report do
|
444
|
+
scope { Entry }
|
445
|
+
column(:name)
|
446
|
+
column(:category)
|
422
447
|
end
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
448
|
+
end
|
449
|
+
|
450
|
+
let(:entry) do
|
451
|
+
Entry.create!(:name => "Hello", :category => "greetings")
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should provide access to row data" do
|
455
|
+
r = subject.datagrid_row(grid, entry)
|
456
|
+
expect(r.name).to eq("Hello")
|
457
|
+
expect(r.category).to eq("greetings")
|
458
|
+
end
|
459
|
+
it "should yield block" do
|
460
|
+
subject.datagrid_row(grid, entry) do |row|
|
461
|
+
expect(row.name).to eq("Hello")
|
462
|
+
expect(row.category).to eq("greetings")
|
428
463
|
end
|
464
|
+
end
|
429
465
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
end
|
436
|
-
expect(name).to eq("Hello,greetings")
|
466
|
+
it "should output data from block" do
|
467
|
+
name = subject.datagrid_row(grid, entry) do |row|
|
468
|
+
subject.concat(row.name)
|
469
|
+
subject.concat(",")
|
470
|
+
subject.concat(row.category)
|
437
471
|
end
|
472
|
+
expect(name).to eq("Hello,greetings")
|
438
473
|
end
|
439
474
|
end
|
440
475
|
|
data/spec/support/matchers.rb
CHANGED
@@ -83,7 +83,11 @@ class CssPattern
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def failure_message
|
86
|
-
"Expected
|
86
|
+
"Expected to match dom pattern. But it wasn't."
|
87
|
+
end
|
88
|
+
|
89
|
+
def failure_message_when_negated
|
90
|
+
"Expected to not match dom pattern. But it was."
|
87
91
|
end
|
88
92
|
|
89
93
|
def description
|
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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bogdan Gusiev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|