Permalink
Browse files

Added that nil options are not included in tags, so tag("p", :ignore …

…=> nil) now returns <p /> not <p ignore="" /> but that tag("p", :ignore => "") still includes it #1465 [michael@schuerig.de]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1789 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 0fe8e3d commit 2abe3d2cd92e5ee55c39f1b4062ccf60043105f7 @dhh dhh committed Jul 9, 2005
@@ -1,5 +1,7 @@
*SVN*
+* Added that nil options are not included in tags, so tag("p", :ignore => nil) now returns <p /> not <p ignore="" /> but that tag("p", :ignore => "") still includes it #1465 [michael@schuerig.de]
+
* Fixed that UrlHelper#link_to_unless/link_to_if used html_escape on the name if no link was to be applied. This is unnecessary and breaks its use with images #1649 [joergd@pobox.com]
* Added even more goodies to script.aculo.us #1677 [Thomas Fuchs]
@@ -24,8 +24,9 @@ def content_tag(name, content, options = {})
private
def tag_options(options)
- unless options.empty?
- " " + options.symbolize_keys.map { |key, value|
+ cleaned_options = options.reject { |key, value| value.nil? }
+ unless cleaned_options.empty?
+ " " + cleaned_options.symbolize_keys.map { |key, value|
%(#{key}="#{html_escape(value.to_s)}")
}.sort.join(" ")
end
@@ -37,7 +37,7 @@ def test_text_field
'<input id="post_title" name="post[title]" size="30" type="password" value="Hello World" />', password_field("post", "title")
)
assert_equal(
- '<input id="person_name" name="person[name]" size="30" type="password" value="" />', password_field("person", "name")
+ '<input id="person_name" name="person[name]" size="30" type="password" />', password_field("person", "name")
)
end
@@ -71,7 +71,7 @@ def test_check_box
check_box("post", "secret")
)
assert_equal(
- '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
+ '<input checked="checked" id="post_secret" name="post[secret]" type="checkbox" value="1" /><input name="post[secret]" type="hidden" value="0" />',
check_box("post", "secret" ,{"checked"=>"checked"})
)
@post.secret = true
@@ -80,7 +80,7 @@ def test_check_box
check_box("post", "secret")
)
end
-
+
def test_check_box_with_explicit_checked_and_unchecked_values
@post.secret = "on"
assert_equal(
@@ -22,7 +22,7 @@ def test_check_box_tag
end
def test_form_tag
- actual = form_tag
+ actual = form_tag
expected = %(<form action="http://www.example.com" method="post">)
assert_equal expected, actual
end
@@ -41,7 +41,7 @@ def test_hidden_field_tag
def test_password_field_tag
actual = password_field_tag
- expected = %(<input id="password" name="password" type="password" value="" />)
+ expected = %(<input id="password" name="password" type="password" />)
assert_equal expected, actual
end
@@ -88,7 +88,7 @@ def test_auto_complete_result
def test_text_field_with_auto_complete
assert_match "<style>",
text_field_with_auto_complete(:message, :recipient)
- assert_equal %(<input autocomplete=\"off\" id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" value=\"\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})</script>),
+ assert_equal %(<input autocomplete=\"off\" id=\"message_recipient\" name=\"message[recipient]\" size=\"30\" type=\"text\" /><div class=\"auto_complete\" id=\"message_recipient_auto_complete\"></div><script type=\"text/javascript\">new Ajax.Autocompleter('message_recipient', 'message_recipient_auto_complete', 'http://www.example.com/auto_complete_for_message_recipient', {})</script>),
text_field_with_auto_complete(:message, :recipient, {}, :skip_style => true)
end
@@ -16,6 +16,14 @@ def test_tag_options
assert_equal "<p class=\"elsewhere\" />", tag("p", "class" => "show", :class => "elsewhere")
end
+ def test_tag_options_rejects_nil_option
+ assert_equal "<p />", tag("p", :ignored => nil)
+ end
+
+ def test_tag_options_accepts_blank_option
+ assert_equal "<p included=\"\" />", tag("p", :included => '')
+ end
+
def test_content_tag
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
assert_equal content_tag("a", "Create", "href" => "create"),

0 comments on commit 2abe3d2

Please sign in to comment.