From b67990cf342fb1d8f9ecab532db7e5b884981d7d Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 14 Jan 2015 16:46:04 -0700 Subject: Add tests with an explanation of why we're using `_before_type_cast` If you entered incorrect input into a form (particularly with a numericality validation), we should not replace what you typed in with `0`, since clicking submit a second time would essentially be the same as erroneously accepting the junk input as 0. --- actionview/test/template/form_helper_test.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'actionview') diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb index fff1e1e572..fa8d11d08b 100644 --- a/actionview/test/template/form_helper_test.rb +++ b/actionview/test/template/form_helper_test.rb @@ -99,7 +99,8 @@ class FormHelperTest < ActionView::TestCase }.new end def @post.to_key; [123]; end - def @post.id_before_type_cast; 123; end + def @post.id; 0; end + def @post.id_before_type_cast; "omg"; end def @post.to_param; '123'; end @post.persisted = true @@ -900,9 +901,9 @@ class FormHelperTest < ActionView::TestCase ) end - def test_text_area_with_value_before_type_cast + def test_inputs_use_before_type_cast_to_retain_information_from_validations_like_numericality assert_dom_equal( - %{}, + %{}, text_area("post", "id") ) end -- cgit v1.2.3