aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/form_helper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test/template/form_helper_test.rb')
-rw-r--r--actionview/test/template/form_helper_test.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/actionview/test/template/form_helper_test.rb b/actionview/test/template/form_helper_test.rb
index fa8d11d08b..e4fd797924 100644
--- a/actionview/test/template/form_helper_test.rb
+++ b/actionview/test/template/form_helper_test.rb
@@ -101,6 +101,7 @@ class FormHelperTest < ActionView::TestCase
def @post.to_key; [123]; end
def @post.id; 0; end
def @post.id_before_type_cast; "omg"; end
+ def @post.id_came_from_user?; true; end
def @post.to_param; '123'; end
@post.persisted = true
@@ -908,6 +909,22 @@ class FormHelperTest < ActionView::TestCase
)
end
+ def test_inputs_dont_use_before_type_cast_when_value_did_not_come_from_user
+ def @post.id_came_from_user?; false; end
+ assert_dom_equal(
+ %{<textarea id="post_id" name="post[id]">\n0</textarea>},
+ text_area("post", "id")
+ )
+ end
+
+ def test_inputs_use_before_typecast_when_object_doesnt_respond_to_came_from_user
+ class << @post; undef id_came_from_user?; end
+ assert_dom_equal(
+ %{<textarea id="post_id" name="post[id]">\nomg</textarea>},
+ text_area("post", "id")
+ )
+ end
+
def test_text_area_with_html_entities
@post.body = "The HTML Entity for & is &amp;"
assert_dom_equal(