|
163 | 163 | it "should call save on the association" do |
164 | 164 | subject.child.foo = "bar" |
165 | 165 | subject.child.should_receive(:save) |
| 166 | + |
166 | 167 | subject.save |
| 168 | + |
| 169 | + subject.instance_variable_get(:@child).should be_nil |
167 | 170 | end |
168 | 171 |
|
169 | 172 | it "should not call save on the association if they are synced" do |
170 | 173 | subject.child.should_not_receive(:save) |
| 174 | + |
171 | 175 | subject.save |
| 176 | + |
| 177 | + subject.instance_variable_get(:@child).should be_nil |
172 | 178 | end |
173 | 179 | end |
174 | 180 |
|
|
186 | 192 | subject.children_ids = [1] |
187 | 193 | subject.save |
188 | 194 | subject.children_ids.should == [2,3] |
| 195 | + subject.instance_variable_get(:@children).should be_nil |
189 | 196 | end |
190 | 197 |
|
191 | 198 | it "should not save the associated objects when there are no changes" do |
192 | 199 | subject.children = [2] |
193 | 200 | subject.children.first.should_not_receive(:save) |
194 | 201 | subject.save |
| 202 | + subject.instance_variable_get(:@children).should be_nil |
195 | 203 | end |
196 | 204 |
|
197 | 205 | it "should save the associated objects when it is new" do |
198 | 206 | subject.children = [{:foo => "bar"}] |
199 | 207 | subject.children.first.should_receive(:save) |
200 | 208 | subject.save |
| 209 | + subject.instance_variable_get(:@children).should be_nil |
201 | 210 | end |
202 | 211 |
|
203 | 212 | it "should not save the associated objects when it is set via full hash" do |
204 | 213 | subject.children = [{:id => 1, :foo => "bar"}] |
205 | 214 | subject.children.first.should_not_receive(:save) |
206 | 215 | subject.save |
| 216 | + subject.instance_variable_get(:@children).should be_nil |
207 | 217 | end |
208 | 218 |
|
209 | 219 | it "should save the associated objects when it is changes" do |
210 | 220 | subject.children = [{:id => 1}] |
211 | 221 | subject.children.first.foo = "bar" |
212 | 222 | subject.children.first.should_receive(:save) |
213 | 223 | subject.save |
| 224 | + subject.instance_variable_get(:@children).should be_nil |
214 | 225 | end |
215 | 226 | end |
216 | 227 |
|
|
0 commit comments