diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 5b1d6b1..37e484a 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -57,7 +57,11 @@ class CmsController < MyProfileController if params[:parent_id] - @article.parent = profile.articles.find(params[:parent_id]) + parent = profile.articles.find(params[:parent_id]) + if ! parent.allow_children? + raise ArgumentError.new("cannot create child of article which does not accept children") + end + @article.parent = parent end @article.profile = profile @article.last_changed_by = user diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 715a0fb..c06f4aa 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -143,7 +143,7 @@ class CmsControllerTest < Test::Unit::TestCase end should 'be able to create a RSS feed' do - login_as('ze') + login_as(profile.identifier) assert_difference RssFeed, :count do post :new, :type => RssFeed.name, :profile => profile.identifier, :article => { :name => 'feed', :limit => 15, :include => 'all', :feed_item_description => 'body' } assert_response :redirect @@ -151,7 +151,7 @@ class CmsControllerTest < Test::Unit::TestCase end should 'be able to update a RSS feed' do - login_as('ze') + login_as(profile.identifier) feed = RssFeed.create!(:name => 'myfeed', :limit => 5, :feed_item_description => 'body', :include => 'all', :profile_id => profile.id) post :edit, :profile => profile.identifier, :id => feed.id, :article => { :limit => 77, :feed_item_description => 'abstract', :include => 'parent_and_children' } assert_response :redirect @@ -198,8 +198,18 @@ class CmsControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/new?parent_id=#{article.id}"} end - should 'not allow to create children of non-child articles' do - flunk 'pending' + should 'refuse to create children of non-child articles' do + Article.any_instance.stubs(:allow_children?).returns(false) + + article = Article.new(:name => 'test') + article.profile = profile + article.save! + + assert_no_difference UploadedFile, :count do + assert_raise ArgumentError do + post :new, :type => UploadedFile.name, :parent_id => article.id, :profile => profile.identifier, :article => { :uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain')} + end + end end end -- libgit2 0.21.2