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 57  
58 58  
59 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 65 end
62 66 @article.profile = profile
63 67 @article.last_changed_by = user
... ...
test/functional/cms_controller_test.rb
... ... @@ -143,7 +143,7 @@ class CmsControllerTest < Test::Unit::TestCase
143 143 end
144 144  
145 145 should 'be able to create a RSS feed' do
146   - login_as('ze')
  146 + login_as(profile.identifier)
147 147 assert_difference RssFeed, :count do
148 148 post :new, :type => RssFeed.name, :profile => profile.identifier, :article => { :name => 'feed', :limit => 15, :include => 'all', :feed_item_description => 'body' }
149 149 assert_response :redirect
... ... @@ -151,7 +151,7 @@ class CmsControllerTest < Test::Unit::TestCase
151 151 end
152 152  
153 153 should 'be able to update a RSS feed' do
154   - login_as('ze')
  154 + login_as(profile.identifier)
155 155 feed = RssFeed.create!(:name => 'myfeed', :limit => 5, :feed_item_description => 'body', :include => 'all', :profile_id => profile.id)
156 156 post :edit, :profile => profile.identifier, :id => feed.id, :article => { :limit => 77, :feed_item_description => 'abstract', :include => 'parent_and_children' }
157 157 assert_response :redirect
... ... @@ -198,8 +198,18 @@ class CmsControllerTest < Test::Unit::TestCase
198 198 assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/new?parent_id=#{article.id}"}
199 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 213 end
204 214  
205 215 end
... ...