aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorAngelo capilleri <capilleri@yahoo.com>2012-06-08 10:09:28 +0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-19 01:54:34 -0300
commitb9ec47da00e7f5e159ff130441585c3b42e41849 (patch)
tree58908be96097647185a2659c588cfe81154f6053 /activerecord/test/cases/nested_attributes_test.rb
parent69f19b292ad4b228f2bc5f89732a8ef3b704fab6 (diff)
downloadrails-b9ec47da00e7f5e159ff130441585c3b42e41849.tar.gz
rails-b9ec47da00e7f5e159ff130441585c3b42e41849.tar.bz2
rails-b9ec47da00e7f5e159ff130441585c3b42e41849.zip
Validates_numericality_of is skipped when changing 0 to to non-empty string
This happens when A has_many many B and A accepts_nested_attributes B that has a numeric colum with initial 0 value. So a.update_attributes({:b_attributes => { :id => b.id, :numeric => 'foo' }}) passes the validation test but, the value of :numeric doesn't change. his commit forces that the update fails with the above conditions. Fixes #6393 Fixes #2331
Diffstat (limited to 'activerecord/test/cases/nested_attributes_test.rb')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 0559bbbe9a..3daa033ed0 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -781,6 +781,16 @@ module NestedAttributesOnACollectionAssociationTests
assert_nothing_raised(NoMethodError) { @pirate.save! }
end
+ def test_numeric_colum_changes_from_zero_to_no_empty_string
+ Man.accepts_nested_attributes_for(:interests)
+ Interest.validates_numericality_of(:zine_id)
+ man = Man.create(:name => 'John')
+ interest = man.interests.create(:topic=>'bar',:zine_id => 0)
+ assert interest.save
+
+ assert !man.update_attributes({:interests_attributes => { :id => interest.id, :zine_id => 'foo' }})
+ end
+
private
def association_setter