passive_record 0.2.1 → 0.2.2

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: 9b53a2a2b1407842b155927cd33dcd17edf6122e
4
- data.tar.gz: 683d3db18dda5ed63fe3c38eaa04245869384589
3
+ metadata.gz: cef72fdda85e2a5d1dabfd009842c092780ce77d
4
+ data.tar.gz: a6f81fbd8c7a0b88d318e46a8aa232ae69b0a549
5
5
  SHA512:
6
- metadata.gz: a84823bc45ca818c2b9d4321e866a27d0fccf96e9fd577127c733da3cdc1f0417af3e213fc4601097c4e60faa4005e7dbb5743554d4b5b5e370f8a6411d99c01
7
- data.tar.gz: b908e5b58a80c708bd015365807e5947643d4c2090b5dae48d070bdae439777c934bb9a3b876cbc102b290663889742a5dcc0f5a777135011eac05050ddcceb8
6
+ metadata.gz: bb22e938cd0081234dd6f02b02ae060d3fc37e794b78b479a313e6793ab0fe486f367dfa38c91abb98b1f2594297a33ae4b529968d8b3906c1addcaacea6c8a1
7
+ data.tar.gz: d0e3ee535809bb7817be14dece26cb727bb0db7621fb1a090f9baa2ad69b9f54366c29a73f4651e15f938e2edf802e424390398212510aa6cd5fcc7d50af4cf1
@@ -52,7 +52,15 @@ module PassiveRecord
52
52
  when target_name
53
53
  matching_relation.lookup
54
54
  when "#{target_name}="
55
- matching_relation.parent_model_id = args.first.id
55
+ if args.first.is_a?(Array)
56
+ # need to loop through each arg and set id
57
+ args.first.each do |child|
58
+ child.send(matching_relation.parent_model_id_field + "=", id)
59
+ end
60
+ else
61
+ # assume simple assignment
62
+ matching_relation.parent_model_id = args.first.id
63
+ end
56
64
  when "create_#{target_name}", "create_#{target_name.singularize}"
57
65
  matching_relation.create(*args)
58
66
  when "#{target_name}_id"
@@ -1,4 +1,4 @@
1
1
  module PassiveRecord
2
2
  # passive_record version
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
@@ -182,12 +182,18 @@ describe "passive record models" do
182
182
 
183
183
  context 'one-to-many relationships' do
184
184
  let(:parent) { Parent.create }
185
+ let(:another_parent) { Parent.create(children: [another_child]) }
186
+ let(:another_child) { Child.create }
185
187
 
186
188
  it 'should create children' do
187
189
  expect { parent.create_child }.to change{ Child.count }.by(1)
188
190
  expect(parent.children).to all(be_a(Child))
189
191
  end
190
192
 
193
+ it 'should assign children on creation' do
194
+ expect(another_parent.children).to match_array([another_child])
195
+ end
196
+
191
197
  it 'should create inverse relationships' do
192
198
  child = parent.create_child
193
199
  expect(child.parent).to eq(parent)
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.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joseph Weissman