magic_grid 0.12.3 → 0.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -2
- data/lib/magic_grid/collection.rb +33 -21
- data/lib/magic_grid/column.rb +3 -3
- data/lib/magic_grid/definition.rb +21 -22
- data/lib/magic_grid/html_grid.rb +37 -37
- data/lib/magic_grid/version.rb +1 -1
- data/spec/collection_spec.rb +95 -19
- data/spec/column_spec.rb +1 -1
- data/spec/definition_spec.rb +32 -32
- data/spec/helpers_spec.rb +25 -25
- data/spec/html_grid_spec.rb +37 -10
- data/spec/spec_helper.rb +12 -7
- data/test/dummy/app/controllers/posts_controller.rb +11 -11
- data/test/dummy/app/controllers/users_controller.rb +11 -11
- data/test/dummy/app/views/posts/by_user.html.erb +1 -1
- data/test/dummy/app/views/posts/index.html.erb +4 -4
- data/test/dummy/app/views/users/index.html.erb +2 -2
- data/test/dummy/config/initializers/session_store.rb +1 -1
- data/test/dummy/config/initializers/wrap_parameters.rb +1 -1
- data/test/dummy/test/fixtures/posts.yml +1 -1
- data/test/dummy/test/functional/posts_controller_test.rb +5 -5
- data/test/dummy/test/functional/users_controller_test.rb +5 -5
- metadata +26 -26
data/spec/column_spec.rb
CHANGED
@@ -45,7 +45,7 @@ describe MagicGrid::Column do
|
|
45
45
|
data = [1,2,3].tap do |c|
|
46
46
|
c.stub(:search) { c }
|
47
47
|
end
|
48
|
-
MagicGrid::Collection.new(data, search_method
|
48
|
+
MagicGrid::Collection.new(data, :search_method => :search)
|
49
49
|
}
|
50
50
|
# I actually consider this a bug, since it is totally inconsistent, but
|
51
51
|
# it's how things are currently implemented.
|
data/spec/definition_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe MagicGrid::Definition do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
let (:empty_collection) { [] }
|
27
|
-
let (:large_collection) { 200.times.map { |i| {id
|
27
|
+
let (:large_collection) { 200.times.map { |i| {:id => i, :name => "Name", :description => "Describe me!"} } }
|
28
28
|
let (:column_list) { [:name, :description] }
|
29
29
|
let (:column_hash) { {} }
|
30
30
|
|
@@ -52,13 +52,13 @@ describe MagicGrid::Definition do
|
|
52
52
|
}
|
53
53
|
it "doesn't barf when listeners are given for a dumb collection" do
|
54
54
|
expect {
|
55
|
-
MagicGrid::Definition.new([:a], [1], controller, listeners
|
55
|
+
MagicGrid::Definition.new([:a], [1], controller, :listeners => {:a => :a})
|
56
56
|
}.not_to raise_error
|
57
57
|
end
|
58
58
|
|
59
59
|
it "doesn't barf when search columns are given for a dumb collection" do
|
60
60
|
expect {
|
61
|
-
MagicGrid::Definition.new([:a], [1], controller, searchable
|
61
|
+
MagicGrid::Definition.new([:a], [1], controller, :searchable => [:a])
|
62
62
|
}.not_to raise_error
|
63
63
|
end
|
64
64
|
end
|
@@ -71,7 +71,7 @@ describe MagicGrid::Definition do
|
|
71
71
|
it_behaves_like "a basic grid"
|
72
72
|
|
73
73
|
context "when pagination is disabled" do
|
74
|
-
subject { MagicGrid::Definition.new(column_list, empty_collection, nil, per_page
|
74
|
+
subject { MagicGrid::Definition.new(column_list, empty_collection, nil, :per_page => false) }
|
75
75
|
its(:current_page) { should == 1 }
|
76
76
|
its(:collection) { should be_empty }
|
77
77
|
end
|
@@ -80,7 +80,7 @@ describe MagicGrid::Definition do
|
|
80
80
|
context "when given a large collection and default options" do
|
81
81
|
let(:controller) {
|
82
82
|
controller = double()
|
83
|
-
controller.stub(:params) { {page
|
83
|
+
controller.stub(:params) { {:page => 2} }
|
84
84
|
controller
|
85
85
|
}
|
86
86
|
subject { MagicGrid::Definition.new(column_list, large_collection, controller) }
|
@@ -101,10 +101,10 @@ describe MagicGrid::Definition do
|
|
101
101
|
context "when given a large collection and some options" do
|
102
102
|
let(:controller) {
|
103
103
|
controller = double()
|
104
|
-
controller.stub(:params) { HashWithIndifferentAccess.new({grid_page
|
104
|
+
controller.stub(:params) { HashWithIndifferentAccess.new({:grid_page => 2}) }
|
105
105
|
controller
|
106
106
|
}
|
107
|
-
subject { MagicGrid::Definition.new(column_list, large_collection, controller, id
|
107
|
+
subject { MagicGrid::Definition.new(column_list, large_collection, controller, :id => :grid, :per_page => 17) }
|
108
108
|
its(:collection) { should_not == empty_collection }
|
109
109
|
it "should give a collection with a page worth of items" do
|
110
110
|
subject.magic_collection.per_page.should < large_collection.count
|
@@ -124,13 +124,13 @@ describe MagicGrid::Definition do
|
|
124
124
|
data = [1,56,7,21,1]
|
125
125
|
let(:controller) {
|
126
126
|
controller = double()
|
127
|
-
controller.stub(:params) { HashWithIndifferentAccess.new({grid_order
|
127
|
+
controller.stub(:params) { HashWithIndifferentAccess.new({:grid_order => 1}) }
|
128
128
|
controller
|
129
129
|
}
|
130
130
|
let(:collection) { data }
|
131
131
|
it "should sort collection using #order" do
|
132
132
|
collection.should_receive(:order).with("foo DESC") { data.sort.reverse }
|
133
|
-
grid = MagicGrid::Definition.new([{sql
|
133
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}], collection, controller, :id => :grid)
|
134
134
|
|
135
135
|
grid.collection.should == data.sort.reverse
|
136
136
|
end
|
@@ -139,14 +139,14 @@ describe MagicGrid::Definition do
|
|
139
139
|
|
140
140
|
context "filtering with #where" do
|
141
141
|
it "should use listeners with #where when asked to" do
|
142
|
-
filter_param = HashWithIndifferentAccess.new({f1
|
143
|
-
controller = double(params
|
142
|
+
filter_param = HashWithIndifferentAccess.new({:f1 => 1})
|
143
|
+
controller = double(:params => filter_param)
|
144
144
|
collection = [1,56,7,21,1]
|
145
145
|
collection.should_receive(:where).with(filter_param).and_return([1, 7, 1])
|
146
|
-
grid = MagicGrid::Definition.new([{sql
|
146
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}],
|
147
147
|
collection,
|
148
148
|
controller,
|
149
|
-
id
|
149
|
+
:id => :grid, :listeners => {:f1 => :f1})
|
150
150
|
grid.collection.should == [1, 7, 1]
|
151
151
|
end
|
152
152
|
end
|
@@ -158,17 +158,17 @@ describe MagicGrid::Definition do
|
|
158
158
|
end
|
159
159
|
let(:controller) {
|
160
160
|
controller = double.tap do |c|
|
161
|
-
c.stub(:params) { HashWithIndifferentAccess.new({column_name
|
161
|
+
c.stub(:params) { HashWithIndifferentAccess.new({:column_name => 1}) }
|
162
162
|
end
|
163
163
|
}
|
164
164
|
let(:collection) { data }
|
165
165
|
|
166
166
|
it "should use a listener_hanlder callback when given one" do
|
167
167
|
options = {
|
168
|
-
id
|
169
|
-
listener_handler
|
168
|
+
:id => :grid,
|
169
|
+
:listener_handler => filter
|
170
170
|
}
|
171
|
-
grid = MagicGrid::Definition.new([{sql
|
171
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}],
|
172
172
|
collection,
|
173
173
|
controller,
|
174
174
|
options)
|
@@ -177,11 +177,11 @@ describe MagicGrid::Definition do
|
|
177
177
|
|
178
178
|
it "should use listeners as where filters when given and set" do
|
179
179
|
options = {
|
180
|
-
id
|
181
|
-
listeners
|
180
|
+
:id => :grid,
|
181
|
+
:listeners => { :input_id => :column_name }
|
182
182
|
}
|
183
183
|
collection.should_receive(:where).with("column_name" => 1).and_return([1,2,3])
|
184
|
-
grid = MagicGrid::Definition.new([{sql
|
184
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}],
|
185
185
|
collection,
|
186
186
|
controller,
|
187
187
|
options)
|
@@ -190,12 +190,12 @@ describe MagicGrid::Definition do
|
|
190
190
|
|
191
191
|
it "should ignore listener params when a listener_hanlder callback is given" do
|
192
192
|
options = {
|
193
|
-
id
|
194
|
-
listener_handler
|
195
|
-
listeners
|
193
|
+
:id => :grid,
|
194
|
+
:listener_handler => filter,
|
195
|
+
:listeners => { :input_id => :column_name }
|
196
196
|
}
|
197
197
|
collection.should_not_receive(:where)
|
198
|
-
grid = MagicGrid::Definition.new([{sql
|
198
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}],
|
199
199
|
collection,
|
200
200
|
controller,
|
201
201
|
options)
|
@@ -213,16 +213,16 @@ describe MagicGrid::Definition do
|
|
213
213
|
end
|
214
214
|
let(:controller) {
|
215
215
|
controller = double.tap do |c|
|
216
|
-
c.stub(:params) { HashWithIndifferentAccess.new({f1
|
216
|
+
c.stub(:params) { HashWithIndifferentAccess.new({:f1 => 1}) }
|
217
217
|
end
|
218
218
|
}
|
219
219
|
let(:collection) {
|
220
220
|
data
|
221
221
|
}
|
222
|
-
subject { MagicGrid::Definition.new([{sql
|
222
|
+
subject { MagicGrid::Definition.new([{:sql => "foo"}],
|
223
223
|
collection,
|
224
224
|
controller,
|
225
|
-
id
|
225
|
+
:id => :grid, :post_filter => filter) }
|
226
226
|
its(:collection) { should == [56, 21] }
|
227
227
|
end
|
228
228
|
|
@@ -230,7 +230,7 @@ describe MagicGrid::Definition do
|
|
230
230
|
data = [1,56,7,21,1]
|
231
231
|
let(:controller) {
|
232
232
|
controller = double.tap do |c|
|
233
|
-
c.stub(:params) { HashWithIndifferentAccess.new({f1
|
233
|
+
c.stub(:params) { HashWithIndifferentAccess.new({:f1 => 1}) }
|
234
234
|
end
|
235
235
|
}
|
236
236
|
let(:collection) {
|
@@ -241,20 +241,20 @@ describe MagicGrid::Definition do
|
|
241
241
|
end
|
242
242
|
}
|
243
243
|
it "should use the collection's post_filter method" do
|
244
|
-
grid = MagicGrid::Definition.new([{sql
|
244
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}],
|
245
245
|
collection,
|
246
246
|
controller,
|
247
|
-
id
|
247
|
+
:id => :grid, :collection_post_filter => true)
|
248
248
|
|
249
249
|
data.should_receive(:post_filter).with().and_return([1,2,3,4])
|
250
250
|
grid.collection.should == [1,2,3,4]
|
251
251
|
grid.collection.should_not be_empty
|
252
252
|
end
|
253
253
|
it "can be disabled via the collection_post_filter option" do
|
254
|
-
grid = MagicGrid::Definition.new([{sql
|
254
|
+
grid = MagicGrid::Definition.new([{:sql => "foo"}],
|
255
255
|
collection,
|
256
256
|
controller,
|
257
|
-
id
|
257
|
+
:id => :grid, :collection_post_filter => false)
|
258
258
|
|
259
259
|
data.should_not_receive(:post_filter)
|
260
260
|
grid.collection.should == data
|
data/spec/helpers_spec.rb
CHANGED
@@ -44,7 +44,7 @@ describe MagicGrid::Helpers do
|
|
44
44
|
if_emtpy_string
|
45
45
|
}
|
46
46
|
end
|
47
|
-
grid = magic_grid empty_collection, column_list, if_empty
|
47
|
+
grid = magic_grid empty_collection, column_list, :if_empty => callback
|
48
48
|
grid.should include(if_emtpy_string)
|
49
49
|
end
|
50
50
|
end
|
@@ -54,8 +54,8 @@ describe MagicGrid::Helpers do
|
|
54
54
|
it "should not indicate there is no data" do
|
55
55
|
should_not match(/if-empty/)
|
56
56
|
end
|
57
|
-
it { should match_select("td", text
|
58
|
-
it { should match_select("td", text
|
57
|
+
it { should match_select("td", :text => "1") }
|
58
|
+
it { should match_select("td", :text => "2") }
|
59
59
|
end
|
60
60
|
|
61
61
|
context "when given a block" do
|
@@ -92,7 +92,7 @@ describe MagicGrid::Helpers do
|
|
92
92
|
context "renders top and bottom pagers as told" do
|
93
93
|
large_collection = (1..1000).to_a
|
94
94
|
|
95
|
-
if
|
95
|
+
if defined? Kaminari
|
96
96
|
def render(*args)
|
97
97
|
"<nav class='pagination'><!-- paginate! --></nav>".html_safe
|
98
98
|
end
|
@@ -100,9 +100,9 @@ describe MagicGrid::Helpers do
|
|
100
100
|
|
101
101
|
it "should render an actual pager" do
|
102
102
|
grid = magic_grid(large_collection, [:to_s])
|
103
|
-
if
|
103
|
+
if $will_paginate
|
104
104
|
grid.should match_select("tfoot>tr>td.magic-pager>div.pagination", 1)
|
105
|
-
elsif
|
105
|
+
elsif $kaminari
|
106
106
|
grid.should match_select("tfoot>tr>td.magic-pager>nav.pagination", 1)
|
107
107
|
else
|
108
108
|
grid.should match_select("tfoot>tr>td.magic-pager", /INSTALL/)
|
@@ -114,12 +114,12 @@ describe MagicGrid::Helpers do
|
|
114
114
|
grid.should match_select("tfoot>tr>td.magic-pager", 1)
|
115
115
|
end
|
116
116
|
it "should render a top and bottom pager when told" do
|
117
|
-
grid = magic_grid( large_collection, [:to_s], top_pager
|
117
|
+
grid = magic_grid( large_collection, [:to_s], :top_pager => true )
|
118
118
|
grid.should match_select("thead>tr>td.magic-pager", 1)
|
119
119
|
grid.should match_select("tfoot>tr>td.magic-pager", 1)
|
120
120
|
end
|
121
121
|
it "should render only a top pager when told" do
|
122
|
-
grid = magic_grid( large_collection, [:to_s], top_pager
|
122
|
+
grid = magic_grid( large_collection, [:to_s], :top_pager => true, :bottom_pager => false )
|
123
123
|
grid.should match_select("thead>tr>td.magic-pager", 1)
|
124
124
|
grid.should match_select("tfoot>tr>td.magic-pager", 0)
|
125
125
|
end
|
@@ -132,7 +132,7 @@ describe MagicGrid::Helpers do
|
|
132
132
|
end
|
133
133
|
}
|
134
134
|
it "should only render one spinner" do
|
135
|
-
grid = magic_grid(searchabe_collection, column_list, searchable
|
135
|
+
grid = magic_grid(searchabe_collection, column_list, :searchable => [:some_col])
|
136
136
|
grid.should match_select("td.searcher", 1)
|
137
137
|
grid.should match_select("td.magic-pager", 1)
|
138
138
|
grid.should match_select(".magic_grid_spinner", 1)
|
@@ -146,7 +146,7 @@ describe MagicGrid::Helpers do
|
|
146
146
|
end
|
147
147
|
}
|
148
148
|
it "should render a search bar when asked" do
|
149
|
-
grid = magic_grid(searchabe_collection, column_list, searchable
|
149
|
+
grid = magic_grid(searchabe_collection, column_list, :searchable => [:some_col])
|
150
150
|
grid.should match_select('input[type=search]')
|
151
151
|
end
|
152
152
|
|
@@ -154,13 +154,13 @@ describe MagicGrid::Helpers do
|
|
154
154
|
let(:search_param) { 'foobar' }
|
155
155
|
let(:controller) {
|
156
156
|
make_controller.tap { |c|
|
157
|
-
c.stub(:params) { {grid_id_q
|
157
|
+
c.stub(:params) { {:grid_id_q => search_param} }
|
158
158
|
}
|
159
159
|
}
|
160
160
|
it "should search a searchable collection when there are search params" do
|
161
161
|
collection = (1..1000).to_a
|
162
162
|
collection.should_receive(:search).with(search_param) { collection }
|
163
|
-
grid = magic_grid(collection, column_list, id
|
163
|
+
grid = magic_grid(collection, column_list, :id => "grid_id", :searchable => [:some_col])
|
164
164
|
grid.should match_select('input[type=search]')
|
165
165
|
end
|
166
166
|
|
@@ -172,9 +172,9 @@ describe MagicGrid::Helpers do
|
|
172
172
|
|
173
173
|
collection = fake_active_record_collection(table_name)
|
174
174
|
collection.should_receive(:where).
|
175
|
-
with("#{search_sql} LIKE :search", {search
|
175
|
+
with("#{search_sql} LIKE :search", {:search => "%#{search_param}%"})
|
176
176
|
|
177
|
-
grid = magic_grid(collection, column_list, id
|
177
|
+
grid = magic_grid(collection, column_list, :id => "grid_id", :searchable => [search_col])
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should use custom sql from column for call to where when given" do
|
@@ -184,14 +184,14 @@ describe MagicGrid::Helpers do
|
|
184
184
|
|
185
185
|
collection = fake_active_record_collection(table_name)
|
186
186
|
collection.should_receive(:where).
|
187
|
-
with("#{search_sql} LIKE :search", {search
|
187
|
+
with("#{search_sql} LIKE :search", {:search => "%#{search_param}%"})
|
188
188
|
|
189
189
|
magic_grid(collection,
|
190
190
|
[ :name,
|
191
191
|
:description,
|
192
|
-
{col
|
192
|
+
{:col => search_col, :sql => search_sql}
|
193
193
|
],
|
194
|
-
id
|
194
|
+
:id => "grid_id", :searchable => [search_col])
|
195
195
|
end
|
196
196
|
|
197
197
|
it "should use column number to look up search column" do
|
@@ -201,14 +201,14 @@ describe MagicGrid::Helpers do
|
|
201
201
|
|
202
202
|
collection = fake_active_record_collection(table_name)
|
203
203
|
collection.should_receive(:where).
|
204
|
-
with("#{search_sql} LIKE :search", {search
|
204
|
+
with("#{search_sql} LIKE :search", {:search => "%#{search_param}%"})
|
205
205
|
|
206
206
|
magic_grid(collection,
|
207
207
|
[ :name,
|
208
208
|
:description,
|
209
|
-
{col
|
209
|
+
{:col => search_col, :sql => search_sql}
|
210
210
|
],
|
211
|
-
id
|
211
|
+
:id => "grid_id", :searchable => [2])
|
212
212
|
end
|
213
213
|
|
214
214
|
it "should use custom sql for call to where when given" do
|
@@ -219,14 +219,14 @@ describe MagicGrid::Helpers do
|
|
219
219
|
|
220
220
|
collection = fake_active_record_collection(table_name)
|
221
221
|
collection.should_receive(:where).
|
222
|
-
with("#{search_sql} LIKE :search", {search
|
222
|
+
with("#{search_sql} LIKE :search", {:search => "%#{search_param}%"})
|
223
223
|
|
224
224
|
magic_grid(collection,
|
225
225
|
[ :name,
|
226
226
|
:description,
|
227
|
-
{col
|
227
|
+
{:col => search_col, :sql => search_sql}
|
228
228
|
],
|
229
|
-
id
|
229
|
+
:id => "grid_id", :searchable => [custom_search_col])
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should fail when given bad searchable columns" do
|
@@ -236,7 +236,7 @@ describe MagicGrid::Helpers do
|
|
236
236
|
expect {
|
237
237
|
magic_grid(collection,
|
238
238
|
[ :name, :description],
|
239
|
-
id
|
239
|
+
:id => "grid_id", :searchable => [nil])
|
240
240
|
}.to raise_error
|
241
241
|
end
|
242
242
|
|
@@ -253,7 +253,7 @@ describe MagicGrid::Helpers do
|
|
253
253
|
end
|
254
254
|
|
255
255
|
expect {
|
256
|
-
magic_grid(collection, column_list, id
|
256
|
+
magic_grid(collection, column_list, :id => "grid_id", :searchable => [search_col])
|
257
257
|
}.to_not raise_error
|
258
258
|
end
|
259
259
|
end
|
data/spec/html_grid_spec.rb
CHANGED
@@ -20,7 +20,7 @@ describe MagicGrid::HtmlGrid do
|
|
20
20
|
callable = double.tap do |c|
|
21
21
|
c.should_receive(:call).with( record ) { tracer }
|
22
22
|
end
|
23
|
-
cols = [ {col
|
23
|
+
cols = [ {:col => 'Col', :to_s => callable} ]
|
24
24
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols), self
|
25
25
|
grid.grid_row( record ).should include(tracer)
|
26
26
|
end
|
@@ -29,7 +29,7 @@ describe MagicGrid::HtmlGrid do
|
|
29
29
|
callable = double.tap do |c|
|
30
30
|
c.should_receive(:call).with( record ) { tracer }
|
31
31
|
end
|
32
|
-
cols = [ {col
|
32
|
+
cols = [ {:col => callable, :label => "Column"} ]
|
33
33
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols), self
|
34
34
|
grid.grid_row( record ).should include(tracer)
|
35
35
|
end
|
@@ -40,14 +40,14 @@ describe MagicGrid::HtmlGrid do
|
|
40
40
|
|
41
41
|
it "should use :to_s as a method on record if it responds to it" do
|
42
42
|
record.should_receive(:some_inconceivable_method_name) { tracer }
|
43
|
-
cols = [ {col
|
43
|
+
cols = [ {:col => :some_col, :to_s => :some_inconceivable_method_name} ]
|
44
44
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols), self
|
45
45
|
grid.grid_row( record ).should include(tracer)
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should use :col as a method on record if it responds to it" do
|
49
49
|
record.should_receive(:some_inconceivable_method_name) { tracer }
|
50
|
-
cols = [ {col
|
50
|
+
cols = [ {:col => :some_inconceivable_method_name} ]
|
51
51
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols), self
|
52
52
|
grid.grid_row( record ).should include(tracer)
|
53
53
|
end
|
@@ -63,13 +63,13 @@ describe MagicGrid::HtmlGrid do
|
|
63
63
|
end
|
64
64
|
it "should use :label if no :sql is given" do
|
65
65
|
title = "A String"
|
66
|
-
cols = [{label
|
66
|
+
cols = [{:label => title}]
|
67
67
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols), self
|
68
68
|
grid.magic_column_headers.should include(title)
|
69
69
|
end
|
70
70
|
it "should make a sortable header if :sql is specified" do
|
71
71
|
tracer = "A MAGIC BULL??"
|
72
|
-
col = {sql
|
72
|
+
col = {:sql => 'some_col'}
|
73
73
|
cols = [col]
|
74
74
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols), self
|
75
75
|
# TODO: check parameters to sortable_header
|
@@ -80,7 +80,7 @@ describe MagicGrid::HtmlGrid do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
describe "#searcher_input" do
|
83
|
-
searchable_opts = { needs_searcher
|
83
|
+
searchable_opts = { :needs_searcher => true }
|
84
84
|
it "renders a search field" do
|
85
85
|
cols = [:some_col]
|
86
86
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols, nil, nil, searchable_opts), self
|
@@ -89,10 +89,10 @@ describe MagicGrid::HtmlGrid do
|
|
89
89
|
it "renders a search button if told to" do
|
90
90
|
tracer = "ZOMG! A BUTTON!"
|
91
91
|
cols = [:some_col]
|
92
|
-
opts = searchable_opts.merge(search_button
|
93
|
-
searcher_button
|
92
|
+
opts = searchable_opts.merge(:search_button => true,
|
93
|
+
:searcher_button => tracer)
|
94
94
|
grid = MagicGrid::HtmlGrid.new MagicGrid::Definition.new(cols, nil, nil, opts), self
|
95
|
-
grid.searcher_input.should match_select("button", text
|
95
|
+
grid.searcher_input.should match_select("button", :text => tracer)
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -114,4 +114,31 @@ describe MagicGrid::HtmlGrid do
|
|
114
114
|
subject.order_class(2).should == 'sort-none'
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
describe "#magic_pager" do
|
119
|
+
let(:definition) { MagicGrid::Definition.new(column_list) }
|
120
|
+
let(:collection) { definition.magic_collection }
|
121
|
+
it "should use will_paginate if available" do
|
122
|
+
view = double.tap { |v|
|
123
|
+
v.should_receive(:will_paginate).
|
124
|
+
with(collection.collection, {}).
|
125
|
+
and_return("WillPaginate was used!")
|
126
|
+
}
|
127
|
+
grid = MagicGrid::HtmlGrid.new(definition, view)
|
128
|
+
grid.magic_pager(collection).should == "WillPaginate was used!"
|
129
|
+
end
|
130
|
+
it "should use paginate if available and will_paginate is not" do
|
131
|
+
view = double.tap { |v|
|
132
|
+
v.should_receive(:paginate).
|
133
|
+
with(collection.collection, {}).
|
134
|
+
and_return("#paginate was used!")
|
135
|
+
}
|
136
|
+
grid = MagicGrid::HtmlGrid.new(definition, view)
|
137
|
+
grid.magic_pager(collection).should == "#paginate was used!"
|
138
|
+
end
|
139
|
+
it "should leave a comment for the dev if paginate and will_paginate are both missing" do
|
140
|
+
grid = MagicGrid::HtmlGrid.new(definition, double)
|
141
|
+
grid.magic_pager(collection).should =~ /INSTALL WillPaginate or Kaminari/
|
142
|
+
end
|
143
|
+
end
|
117
144
|
end
|