Commit 88e8b5e910581e06e9e774096a8be90f77650e92

Authored by AntonioTerceiro
1 parent 17e97b0c

ActionItem24: don't allow to create children of articles which don't accept them



git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1152 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/my_profile/cms_controller.rb
@@ -57,7 +57,11 @@ class CmsController < MyProfileController @@ -57,7 +57,11 @@ class CmsController < MyProfileController
57 57
58 58
59 if params[:parent_id] 59 if params[:parent_id]
60 - @article.parent = profile.articles.find(params[:parent_id]) 60 + parent = profile.articles.find(params[:parent_id])
  61 + if ! parent.allow_children?
  62 + raise ArgumentError.new("cannot create child of article which does not accept children")
  63 + end
  64 + @article.parent = parent
61 end 65 end
62 @article.profile = profile 66 @article.profile = profile
63 @article.last_changed_by = user 67 @article.last_changed_by = user
test/functional/cms_controller_test.rb
@@ -143,7 +143,7 @@ class CmsControllerTest < Test::Unit::TestCase @@ -143,7 +143,7 @@ class CmsControllerTest < Test::Unit::TestCase
143 end 143 end
144 144
145 should 'be able to create a RSS feed' do 145 should 'be able to create a RSS feed' do
146 - login_as('ze') 146 + login_as(profile.identifier)
147 assert_difference RssFeed, :count do 147 assert_difference RssFeed, :count do
148 post :new, :type => RssFeed.name, :profile => profile.identifier, :article => { :name => 'feed', :limit => 15, :include => 'all', :feed_item_description => 'body' } 148 post :new, :type => RssFeed.name, :profile => profile.identifier, :article => { :name => 'feed', :limit => 15, :include => 'all', :feed_item_description => 'body' }
149 assert_response :redirect 149 assert_response :redirect
@@ -151,7 +151,7 @@ class CmsControllerTest < Test::Unit::TestCase @@ -151,7 +151,7 @@ class CmsControllerTest < Test::Unit::TestCase
151 end 151 end
152 152
153 should 'be able to update a RSS feed' do 153 should 'be able to update a RSS feed' do
154 - login_as('ze') 154 + login_as(profile.identifier)
155 feed = RssFeed.create!(:name => 'myfeed', :limit => 5, :feed_item_description => 'body', :include => 'all', :profile_id => profile.id) 155 feed = RssFeed.create!(:name => 'myfeed', :limit => 5, :feed_item_description => 'body', :include => 'all', :profile_id => profile.id)
156 post :edit, :profile => profile.identifier, :id => feed.id, :article => { :limit => 77, :feed_item_description => 'abstract', :include => 'parent_and_children' } 156 post :edit, :profile => profile.identifier, :id => feed.id, :article => { :limit => 77, :feed_item_description => 'abstract', :include => 'parent_and_children' }
157 assert_response :redirect 157 assert_response :redirect
@@ -198,8 +198,18 @@ class CmsControllerTest < Test::Unit::TestCase @@ -198,8 +198,18 @@ class CmsControllerTest < Test::Unit::TestCase
198 assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/new?parent_id=#{article.id}"} 198 assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/new?parent_id=#{article.id}"}
199 end 199 end
200 200
201 - should 'not allow to create children of non-child articles' do  
202 - flunk 'pending' 201 + should 'refuse to create children of non-child articles' do
  202 + Article.any_instance.stubs(:allow_children?).returns(false)
  203 +
  204 + article = Article.new(:name => 'test')
  205 + article.profile = profile
  206 + article.save!
  207 +
  208 + assert_no_difference UploadedFile, :count do
  209 + assert_raise ArgumentError do
  210 + post :new, :type => UploadedFile.name, :parent_id => article.id, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')}
  211 + end
  212 + end
203 end 213 end
204 214
205 end 215 end