require File.dirname(__FILE__) + '/../test_helper'
class BlogHelperTest < Test::Unit::TestCase
include BlogHelper
include ContentViewerHelper
include ActionView::Helpers::AssetTagHelper
include ApplicationHelper
def setup
stubs(:show_date).returns('')
@environment = Environment.default
@profile = create_user('blog_helper_test').person
@blog = fast_create(Blog, :profile_id => profile.id, :name => 'Blog test')
end
attr :profile
attr :blog
def _(s); s; end
def h(s); s; end
should 'list published posts with class blog-post' do
blog.children << published_post = TextileArticle.create!(:name => 'Post', :profile => profile, :parent => blog, :published => true)
expects(:display_post).with(anything, anything).returns('POST')
expects(:content_tag).with('div', "POST
", :class => 'blog-post position-1 first last odd-post-inner', :id => "post-#{published_post.id}").returns('POST')
expects(:content_tag).with('div', 'POST', {:class => 'odd-post'}).returns('RESULT')
assert_equal 'RESULT', list_posts(profile, blog.posts)
end
should 'list unpublished posts to owner with a different class' do
blog.children << unpublished_post = TextileArticle.create!(:name => 'Post', :profile => profile, :parent => blog, :published => false)
expects(:display_post).with(anything, anything).returns('POST')
expects(:content_tag).with('div', "POST
", :class => 'blog-post position-1 first last not-published odd-post-inner', :id => "post-#{unpublished_post.id}").returns('POST')
expects(:content_tag).with('div', 'POST', {:class => 'odd-post'}).returns('RESULT')
assert_equal 'RESULT', list_posts(profile, blog.posts)
end
should 'not list unpublished posts to not owner' do
blog.children << unpublished_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => blog, :published => false)
blog.children << published_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true)
expects(:display_post).with(anything, anything).returns('POST')
expects(:content_tag).with('div', "POST
", has_entries(:id => "post-#{unpublished_post.id}")).never
expects(:content_tag).with('div', "POST
", has_entries(:id => "post-#{published_post.id}")).returns('POST')
expects(:content_tag).with('div', 'POST', {:class => 'odd-post'}).returns('RESULT')
assert_equal 'RESULT', list_posts(nil, blog.posts)
end
should 'list even/odd posts with a different class' do
blog.children << older_post = TextileArticle.create!(:name => 'First post', :profile => profile, :parent => blog, :published => true)
blog.children << newer_post = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true)
expects(:display_post).with(anything, anything).returns('POST').times(2)
expects(:content_tag).with('div', "POST
", :class => 'blog-post position-1 first odd-post-inner', :id => "post-#{newer_post.id}").returns('POST 1')
expects(:content_tag).with('div', "POST 1", :class => 'odd-post').returns('ODD-POST')
expects(:content_tag).with('div', "POST
", :class => 'blog-post position-2 last even-post-inner', :id => "post-#{older_post.id}").returns('POST 2')
expects(:content_tag).with('div', "POST 2", :class => 'even-post').returns('EVEN-POST')
assert_equal "ODD-POST\n