Commit c8dc029761b6cbb2aa4054b279be2fbd340e7d0a
1 parent
8b024299
Exists in
master
and in
29 other branches
publish: fix tests
Showing
2 changed files
with
34 additions
and
43 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -71,6 +71,7 @@ class CmsController < MyProfileController |
71 | 71 | |
72 | 72 | def index |
73 | 73 | @article = nil |
74 | + @portal_enabled = environment.portal_community && environment.enabled?('use_portal_community') | |
74 | 75 | @articles = profile.top_level_articles.paginate( |
75 | 76 | :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", |
76 | 77 | :per_page => per_page, |
... | ... | @@ -274,7 +275,7 @@ class CmsController < MyProfileController |
274 | 275 | begin |
275 | 276 | task.finish |
276 | 277 | rescue Exception => ex |
277 | - @failed[ex.message] ? @failed[ex.message] << item.name : @failed[ex.message] = [item.name] | |
278 | + @failed[ex.message] ? @failed[ex.message] << @article.name : @failed[ex.message] = [@article.name] | |
278 | 279 | end |
279 | 280 | if @failed.blank? |
280 | 281 | session[:notice] = _("Your publish request was sent successfully") |
... | ... | @@ -293,7 +294,7 @@ class CmsController < MyProfileController |
293 | 294 | @article = profile.articles.find(params[:id]) |
294 | 295 | @failed = {} |
295 | 296 | article_name = params[:name] |
296 | - params_marked = params['q'].split(',').select { |marked| user.memberships.map(&:id).include? marked.to_i } | |
297 | + params_marked = (params['q'] || '').split(',').select { |marked| user.memberships.map(&:id).include? marked.to_i } | |
297 | 298 | @marked_groups = Profile.find(params_marked) |
298 | 299 | if @marked_groups.empty? |
299 | 300 | return session[:notice] = _("Select some group to publish your article") | ... | ... |
test/functional/cms_controller_test.rb
... | ... | @@ -742,25 +742,14 @@ class CmsControllerTest < ActionController::TestCase |
742 | 742 | assert !folder.children[0].published? |
743 | 743 | end |
744 | 744 | |
745 | - should 'load communities for that the user belongs' do | |
746 | - c = Community.create!(:name => 'test comm', :identifier => 'test_comm') | |
747 | - c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) | |
748 | - a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | |
749 | - | |
750 | - get :publish, :profile => profile.identifier, :id => a.id | |
751 | - | |
752 | - assert_equal [c], assigns(:groups) | |
753 | - assert_template 'publish' | |
754 | - end | |
755 | - | |
756 | 745 | should 'publish the article in the selected community if community is not moderated' do |
757 | 746 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) |
758 | 747 | c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
759 | 748 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
760 | 749 | |
761 | 750 | assert_difference 'article.class.count' do |
762 | - post :publish, :profile => profile.identifier, :id => article.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}} | |
763 | - assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) | |
751 | + post :publish_on_communities, :profile => profile.identifier, :id => article.id, :q => c.id.to_s | |
752 | + assert_includes assigns(:marked_groups), c | |
764 | 753 | end |
765 | 754 | end |
766 | 755 | |
... | ... | @@ -770,7 +759,7 @@ class CmsControllerTest < ActionController::TestCase |
770 | 759 | a = Event.create!(:name => "Some event", :profile => profile, :start_date => Date.today) |
771 | 760 | |
772 | 761 | assert_difference 'Event.count' do |
773 | - post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}} | |
762 | + post :publish_on_communities, :profile => profile.identifier, :id => a.id, :q => c.id.to_s | |
774 | 763 | end |
775 | 764 | end |
776 | 765 | |
... | ... | @@ -786,7 +775,10 @@ class CmsControllerTest < ActionController::TestCase |
786 | 775 | portal_community = fast_create(Community) |
787 | 776 | portal_community.moderated_articles = false |
788 | 777 | portal_community.save |
789 | - Environment.any_instance.stubs(:portal_community).returns(portal_community) | |
778 | + environment = portal_community.environment | |
779 | + environment.portal_community = portal_community | |
780 | + environment.enable('use_portal_community') | |
781 | + environment.save! | |
790 | 782 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
791 | 783 | |
792 | 784 | assert_difference 'article.class.count' do |
... | ... | @@ -802,8 +794,8 @@ class CmsControllerTest < ActionController::TestCase |
802 | 794 | assert_no_difference 'a.class.count' do |
803 | 795 | assert_difference 'ApproveArticle.count' do |
804 | 796 | assert_difference 'c.tasks.count' do |
805 | - post :publish, :profile => profile.identifier, :id => a.id, :marked_groups => {c.id.to_s => {:name => 'bli', :group_id => c.id.to_s}} | |
806 | - assert_equal [{'group' => c, 'name' => 'bli'}], assigns(:marked_groups) | |
797 | + post :publish_on_communities, :profile => profile.identifier, :id => a.id, :q => c.id.to_s | |
798 | + assert_includes assigns(:marked_groups), c | |
807 | 799 | end |
808 | 800 | end |
809 | 801 | end |
... | ... | @@ -812,8 +804,11 @@ class CmsControllerTest < ActionController::TestCase |
812 | 804 | should 'create a task for article approval if portal community is moderated' do |
813 | 805 | portal_community = fast_create(Community) |
814 | 806 | portal_community.moderated_articles = true |
815 | - portal_community.save | |
816 | - Environment.any_instance.stubs(:portal_community).returns(portal_community) | |
807 | + portal_community.save! | |
808 | + environment = portal_community.environment | |
809 | + environment.portal_community = portal_community | |
810 | + environment.enable('use_portal_community') | |
811 | + environment.save! | |
817 | 812 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
818 | 813 | |
819 | 814 | assert_no_difference 'article.class.count' do |
... | ... | @@ -1146,30 +1141,33 @@ class CmsControllerTest < ActionController::TestCase |
1146 | 1141 | assert_no_tag :div, :attributes => { :id => "text-editor-sidebar" } |
1147 | 1142 | end |
1148 | 1143 | |
1149 | - should "display 'Publish' when profile is a person" do | |
1144 | + should "display 'Publish' when profile is a person and is member of communities" do | |
1150 | 1145 | a = fast_create(TextileArticle, :profile_id => profile.id, :updated_at => DateTime.now) |
1151 | - Article.stubs(:short_description).returns('bli') | |
1146 | + c1 = fast_create(Community) | |
1147 | + c2 = fast_create(Community) | |
1148 | + c1.add_member(profile) | |
1149 | + c2.add_member(profile) | |
1150 | + get :index, :profile => profile.identifier | |
1151 | + assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} | |
1152 | + end | |
1153 | + | |
1154 | + should "display 'Publish' when profile is a person and there is a portal community" do | |
1155 | + a = fast_create(TextileArticle, :profile_id => profile.id, :updated_at => DateTime.now) | |
1156 | + environment = profile.environment | |
1157 | + environment.portal_community = fast_create(Community) | |
1158 | + environment.enable('use_portal_community') | |
1159 | + environment.save! | |
1152 | 1160 | get :index, :profile => profile.identifier |
1153 | 1161 | assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} |
1154 | 1162 | end |
1155 | 1163 | |
1156 | 1164 | should "display 'Publish' when profile is a community" do |
1157 | 1165 | community = fast_create(Community) |
1158 | - community.add_member(profile) | |
1159 | - Environment.any_instance.stubs(:portal_community).returns(community) | |
1166 | + community.add_admin(profile) | |
1160 | 1167 | a = fast_create(TextileArticle, :profile_id => community.id, :updated_at => DateTime.now) |
1161 | 1168 | Article.stubs(:short_description).returns('bli') |
1162 | 1169 | get :index, :profile => community.identifier |
1163 | - assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{community.identifier}/cms/publish_on_portal_community/#{a.id}"} | |
1164 | - end | |
1165 | - | |
1166 | - should "not display 'Publish' when profile is not a person nor a community" do | |
1167 | - p = Community.create!(:name => 'community-test') | |
1168 | - p.add_admin(profile) | |
1169 | - a = p.articles.create!(:name => 'my new home page') | |
1170 | - Article.stubs(:short_description).returns('bli') | |
1171 | - get :index, :profile => p.identifier | |
1172 | - assert_no_tag :tag => 'a', :attributes => {:href => "/myprofile/#{p.identifier}/cms/publish/#{a.id}"} | |
1170 | + assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{community.identifier}/cms/publish/#{a.id}"} | |
1173 | 1171 | end |
1174 | 1172 | |
1175 | 1173 | should 'not offer to upload files to blog' do |
... | ... | @@ -1799,14 +1797,6 @@ class CmsControllerTest < ActionController::TestCase |
1799 | 1797 | assert_equal other_person, a.created_by |
1800 | 1798 | end |
1801 | 1799 | |
1802 | - should 'continue on the same page, when no group is selected' do | |
1803 | - c = Community.create!(:name => 'test comm', :identifier => 'test_comm') | |
1804 | - c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) | |
1805 | - article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | |
1806 | - post :publish, :profile => profile.identifier, :id => article.id, :marked_groups => {c.id.to_s => {}} | |
1807 | - assert_template 'cms/publish' | |
1808 | - end | |
1809 | - | |
1810 | 1800 | should 'response of search_tags be json' do |
1811 | 1801 | get :search_tags, :profile => profile.identifier, :term => 'linux' |
1812 | 1802 | assert_equal 'application/json', @response.content_type | ... | ... |