passive_record 0.4.7 → 0.4.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50c7310ba09f037ee279f9ee0fb42cadb875c7b8
4
- data.tar.gz: 6d61cec9dca1338c117a996fa2330580e66861b4
3
+ metadata.gz: 7f039ca57502dbf0119be19278464cfc7cae14ab
4
+ data.tar.gz: 414f80e091cf917d897fd89fd28902c6f2563398
5
5
  SHA512:
6
- metadata.gz: 7422229e4baeac8309309ab02e043a1bda67ecdec36be394eea4ec29ad5c25dc21eeda9384c5f3e6b46120a3f28cfe36a81e350050596ce9f8d846e093d61fc9
7
- data.tar.gz: ef897faa83e6699f666f46c29334045ae1962ebe071ac87a19efbf840c9b3716d2c0e6ea176ec4b868f9d007dab8d0d75796a3c344538a714aa548fb6d7e26cd
6
+ metadata.gz: 24ce6d75265f9edf97ecf7aa55bb1e4d10f4deed2c7452c0f08758d5890db1bb12fd6369709e7ef06f6ac5bd66df1097ac64a7ca580bf1b5fffbba2bbd1f384b
7
+ data.tar.gz: 1f25bb2ec4160669a6332da359410a7f1f8fc0359bb175189f54fd4b84139d61565f92e74bc6e0640f220abda45b01905df3cb16296f44af73e33e92fa00099b
@@ -40,21 +40,19 @@ module PassiveRecord
40
40
  if @scope
41
41
  matching = @scope.method(:matching_instances)
42
42
  if negated?
43
- @klass.all.each do |instance| #reject(&matching)
43
+ @klass.all.each do |instance|
44
44
  yield instance unless matching[instance]
45
45
  end
46
46
  else
47
47
  @klass.all.each do |instance|
48
48
  yield instance if matching[instance]
49
49
  end
50
- # @klass.select(&matching)
51
50
  end
52
51
  else
53
52
  matching = method(:matching_instances)
54
53
  @klass.all.each do |instance|
55
54
  yield instance if matching[instance]
56
55
  end
57
- # @klass.select(&matching)
58
56
  end
59
57
  end
60
58
 
@@ -152,14 +150,15 @@ module PassiveRecord
152
150
  end
153
151
 
154
152
  class DisjoinedQuery < Query
155
- def initialize(klass, first_query, second_query)
153
+ def initialize(klass, first_query, second_query, conditions={})
156
154
  @klass = klass
157
155
  @first_query = first_query
158
156
  @second_query = second_query
157
+ @conditions = conditions
159
158
  end
160
159
 
161
160
  def all
162
- (@first_query.all + @second_query.all).uniq
161
+ (@first_query.where(conditions).all + @second_query.where(conditions).all).uniq
163
162
  end
164
163
 
165
164
  def disjoined?
@@ -168,18 +167,15 @@ module PassiveRecord
168
167
  end
169
168
 
170
169
  class ConjoinedQuery < Query
171
- def initialize(klass, first_query, second_query)
170
+ def initialize(klass, first_query, second_query, conditions={})
172
171
  @klass = klass
173
172
  @first_query = first_query
174
173
  @second_query = second_query
174
+ @conditions = conditions
175
175
  end
176
176
 
177
177
  def all
178
- @first_query.all & @second_query.all
179
- end
180
-
181
- def where(new_conditions={})
182
- @first_query.where(new_conditions)
178
+ @first_query.where(conditions).all & @second_query.all
183
179
  end
184
180
 
185
181
  def conjoined?
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.4.7"
3
+ VERSION = "0.4.8"
4
4
  end
@@ -19,7 +19,7 @@ end
19
19
  describe "passive record models" do
20
20
  before(:each) { PassiveRecord.drop_all }
21
21
 
22
- context "with a simple model including PR" do
22
+ context "a simple model including PR" do
23
23
  let!(:model) { SimpleModel.create(foo: value) }
24
24
  let(:value) { 'foo_value' }
25
25
 
@@ -72,6 +72,7 @@ describe "passive record models" do
72
72
  describe "#id" do
73
73
  it 'should be retrievable by id' do
74
74
  expect(SimpleModel.find_by(model.id)).to eq(model)
75
+ expect(SimpleModel.find(model.id)).to eq(model)
75
76
  end
76
77
  end
77
78
  end
@@ -216,17 +217,35 @@ describe "passive record models" do
216
217
  end
217
218
 
218
219
  context 'queries with disjunctions' do
220
+ let(:poms_or_pugs) do
221
+ Family::Dog.
222
+ where(breed: 'pom').or(Family::Dog.where(breed: 'pug'))
223
+ end
224
+
225
+ let(:poms_or_small_dogs) do
226
+ Family::Dog.
227
+ where(breed: 'pom').or(Family::Dog.where(size: %w[ tiny small ]))
228
+ end
229
+
230
+ before do
231
+ @pom = Family::Dog.create(breed: 'pom', size: 'tiny')
232
+ @pug = Family::Dog.create(breed: 'pug', size: 'big')
233
+
234
+ Family::Dog.create(breed: 'mutt', size: 'medium')
235
+ Family::Dog.create(breed: 'lab', size: 'large')
236
+
237
+ @pap = Family::Dog.create(breed: 'papillon', size: 'small')
238
+ end
239
+
219
240
  it 'should find where attributes match EITHER query' do
220
- pom = Family::Dog.create breed: 'pom'
221
- pug = Family::Dog.create breed: 'pug'
222
- Family::Dog.create breed: 'mutt'
223
- Family::Dog.create breed: 'lab'
224
- Family::Dog.create breed: 'papillon'
241
+ expect(poms_or_pugs.all).to eq([@pom, @pug])
242
+ expect(poms_or_small_dogs.all).to eq([@pom, @pap])
243
+ end
225
244
 
245
+ it 'should be able to refine a disjunction' do
226
246
  expect(
227
- Family::Dog.
228
- where(breed: 'pom').or(Family::Dog.where(breed: 'pug')).all
229
- ).to eq([pom, pug])
247
+ poms_or_pugs.where(size: %w[ tiny small ]).all
248
+ ).to eq([@pom])
230
249
  end
231
250
  end
232
251
 
data/spec/spec_helper.rb CHANGED
@@ -20,7 +20,7 @@ end
20
20
  module Family
21
21
  class Dog < Model
22
22
  attr_reader :sound
23
- attr_accessor :breed
23
+ attr_accessor :breed, :size
24
24
  belongs_to :child
25
25
  before_create { @breed = %w[pom pug].sample }
26
26
  after_create { @sound = 'bark' }
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.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman