active_record-acts_as 1.0.4 → 1.0.5
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/active_record/acts_as/instance_methods.rb +5 -1
- data/lib/active_record/acts_as/version.rb +1 -1
- data/spec/acts_as_spec.rb +11 -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: 05ede0788d02924d7ddfff896c7afc9cfd65699e
|
4
|
+
data.tar.gz: 6c07973b511504c7fbc59648560a3bab71799620
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec862802c12677bd788fceade3c11d7204163d0d223a477852fbec7a2f617218b8f96f80032c377284d4d6ef62844cff164af7a64af17f95277baf87b0032a60
|
7
|
+
data.tar.gz: a1ede8555a018302ca0ce07d48e065f0d920240cceadb4cfb4acda9297f43de92b1f99927d69590e7447352cd945c11ae57c58dd35c24ec79a26f04448570aa2
|
@@ -10,10 +10,14 @@ module ActiveRecord
|
|
10
10
|
super || acting_as?(klass)
|
11
11
|
end
|
12
12
|
|
13
|
+
def acting_as_foreign_key
|
14
|
+
acting_as[acting_as_reflection.foreign_key]
|
15
|
+
end
|
16
|
+
|
13
17
|
# Is the superclass persisted to the database?
|
14
18
|
def acting_as_persisted?
|
15
19
|
return false if acting_as.nil?
|
16
|
-
!acting_as.id.nil? && !
|
20
|
+
!acting_as.id.nil? && !acting_as_foreign_key.nil?
|
17
21
|
end
|
18
22
|
|
19
23
|
def actable_must_be_valid
|
data/spec/acts_as_spec.rb
CHANGED
@@ -82,6 +82,17 @@ RSpec.describe "ActiveRecord::Base model with #acts_as called" do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
describe "#acting_as_foreign_key" do
|
86
|
+
let(:product_foreign_key_value) do
|
87
|
+
pen.acting_as[pen.acting_as.actable_reflection.foreign_key]
|
88
|
+
end
|
89
|
+
it "return acts_as foreign key value" do
|
90
|
+
pen.save
|
91
|
+
expect(pen.acting_as_foreign_key).to eq(product_foreign_key_value)
|
92
|
+
expect(pen.acting_as_foreign_key).to eq(pen.id)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
85
96
|
describe "#acting_as=" do
|
86
97
|
it "sets acts_as model" do
|
87
98
|
product = Product.new(name: 'new product', price: 0.99)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-acts_as
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hassan Zamani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sqlite3
|