Commit b6ec7ab024edbd686985bc0d70bf44754f4c609c

Authored by Rodrigo Souto
1 parent 03c1131a

publish_on_communities: not crash when no community is selected

app/controllers/my_profile/cms_controller.rb
@@ -295,6 +295,7 @@ class CmsController < MyProfileController @@ -295,6 +295,7 @@ class CmsController < MyProfileController
295 params_marked = (params['q'] || '').split(',').select { |marked| user.memberships.map(&:id).include? marked.to_i } 295 params_marked = (params['q'] || '').split(',').select { |marked| user.memberships.map(&:id).include? marked.to_i }
296 @marked_groups = Profile.find(params_marked) 296 @marked_groups = Profile.find(params_marked)
297 if @marked_groups.empty? 297 if @marked_groups.empty?
  298 + redirect_to @back_to
298 return session[:notice] = _("Select some group to publish your article") 299 return session[:notice] = _("Select some group to publish your article")
299 end 300 end
300 @marked_groups.each do |item| 301 @marked_groups.each do |item|
test/functional/cms_controller_test.rb
@@ -763,6 +763,14 @@ class CmsControllerTest < ActionController::TestCase @@ -763,6 +763,14 @@ class CmsControllerTest < ActionController::TestCase
763 end 763 end
764 end 764 end
765 765
  766 + should 'not crash if no community is selected' do
  767 + article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')
  768 +
  769 + assert_nothing_raised do
  770 + post :publish_on_communities, :profile => profile.identifier, :id => article.id, :q => '', :back_to => '/'
  771 + end
  772 + end
  773 +
766 should "not crash if there is a post and no portal community defined" do 774 should "not crash if there is a post and no portal community defined" do
767 Environment.any_instance.stubs(:portal_community).returns(nil) 775 Environment.any_instance.stubs(:portal_community).returns(nil)
768 article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') 776 article = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails')