blog_helper_test.rb
2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require File.dirname(__FILE__) + '/../test_helper'
class BlogHelperTest < Test::Unit::TestCase
include BlogHelper
def setup
stubs(:show_date).returns('')
@environment = Environment.default
@profile = create_user('blog_helper_test').person
@blog = Blog.create!(:profile => profile, :name => 'Blog test')
end
attr :profile
attr :blog
def _(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).returns('POST')
expects(:content_tag).with('div', 'POST', :class => 'blog-post position-1 first last', :id => "post-#{published_post.id}").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).returns('POST')
expects(:content_tag).with('div', 'POST', :class => 'blog-post position-1 first last not-published', :id => "post-#{unpublished_post.id}").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).returns('POST')
expects(:content_tag).with('div', 'POST', :class => 'blog-post position-2 last', :id => "post-#{published_post.id}").returns('RESULT')
expects(:content_tag).with('div', 'POST', :class => 'blog-post position-1 first', :id => "post-#{unpublished_post.id}").never
assert_equal 'RESULT', list_posts(nil, blog.posts)
end
should 'display post' do
blog.children << article = TextileArticle.create!(:name => 'Second post', :profile => profile, :parent => blog, :published => true)
expects(:article_title).with(article).returns('TITLE')
expects(:content_tag).with('p', article.to_html).returns(' TO_HTML')
assert_equal 'TITLE TO_HTML', display_post(article)
end
def will_paginate(arg1, arg2)
end
def link_to(content, url)
content
end
def content_tag(tag, content, options = {})
"<#{tag}>#{content}</#{tag}>"
end
end