diff options
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 11 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 13 |
2 files changed, 21 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ebe055bebd..938da7aea7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1006,9 +1006,14 @@ module ActionView def value_before_type_cast(object, method_name) unless object.nil? - object.respond_to?(method_name) ? - object.send(method_name) : - object.send(method_name + "_before_type_cast") + if object.respond_to?(method_name) + object.send(method_name) + # FIXME: this is AR dependent + elsif object.respond_to?(method_name + "_before_type_cast") + object.send(method_name + "_before_type_cast") + else + raise NoMethodError, "Model #{object.class} does not respond to #{method_name}" + end end end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 71a5ae0245..8ba4aa1639 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -12,6 +12,8 @@ class FormHelperTest < ActionView::TestCase def name "Santiago" end + + attr_writer :language end def form_for(*) @@ -257,6 +259,17 @@ class FormHelperTest < ActionView::TestCase ) end + def test_text_field_on_a_model_with_undefined_attr_reader + @developer = Developer.new + @developer.language = 'ruby' + begin + text_field("developer", "language") + rescue NoMethodError => error + message = error.message + end + assert_equal "Model #{Developer} does not respond to language", message + end + def test_check_box assert_dom_equal( '<input name="post[secret]" type="hidden" value="0" /><input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" />', |