datagrid 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -97,7 +97,6 @@ describe Datagrid::Helper do
97
97
  end
98
98
 
99
99
  describe ".datagrid_rows" do
100
-
101
100
  it "should support urls" do
102
101
  rp = test_report do
103
102
  scope { Entry }
@@ -107,6 +106,7 @@ describe Datagrid::Helper do
107
106
  "tr td.name a[href=Star]" => "Star"
108
107
  )
109
108
  end
109
+
110
110
  it "should support conditional urls" do
111
111
  rp = test_report do
112
112
  scope { Entry }
@@ -114,9 +114,9 @@ describe Datagrid::Helper do
114
114
  end
115
115
  subject.datagrid_rows(rp, [entry]).should match_css_pattern(
116
116
  "tr td.name" => "Star"
117
- )
118
-
117
+ )
119
118
  end
119
+
120
120
  it "should add ordering classes to column" do
121
121
  rp = test_report(:order => :name) do
122
122
  scope { Entry }
@@ -125,8 +125,8 @@ describe Datagrid::Helper do
125
125
  subject.datagrid_rows(rp, [entry]).should match_css_pattern(
126
126
  "tr td.name.ordered.asc" => "Star"
127
127
  )
128
-
129
128
  end
129
+
130
130
  it "should add ordering classes to column" do
131
131
  rp = test_report(:order => :name, :descending => true) do
132
132
  scope { Entry }
@@ -138,7 +138,6 @@ describe Datagrid::Helper do
138
138
  end
139
139
 
140
140
  it "should render html columns" do
141
-
142
141
  rp = test_report do
143
142
  scope { Entry }
144
143
  column(:name, :html => true) do |model|
@@ -150,6 +149,28 @@ describe Datagrid::Helper do
150
149
  )
151
150
  end
152
151
 
152
+ it "should render argument-based html columns" do
153
+ rp = test_report do
154
+ scope { Entry }
155
+ column(:name, :html => lambda {|data| content_tag :h1, data})
156
+ end
157
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
158
+ "tr td.name h1" => "Star"
159
+ )
160
+ end
161
+
162
+ it "should render argument-based html columns with custom data" do
163
+ rp = test_report do
164
+ scope { Entry }
165
+ column(:name, :html => lambda {|data| content_tag :em, data}) do
166
+ self.name.upcase
167
+ end
168
+ end
169
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
170
+ "tr td.name em" => "STAR"
171
+ )
172
+ end
173
+
153
174
  it "should render html columns with double arguments for column" do
154
175
  rp = test_report do
155
176
  scope { Entry }
@@ -162,6 +183,58 @@ describe Datagrid::Helper do
162
183
  )
163
184
  end
164
185
 
186
+ it "should render argument-based html blocks with double arguments" do
187
+ rp = test_report do
188
+ scope { Entry }
189
+ column(:name, :html => lambda { |data, model|
190
+ content_tag :h1, "#{data}-#{model.name.downcase}"
191
+ })
192
+ end
193
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
194
+ "tr td.name h1" => "Star-star"
195
+ )
196
+ end
197
+
198
+ it "should render argument-based html blocks with triple arguments" do
199
+ rp = test_report do
200
+ scope { Entry }
201
+ column(:name, :html => lambda { |data, model, grid|
202
+ content_tag :h1, "#{data}-#{model.name.downcase}-#{grid.assets.klass}"
203
+ })
204
+ end
205
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
206
+ "tr td.name h1" => "Star-star-Entry"
207
+ )
208
+ end
209
+
210
+ it "should render argument-based html blocks with double arguments and custom data" do
211
+ rp = test_report do
212
+ scope { Entry }
213
+ column(:name, :html => lambda { |data, model|
214
+ content_tag :h1, "#{data}-#{model.name}"
215
+ }) do
216
+ self.name.upcase
217
+ end
218
+ end
219
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
220
+ "tr td.name h1" => "STAR-Star"
221
+ )
222
+ end
223
+
224
+ it "should render argument-based html blocks with triple arguments and custom data" do
225
+ rp = test_report do
226
+ scope { Entry }
227
+ column(:name, :html => lambda { |data, model, grid|
228
+ content_tag :h1, "#{data}-#{model.name}-#{grid.assets.klass}"
229
+ }) do
230
+ self.name.upcase
231
+ end
232
+ end
233
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
234
+ "tr td.name h1" => "STAR-Star-Entry"
235
+ )
236
+ end
237
+
165
238
  it "should support columns option" do
166
239
  rp = test_report do
167
240
  scope { Entry }
@@ -176,6 +249,17 @@ describe Datagrid::Helper do
176
249
  )
177
250
  end
178
251
 
252
+ it "should allow CSS classes to be specified for a column" do
253
+ rp = test_report do
254
+ scope { Entry }
255
+ column(:name, :class => 'my_class')
256
+ end
257
+
258
+ subject.datagrid_rows(rp, [entry]).should match_css_pattern(
259
+ "tr td.name.my_class" => "Star"
260
+ )
261
+ end
262
+
179
263
  end
180
264
 
181
265
  describe ".datagrid_order_for" do
@@ -14,7 +14,7 @@ describe Datagrid::Ordering do
14
14
  Entry
15
15
  end
16
16
  column :name
17
- end.assets.should discover(first, second, third).with_exact_order
17
+ end.assets.should == [first, second, third]
18
18
 
19
19
  end
20
20
 
@@ -24,9 +24,7 @@ describe Datagrid::Ordering do
24
24
  Entry
25
25
  end
26
26
  column :name
27
- end.assets.should discover(third, second, first).with_exact_order
28
-
29
-
27
+ end.assets.should == [third, second, first]
30
28
  end
31
29
 
32
30
 
@@ -47,13 +45,25 @@ describe Datagrid::Ordering do
47
45
  end
48
46
 
49
47
  it "should override default order" do
48
+ test_report(:order => :name) do
49
+ scope { Entry.order("name desc")}
50
+ column(:name, :order => "name asc")
51
+ end.assets.should == [first, second, third]
52
+ end
50
53
 
51
- test_report(:order => :id) do
52
- scope { Entry.order("id desc")}
53
- column(:id) do
54
- self.order("id asc")
55
- end
56
- end.assets.should discover(first, second, third).with_exact_order
54
+ it "should support order given as block" do
55
+ test_report(:order => :name) do
56
+ scope { Entry }
57
+ column(:name, :order => proc { order("name desc") })
58
+ end.assets.should == [third, second, first]
59
+ end
60
+
61
+ it "should support order desc given as block" do
62
+ test_report(:order => :name, :descending => true) do
63
+ scope { Entry }
64
+ column(:name, :order_desc => proc { order("name desc")})
65
+ end.assets.should == [third, second, first]
57
66
  end
67
+
58
68
 
59
69
  end
@@ -17,7 +17,6 @@ require 'action_view'
17
17
  require "mongoid"
18
18
  require "mongo_mapper"
19
19
  require 'datagrid'
20
- require "discover"
21
20
  begin
22
21
  require 'ruby-debug'
23
22
  rescue LoadError
@@ -14,6 +14,8 @@ ActiveRecord::Schema.define(:version => 1) do
14
14
  t.integer :group_id
15
15
  t.string :name
16
16
  t.string :category
17
+ t.string :access_level
18
+ t.string :pet
17
19
  t.boolean :disabled, :null => false, :default => false
18
20
  t.boolean :confirmed, :null => false, :default => false
19
21
  t.date :shipping_date
@@ -40,6 +40,12 @@ class SimpleReport
40
40
  render :partial => "actions", :locals => {:model => model}
41
41
  end
42
42
 
43
+ column(:access_level, :html => lambda {|data| content_tag :h1, data})
44
+
45
+ column(:pet, :html => lambda {|data| content_tag :em, data}) do
46
+ self.pet.try(:upcase)
47
+ end
48
+
43
49
  def param_name
44
50
  :report
45
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-17 00:00:00.000000000 Z
12
+ date: 2012-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -107,22 +107,6 @@ dependencies:
107
107
  - - ! '>='
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
- - !ruby/object:Gem::Dependency
111
- name: accept_values_for
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
110
  - !ruby/object:Gem::Dependency
127
111
  name: nokogiri
128
112
  requirement: !ruby/object:Gem::Requirement
@@ -275,6 +259,7 @@ files:
275
259
  - lib/datagrid/filters/enum_filter.rb
276
260
  - lib/datagrid/filters/float_filter.rb
277
261
  - lib/datagrid/filters/integer_filter.rb
262
+ - lib/datagrid/filters/ranged_filter.rb
278
263
  - lib/datagrid/filters/string_filter.rb
279
264
  - lib/datagrid/form_builder.rb
280
265
  - lib/datagrid/helper.rb
@@ -291,8 +276,10 @@ files:
291
276
  - spec/datagrid/drivers/mongoid_spec.rb
292
277
  - spec/datagrid/filters/boolean_enum_filter_spec.rb
293
278
  - spec/datagrid/filters/composite_filters_spec.rb
279
+ - spec/datagrid/filters/date_filter_spec.rb
294
280
  - spec/datagrid/filters/enum_filter_spec.rb
295
281
  - spec/datagrid/filters/float_filter_spec.rb
282
+ - spec/datagrid/filters/integer_filter_spec.rb
296
283
  - spec/datagrid/filters_spec.rb
297
284
  - spec/datagrid/form_builder_spec.rb
298
285
  - spec/datagrid/helper_spec.rb
@@ -321,7 +308,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
321
308
  version: '0'
322
309
  segments:
323
310
  - 0
324
- hash: -1803543762513057738
311
+ hash: 813907041614063922
325
312
  required_rubygems_version: !ruby/object:Gem::Requirement
326
313
  none: false
327
314
  requirements: