acts_as 0.3.2 → 0.4.0

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: c90c95f6d896433e7328bb39122e91ba42dee1e9
4
- data.tar.gz: 0446d276693782466bfe2439ee861d73f168713b
3
+ metadata.gz: cbeabb43ed80dd4e50b939377b9a089c639460c9
4
+ data.tar.gz: 90a45695199493b9e374935120922ddaead80d3b
5
5
  SHA512:
6
- metadata.gz: 962d43563fc9fa62e3eb786761e7a2ae6bb1839eab4cdba0cadc6fa11f8e246215378ea8d1bc40a5a3bd5a740e724478bff28a07a70619782ffbb6cb27d79415
7
- data.tar.gz: 7bf74336f03f980392db80d1fdf62c2b556055b6637d7afe1dfd736b5d3bb018b1f2a712c50d3dac5ee53922365e645f38e917fa70b463c611b2ffaa500396e6
6
+ metadata.gz: cbea4d58639ee1b234f882847627cdd9b0b6543704f968766fdcd2021f484fb8e6c869a89d4903fd6a2c7001dc37f3a5aff37b89074bbd5df4b1eaafed1ddaa4
7
+ data.tar.gz: 6a51f37065b9bd9828fcf2ae560bbb562b71a9c315e5b68b0cb2ca6755ae7e68bcba070a995742e9c9c5aa79481b666fd0f733e899be394ce1f0a841b79ddd8d
@@ -1,3 +1,3 @@
1
1
  module ActsAs
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/acts_as.rb CHANGED
@@ -33,7 +33,11 @@ module ActsAs
33
33
  module ClassMethods
34
34
  def acts_as(association, with: [], prefix: [], **options)
35
35
  belongs_to(association, **options.merge(autosave: true))
36
- define_method(association) { |*args| super(*args) || send("build_#{association}", *args) }
36
+ define_method(association) do |*args|
37
+ acted = super(*args) || send("build_#{association}", *args)
38
+ acted.save(validate: false) unless acted.persisted?
39
+ acted
40
+ end
37
41
 
38
42
  if (association_class = (options[:class_name] || association).to_s.camelcase.constantize).table_exists?
39
43
  whitelist_and_delegate_fields(association_class, association, prefix, with)
data/spec/acts_as_spec.rb CHANGED
@@ -45,6 +45,24 @@ describe ActsAs do
45
45
  }.to raise_error(ActsAs::ActiveRecordOnly)
46
46
  end
47
47
 
48
+ describe 'automatic association building' do
49
+ describe 'when acted model has already been created' do
50
+ it 'retrieves it from the database' do
51
+ rebel.profile.serial_data = '123'
52
+ rebel.save
53
+ rebel.reload.profile.serial_data.should == '123'
54
+ end
55
+ end
56
+
57
+ describe 'when acted model has not been created' do
58
+ it 'creates it empty automatically' do
59
+ expect {
60
+ rebel.profile.should be_persisted
61
+ }.to change(RebelProfile, :count).by(1)
62
+ end
63
+ end
64
+ end
65
+
48
66
  describe 'with' do
49
67
  it { should respond_to(:delegate_at_will) }
50
68
  its(:delegate_at_will) { should == rebel.clan.delegate_at_will }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - winfred
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-08 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler