aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-03-27 11:07:07 +0100
committerJosé Valim <jose.valim@gmail.com>2010-03-27 11:07:07 +0100
commit418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2 (patch)
tree33d51b954b8f6cac5e64e64d2152d6b0ca8cc40c /actionpack
parent0cb3311d06c02649fb7444c34b6fdf2214ab85f5 (diff)
parenta24a888afe5652e391ce2ea682596686af5ec58b (diff)
downloadrails-418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2.tar.gz
rails-418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2.tar.bz2
rails-418e5fc279b19c0d35d3f2b6b5ce216a566c8fc2.zip
Merge branch 'master' of gitproxy:rails/rails
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/active_model_helper.rb4
-rw-r--r--actionpack/test/template/active_model_helper_test.rb14
2 files changed, 18 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb
index e3db2923f7..bbe8609e91 100644
--- a/actionpack/lib/action_view/helpers/active_model_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_model_helper.rb
@@ -295,6 +295,10 @@ module ActionView
end
end
+ def error_message
+ object.errors[@method_name]
+ end
+
def column_type
object.send(:column_for_attribute, @method_name).type
end
diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb
index 371aa53c68..71c7d5b621 100644
--- a/actionpack/test/template/active_model_helper_test.rb
+++ b/actionpack/test/template/active_model_helper_test.rb
@@ -147,6 +147,20 @@ class ActiveModelHelperTest < ActionView::TestCase
)
end
+ def test_field_error_proc
+ old_proc = ActionView::Base.field_error_proc
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+ %(<div class=\"fieldWithErrors\">#{html_tag} <span class="error">#{[instance.error_message].join(', ')}</span></div>).html_safe
+ end
+
+ assert_dom_equal(
+ %(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /> <span class="error">can't be empty</span></div>),
+ text_field("post", "author_name")
+ )
+ ensure
+ ActionView::Base.field_error_proc = old_proc if old_proc
+ end
+
def test_form_with_string
assert_dom_equal(
%(<form action="create" method="post"><p><label for="post_title">Title</label><br /><input id="post_title" name="post[title]" size="30" type="text" value="Hello World" /></p>\n<p><label for="post_body">Body</label><br /><div class="fieldWithErrors"><textarea cols="40" id="post_body" name="post[body]" rows="20">Back to the hill and over it again!</textarea></div></p><input name="commit" type="submit" value="Create" /></form>),