From e8aff3e44f799c242603da0f138aeb2278ecb65d Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 1 Dec 2007 19:35:34 +0000 Subject: [PATCH] ActionItem21: removing articles --- app/controllers/my_profile/cms_controller.rb | 7 +++++++ test/functional/cms_controller_test.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 91a9565..650b3df 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -59,6 +59,13 @@ class CmsController < MyProfileController redirect_to :action => 'view', :id => @article.id end + post_only :destroy + def destroy + @article = profile.articles.find(params[:id]) + @article.destroy + redirect_to :action => (@article.parent ? 'view' : 'index'), :id => @article.parent + end + protected class << self diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index 70a1c05..f5154b4 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -136,4 +136,14 @@ class CmsControllerTest < Test::Unit::TestCase assert_equal 'application_xnoosferosomething', obj.mime_type_to_action_name('application/x-noosfero-something') end + should 'be able to remove article' do + a = profile.articles.build(:name => 'my-article') + a.save! + + assert_difference Article, :count, -1 do + post :destroy, :profile => profile.identifier, :id => a.id + assert_redirected_to :action => 'index' + end + end + end -- libgit2 0.21.2