Skip to content

Commit b079dd2

Browse files
author
Kyle d'Oliveira
committed
Need to add a []= method too
1 parent df946c1 commit b079dd2

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/polymorphic_integer_type/extensions.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ def [](value)
8282
end
8383
end
8484

85+
def []=(attr_name, value)
86+
if _polymorphic_foreign_types.include?(attr_name)
87+
send("#{attr_name}=", value)
88+
else
89+
super(attr_name, value)
90+
end
91+
end
92+
8593
end
8694

8795
end

spec/polymorphic_integer_type_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@
3737
let(:link) { source.source_links.create }
3838
let(:source) { cat }
3939
include_examples "proper source"
40+
41+
context "and the link is accessed through the associations" do
42+
before { link }
43+
44+
it "should have the proper source" do
45+
expect(source.source_links[0].source).to eql source
46+
end
47+
end
4048

4149
end
4250
context "When a link is given polymorphic record" do

0 commit comments

Comments
 (0)