|
24 | 24 | end |
25 | 25 | end |
26 | 26 |
|
| 27 | + context "when querying the associations" do |
| 28 | + let(:source) { cat } |
| 29 | + let(:target) { nil } |
| 30 | + it "properly finds the object with a where" do |
| 31 | + expect(Link.where(source: source, id: link.id).first).to eql link |
| 32 | + end |
| 33 | + it "properly finds the object with a find_by" do |
| 34 | + expect(Link.find_by(source: source, id: link.id)).to eql link |
| 35 | + end |
| 36 | + end |
| 37 | + |
27 | 38 | shared_examples "proper source" do |
28 | 39 | it "should have the proper id, type and object for the source" do |
29 | 40 | expect(link.source_id).to eql source.id |
|
47 | 58 |
|
48 | 59 | context "and the link is accessed through the associations" do |
49 | 60 | before { link } |
50 | | - |
| 61 | + |
51 | 62 | it "should have the proper source" do |
52 | 63 | expect(source.source_links[0].source).to eql source |
53 | 64 | end |
54 | 65 | end |
55 | | - |
| 66 | + |
56 | 67 | end |
57 | 68 | context "When a link is given polymorphic record" do |
58 | 69 | let(:link) { Link.create(source: source) } |
|
137 | 148 |
|
138 | 149 |
|
139 | 150 | end |
140 | | - |
| 151 | + |
141 | 152 | context "when the association is an STI table" do |
142 | 153 | let(:link) { Link.create(source: source, target: whiskey) } |
143 | 154 | let(:source) { Dog.create(name: "Bela", kind: "Dog", owner: owner) } |
|
147 | 158 | expect(link.source).to eql source |
148 | 159 | end |
149 | 160 | end |
150 | | - |
| 161 | + |
151 | 162 | context "when mapping is given inline in the belongs_to model" do |
152 | 163 | class InlineLink < ActiveRecord::Base |
153 | 164 | include PolymorphicIntegerType::Extensions |
@@ -187,7 +198,7 @@ class InlineDrink < ActiveRecord::Base |
187 | 198 | include_examples "proper target" |
188 | 199 |
|
189 | 200 | it "creates foreign_type mapping method" do |
190 | | - expect(Link.source_type_mapping).to eq({0 => "Person", 1 => "Animal"}) |
| 201 | + expect(Link.source_type_mapping).to eq({1 => "Person", 2 => "Animal"}) |
191 | 202 | expect(InlineLink.source_type_mapping).to eq({10 => "Person", 11 => "InlineAnimal"}) |
192 | 203 | end |
193 | 204 |
|
|
0 commit comments