vendor/plugins/haml/test/haml/helper_test.rb in radiant-0.7.2 vs vendor/plugins/haml/test/haml/helper_test.rb in radiant-0.8.0

- old
+ new

@@ -1,11 +1,16 @@ #!/usr/bin/env ruby require File.dirname(__FILE__) + '/../test_helper' require 'haml/template' +class ActionView::Base + def nested_tag + content_tag(:span) {content_tag(:div) {"something"}} + end +end + class HelperTest < Test::Unit::TestCase - include Haml::Helpers Post = Struct.new('Post', :body) def setup @base = ActionView::Base.new @base.controller = ActionController::Base.new @@ -20,18 +25,18 @@ Haml::Engine.new(text, options).to_html(scope ? scope : Object.new) end end def test_flatten - assert_equal("FooBar", flatten("FooBar")) + assert_equal("FooBar", Haml::Helpers.flatten("FooBar")) - assert_equal("FooBar", flatten("Foo\rBar")) + assert_equal("FooBar", Haml::Helpers.flatten("Foo\rBar")) - assert_equal("Foo&#x000A;Bar", flatten("Foo\nBar")) + assert_equal("Foo&#x000A;Bar", Haml::Helpers.flatten("Foo\nBar")) assert_equal("Hello&#x000A;World!&#x000A;YOU ARE FLAT?&#x000A;OMGZ!", - flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!")) + Haml::Helpers.flatten("Hello\nWorld!\nYOU ARE \rFLAT?\n\rOMGZ!")) end def test_list_of_should_render_correctly assert_equal("<li>1</li>\n<li>2</li>\n", render("= list_of([1, 2]) do |i|\n = i")) assert_equal("<li>[1]</li>\n", render("= list_of([[1]]) do |i|\n = i.inspect")) @@ -93,11 +98,23 @@ end def test_capture_haml assert_equal("\"<p>13</p>\\n\"\n", render("- foo = capture_haml(13) do |a|\n %p= a\n= foo.dump")) end - + + def test_content_tag_block + assert_equal(<<HTML.strip, render(<<HAML, :action_view)) +<div><p>bar</p> +<strong>bar</strong> +</div> +HTML +- content_tag :div do + %p bar + %strong bar +HAML + end + def test_haml_tag_attribute_html_escaping assert_equal("<p id='foo&amp;bar'>baz</p>\n", render("%p{:id => 'foo&bar'} baz", :escape_html => true)) end def test_haml_tag_autoclosed_tags_are_closed @@ -146,11 +163,11 @@ def test_capture_deals_properly_with_collections Haml::Helpers.module_eval do def trc(collection, &block) collection.each do |record| - puts capture_haml(record, &block) + haml_concat capture_haml(record, &block) end end end assert_equal("1\n\n2\n\n3\n\n", render("- trc([1, 2, 3]) do |i|\n = i.inspect")) @@ -173,18 +190,22 @@ end context.init_haml_helpers result = context.capture_haml do context.haml_tag :p, :attr => "val" do - context.puts "Blah" + context.haml_concat "Blah" end end assert_equal("<p attr='val'>\n Blah\n</p>\n", result) end def test_non_haml assert_equal("false\n", render("= non_haml { is_haml? }")) + end + + def test_content_tag_nested + assert_equal "<span><div>something</div></span>", render("= nested_tag", :action_view).strip end class ActsLikeTag # We want to be able to have people include monkeypatched ActionView helpers # without redefining is_haml?.