Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make InstanceTagMethods#value_before_type_cast raise if the model don…

…'t respond to attr_before_type_cast or attr method

[#3374] [#5471 state:committed]
  • Loading branch information...
commit 3ba8e3100548f10fce0c9784981a4589531476dd 1 parent e8a083e
Santiago Pastorino spastorino authored
11 actionpack/lib/action_view/helpers/form_helper.rb
View
@@ -1006,9 +1006,14 @@ def value(object, method_name)
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
13 actionpack/test/template/form_helper_test.rb
View
@@ -12,6 +12,8 @@ def name_before_type_cast
def name
"Santiago"
end
+
+ attr_writer :language
end
def form_for(*)
@@ -257,6 +259,17 @@ def test_text_field_from_a_user_defined_method
)
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" />',
Please sign in to comment.
Something went wrong with that request. Please try again.