pose 1.2.1 → 1.2.2
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/lib/pose/static_api.rb +4 -4
- data/lib/pose/version.rb +1 -1
- data/spec/pose_api_spec.rb +9 -10
- metadata +1 -1
data/lib/pose/static_api.rb
CHANGED
@@ -57,12 +57,12 @@ module Pose
|
|
57
57
|
if options[:result_type] == :ids
|
58
58
|
# Ids requested for result.
|
59
59
|
|
60
|
-
if options[:
|
60
|
+
if options[:where].blank?
|
61
61
|
# No scope.
|
62
62
|
result[result_class] = ids
|
63
63
|
else
|
64
64
|
# We have a scope.
|
65
|
-
options[:
|
65
|
+
options[:where].each do |scope|
|
66
66
|
query = result_class.select('id').where('id IN (?)', ids).where(scope).to_sql
|
67
67
|
result[result_class] = result_class.connection.select_values(query).map(&:to_i)
|
68
68
|
end
|
@@ -72,8 +72,8 @@ module Pose
|
|
72
72
|
# Classes requested for result.
|
73
73
|
|
74
74
|
result[result_class] = result_class.where(id: ids)
|
75
|
-
|
76
|
-
options[:
|
75
|
+
unless options[:where].blank?
|
76
|
+
options[:where].each do |scope|
|
77
77
|
result[result_class] = result[result_class].where('id IN (?)', ids).where(scope)
|
78
78
|
end
|
79
79
|
end
|
data/lib/pose/version.rb
CHANGED
data/spec/pose_api_spec.rb
CHANGED
@@ -45,7 +45,6 @@ describe Pose do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# TODO(REMOVE).
|
49
48
|
context "in the 'production' environment' do" do
|
50
49
|
before :each do
|
51
50
|
@old_env = Rails.env
|
@@ -197,7 +196,7 @@ describe Pose do
|
|
197
196
|
end
|
198
197
|
|
199
198
|
|
200
|
-
describe "'
|
199
|
+
describe "'where' parameter" do
|
201
200
|
|
202
201
|
before :each do
|
203
202
|
@one = FactoryGirl.create :posable_one, text: 'foo one', private: true
|
@@ -207,27 +206,27 @@ describe Pose do
|
|
207
206
|
|
208
207
|
context 'with result type :classes' do
|
209
208
|
|
210
|
-
it 'limits the result set by the given
|
211
|
-
result = Pose.search 'foo', PosableOne,
|
209
|
+
it 'limits the result set by the given conditions' do
|
210
|
+
result = Pose.search 'foo', PosableOne, where: [ private: true ]
|
212
211
|
result[PosableOne].should have(1).item
|
213
212
|
result[PosableOne].should include @one
|
214
213
|
end
|
215
214
|
|
216
215
|
it 'allows to use the hash syntax for queries' do
|
217
|
-
result = Pose.search 'foo', PosableOne,
|
216
|
+
result = Pose.search 'foo', PosableOne, where: [ private: true ]
|
218
217
|
result[PosableOne].should have(1).item
|
219
218
|
result[PosableOne].should include @one
|
220
219
|
end
|
221
220
|
|
222
221
|
it 'allows to use the string syntax for queries' do
|
223
|
-
result = Pose.search 'foo', PosableOne,
|
222
|
+
result = Pose.search 'foo', PosableOne, where: [ ['private = ?', true] ]
|
224
223
|
result[PosableOne].should have(1).item
|
225
224
|
result[PosableOne].should include @one
|
226
225
|
end
|
227
226
|
|
228
|
-
it 'allows to combine several
|
227
|
+
it 'allows to combine several conditions' do
|
229
228
|
@three = FactoryGirl.create :posable_one, text: 'foo two', private: true
|
230
|
-
result = Pose.search 'foo', PosableOne,
|
229
|
+
result = Pose.search 'foo', PosableOne, where: [ {private: true}, ['text = ?', 'foo two'] ]
|
231
230
|
result[PosableOne].should have(1).item
|
232
231
|
result[PosableOne].should include @three
|
233
232
|
end
|
@@ -235,8 +234,8 @@ describe Pose do
|
|
235
234
|
|
236
235
|
context 'with result type :ids' do
|
237
236
|
|
238
|
-
it 'limits the result set by the given
|
239
|
-
result = Pose.search 'foo', PosableOne, result_type: :ids,
|
237
|
+
it 'limits the result set by the given condition' do
|
238
|
+
result = Pose.search 'foo', PosableOne, result_type: :ids, where: [ private: true ]
|
240
239
|
result[PosableOne].should have(1).item
|
241
240
|
result[PosableOne].should include @one.id
|
242
241
|
end
|