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,6 +71,7 @@ class CmsController < MyProfileController | ||
71 | 71 | ||
72 | def index | 72 | def index |
73 | @article = nil | 73 | @article = nil |
74 | + @portal_enabled = environment.portal_community && environment.enabled?('use_portal_community') | ||
74 | @articles = profile.top_level_articles.paginate( | 75 | @articles = profile.top_level_articles.paginate( |
75 | :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", | 76 | :order => "case when type = 'Folder' then 0 when type ='Blog' then 1 else 2 end, updated_at DESC", |
76 | :per_page => per_page, | 77 | :per_page => per_page, |
@@ -274,7 +275,7 @@ class CmsController < MyProfileController | @@ -274,7 +275,7 @@ class CmsController < MyProfileController | ||
274 | begin | 275 | begin |
275 | task.finish | 276 | task.finish |
276 | rescue Exception => ex | 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 | end | 279 | end |
279 | if @failed.blank? | 280 | if @failed.blank? |
280 | session[:notice] = _("Your publish request was sent successfully") | 281 | session[:notice] = _("Your publish request was sent successfully") |
@@ -293,7 +294,7 @@ class CmsController < MyProfileController | @@ -293,7 +294,7 @@ class CmsController < MyProfileController | ||
293 | @article = profile.articles.find(params[:id]) | 294 | @article = profile.articles.find(params[:id]) |
294 | @failed = {} | 295 | @failed = {} |
295 | article_name = params[:name] | 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 | @marked_groups = Profile.find(params_marked) | 298 | @marked_groups = Profile.find(params_marked) |
298 | if @marked_groups.empty? | 299 | if @marked_groups.empty? |
299 | return session[:notice] = _("Select some group to publish your article") | 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,25 +742,14 @@ class CmsControllerTest < ActionController::TestCase | ||
742 | assert !folder.children[0].published? | 742 | assert !folder.children[0].published? |
743 | end | 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 | should 'publish the article in the selected community if community is not moderated' do | 745 | should 'publish the article in the selected community if community is not moderated' do |
757 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) | 746 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) |
758 | c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) | 747 | c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
759 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | 748 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
760 | 749 | ||
761 | assert_difference 'article.class.count' do | 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 | end | 753 | end |
765 | end | 754 | end |
766 | 755 | ||
@@ -770,7 +759,7 @@ class CmsControllerTest < ActionController::TestCase | @@ -770,7 +759,7 @@ class CmsControllerTest < ActionController::TestCase | ||
770 | a = Event.create!(:name => "Some event", :profile => profile, :start_date => Date.today) | 759 | a = Event.create!(:name => "Some event", :profile => profile, :start_date => Date.today) |
771 | 760 | ||
772 | assert_difference 'Event.count' do | 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 | end | 763 | end |
775 | end | 764 | end |
776 | 765 | ||
@@ -786,7 +775,10 @@ class CmsControllerTest < ActionController::TestCase | @@ -786,7 +775,10 @@ class CmsControllerTest < ActionController::TestCase | ||
786 | portal_community = fast_create(Community) | 775 | portal_community = fast_create(Community) |
787 | portal_community.moderated_articles = false | 776 | portal_community.moderated_articles = false |
788 | portal_community.save | 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 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | 782 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
791 | 783 | ||
792 | assert_difference 'article.class.count' do | 784 | assert_difference 'article.class.count' do |
@@ -802,8 +794,8 @@ class CmsControllerTest < ActionController::TestCase | @@ -802,8 +794,8 @@ class CmsControllerTest < ActionController::TestCase | ||
802 | assert_no_difference 'a.class.count' do | 794 | assert_no_difference 'a.class.count' do |
803 | assert_difference 'ApproveArticle.count' do | 795 | assert_difference 'ApproveArticle.count' do |
804 | assert_difference 'c.tasks.count' do | 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 | end | 799 | end |
808 | end | 800 | end |
809 | end | 801 | end |
@@ -812,8 +804,11 @@ class CmsControllerTest < ActionController::TestCase | @@ -812,8 +804,11 @@ class CmsControllerTest < ActionController::TestCase | ||
812 | should 'create a task for article approval if portal community is moderated' do | 804 | should 'create a task for article approval if portal community is moderated' do |
813 | portal_community = fast_create(Community) | 805 | portal_community = fast_create(Community) |
814 | portal_community.moderated_articles = true | 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 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | 812 | article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
818 | 813 | ||
819 | assert_no_difference 'article.class.count' do | 814 | assert_no_difference 'article.class.count' do |
@@ -1146,30 +1141,33 @@ class CmsControllerTest < ActionController::TestCase | @@ -1146,30 +1141,33 @@ class CmsControllerTest < ActionController::TestCase | ||
1146 | assert_no_tag :div, :attributes => { :id => "text-editor-sidebar" } | 1141 | assert_no_tag :div, :attributes => { :id => "text-editor-sidebar" } |
1147 | end | 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 | a = fast_create(TextileArticle, :profile_id => profile.id, :updated_at => DateTime.now) | 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 | get :index, :profile => profile.identifier | 1160 | get :index, :profile => profile.identifier |
1153 | assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} | 1161 | assert_tag :tag => 'a', :attributes => {:href => "/myprofile/#{profile.identifier}/cms/publish/#{a.id}"} |
1154 | end | 1162 | end |
1155 | 1163 | ||
1156 | should "display 'Publish' when profile is a community" do | 1164 | should "display 'Publish' when profile is a community" do |
1157 | community = fast_create(Community) | 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 | a = fast_create(TextileArticle, :profile_id => community.id, :updated_at => DateTime.now) | 1167 | a = fast_create(TextileArticle, :profile_id => community.id, :updated_at => DateTime.now) |
1161 | Article.stubs(:short_description).returns('bli') | 1168 | Article.stubs(:short_description).returns('bli') |
1162 | get :index, :profile => community.identifier | 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 | end | 1171 | end |
1174 | 1172 | ||
1175 | should 'not offer to upload files to blog' do | 1173 | should 'not offer to upload files to blog' do |
@@ -1799,14 +1797,6 @@ class CmsControllerTest < ActionController::TestCase | @@ -1799,14 +1797,6 @@ class CmsControllerTest < ActionController::TestCase | ||
1799 | assert_equal other_person, a.created_by | 1797 | assert_equal other_person, a.created_by |
1800 | end | 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 | should 'response of search_tags be json' do | 1800 | should 'response of search_tags be json' do |
1811 | get :search_tags, :profile => profile.identifier, :term => 'linux' | 1801 | get :search_tags, :profile => profile.identifier, :term => 'linux' |
1812 | assert_equal 'application/json', @response.content_type | 1802 | assert_equal 'application/json', @response.content_type |