aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/record_tag_helper_test.rb
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2011-09-02 21:35:24 +0700
committerPrem Sichanugrist <s@sikachu.com>2011-09-04 11:55:12 +0700
commitb84cee08c6129717d7c3291918f06f95cc9eb916 (patch)
tree84dcf7af7d54265602f7499ed69ca5cec345ebdd /actionpack/test/template/record_tag_helper_test.rb
parentd50c0acc95d9ac9b258594c7d68e1eeef9b6d41e (diff)
downloadrails-b84cee08c6129717d7c3291918f06f95cc9eb916.tar.gz
rails-b84cee08c6129717d7c3291918f06f95cc9eb916.tar.bz2
rails-b84cee08c6129717d7c3291918f06f95cc9eb916.zip
Make `content_tag_for` and `div_for` accepts the array of records
So instead of having to do this: @items.each do |item| content_tag_for(:li, item) do Title: <%= item.title %> end end You can now do this: content_tag_for(:li, @items) do |item| Title: <%= item.title %> end
Diffstat (limited to 'actionpack/test/template/record_tag_helper_test.rb')
-rw-r--r--actionpack/test/template/record_tag_helper_test.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb
index 1ba14e8bc9..edc2689896 100644
--- a/actionpack/test/template/record_tag_helper_test.rb
+++ b/actionpack/test/template/record_tag_helper_test.rb
@@ -4,11 +4,12 @@ require 'controller/fake_models'
class Post
extend ActiveModel::Naming
include ActiveModel::Conversion
+ attr_writer :id, :body
def id
- 45
+ @id || 45
end
def body
- super || "What a wonderful world!"
+ super || @body || "What a wonderful world!"
end
end
@@ -58,4 +59,23 @@ class RecordTagHelperTest < ActionView::TestCase
actual = div_for(@post, :class => "bar") { concat @post.body }
assert_dom_equal expected, actual
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 }
+ 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| concat post.body }
+ assert_dom_equal expected, actual
+ end
+
+ def test_content_tag_for_collection_is_html_safe
+ 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 }
+ 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| concat post.body }
+ assert_dom_equal expected, actual
+ end
end