Commit bff86e47093019ee034e7fc11b5a8d7a87407016

Authored by Rodrigo Souto
1 parent b827a3e8

rails3: fix cms_helper tests

PS: there is still one test failing due to deprecated observe_field.
Showing 1 changed file with 13 additions and 15 deletions   Show diff stats
test/unit/cms_helper_test.rb
1 require File.dirname(__FILE__) + '/../test_helper' 1 require File.dirname(__FILE__) + '/../test_helper'
2 2
3 -class CmsHelperTest < ActiveSupport::TestCase 3 +class CmsHelperTest < ActionView::TestCase
4 4
5 include CmsHelper 5 include CmsHelper
6 include BlogHelper 6 include BlogHelper
7 include ApplicationHelper 7 include ApplicationHelper
8 include ActionView::Helpers::UrlHelper 8 include ActionView::Helpers::UrlHelper
  9 + include Noosfero::Plugin::HotSpot
9 10
10 should 'show default options for article' do 11 should 'show default options for article' do
11 - CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)  
12 - result = options_for_article(RssFeed.new(:profile => Profile.new)) 12 + result = options_for_article(build(RssFeed, :profile => Profile.new))
13 assert_match /id="article_published_true" name="article\[published\]" type="radio" value="true"/, result 13 assert_match /id="article_published_true" name="article\[published\]" type="radio" value="true"/, result
14 assert_match /id="article_published_false" name="article\[published\]" type="radio" value="false"/, result 14 assert_match /id="article_published_false" name="article\[published\]" type="radio" value="false"/, result
15 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result 15 assert_match /id="article_accept_comments" name="article\[accept_comments\]" type="checkbox" value="1"/, result
16 end 16 end
17 17
18 should 'show custom options for blog' do 18 should 'show custom options for blog' do
19 - CmsHelperTest.any_instance.stubs(:controller).returns(ActionController::Base.new)  
20 result = options_for_article(Blog.new) 19 result = options_for_article(Blog.new)
21 assert_tag_in_string result, :tag => 'input', :attributes => { :name => 'article[published]' , :type => "hidden", :value => "1" } 20 assert_tag_in_string result, :tag => 'input', :attributes => { :name => 'article[published]' , :type => "hidden", :value => "1" }
22 assert_tag_in_string result, :tag => 'input', :attributes => { :name => "article[accept_comments]", :type => "hidden", :value => "0" } 21 assert_tag_in_string result, :tag => 'input', :attributes => { :name => "article[accept_comments]", :type => "hidden", :value => "0" }
@@ -40,7 +39,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -40,7 +39,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
40 39
41 should 'display image and link if article is an image' do 40 should 'display image and link if article is an image' do
42 profile = fast_create(Profile) 41 profile = fast_create(Profile)
43 - file = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) 42 + file = create(UploadedFile, :profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
44 icon = icon_for_article(file) 43 icon = icon_for_article(file)
45 expects(:image_tag).with(icon).returns('icon') 44 expects(:image_tag).with(icon).returns('icon')
46 45
@@ -49,8 +48,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -49,8 +48,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
49 end 48 end
50 49
51 should 'display spread button when profile is a person' do 50 should 'display spread button when profile is a person' do
52 - @controller = ApplicationController.new  
53 - @plugins.stubs(:dispatch).returns([]) 51 + plugins.stubs(:dispatch).returns([])
54 profile = fast_create(Person) 52 profile = fast_create(Person)
55 article = fast_create(TinyMceArticle, :name => 'My article', :profile_id => profile.id) 53 article = fast_create(TinyMceArticle, :name => 'My article', :profile_id => profile.id)
56 expects(:link_to).with('Spread this', {:action => 'publish', :id => article.id}, :class => 'button with-text icon-spread', :title => nil) 54 expects(:link_to).with('Spread this', {:action => 'publish', :id => article.id}, :class => 'button with-text icon-spread', :title => nil)
@@ -59,8 +57,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -59,8 +57,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
59 end 57 end
60 58
61 should 'display spread button when profile is a community and env has portal_community' do 59 should 'display spread button when profile is a community and env has portal_community' do
62 - @controller = ApplicationController.new  
63 - @plugins.stubs(:dispatch).returns([]) 60 + plugins.stubs(:dispatch).returns([])
64 env = fast_create(Environment) 61 env = fast_create(Environment)
65 env.expects(:portal_community).returns(true) 62 env.expects(:portal_community).returns(true)
66 profile = fast_create(Community, :environment_id => env.id) 63 profile = fast_create(Community, :environment_id => env.id)
@@ -74,8 +71,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -74,8 +71,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
74 end 71 end
75 72
76 should 'not display spread button when profile is a community and env has not portal_community' do 73 should 'not display spread button when profile is a community and env has not portal_community' do
77 - @controller = ApplicationController.new  
78 - @plugins.stubs(:dispatch).returns([]) 74 + plugins.stubs(:dispatch).returns([])
79 env = fast_create(Environment) 75 env = fast_create(Environment)
80 env.expects(:portal_community).returns(nil) 76 env.expects(:portal_community).returns(nil)
81 profile = fast_create(Community, :environment_id => env.id) 77 profile = fast_create(Community, :environment_id => env.id)
@@ -89,8 +85,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -89,8 +85,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
89 end 85 end
90 86
91 should 'display delete_button to folder' do 87 should 'display delete_button to folder' do
92 - @controller = ApplicationController.new  
93 - @plugins.stubs(:dispatch).returns([]) 88 + plugins.stubs(:dispatch).returns([])
94 profile = fast_create(Profile) 89 profile = fast_create(Profile)
95 name = 'My folder' 90 name = 'My folder'
96 folder = fast_create(Folder, :name => name, :profile_id => profile.id) 91 folder = fast_create(Folder, :name => name, :profile_id => profile.id)
@@ -101,8 +96,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -101,8 +96,7 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
101 end 96 end
102 97
103 should 'display delete_button to article' do 98 should 'display delete_button to article' do
104 - @controller = ApplicationController.new  
105 - @plugins.stubs(:dispatch).returns([]) 99 + plugins.stubs(:dispatch).returns([])
106 profile = fast_create(Profile) 100 profile = fast_create(Profile)
107 name = 'My article' 101 name = 'My article'
108 article = fast_create(TinyMceArticle, :name => name, :profile_id => profile.id) 102 article = fast_create(TinyMceArticle, :name => name, :profile_id => profile.id)
@@ -114,6 +108,10 @@ class CmsHelperTest &lt; ActiveSupport::TestCase @@ -114,6 +108,10 @@ class CmsHelperTest &lt; ActiveSupport::TestCase
114 108
115 def link_to(text, *args); puts text; puts args.inspect; text; end 109 def link_to(text, *args); puts text; puts args.inspect; text; end
116 110
  111 + def environment
  112 + Environment.default
  113 + end
  114 +
117 end 115 end
118 116
119 module RssFeedHelper 117 module RssFeedHelper