From eb23754ebbfbf2d465cc0f900720704fb3703633 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Wed, 17 Apr 2013 00:06:11 +0200 Subject: Move template tests from actionpack to actionview --- actionview/test/template/record_tag_helper_test.rb | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 actionview/test/template/record_tag_helper_test.rb (limited to 'actionview/test/template/record_tag_helper_test.rb') diff --git a/actionview/test/template/record_tag_helper_test.rb b/actionview/test/template/record_tag_helper_test.rb new file mode 100644 index 0000000000..ab84bccb56 --- /dev/null +++ b/actionview/test/template/record_tag_helper_test.rb @@ -0,0 +1,117 @@ +require 'abstract_unit' + +class RecordTagPost + extend ActiveModel::Naming + include ActiveModel::Conversion + attr_accessor :id, :body + + def initialize + @id = 45 + @body = "What a wonderful world!" + + yield self if block_given? + end +end + +class RecordTagHelperTest < ActionView::TestCase + include RenderERBUtils + + tests ActionView::Helpers::RecordTagHelper + + def setup + super + @post = RecordTagPost.new + end + + def test_content_tag_for + expected = %(
  • ) + actual = content_tag_for(:li, @post) + assert_dom_equal expected, actual + end + + def test_content_tag_for_prefix + expected = %() + actual = content_tag_for(:ul, @post, :archived) + assert_dom_equal expected, actual + end + + def test_content_tag_for_with_extra_html_options + expected = %() + actual = content_tag_for(:tr, @post, class: "special", style: "background-color: #f0f0f0") + assert_dom_equal expected, actual + end + + def test_content_tag_for_with_array_css_class + expected = %() + actual = content_tag_for(:tr, @post, class: ["special", "odd"]) + assert_dom_equal expected, actual + end + + def test_content_tag_for_with_prefix_and_extra_html_options + expected = %() + actual = content_tag_for(:tr, @post, :archived, class: "special", style: "background-color: #f0f0f0") + assert_dom_equal expected, actual + end + + def test_block_not_in_erb_multiple_calls + expected = %(
    What a wonderful world!
    ) + actual = div_for(@post, class: "special") { @post.body } + assert_dom_equal expected, actual + actual = div_for(@post, class: "special") { @post.body } + assert_dom_equal expected, actual + end + + def test_block_works_with_content_tag_for_in_erb + expected = %(What a wonderful world!) + actual = render_erb("<%= content_tag_for(:tr, @post) do %><%= @post.body %><% end %>") + assert_dom_equal expected, actual + end + + def test_div_for_in_erb + expected = %(
    What a wonderful world!
    ) + actual = render_erb("<%= div_for(@post, class: 'special') do %><%= @post.body %><% end %>") + assert_dom_equal expected, actual + end + + def test_content_tag_for_collection + post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" } + post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" } + expected = %(
  • Hello!
  • \n
  • World!
  • ) + actual = content_tag_for(:li, [post_1, post_2]) { |post| post.body } + assert_dom_equal expected, actual + end + + def test_content_tag_for_collection_without_given_block + post_1 = RecordTagPost.new.tap { |post| post.id = 101; post.body = "Hello!" } + post_2 = RecordTagPost.new.tap { |post| post.id = 102; post.body = "World!" } + expected = %(
  • \n
  • ) + actual = content_tag_for(:li, [post_1, post_2]) + assert_dom_equal expected, actual + end + + def test_div_for_collection + post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" } + post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" } + expected = %(
    Hello!
    \n
    World!
    ) + actual = div_for([post_1, post_2]) { |post| post.body } + assert_dom_equal expected, actual + end + + def test_content_tag_for_single_record_is_html_safe + result = div_for(@post, class: "special") { @post.body } + assert result.html_safe? + end + + def test_content_tag_for_collection_is_html_safe + post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" } + post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" } + result = content_tag_for(:li, [post_1, post_2]) { |post| post.body } + assert result.html_safe? + end + + def test_content_tag_for_does_not_change_options_hash + options = { class: "important" } + content_tag_for(:li, @post, options) + assert_equal({ class: "important" }, options) + end +end -- cgit v1.2.3