diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb index c4add70..74a1669 100644 --- a/test/unit/content_viewer_helper_test.rb +++ b/test/unit/content_viewer_helper_test.rb @@ -1,6 +1,6 @@ require File.dirname(__FILE__) + '/../test_helper' -class ContentViewerHelperTest < ActiveSupport::TestCase +class ContentViewerHelperTest < ActionView::TestCase include ActionView::Helpers::TagHelper include ContentViewerHelper @@ -14,13 +14,13 @@ class ContentViewerHelperTest < ActiveSupport::TestCase should 'display published-at for blog posts' do blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) - post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) + post = create(TextileArticle, :name => 'post test', :profile => profile, :parent => blog) result = article_title(post) assert_tag_in_string result, :tag => 'span', :content => show_date(post.published_at) end should 'not display published-at for non-blog posts' do - article = TextileArticle.create!(:name => 'article for test', :profile => profile) + article = create(TextileArticle, :name => 'article for test', :profile => profile) result = article_title(article) assert_no_match /#{show_date(article.published_at)}<\/span>, by .*#{profile.identifier}/, result end @@ -37,13 +37,13 @@ class ContentViewerHelperTest < ActiveSupport::TestCase blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) result = article_title(post, :no_link => :true) - assert_no_match /a href='#{post.url}'>#{post.name}#{post.name} 'art test', :profile_id => profile.id) result = article_title(article) - assert_no_match /a href='#{article.url}'>#{article.name}#{article.name} profile.id) - article.comments.create!(:author => profile, :title => 'test', :body => 'test') + create(Comment, :article => article, :author => profile, :title => 'test', :body => 'test') result = link_to_comments(article) assert_match /One comment/, result end should 'not display total of comments if the article doesn\'t allow comments' do - article = TextileArticle.new(:name => 'first post for test', :body => 'first post for test', :profile => profile, :accept_comments => false) + article = build(TextileArticle, :name => 'first post for test', :body => 'first post for test', :profile => profile, :accept_comments => false) article.stubs(:url).returns({}) - article.stubs(:comments).returns([Comment.new(:author => profile, :title => 'test', :body => 'test')]) + article.stubs(:comments).returns([build(Comment, :author => profile, :title => 'test', :body => 'test')]) result = link_to_comments(article) assert_equal '', result end should 'not list feed article' do - profile.articles << Blog.new(:name => 'Blog test', :profile => profile) + profile.articles << build(Blog, :name => 'Blog test', :profile => profile) assert_includes profile.blog.children.map{|i| i.class}, RssFeed result = list_posts(profile.blog.posts) assert_no_match /feed/, result @@ -85,33 +85,33 @@ class ContentViewerHelperTest < ActiveSupport::TestCase should 'generate facebook addthis url for article' do Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') [TextileArticle, Blog, Folder, Gallery, UploadedFile, Forum, Event, TextArticle, TinyMceArticle].each do |model| - a = model.new(:name => 'Some title', :body => 'Some text here.', :profile => profile) - 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) + a = build(model, :body => 'Some text here.', :profile => profile) + 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) end end should 'generate facebook addthis url without body' do Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') - a = TinyMceArticle.new(:name => 'Test', :body => nil, :profile => profile) - 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) + a = build(TinyMceArticle, :body => nil, :profile => profile) + 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) end should 'generate facebook addthis url without tags in body' do Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') - a = TinyMceArticle.new(:name => 'Some title', :body => '

This is a test

', :profile => profile) - 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) + a = build(TinyMceArticle, :body => '

This is a test

', :profile => profile) + 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) end should 'generate facebook addthis url with truncated body' do Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') - a = TinyMceArticle.new(:name => 'Some title', :body => 'test' * 76, :profile => profile) - 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) + a = build(TinyMceArticle, :body => 'test' * 76, :profile => profile) + 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) end should 'generate facebook addthis url for tinymce article with images' do Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') - a = TinyMceArticle.new(:name => 'Some title', :body => '

This is a test

', :profile => profile) - 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) + a = build(TinyMceArticle, :body => '

This is a test

', :profile => profile) + 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) end should 'theme provides addthis custom icon' do -- libgit2 0.21.2