acts_as 0.3.2 → 0.4.0
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/acts_as/version.rb +1 -1
- data/lib/acts_as.rb +5 -1
- data/spec/acts_as_spec.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbeabb43ed80dd4e50b939377b9a089c639460c9
|
4
|
+
data.tar.gz: 90a45695199493b9e374935120922ddaead80d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbea4d58639ee1b234f882847627cdd9b0b6543704f968766fdcd2021f484fb8e6c869a89d4903fd6a2c7001dc37f3a5aff37b89074bbd5df4b1eaafed1ddaa4
|
7
|
+
data.tar.gz: 6a51f37065b9bd9828fcf2ae560bbb562b71a9c315e5b68b0cb2ca6755ae7e68bcba070a995742e9c9c5aa79481b666fd0f733e899be394ce1f0a841b79ddd8d
|
data/lib/acts_as/version.rb
CHANGED
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)
|
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.
|
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-
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|