提交 b67990cf 编写于 作者: S Sean Griffin

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.
上级 99b6cf53
......@@ -99,7 +99,8 @@ def full_messages() ["Author name can't be empty"] end
}.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 @@ def test_text_area_with_nil_alternate_value
)
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(
%{<textarea id="post_id" name="post[id]">\n123</textarea>},
%{<textarea id="post_id" name="post[id]">\nomg</textarea>},
text_area("post", "id")
)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册