passive_record 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f2a727f0eddce997336fe91ab47ded8d9778365f
4
- data.tar.gz: d4db3194d0dffcc25ef26a73bbe6b777c3ff55ed
3
+ metadata.gz: 18a1452f744235927c24058ecabbe3e0314a21f6
4
+ data.tar.gz: e62c71b8af66ad7e22ce0d9ecae97d2c5b541ac1
5
5
  SHA512:
6
- metadata.gz: 61397fdf078c03795f36ebaec7a0a198cffb1cb05a6afc89468bc174392df06c17fdc8b4fa7681e1f200570393ff403e4b6872701312fdbfdc61203a6a389941
7
- data.tar.gz: 41e04c0eb08a0138cda6033ffa394440f0980fd174d3d579f0db62f5cb7d01a8e9293ff85a615e52b3d04af2acfdfe423c49d8673b4d7b58f5426289e5df7334
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
@@ -45,7 +45,6 @@ module PassiveRecord
45
45
  self
46
46
  end
47
47
 
48
-
49
48
  def before_update_hooks
50
49
  @hooks ||= []
51
50
  @hooks.select { |hook| hook.kind == :before_update }
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.3.3"
3
+ VERSION = "0.3.4"
4
4
  end
@@ -2,6 +2,7 @@ require 'ostruct'
2
2
 
3
3
  require 'active_support'
4
4
  require 'active_support/core_ext/string/inflections'
5
+ require 'active_support/core_ext/numeric/time'
5
6
 
6
7
  require 'passive_record/version'
7
8
  require 'passive_record/core/identifier'
@@ -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
@@ -7,7 +7,7 @@ require 'passive_record'
7
7
 
8
8
  class Model
9
9
  include PassiveRecord
10
- attr_reader :created_at
10
+ attr_accessor :created_at
11
11
  after_create { @created_at = Time.now }
12
12
  end
13
13
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passive_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman