Skip to content

Commit

Permalink
Fix errors when running entire suite due to class name collision
Browse files Browse the repository at this point in the history
The Post class is created everywhere in the test suite, and due to that
when applying the Array() logic to refactor content_tag_for, some other
change to the Post class was breaking record tag tests.

The solution is to rename the class to not collide with others
already defined in the test suite.
  • Loading branch information
carlosantoniodasilva committed Jan 18, 2012
1 parent b64b7d0 commit 8470fc9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_view/helpers/record_tag_helper.rb
Expand Up @@ -83,8 +83,8 @@ def div_for(record, *args, &block)
def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block) def content_tag_for(tag_name, single_or_multiple_records, prefix = nil, options = nil, &block)
options, prefix = prefix, nil if prefix.is_a?(Hash) options, prefix = prefix, nil if prefix.is_a?(Hash)


Array.wrap(single_or_multiple_records).map do |single_record| Array(single_or_multiple_records).map do |single_record|
content_tag_for_single_record tag_name, single_record, prefix, options, &block content_tag_for_single_record(tag_name, single_record, prefix, options, &block)
end.join("\n").html_safe end.join("\n").html_safe
end end


Expand Down
46 changes: 23 additions & 23 deletions actionpack/test/template/record_tag_helper_test.rb
@@ -1,6 +1,6 @@
require 'abstract_unit' require 'abstract_unit'


class Post class RecordTagPost
extend ActiveModel::Naming extend ActiveModel::Naming
include ActiveModel::Conversion include ActiveModel::Conversion
attr_accessor :id, :body attr_accessor :id, :body
Expand All @@ -20,77 +20,77 @@ class RecordTagHelperTest < ActionView::TestCase


def setup def setup
super super
@post = Post.new @post = RecordTagPost.new
end end


def test_content_tag_for def test_content_tag_for
expected = %(<li class="post" id="post_45"></li>) expected = %(<li class="record_tag_post" id="record_tag_post_45"></li>)
actual = content_tag_for(:li, @post) { } actual = content_tag_for(:li, @post) { }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_content_tag_for_prefix def test_content_tag_for_prefix
expected = %(<ul class="archived_post" id="archived_post_45"></ul>) expected = %(<ul class="archived_record_tag_post" id="archived_record_tag_post_45"></ul>)
actual = content_tag_for(:ul, @post, :archived) { } actual = content_tag_for(:ul, @post, :archived) { }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_content_tag_for_with_extra_html_options def test_content_tag_for_with_extra_html_options
expected = %(<tr class="post bar" id="post_45" style='background-color: #f0f0f0'></tr>) expected = %(<tr class="record_tag_post special" id="record_tag_post_45" style='background-color: #f0f0f0'></tr>)
actual = content_tag_for(:tr, @post, :class => "bar", :style => "background-color: #f0f0f0") { } actual = content_tag_for(:tr, @post, :class => "special", :style => "background-color: #f0f0f0") { }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_content_tag_for_with_prefix_and_extra_html_options def test_content_tag_for_with_prefix_and_extra_html_options
expected = %(<tr class="archived_post bar" id="archived_post_45" style='background-color: #f0f0f0'></tr>) expected = %(<tr class="archived_record_tag_post special" id="archived_record_tag_post_45" style='background-color: #f0f0f0'></tr>)
actual = content_tag_for(:tr, @post, :archived, :class => "bar", :style => "background-color: #f0f0f0") { } actual = content_tag_for(:tr, @post, :archived, :class => "special", :style => "background-color: #f0f0f0") { }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_block_not_in_erb_multiple_calls def test_block_not_in_erb_multiple_calls
expected = %(<div class="post bar" id="post_45">What a wonderful world!</div>) expected = %(<div class="record_tag_post special" id="record_tag_post_45">What a wonderful world!</div>)
actual = div_for(@post, :class => "bar") { @post.body } actual = div_for(@post, :class => "special") { @post.body }
assert_dom_equal expected, actual assert_dom_equal expected, actual
actual = div_for(@post, :class => "bar") { @post.body } actual = div_for(@post, :class => "special") { @post.body }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_block_works_with_content_tag_for_in_erb def test_block_works_with_content_tag_for_in_erb
expected = %(<tr class="post" id="post_45">What a wonderful world!</tr>) expected = %(<tr class="record_tag_post" id="record_tag_post_45">What a wonderful world!</tr>)
actual = render_erb("<%= content_tag_for(:tr, @post) do %><%= @post.body %><% end %>") actual = render_erb("<%= content_tag_for(:tr, @post) do %><%= @post.body %><% end %>")
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_div_for_in_erb def test_div_for_in_erb
expected = %(<div class="post bar" id="post_45">What a wonderful world!</div>) expected = %(<div class="record_tag_post special" id="record_tag_post_45">What a wonderful world!</div>)
actual = render_erb("<%= div_for(@post, :class => 'bar') do %><%= @post.body %><% end %>") actual = render_erb("<%= div_for(@post, :class => 'special') do %><%= @post.body %><% end %>")
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_content_tag_for_collection def test_content_tag_for_collection
post_1 = Post.new { |post| post.id = 101; post.body = "Hello!" } post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" }
post_2 = Post.new { |post| post.id = 102; post.body = "World!" } post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" }
expected = %(<li class="post" id="post_101">Hello!</li>\n<li class="post" id="post_102">World!</li>) expected = %(<li class="record_tag_post" id="record_tag_post_101">Hello!</li>\n<li class="record_tag_post" id="record_tag_post_102">World!</li>)
actual = content_tag_for(:li, [post_1, post_2]) { |post| post.body } actual = content_tag_for(:li, [post_1, post_2]) { |post| post.body }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_div_for_collection def test_div_for_collection
post_1 = Post.new { |post| post.id = 101; post.body = "Hello!" } post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" }
post_2 = Post.new { |post| post.id = 102; post.body = "World!" } post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" }
expected = %(<div class="post" id="post_101">Hello!</div>\n<div class="post" id="post_102">World!</div>) expected = %(<div class="record_tag_post" id="record_tag_post_101">Hello!</div>\n<div class="record_tag_post" id="record_tag_post_102">World!</div>)
actual = div_for([post_1, post_2]) { |post| post.body } actual = div_for([post_1, post_2]) { |post| post.body }
assert_dom_equal expected, actual assert_dom_equal expected, actual
end end


def test_content_tag_for_single_record_is_html_safe def test_content_tag_for_single_record_is_html_safe
result = div_for(@post, :class => "bar") { @post.body } result = div_for(@post, :class => "special") { @post.body }
assert result.html_safe? assert result.html_safe?
end end


def test_content_tag_for_collection_is_html_safe def test_content_tag_for_collection_is_html_safe
post_1 = Post.new { |post| post.id = 101; post.body = "Hello!" } post_1 = RecordTagPost.new { |post| post.id = 101; post.body = "Hello!" }
post_2 = Post.new { |post| post.id = 102; post.body = "World!" } post_2 = RecordTagPost.new { |post| post.id = 102; post.body = "World!" }
result = content_tag_for(:li, [post_1, post_2]) { |post| post.body } result = content_tag_for(:li, [post_1, post_2]) { |post| post.body }
assert result.html_safe? assert result.html_safe?
end end
Expand Down

0 comments on commit 8470fc9

Please sign in to comment.