This ticket is continuation of discussion from ticket #5053.
Please read that ticket to get a background.
As part of fix for #5053 I created a personal branch where some
discussion took place. Here I am going to copy paste some of the
discussions that took place. It will not contain all the
discussions, just some of them which seem relevant.
Alloy:
In nested_attributes_test.rb following should be changed
from
test "if association is not loaded and child doesn't change and I am saving a grandchild then in memory record should be used" do
@ship.parts_attributes=[{:id => @part.id,:trinkets_attributes =>[{:id => @trinket.id, :name => 'Ruby'}]}]
assert_equal 1, @ship.parts.proxy_target.size
assert_equal 'Mast', @ship.parts[0].name
assert_no_difference("@ship.parts[0].trinkets.proxy_target.size") do
@ship.parts[0].trinkets.proxy_target.size
end
assert_equal 'Ruby', @ship.parts[0].trinkets[0].name
@ship.save
assert_equal 'Ruby', @ship.parts[0].trinkets[0].name
end
to
What I actually meant, in the last comment, was to make the test look something like:
<pre>
test "load_target does not replace updated attributes set on an in-memory version of the same record" do
@trinket.name = 'Ruby'
assert !@part.trinkets.loaded?
assert_equal 'Ruby', @ship.parts[0].trinkets[0].name
assert_no_difference("@part.trinkets.proxy_target.size") { @ship.save! }
assert_equal 'Ruby', @ship.parts[0].trinkets[0].name
end
</pre>
I also tried to make the test description a bit more clearer, but I'm not sure if I got that right.
Alloy:
As a final note, it seems that some of these patches are written
because of an issue encountered when using nested attributes.
However, they are not specifically about nested attributes. For
instance the one mentioned above, which is really about association
collection. So I would expect at least a test added to the
association collection test, and maybe a regression one to the
nested attributes tests. I especially was a bit surprised to find
that there are a whole bunch of these ‘lost’ tests in
the nested attributes tests.
All tests from line 811 down should not be there at all:
http://github.com/neerajdotname/rails/blob/49cc2d682f17dcf74e11b56c...
They should either be in the autosave association tests, or in the
association collection tests, as far as I have studied them.
Furthermore, they should not use the nested attributes API, as
again, it's unrelated and only adds noise.