test/test_attributes.rb in attrtastic-0.2.2 vs test/test_attributes.rb in attrtastic-0.3.0

- old
+ new

@@ -1,8 +1,8 @@ require 'helper' -class TestAttributes < Test::Unit::TestCase +class TestAttributes < TestCase context "attributes" do setup do setup_fixtures @@ -20,28 +20,24 @@ should "generate output even when no block given" do expected = html <<-EOHTML <div class="attributes"> </div> EOHTML + actual = @user_builder.attributes - @user_builder.attributes - actual = @template.output_buffer.to_s - assert_equal expected, actual end should "generate output with block given" do expected = html <<-EOHTML <div class="attributes"> <ol> </ol> </div> EOHTML + actual = @user_builder.attributes do end - @user_builder.attributes do end - actual = @template.output_buffer.to_s - assert_equal expected, actual end should "show header" do expected = html <<-EOHTML @@ -49,18 +45,17 @@ <div class="legend">Legend</div> <ol> </ol> </div> EOHTML + actual = @user_builder.attributes "Legend" do end - @user_builder.attributes "Legend" do end - actual = @template.output_buffer.to_s assert_equal expected, actual - @template.output_buffer.clear - @user_builder.attributes :name => "Legend" do end - actual = @template.output_buffer.to_s + #@template.output_buffer.clear + actual = @user_builder.attributes :name => "Legend" do end + assert_equal expected, actual end context "with fields list" do @@ -77,13 +72,12 @@ <span class="value">john@doe.com</span> </li> </ol> </div> EOHTML + actual = @user_builder.attributes :full_name, :email - @user_builder.attributes :full_name, :email - actual = @template.output_buffer.to_s assert_equal expected, actual end should "show header" do expected = html <<-EOHTML @@ -103,13 +97,12 @@ <span class="value">john@doe.com</span> </li> </ol> </div> EOHTML + actual = @user_builder.attributes "Contact", :full_name, :title, :email, :html => {:class => "contact"}, :display_empty => true - @user_builder.attributes "Contact", :full_name, :title, :email, :html => {:class => "contact"}, :display_empty => true - actual = @template.output_buffer.to_s assert_equal expected, actual end end @@ -134,11 +127,11 @@ end end should "generate output for given inner object" do - @blog_builder.attributes :for => :author do |author| + actual = @blog_builder.attributes :for => :author do |author| expected = html <<-EOHTML <li class="attribute"> <span class="label">Full name</span> <span class="value">Doe, John</span> @@ -155,27 +148,24 @@ <ol> </ol> </div> EOHTML - actual = @template.output_buffer assert_equal expected, actual end should "show header" do - @blog_builder.attributes "Author", :for => :author do |author| - end - expected = html <<-EOHTML <div class="attributes user"> <div class="legend">Author</div> <ol> </ol> </div> EOHTML + actual = @blog_builder.attributes "Author", :for => :author do |author| + end - actual = @template.output_buffer assert_equal expected, actual end should "work with field list" do expected = html <<-EOHTML @@ -186,14 +176,12 @@ <span class="value">Doe, John</span> </li> </ol> </div> EOHTML + actual = @blog_builder.attributes :full_name, :for => :author - @blog_builder.attributes :full_name, :for => :author - - actual = @template.output_buffer assert_equal expected, actual end end context "with :for => object" do @@ -205,11 +193,11 @@ end end should "generate output for given inner object" do - @blog_builder.attributes :for => @user do |author| + actual = @blog_builder.attributes :for => @user do |author| expected = html <<-EOHTML <li class="attribute"> <span class="label">Full name</span> <span class="value">Doe, John</span> @@ -226,27 +214,25 @@ <ol> </ol> </div> EOHTML - actual = @template.output_buffer assert_equal expected, actual end should "show header" do - @blog_builder.attributes "Author", :for => @user do |author| + actual = @blog_builder.attributes "Author", :for => @user do |author| end expected = html <<-EOHTML <div class="attributes user"> <div class="legend">Author</div> <ol> </ol> </div> EOHTML - actual = @template.output_buffer assert_equal expected, actual end should "work with field list" do expected = html <<-EOHTML @@ -257,14 +243,12 @@ <span class="value">Doe, John</span> </li> </ol> </div> EOHTML + actual = @user_builder.attributes :full_name, :for => @user - @blog_builder.attributes :full_name, :for => @user - - actual = @template.output_buffer assert_equal expected, actual end end context "with :for => :method_name pointing to collection" do @@ -280,32 +264,27 @@ assert_equal @blog.posts, posts end should "generate output for given objects" do - @blog_builder.attributes :for => :posts do |post| - end - expected = html <<-EOHTML <div class="attributes post"> <ol> </ol> </div> <div class="attributes post"> <ol> </ol> </div> EOHTML + actual = @blog_builder.attributes :for => :posts do |post| + end - actual = @template.output_buffer assert_equal expected, actual end should "show header" do - @blog_builder.attributes "Post", :for => :posts do |post| - end - expected = html <<-EOHTML <div class="attributes post"> <div class="legend">Post</div> <ol> </ol> @@ -314,12 +293,13 @@ <div class="legend">Post</div> <ol> </ol> </div> EOHTML + actual = @blog_builder.attributes "Post", :for => :posts do |post| + end - actual = @template.output_buffer assert_equal expected, actual end should "work with field list" do expected = html <<-EOHTML @@ -338,14 +318,12 @@ <span class="value">Sorry</span> </li> </ol> </div> EOHTML + actual = @blog_builder.attributes :title, :for => :posts - @blog_builder.attributes :title, :for => :posts - - actual = @template.output_buffer assert_equal expected, actual end end context "with :for => collection" do @@ -361,32 +339,27 @@ assert_equal @blog.posts, posts end should "generate output for given objects" do - @blog_builder.attributes :for => @blog.posts do |post| - end - expected = html <<-EOHTML <div class="attributes post"> <ol> </ol> </div> <div class="attributes post"> <ol> </ol> </div> EOHTML + actual = @blog_builder.attributes :for => @blog.posts do |post| + end - actual = @template.output_buffer assert_equal expected, actual end should "show header" do - @blog_builder.attributes "Post", :for => @blog.posts do |post| - end - expected = html <<-EOHTML <div class="attributes post"> <div class="legend">Post</div> <ol> </ol> @@ -395,12 +368,13 @@ <div class="legend">Post</div> <ol> </ol> </div> EOHTML + actual = @blog_builder.attributes "Post", :for => @blog.posts do |post| + end - actual = @template.output_buffer assert_equal expected, actual end should "work with field list" do expected = html <<-EOHTML @@ -419,13 +393,11 @@ <span class="value">Sorry</span> </li> </ol> </div> EOHTML + actual = @blog_builder.attributes :title, :for => @blog.posts - @blog_builder.attributes :title, :for => @blog.posts - - actual = @template.output_buffer assert_equal expected, actual end end end