From c8dc029761b6cbb2aa4054b279be2fbd340e7d0a Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Mon, 12 Jan 2015 18:33:21 -0300 Subject: [PATCH] publish: fix tests --- app/controllers/my_profile/cms_controller.rb | 5 +++-- test/functional/cms_controller_test.rb | 72 +++++++++++++++++++++++++++++++----------------------------------------- 2 files changed, 34 insertions(+), 43 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 50a42f1..3ea338b 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -71,6 +71,7 @@ class CmsController < MyProfileController def index @article = nil + @portal_enabled = environment.portal_community && environment.enabled?('use_portal_community') @articles = profile.top_level_articles.paginate( :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", :per_page => per_page, @@ -274,7 +275,7 @@ class CmsController < MyProfileController begin task.finish rescue Exception => ex - @failed[ex.message] ? @failed[ex.message] << item.name : @failed[ex.message] = [item.name] + @failed[ex.message] ? @failed[ex.message] << @article.name : @failed[ex.message] = [@article.name] end if @failed.blank? session[:notice] = _("Your publish request was sent successfully") @@ -293,7 +294,7 @@ class CmsController < MyProfileController @article = profile.articles.find(params[:id]) @failed = {} article_name = params[:name] - params_marked = params['q'].split(',').select { |marked| user.memberships.map(&:id).include? marked.to_i } + params_marked = (params['q'] || '').split(',').select { |marked| user.memberships.map(&:id).include? marked.to_i } @marked_groups = Profile.find(params_marked) if @marked_groups.empty? return session[:notice] = _("Select some group to publish your article") diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index fa7b79b..6b150fb 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -742,25 +742,14 @@ class CmsControllerTest < ActionController::TestCase assert !folder.children[0].published? end - should 'load communities for that the user belongs' do - c = Community.create!(:name => 'test comm', :identifier => 'test_comm') - c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) - a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') - - get :publish, :profile => profile.identifier, :id => a.id - - assert_equal [c], assigns(:groups) - assert_template 'publish' - end - should 'publish the article in the selected community if community is not moderated' do c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') assert_difference 'article.class.count' do - post :publish, :profile => profile.identifier, :id => article.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}} - assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) + post :publish_on_communities, :profile => profile.identifier, :id => article.id, :q => c.id.to_s + assert_includes assigns(:marked_groups), c end end @@ -770,7 +759,7 @@ class CmsControllerTest < ActionController::TestCase a = Event.create!(:name => "Some event", :profile => profile, :start_date => Date.today) assert_difference 'Event.count' do - post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}} + post :publish_on_communities, :profile => profile.identifier, :id => a.id, :q => c.id.to_s end end @@ -786,7 +775,10 @@ class CmsControllerTest < ActionController::TestCase portal_community = fast_create(Community) portal_community.moderated_articles = false portal_community.save - Environment.any_instance.stubs(:portal_community).returns(portal_community) + environment = portal_community.environment + environment.portal_community = portal_community + environment.enable('use_portal_community') + environment.save! article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') assert_difference 'article.class.count' do @@ -802,8 +794,8 @@ class CmsControllerTest < ActionController::TestCase assert_no_difference 'a.class.count' do assert_difference 'ApproveArticle.count' do assert_difference 'c.tasks.count' do - post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}} - assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) + post :publish_on_communities, :profile => profile.identifier, :id => a.id, :q => c.id.to_s + assert_includes assigns(:marked_groups), c end end end @@ -812,8 +804,11 @@ class CmsControllerTest < ActionController::TestCase should 'create a task for article approval if portal community is moderated' do portal_community = fast_create(Community) portal_community.moderated_articles = true - portal_community.save - Environment.any_instance.stubs(:portal_community).returns(portal_community) + portal_community.save! + environment = portal_community.environment + environment.portal_community = portal_community + environment.enable('use_portal_community') + environment.save! article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') assert_no_difference 'article.class.count' do @@ -1146,30 +1141,33 @@ class CmsControllerTest < ActionController::TestCase assert_no_tag :div, :attributes => { :id => "text-editor-sidebar" } end - should "display 'Publish' when profile is a person" do + should "display 'Publish' when profile is a person and is member of communities" do a = fast_create(TextileArticle, :profile_id => profile.id, :updated_at => DateTime.now) - Article.stubs(:short_description).returns('bli') + c1 = fast_create(Community) + c2 = fast_create(Community) + c1.add_member(profile) + c2.add_member(profile) + get :index, :profile => profile.identifier + assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} + end + + should "display 'Publish' when profile is a person and there is a portal community" do + a = fast_create(TextileArticle, :profile_id => profile.id, :updated_at => DateTime.now) + environment = profile.environment + environment.portal_community = fast_create(Community) + environment.enable('use_portal_community') + environment.save! get :index, :profile => profile.identifier assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} end should "display 'Publish' when profile is a community" do community = fast_create(Community) - community.add_member(profile) - Environment.any_instance.stubs(:portal_community).returns(community) + community.add_admin(profile) a = fast_create(TextileArticle, :profile_id => community.id, :updated_at => DateTime.now) Article.stubs(:short_description).returns('bli') get :index, :profile => community.identifier - assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{community.identifier}/cms/publish_on_portal_community/#{a.id}"} - end - - should "not display 'Publish' when profile is not a person nor a community" do - p = Community.create!(:name => 'community-test') - p.add_admin(profile) - a = p.articles.create!(:name => 'my new home page') - Article.stubs(:short_description).returns('bli') - get :index, :profile => p.identifier - assert_no_tag :tag => 'a', :attributes => {:href => "/myprofile/#{p.identifier}/cms/publish/#{a.id}"} + assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{community.identifier}/cms/publish/#{a.id}"} end should 'not offer to upload files to blog' do @@ -1799,14 +1797,6 @@ class CmsControllerTest < ActionController::TestCase assert_equal other_person, a.created_by end - should 'continue on the same page, when no group is selected' do - c = Community.create!(:name => 'test comm', :identifier => 'test_comm') - c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) - article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') - post :publish, :profile => profile.identifier, :id => article.id, :marked_groups => {c.id.to_s => {}} - assert_template 'cms/publish' - end - should 'response of search_tags be json' do get :search_tags, :profile => profile.identifier, :term => 'linux' assert_equal 'application/json', @response.content_type -- libgit2 0.21.2