Skip to content

Commit ded8795

Browse files
author
Kyle d'Oliveira
committed
Creating the record through an association should work
1 parent 0427093 commit ded8795

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

lib/polymorphic_integer_type/extensions.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def belongs_to(name, options = {})
1717
end
1818

1919
define_method "#{foreign_type}=" do |klass|
20-
enum = mapping.key(klass.to_s)
20+
case klass
21+
when Integer then enum = klass
22+
when String then enum = mapping.key(klass)
23+
end
2124
super(enum)
2225
end
2326

spec/polymorphic_integer_type_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
end
3434
end
3535

36+
context "When a link is created through an association" do
37+
let(:link) { source.source_links.create }
38+
let(:source) { cat }
39+
include_examples "proper source"
40+
41+
end
3642
context "When a link is given polymorphic record" do
3743
let(:link) { Link.create(:source => source) }
3844
let(:source) { cat }
@@ -116,5 +122,6 @@
116122

117123

118124
end
125+
119126

120127
end

0 commit comments

Comments
 (0)