passive_record 0.3.3 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/passive_record/core/query.rb +2 -0
- data/lib/passive_record/hooks.rb +0 -1
- data/lib/passive_record/version.rb +1 -1
- data/lib/passive_record.rb +1 -0
- data/spec/passive_record_spec.rb +19 -3
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18a1452f744235927c24058ecabbe3e0314a21f6
|
4
|
+
data.tar.gz: e62c71b8af66ad7e22ce0d9ecae97d2c5b541ac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e00bbcd3a411a87b31937a7bba75268568c451ca78b645da61e818e6fa27ddc269e25fc9a951bd087b620995c739d396c436301518fffc97ac7dac6d060a7662
|
7
|
+
data.tar.gz: 426d3d9ec2026ac6a10c53ffac4d6ef35e5f919c3e5019faf9e676233c687b5320a2f35e8561e1722a78961169c6783e7652920621751218dfc6bfb300a834a3
|
@@ -17,6 +17,8 @@ module PassiveRecord
|
|
17
17
|
conditions.all? do |(field,value)|
|
18
18
|
if value.is_a?(Hash)
|
19
19
|
evaluate_nested_conditions(instance, field, value)
|
20
|
+
elsif value.is_a?(Range) || value.is_a?(Array)
|
21
|
+
value.include?(instance.send(field))
|
20
22
|
else
|
21
23
|
instance.send(field) == value
|
22
24
|
end
|
data/lib/passive_record/hooks.rb
CHANGED
data/lib/passive_record.rb
CHANGED
data/spec/passive_record_spec.rb
CHANGED
@@ -149,7 +149,6 @@ describe "passive record models" do
|
|
149
149
|
end
|
150
150
|
|
151
151
|
it 'should find a single record through a nested query' do
|
152
|
-
# post_again = Post.find_by comments: { user: user }
|
153
152
|
expect(post).to eq(posts_with_comment_by_user)
|
154
153
|
end
|
155
154
|
|
@@ -159,9 +158,26 @@ describe "passive record models" do
|
|
159
158
|
|
160
159
|
posts = Post.find_all_by comments: { user: user }
|
161
160
|
expect(posts.count).to eq(2)
|
162
|
-
# expect(posts).to eq([post,another_post])
|
163
161
|
end
|
164
162
|
end
|
163
|
+
|
164
|
+
context 'queries with ranges' do
|
165
|
+
let(:model) { Model.create }
|
166
|
+
it 'should find where attribute value is in range' do
|
167
|
+
model.created_at = 2.days.ago
|
168
|
+
expect(Model.find_by(created_at: 3.days.ago..1.day.ago)).to eq(model)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'queries with arrays (subset)' do
|
173
|
+
it 'should find where attribute value is included in subset' do
|
174
|
+
model_a = Model.create(id: 10)
|
175
|
+
model_b = Model.create(id: 11)
|
176
|
+
Model.create(id: 12)
|
177
|
+
expect(Model.find_all_by(id: [10,11])).to eq([model_a, model_b])
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
165
181
|
end
|
166
182
|
end
|
167
183
|
end
|
@@ -199,7 +215,7 @@ describe "passive record models" do
|
|
199
215
|
another_toy = another_child.create_toy
|
200
216
|
expect(another_toy.child).to eq(another_child)
|
201
217
|
end
|
202
|
-
|
218
|
+
|
203
219
|
it 'should assign parents' do
|
204
220
|
toy = Toy.create
|
205
221
|
toy.child = child
|
data/spec/spec_helper.rb
CHANGED