blog_helper_test.rb
3.5 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require File.dirname(__FILE__) + '/../test_helper'
class BlogHelperTest < Test::Unit::TestCase
include BlogHelper
include ContentViewerHelper
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<br style=\"clear:both\"/>", :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<br style=\"clear:both\"/>", :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<br style=\"clear:both\"/>", has_entries(:id => "post-#{published_post.id}")).returns('RESULT')
expects(:content_tag).with('div', "POST<br style=\"clear:both\"/>", has_entries(: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')
self.stubs(:params).returns({:npage => nil})
assert_equal 'TITLE TO_HTML', display_post(article)
end
should 'display link to file if post is an uploaded_file' do
file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :profile => profile, :published => true, :parent => blog)
expects(:article_to_html).with(file).returns('TO HTML')
result = display_post(file)
assert_tag_in_string result, :content => /TO HTML/
end
should 'display image if post is an image' do
file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :profile => profile, :published => true, :parent => blog)
self.stubs(:params).returns({:npage => nil})
result = display_post(file)
assert_tag_in_string result, :content => 'rails.png'
assert_tag_in_string result, :tag => 'img', :attributes => { :src => /#{file.public_filename(:display)}/ }
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