magic_grid 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/magic_grid/collection.rb +8 -5
- data/lib/magic_grid/version.rb +1 -1
- data/spec/definition_spec.rb +41 -8
- metadata +3 -3
@@ -222,11 +222,14 @@ module MagicGrid
|
|
222
222
|
@sorts.each do |ordering|
|
223
223
|
collection = collection.order(ordering)
|
224
224
|
end
|
225
|
-
@filter_callbacks.
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
225
|
+
if @filter_callbacks.empty?
|
226
|
+
@filters.each do |hsh|
|
227
|
+
collection = collection.where(hsh)
|
228
|
+
end
|
229
|
+
else
|
230
|
+
@filter_callbacks.each do |callback|
|
231
|
+
collection = callback.call(collection)
|
232
|
+
end
|
230
233
|
end
|
231
234
|
@searches.each do |query|
|
232
235
|
collection = perform_search(collection, query)
|
data/lib/magic_grid/version.rb
CHANGED
data/spec/definition_spec.rb
CHANGED
@@ -151,24 +151,57 @@ describe MagicGrid::Definition do
|
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
context "filtering
|
154
|
+
context "filtering" do
|
155
155
|
data = [1,56,7,21,1]
|
156
156
|
filter = Proc.new do |c|
|
157
157
|
c.select { |i| i > 10 }
|
158
158
|
end
|
159
159
|
let(:controller) {
|
160
160
|
controller = double.tap do |c|
|
161
|
-
c.stub(:params) { HashWithIndifferentAccess.new({
|
161
|
+
c.stub(:params) { HashWithIndifferentAccess.new({column_name: 1}) }
|
162
162
|
end
|
163
163
|
}
|
164
|
-
let(:collection) {
|
165
|
-
|
166
|
-
|
167
|
-
|
164
|
+
let(:collection) { data }
|
165
|
+
|
166
|
+
it "should use a listener_hanlder callback when given one" do
|
167
|
+
options = {
|
168
|
+
id: :grid,
|
169
|
+
listener_handler: filter
|
170
|
+
}
|
171
|
+
grid = MagicGrid::Definition.new([{sql: "foo"}],
|
168
172
|
collection,
|
169
173
|
controller,
|
170
|
-
|
171
|
-
|
174
|
+
options)
|
175
|
+
grid.collection.should == [56, 21]
|
176
|
+
end
|
177
|
+
|
178
|
+
it "should use listeners as where filters when given and set" do
|
179
|
+
options = {
|
180
|
+
id: :grid,
|
181
|
+
listeners: { input_id: :column_name }
|
182
|
+
}
|
183
|
+
collection.should_receive(:where).with("column_name" => 1).and_return([1,2,3])
|
184
|
+
grid = MagicGrid::Definition.new([{sql: "foo"}],
|
185
|
+
collection,
|
186
|
+
controller,
|
187
|
+
options)
|
188
|
+
grid.collection.should == [1,2,3]
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should ignore listener params when a listener_hanlder callback is given" do
|
192
|
+
options = {
|
193
|
+
id: :grid,
|
194
|
+
listener_handler: filter,
|
195
|
+
listeners: { input_id: :column_name }
|
196
|
+
}
|
197
|
+
collection.should_not_receive(:where)
|
198
|
+
grid = MagicGrid::Definition.new([{sql: "foo"}],
|
199
|
+
collection,
|
200
|
+
controller,
|
201
|
+
options)
|
202
|
+
grid.collection.should == [56, 21]
|
203
|
+
end
|
204
|
+
|
172
205
|
end
|
173
206
|
|
174
207
|
pending "test listening on a dumb collection"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magic_grid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -215,7 +215,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
215
215
|
version: '0'
|
216
216
|
segments:
|
217
217
|
- 0
|
218
|
-
hash:
|
218
|
+
hash: 1453942600846998467
|
219
219
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
220
|
none: false
|
221
221
|
requirements:
|
@@ -224,7 +224,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
224
|
version: '0'
|
225
225
|
segments:
|
226
226
|
- 0
|
227
|
-
hash:
|
227
|
+
hash: 1453942600846998467
|
228
228
|
requirements: []
|
229
229
|
rubyforge_project:
|
230
230
|
rubygems_version: 1.8.23
|