Skip to content

Commit

Permalink
Merge pull request #1563 from tyabe/fix_content_tag
Browse files Browse the repository at this point in the history
Fix behavior of content_tag when use with content that is not a string
  • Loading branch information
namusyaka committed Jan 29, 2014
2 parents 41a329f + 1c73a89 commit a1aeaae
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion padrino-helpers/lib/padrino-helpers/tag_helpers.rb
Expand Up @@ -129,7 +129,7 @@ def content_tag(name, content = nil, options = nil, &block)
if content.respond_to?(:each) && !content.is_a?(String)
content.each { |c| output.concat c; output.safe_concat NEWLINE }
else
output.concat content
output.concat content.to_s
end
output.safe_concat "</#{name}>"

Expand Down
6 changes: 3 additions & 3 deletions padrino-helpers/test/test_form_helpers.rb
Expand Up @@ -646,9 +646,9 @@ def protect_from_csrf; false; end
should "take a range as a collection for options" do
actual_html = select_tag(:favorite_color, :options => (1..3))
assert_has_tag(:select) { actual_html }
assert_has_tag('select option', :value => '1') { actual_html }
assert_has_tag('select option', :value => '2') { actual_html }
assert_has_tag('select option', :value => '3') { actual_html }
assert_has_tag('select option', :content => '1', :value => '1') { actual_html }
assert_has_tag('select option', :content => '2', :value => '2') { actual_html }
assert_has_tag('select option', :content => '3', :value => '3') { actual_html }
end

should "include blank for grouped options" do
Expand Down
5 changes: 5 additions & 0 deletions padrino-helpers/test/test_tag_helpers.rb
Expand Up @@ -64,6 +64,11 @@ def app
assert_has_tag('p.large#star', :content => "<>") { actual_html }
end

should "convert to a string if the content is not a string" do
actual_html = content_tag(:p, 97)
assert_has_tag('p', :content => "97") { actual_html }
end

should "support tags with erb" do
visit '/erb/content_tag'
assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1'
Expand Down

0 comments on commit a1aeaae

Please sign in to comment.