From ff98fde5012e9383c4d40abdb4298cd9f9a5ad42 Mon Sep 17 00:00:00 2001
From: Cheah Chu Yeow
Date: Mon, 23 Jun 2008 22:51:47 +0800
Subject: [PATCH] Don't pass label tags through error wrapping.
Pass symbols instead of strings to Object#respond_to? checks.
---
.../action_view/helpers/active_record_helper.rb | 10 +++++-----
.../test/template/active_record_helper_test.rb | 11 +++++++++--
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb
index f3f204c..86688f4 100644
--- a/actionpack/lib/action_view/helpers/active_record_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_record_helper.rb
@@ -217,7 +217,7 @@ module ActionView
alias_method :tag_without_error_wrapping, :tag
def tag(name, options)
- if object.respond_to?("errors") && object.errors.respond_to?("on")
+ if object.respond_to?(:errors) && object.errors.respond_to?(:on)
error_wrapping(tag_without_error_wrapping(name, options), object.errors.on(@method_name))
else
tag_without_error_wrapping(name, options)
@@ -226,7 +226,7 @@ module ActionView
alias_method :content_tag_without_error_wrapping, :content_tag
def content_tag(name, value, options)
- if object.respond_to?("errors") && object.errors.respond_to?("on")
+ if object.respond_to?(:errors) && object.errors.respond_to?(:on) && name != :label
error_wrapping(content_tag_without_error_wrapping(name, value, options), object.errors.on(@method_name))
else
content_tag_without_error_wrapping(name, value, options)
@@ -235,7 +235,7 @@ module ActionView
alias_method :to_date_select_tag_without_error_wrapping, :to_date_select_tag
def to_date_select_tag(options = {}, html_options = {})
- if object.respond_to?("errors") && object.errors.respond_to?("on")
+ if object.respond_to?(:errors) && object.errors.respond_to?(:on)
error_wrapping(to_date_select_tag_without_error_wrapping(options, html_options), object.errors.on(@method_name))
else
to_date_select_tag_without_error_wrapping(options, html_options)
@@ -244,7 +244,7 @@ module ActionView
alias_method :to_datetime_select_tag_without_error_wrapping, :to_datetime_select_tag
def to_datetime_select_tag(options = {}, html_options = {})
- if object.respond_to?("errors") && object.errors.respond_to?("on")
+ if object.respond_to?(:errors) && object.errors.respond_to?(:on)
error_wrapping(to_datetime_select_tag_without_error_wrapping(options, html_options), object.errors.on(@method_name))
else
to_datetime_select_tag_without_error_wrapping(options, html_options)
@@ -253,7 +253,7 @@ module ActionView
alias_method :to_time_select_tag_without_error_wrapping, :to_time_select_tag
def to_time_select_tag(options = {}, html_options = {})
- if object.respond_to?("errors") && object.errors.respond_to?("on")
+ if object.respond_to?(:errors) && object.errors.respond_to?(:on)
error_wrapping(to_time_select_tag_without_error_wrapping(options, html_options), object.errors.on(@method_name))
else
to_time_select_tag_without_error_wrapping(options, html_options)
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index dfc30e6..26f18f2 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -20,7 +20,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
end
def setup_post
- @post = Post.new
+ @post = Post.new
def @post.errors
Class.new {
def on(field)
@@ -111,7 +111,7 @@ class ActiveRecordHelperTest < ActionView::TestCase
assert_dom_equal(
%(),
text_area("post", "body")
- )
+ )
end
def test_text_field_with_errors
@@ -121,6 +121,13 @@ class ActiveRecordHelperTest < ActionView::TestCase
)
end
+ def test_label_with_errors_is_unchanged
+ assert_dom_equal(
+ '',
+ label('post', 'body')
+ )
+ end
+
def test_form_with_string
assert_dom_equal(
%(
),
--
1.5.6