diff --git a/test/unit/blog_archives_block_test.rb b/test/unit/blog_archives_block_test.rb index 40b0d8b..1f2799a 100644 --- a/test/unit/blog_archives_block_test.rb +++ b/test/unit/blog_archives_block_test.rb @@ -17,6 +17,69 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase assert l.editable? end + should 'has field to configure blog' do + b = BlogArchivesBlock.new + assert b.respond_to?(:blog_id) + assert b.respond_to?(:blog_id=) + end + + should 'not try to load a removed blog' do + block = fast_create(BlogArchivesBlock) + block.blog_id = profile.blog.id + block.save! + block.stubs(:owner).returns(profile) + profile.blog.destroy + assert_nothing_raised do + assert_nil block.blog + end + end + + should 'load next blog if configured blog was removed' do + other_blog = fast_create(Blog, :profile_id => profile.id) + block = fast_create(BlogArchivesBlock) + block.blog_id = profile.blog.id + block.save! + block.stubs(:owner).returns(profile) + profile.blog.destroy + assert_nothing_raised do + assert_equal other_blog, block.blog + end + end + +#FIXME Performance issues with display_to. Must convert it to a scope. +# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705 +# +# should 'not count articles if the user can\'t see them' do +# person = create_user('testuser').person +# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path') +# block = fast_create(BlogArchivesBlock) +# +# feed = mock() +# feed.stubs(:url).returns(blog.url) +# blog.stubs(:feed).returns(feed) +# block.stubs(:blog).returns(blog) +# block.stubs(:owner).returns(profile) +# +# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan')) +# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan')) +# +# assert_match /January \(1\)/, block.content({:person => person}) +# assert_match /January \(1\)/, block.content() +# assert_match /January \(2\)/, block.content({:person => profile}) +# end +end + +require 'boxes_helper' + +class BlogArchivesBlockViewTest < ActionView::TestCase + include BoxesHelper + + def setup + @profile = create_user('flatline').person + @profile.articles << Blog.new(:name => 'Blog One', :profile => @profile) + end + attr_reader :profile + should 'list amount posts by year' do date = DateTime.parse('2008-01-10') blog = profile.blog @@ -26,7 +89,9 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_tag_in_string block.content, :tag => 'li', :content => '2008 (10)' + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).returns("") + assert_tag_in_string render_block_content(block), :tag => 'li', :content => '2008 (10)' end should 'list amount posts by month' do @@ -38,7 +103,18 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_tag_in_string block.content, :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February") + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March") + ActionView::Base.any_instance.stubs(:month_name).with(4).returns("April") + ActionView::Base.any_instance.stubs(:month_name).with(5).returns("May") + ActionView::Base.any_instance.stubs(:month_name).with(6).returns("June") + ActionView::Base.any_instance.stubs(:month_name).with(7).returns("July") + ActionView::Base.any_instance.stubs(:month_name).with(8).returns("August") + ActionView::Base.any_instance.stubs(:month_name).with(9).returns("September") + ActionView::Base.any_instance.stubs(:month_name).with(10).returns("Octuber") + assert_tag_in_string render_block_content(block), :tag => 'a', :content => 'January (10)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } end should 'order list of amount posts' do @@ -49,7 +125,18 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_tag_in_string block.content, :tag => 'li', :content => 'January (1)', + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February") + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March") + ActionView::Base.any_instance.stubs(:month_name).with(4).returns("April") + ActionView::Base.any_instance.stubs(:month_name).with(5).returns("May") + ActionView::Base.any_instance.stubs(:month_name).with(6).returns("June") + ActionView::Base.any_instance.stubs(:month_name).with(7).returns("July") + ActionView::Base.any_instance.stubs(:month_name).with(8).returns("August") + ActionView::Base.any_instance.stubs(:month_name).with(9).returns("September") + ActionView::Base.any_instance.stubs(:month_name).with(10).returns("Octuber") + assert_tag_in_string render_block_content(block), :tag => 'li', :content => 'January (1)', :sibling => {:tag => 'li', :content => 'February (1)', :sibling => {:tag => 'li', :content => 'March (1)', :sibling => {:tag => 'li', :content => 'April (1)', @@ -63,7 +150,9 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_match(/2009.*2008.*2007.*2006.*2005/m, block.content) + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).returns("") + assert_match(/2009.*2008.*2007.*2006.*2005/m, render_block_content(block)) end should 'order months from later to former' do @@ -73,20 +162,20 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_match(/.*March.*February.*January.*/m, block.content) + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") + ActionView::Base.any_instance.stubs(:month_name).with(2).returns("February") + ActionView::Base.any_instance.stubs(:month_name).with(3).returns("March") + assert_match(/.*March.*February.*January.*/m, render_block_content(block)) end should 'not display any content if has no blog' do profile.blogs.destroy_all block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_nil block.content - end - - should 'has field to configure blog' do - b = BlogArchivesBlock.new - assert b.respond_to?(:blog_id) - assert b.respond_to?(:blog_id=) + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).returns("") + assert_empty render_block_content(block) end should 'show posts from first blog' do @@ -98,8 +187,10 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_match(/blog-one/m, block.content) - assert_no_match(/blog-two/m, block.content) + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).returns("") + assert_match(/blog-one/m, render_block_content(block)) + assert_no_match(/blog-two/m, render_block_content(block)) end should 'list amount native posts by year' do @@ -115,7 +206,9 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_tag_in_string block.content, :tag => 'li', :content => '2008 (2)' + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).returns("") + assert_tag_in_string render_block_content(block), :tag => 'li', :content => '2008 (2)' end should 'list amount native posts by month' do @@ -131,51 +224,8 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) - assert_tag_in_string block.content, :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } - end - - should 'not try to load a removed blog' do - block = fast_create(BlogArchivesBlock) - block.blog_id = profile.blog.id - block.save! - block.stubs(:owner).returns(profile) - profile.blog.destroy - assert_nothing_raised do - assert_nil block.blog - end + ActionView::Base.any_instance.stubs(:block_title).returns("") + ActionView::Base.any_instance.stubs(:month_name).with(1).returns("January") + assert_tag_in_string render_block_content(block), :tag => 'a', :content => 'January (2)', :attributes => {:href => /^http:\/\/.*\/flatline\/blog-one\?month=1&year=2008$/ } end - - should 'load next blog if configured blog was removed' do - other_blog = fast_create(Blog, :profile_id => profile.id) - block = fast_create(BlogArchivesBlock) - block.blog_id = profile.blog.id - block.save! - block.stubs(:owner).returns(profile) - profile.blog.destroy - assert_nothing_raised do - assert_equal other_blog, block.blog - end - end - -#FIXME Performance issues with display_to. Must convert it to a scope. -# Checkout this page for further information: http://noosfero.org/Development/ActionItem2705 -# -# should 'not count articles if the user can\'t see them' do -# person = create_user('testuser').person -# blog = fast_create(Blog, :profile_id => profile.id, :path => 'blog_path') -# block = fast_create(BlogArchivesBlock) -# -# feed = mock() -# feed.stubs(:url).returns(blog.url) -# blog.stubs(:feed).returns(feed) -# block.stubs(:blog).returns(blog) -# block.stubs(:owner).returns(profile) -# -# public_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => true, :published_at => Time.mktime(2012, 'jan')) -# private_post = fast_create(TextileArticle, :profile_id => profile.id, :parent_id => blog.id, :published => false, :published_at => Time.mktime(2012, 'jan')) -# -# assert_match /January \(1\)/, block.content({:person => person}) -# assert_match /January \(1\)/, block.content() -# assert_match /January \(2\)/, block.content({:person => profile}) -# end end -- libgit2 0.21.2