Skip to content

Commit

Permalink
Mimic AR models yielding when building new records, avoid using tap
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosantoniodasilva committed Jan 18, 2012
1 parent 5c997cc commit 53381be
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions actionpack/test/template/record_tag_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def initialize
@id = nil
@body = nil
super

yield self if block_given?
end

def id
Expand Down Expand Up @@ -77,16 +79,16 @@ def test_div_for_in_erb
end

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

def test_div_for_collection
post_1 = Post.new.tap { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
post_2 = Post.new.tap { |post| post.id = 102; post.body = "World!"; post.persisted = true }
post_1 = Post.new { |post| post.id = 101; post.body = "Hello!"; post.persisted = true }
post_2 = Post.new { |post| post.id = 102; post.body = "World!"; post.persisted = true }
expected = %(<div class="post" id="post_101">Hello!</div>\n<div class="post" id="post_102">World!</div>)
actual = div_for([post_1, post_2]) { |post| post.body }
assert_dom_equal expected, actual
Expand All @@ -98,8 +100,8 @@ def test_content_tag_for_single_record_is_html_safe
end

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

0 comments on commit 53381be

Please sign in to comment.