Permalink
Browse files

javascript_tag should only concat when block_given?

  • Loading branch information...
1 parent fec0f06 commit e732a405ab7d0d04f8a254764970c9dcda988f01 @jeremy jeremy committed Jun 7, 2008
@@ -172,14 +172,17 @@ def escape_javascript(javascript)
# alert('All is good')
# <% end -%>
def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)
- if block_given?
- html_options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
- content = capture(&block)
- else
- content = content_or_options_with_block
- end
+ content =
+ if block_given?
+ html_options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
+ capture(&block)
+ else
+ content_or_options_with_block
+ end
+
+ tag = content_tag("script", javascript_cdata_section(content), html_options.merge(:type => Mime::JS))
- concat(content_tag("script", javascript_cdata_section(content), html_options.merge(:type => Mime::JS)))
+ block_given? ? concat(tag) : tag
end
def javascript_cdata_section(content) #:nodoc:
@@ -82,8 +82,12 @@ def test_button_to_function_without_function
end
def test_javascript_tag
+ @output_buffer = 'foo'
+
assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>",
javascript_tag("alert('hello')")
+
+ assert_equal 'foo', @output_buffer, 'javascript_tag without a block should not concat to @output_buffer'
end
def test_javascript_tag_with_options

0 comments on commit e732a40

Please sign in to comment.