Commit c12aaa505338f9bce600de89af0b8397e5154089
1 parent
2dbb16f5
Exists in
master
and in
22 other branches
rails3: fix content_viewer_helper test
Showing
1 changed file
with
19 additions
and
19 deletions
Show diff stats
test/unit/content_viewer_helper_test.rb
1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | -class ContentViewerHelperTest < ActiveSupport::TestCase | 3 | +class ContentViewerHelperTest < ActionView::TestCase |
4 | 4 | ||
5 | include ActionView::Helpers::TagHelper | 5 | include ActionView::Helpers::TagHelper |
6 | include ContentViewerHelper | 6 | include ContentViewerHelper |
@@ -14,13 +14,13 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | @@ -14,13 +14,13 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | ||
14 | 14 | ||
15 | should 'display published-at for blog posts' do | 15 | should 'display published-at for blog posts' do |
16 | blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | 16 | blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) |
17 | - post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) | 17 | + post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog) |
18 | result = article_title(post) | 18 | result = article_title(post) |
19 | assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at) | 19 | assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at) |
20 | end | 20 | end |
21 | 21 | ||
22 | should 'not display published-at for non-blog posts' do | 22 | should 'not display published-at for non-blog posts' do |
23 | - article = TextileArticle.create!(:name => 'article for test', :profile => profile) | 23 | + article = create(TextileArticle, :name => 'article for test', :profile => profile) |
24 | result = article_title(article) | 24 | result = article_title(article) |
25 | assert_no_match /<span class="date">#{show_date(article.published_at)}<\/span><span class="author">, by .*#{profile.identifier}/, result | 25 | assert_no_match /<span class="date">#{show_date(article.published_at)}<\/span><span class="author">, by .*#{profile.identifier}/, result |
26 | end | 26 | end |
@@ -37,13 +37,13 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | @@ -37,13 +37,13 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | ||
37 | blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) | 37 | blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) |
38 | post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) | 38 | post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) |
39 | result = article_title(post, :no_link => :true) | 39 | result = article_title(post, :no_link => :true) |
40 | - assert_no_match /a href='#{post.url}'>#{post.name}</, result | 40 | + assert_no_match /a href='#{url_for(post.url)}'>#{post.name}</, result |
41 | end | 41 | end |
42 | 42 | ||
43 | should 'not create link on title if non-blog post' do | 43 | should 'not create link on title if non-blog post' do |
44 | article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id) | 44 | article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id) |
45 | result = article_title(article) | 45 | result = article_title(article) |
46 | - assert_no_match /a href='#{article.url}'>#{article.name}</, result | 46 | + assert_no_match /a href='#{url_for(article.url)}'>#{article.name}</, result |
47 | end | 47 | end |
48 | 48 | ||
49 | should 'not create link to comments if called with no_comments' do | 49 | should 'not create link to comments if called with no_comments' do |
@@ -62,21 +62,21 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | @@ -62,21 +62,21 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | ||
62 | 62 | ||
63 | should 'count total of comments from post' do | 63 | should 'count total of comments from post' do |
64 | article = fast_create(TextileArticle, :profile_id => profile.id) | 64 | article = fast_create(TextileArticle, :profile_id => profile.id) |
65 | - article.comments.create!(:author => profile, :title => 'test', :body => 'test') | 65 | + create(Comment, :article => article, :author => profile, :title => 'test', :body => 'test') |
66 | result = link_to_comments(article) | 66 | result = link_to_comments(article) |
67 | assert_match /One comment/, result | 67 | assert_match /One comment/, result |
68 | end | 68 | end |
69 | 69 | ||
70 | should 'not display total of comments if the article doesn\'t allow comments' do | 70 | should 'not display total of comments if the article doesn\'t allow comments' do |
71 | - article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile, :accept_comments => false) | 71 | + article = build(TextileArticle, :name => 'first post for test', :body => 'first post for test', :profile => profile, :accept_comments => false) |
72 | article.stubs(:url).returns({}) | 72 | article.stubs(:url).returns({}) |
73 | - article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) | 73 | + article.stubs(:comments).returns([build(Comment, :author => profile, :title => 'test', :body => 'test')]) |
74 | result = link_to_comments(article) | 74 | result = link_to_comments(article) |
75 | assert_equal '', result | 75 | assert_equal '', result |
76 | end | 76 | end |
77 | 77 | ||
78 | should 'not list feed article' do | 78 | should 'not list feed article' do |
79 | - profile.articles << Blog.new(:name => 'Blog test', :profile => profile) | 79 | + profile.articles << build(Blog, :name => 'Blog test', :profile => profile) |
80 | assert_includes profile.blog.children.map{|i| i.class}, RssFeed | 80 | assert_includes profile.blog.children.map{|i| i.class}, RssFeed |
81 | result = list_posts(profile.blog.posts) | 81 | result = list_posts(profile.blog.posts) |
82 | assert_no_match /feed/, result | 82 | assert_no_match /feed/, result |
@@ -85,33 +85,33 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | @@ -85,33 +85,33 @@ class ContentViewerHelperTest < ActiveSupport::TestCase | ||
85 | should 'generate facebook addthis url for article' do | 85 | should 'generate facebook addthis url for article' do |
86 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | 86 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') |
87 | [TextileArticle, Blog, Folder, Gallery, UploadedFile, Forum, Event, TextArticle, TinyMceArticle].each do |model| | 87 | [TextileArticle, Blog, Folder, Gallery, UploadedFile, Forum, Event, TextArticle, TinyMceArticle].each do |model| |
88 | - a = model.new(:name => 'Some title', :body => 'Some text here.', :profile => profile) | ||
89 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=Some+text+here.&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) | 88 | + a = build(model, :body => 'Some text here.', :profile => profile) |
89 | + assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=#{a.name.gsub(' ','+')}&p[summary]=Some+text+here.&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2F#{a.slug}&p[images][0]=", addthis_facebook_url(a) | ||
90 | end | 90 | end |
91 | end | 91 | end |
92 | 92 | ||
93 | should 'generate facebook addthis url without body' do | 93 | should 'generate facebook addthis url without body' do |
94 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | 94 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') |
95 | - a = TinyMceArticle.new(:name => 'Test', :body => nil, :profile => profile) | ||
96 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Test&p[summary]=&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Ftest&p[images][0]=", addthis_facebook_url(a) | 95 | + a = build(TinyMceArticle, :body => nil, :profile => profile) |
96 | + assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=#{a.name.gsub(' ','+')}&p[summary]=&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2F#{a.slug}&p[images][0]=", addthis_facebook_url(a) | ||
97 | end | 97 | end |
98 | 98 | ||
99 | should 'generate facebook addthis url without tags in body' do | 99 | should 'generate facebook addthis url without tags in body' do |
100 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | 100 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') |
101 | - a = TinyMceArticle.new(:name => 'Some title', :body => '<p>This <b class="bold">is</b> a test</p>', :profile => profile) | ||
102 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) | 101 | + a = build(TinyMceArticle, :body => '<p>This <b class="bold">is</b> a test</p>', :profile => profile) |
102 | + assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=#{a.name.gsub(' ','+')}&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2F#{a.slug}&p[images][0]=", addthis_facebook_url(a) | ||
103 | end | 103 | end |
104 | 104 | ||
105 | should 'generate facebook addthis url with truncated body' do | 105 | should 'generate facebook addthis url with truncated body' do |
106 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | 106 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') |
107 | - a = TinyMceArticle.new(:name => 'Some title', :body => 'test' * 76, :profile => profile) | ||
108 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=#{'test' * 74}t...&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=", addthis_facebook_url(a) | 107 | + a = build(TinyMceArticle, :body => 'test' * 76, :profile => profile) |
108 | + assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=#{a.name.gsub(' ','+')}&p[summary]=#{'test' * 74}t...&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2F#{a.slug}&p[images][0]=", addthis_facebook_url(a) | ||
109 | end | 109 | end |
110 | 110 | ||
111 | should 'generate facebook addthis url for tinymce article with images' do | 111 | should 'generate facebook addthis url for tinymce article with images' do |
112 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') | 112 | Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') |
113 | - a = TinyMceArticle.new(:name => 'Some title', :body => '<p>This <b class="bold">is</b> a <img src="/images/x.png" />test</p>', :profile => profile) | ||
114 | - assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=Some+title&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2Fsome-title&p[images][0]=http%3A%2F%2Fnoosfero.org%2Fimages%2Fx.png", addthis_facebook_url(a) | 113 | + a = build(TinyMceArticle, :body => '<p>This <b class="bold">is</b> a <img src="/images/x.png" />test</p>', :profile => profile) |
114 | + assert_equal "http://www.facebook.com/sharer.php?s=100&p[title]=#{a.name.gsub(' ','+')}&p[summary]=This+is+a+test&p[url]=http%3A%2F%2Fnoosfero.org%2Fblog_helper_test%2F#{a.slug}&p[images][0]=http%3A%2F%2Fnoosfero.org%2Fimages%2Fx.png", addthis_facebook_url(a) | ||
115 | end | 115 | end |
116 | 116 | ||
117 | should 'theme provides addthis custom icon' do | 117 | should 'theme provides addthis custom icon' do |