ref: master
test/functional/home_controller_test.rb
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
require_relative '../test_helper' class HomeControllerTest < ActionController::TestCase def teardown Thread.current[:enabled_plugins] = nil end all_fixtures def setup @controller = HomeController.new end should 'not display news from portal if disabled in environment' do env = Environment.default env.disable('use_portal_community') env.save! get :index assert_no_tag :tag => 'div', :attributes => { :id => 'portal-news' } end should 'not display news from portal if environment doesnt have portal community' do env = Environment.default env.enable('use_portal_community') env.save! get :index assert_no_tag :tag => 'div', :attributes => { :id => 'portal-news' } end should 'display news from portal if enabled and has portal community' do env = Environment.default env.enable('use_portal_community') c = Community.create!(:name => 'community test') env.portal_community = c env.save! get :index assert_tag :tag => 'div', :attributes => { :id => 'portal-news' } #, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} end should 'display the news leads if there is any' do env = Environment.default env.enable('use_portal_community') c = fast_create(Community) a1 = TextArticle.create!(:name => "Article 1", :profile => c, :abstract => "This is the article1 lead.", :body => "<p>This is the article1 body.</p>", :highlighted => true) a2 = TextArticle.create!(:name => "Article 2", :profile => c, :body => "<p>This is the article2 body.</p>", :highlighted => true) env.portal_community = c env.save! get :index assert_tag :attributes => { :class => 'headline' }, :content => a1.abstract assert_no_tag :attributes => { :class => 'headline' }, :content => 'This is the article1 body.' assert_tag :attributes => { :class => 'headline' }, :content => 'This is the article2 body.' end should 'display block in index page if it\'s configured to display on homepage and its an environment block' do env = Environment.default box = create(Box, :owner_type => 'Environment', :owner_id => env.id) block = Block.create(:title => "Index Block", :box_id => box.id, :display => 'home_page_only') env.save! get :index assert block.visible? end should 'access terms of use of environment' do env = Environment.default env.update_attribute(:terms_of_use, 'Noosfero terms of use') get :terms assert_tag :content => /Noosfero terms of use/ end should 'provide a link to make the user authentication' do class Plugin1 < Noosfero::Plugin def alternative_authentication_link proc {"<a href='plugin1'>Plugin1 link</a>".html_safe} end end class Plugin2 < Noosfero::Plugin def alternative_authentication_link proc {"<a href='plugin2'>Plugin2 link</a>".html_safe} end end Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) Environment.default.enable_plugin(Plugin1) Environment.default.enable_plugin(Plugin2) get :index assert_tag :tag => 'a', :content => 'Plugin1 link' assert_tag :tag => 'a', :content => 'Plugin2 link' end should "not display the new user button on login page if now allowed by any plugin" do class Plugin1 < Noosfero::Plugin def allow_user_registration false end end class Plugin2 < Noosfero::Plugin def allow_user_registration true end end Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new]) get :index assert_no_tag :tag => 'a', :attributes => {:href => '/account/signup'} end should 'display template welcome page' do template = create_user('template').person template.is_template = true welcome_page = TextArticle.create!(:name => 'Welcome page', :profile => template, :published => true, :body => 'Template welcome page') template.welcome_page = welcome_page template.save! get :welcome, :template_id => template.id assert_match /#{welcome_page.body}/, @response.body end should 'not display template welcome page if it is not published' do template = create_user('template').person template.is_template = true welcome_page = TextArticle.create!(:name => 'Welcome page', :profile => template, :published => false, :body => 'Template welcome page') template.welcome_page = welcome_page template.save! get :welcome, :template_id => template.id assert_no_match /#{welcome_page.body}/, @response.body end should 'not crash template doess not have a welcome page' do template = create_user('template').person template.is_template = true template.save! assert_nothing_raised do get :welcome, :template_id => template.id end end should 'add class to the <html>' do get :index # Where am i? assert_select 'html.controller-home.action-home-index' # What is the current layout? assert_select 'html.template-default.theme-noosfero' end should 'plugins add class to the <html>' do class Plugin1 < Noosfero::Plugin def html_tag_classes lambda { ['t1'.html_safe, 't2'.html_safe] } end end class Plugin2 < Noosfero::Plugin def html_tag_classes 'test' end end Noosfero::Plugin.stubs(:all).returns([Plugin1.name, Plugin2.name]) Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([Plugin1.new, Plugin2.new]) get :index # Where am i? assert_select 'html.controller-home.action-home-index' # There are plugin classes? assert_select 'html.t1.t2.test' end end |