Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Makes form_helper use overriden model accessors backport

  • Loading branch information...
commit 8141f0894ecf869ee11f077e5b49e06669790632 1 parent 27651c1
@spastorino spastorino authored
View
6 actionpack/lib/action_view/helpers/form_helper.rb
@@ -877,9 +877,9 @@ def value(object, method_name)
def value_before_type_cast(object, method_name)
unless object.nil?
- object.respond_to?(method_name + "_before_type_cast") ?
- object.send(method_name + "_before_type_cast") :
- object.send(method_name)
+ object.respond_to?(method_name) ?
+ object.send(method_name) :
+ object.send(method_name + "_before_type_cast")
end
end
View
17 actionpack/test/template/form_helper_test.rb
@@ -91,6 +91,16 @@ def post_attributes=(attributes); end
class FormHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormHelper
+ class Developer
+ def name_before_type_cast
+ "David"
+ end
+
+ def name
+ "Santiago"
+ end
+ end
+
def setup
super
@@ -256,6 +266,13 @@ def test_text_field_doesnt_change_param_values
assert_equal object_name, "post[]"
end
+ def test_text_field_from_a_user_defined_method
+ @developer = Developer.new
+ assert_dom_equal(
+ '<input id="developer_name" name="developer[name]" size="30" type="text" value="Santiago" />', text_field("developer", "name")
+ )
+ end
+
def test_hidden_field
assert_dom_equal '<input id="post_title" name="post[title]" type="hidden" value="Hello World" />',
hidden_field("post", "title")
Please sign in to comment.
Something went wrong with that request. Please try again.