polymorphic_integer_type 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTIzOWYzZmZmYTA0NmI4OTQxMzZmNzE0YmNiNGM2YWVmNGIyNGI3Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NzAxOWMxZmJhYWUzZTI4MzNhOWY4OGU4MTg2ZjhkNDY4ZjlhYzE1Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGNkZDRhOWE5MWJiNTA0Njg5YzdmMGM5ZjJiOWQ3ZGM0ZmFiM2Y1ZjI3MWVj
|
10
|
+
ODdiZjYxNWFlNDg0ZjQ2MDQwZTBlMGEzNTA5Y2VlMTE1OTY2NzA1NGYyNzcy
|
11
|
+
MGQ3OWZkYjQ5MDkyOGUzYjQ1MmE0ODM3MTcyN2YwODIwY2U2ZGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGYyOGQ4ZjQwNThkMDE2ODQ2MmU4NTFlNjdlNzg0OWU0NmY1MTg0NDBhYWYy
|
14
|
+
YmViODFlMGFlYzU2NDA1NzE0M2U3NjVmYWM5YTg1N2MwNWI0MmFkOTJmYWFh
|
15
|
+
YzAyZDY5YTk0OTU4OTYwZjA0MDNlODRjOTFlYjZkYzg4MTJiNjA=
|
@@ -16,9 +16,12 @@ module PolymorphicIntegerType
|
|
16
16
|
mapping[t]
|
17
17
|
end
|
18
18
|
|
19
|
-
define_method "#{foreign_type}=" do |klass|
|
20
|
-
klass = klass.base_class if klass.kind_of?(Class)
|
19
|
+
define_method "#{foreign_type}=" do |klass|
|
20
|
+
klass = klass.base_class if klass.kind_of?(Class) && klass <= ActiveRecord::Base
|
21
21
|
enum = mapping.key(klass.to_s) || klass
|
22
|
+
if enum == NilClass
|
23
|
+
enum = nil
|
24
|
+
end
|
22
25
|
super(enum)
|
23
26
|
end
|
24
27
|
|
@@ -17,6 +17,16 @@ describe PolymorphicIntegerType do
|
|
17
17
|
|
18
18
|
let(:link) { Link.create(:source => source, :target => target) }
|
19
19
|
|
20
|
+
context "when the source is nil" do
|
21
|
+
let(:source) { nil }
|
22
|
+
let(:target) { nil }
|
23
|
+
it "should have the no id/type for the source" do
|
24
|
+
expect(link.source_id).to be_nil
|
25
|
+
expect(link.source_type).to be_nil
|
26
|
+
expect(link.source).to be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
20
30
|
shared_examples "proper source" do
|
21
31
|
it "should have the proper id, type and object for the source" do
|
22
32
|
expect(link.source_id).to eql source.id
|