Create returns to index.
DeLynn Berry
committed Apr 02, 2011
commit 29ceab72e7ec3b0629a7c88f7d7dfe090602a505
Showing 2
changed files with
39 additions
and 24 deletions
app/controllers/cms_admin/layouts_controller.rb
+12
-12
| @@ | @@ -1,30 +1,30 @@ |
| class CmsAdmin::LayoutsController < CmsAdmin::BaseController | |
| - | |
| + | |
| before_filter :build_cms_layout, :only => [:new, :create] | |
| before_filter :load_cms_layout, :only => [:edit, :update, :destroy] | |
| - | |
| + | |
| def index | |
| return redirect_to :action => :new if @cms_site.cms_layouts.count == 0 | |
| @cms_layouts = @cms_site.cms_layouts.roots | |
| end | |
| - | |
| + | |
| def new | |
| render | |
| end | |
| - | |
| + | |
| def edit | |
| render | |
| end | |
| - | |
| + | |
| def create | |
| @cms_layout.save! | |
| flash[:notice] = 'Layout created' | |
| - | redirect_to :action => :edit, :id => @cms_layout |
| + | redirect_to (params[:commit] ? {:action => :index} : {:action => :edit, :id => @cms_layout}) |
| rescue ActiveRecord::RecordInvalid | |
| flash.now[:error] = 'Failed to create layout' | |
| render :action => :new | |
| end | |
| - | |
| + | |
| def update | |
| @cms_layout.update_attributes!(params[:cms_layout]) | |
| flash[:notice] = 'Layout updated' | |
| @@ | @@ -33,26 +33,26 @@ class CmsAdmin::LayoutsController < CmsAdmin::BaseController |
| flash.now[:error] = 'Failed to update layout' | |
| render :action => :edit | |
| end | |
| - | |
| + | |
| def destroy | |
| @cms_layout.destroy | |
| flash[:notice] = 'Layout deleted' | |
| redirect_to :action => :index | |
| end | |
| - | |
| + | |
| protected | |
| - | |
| + | |
| def build_cms_layout | |
| @cms_layout = @cms_site.cms_layouts.new(params[:cms_layout]) | |
| @cms_layout.parent ||= CmsLayout.find_by_id(params[:parent_id]) | |
| @cms_layout.content ||= '{{ cms:page:content:text }}' | |
| end | |
| - | |
| + | |
| def load_cms_layout | |
| @cms_layout = @cms_site.cms_layouts.find(params[:id]) | |
| rescue ActiveRecord::RecordNotFound | |
| flash[:error] = 'Layout not found' | |
| redirect_to :action => :index | |
| end | |
| - | |
| + | |
| end | |
test/functional/cms_admin/layouts_controller_test.rb
+27
-12
| @@ | @@ -1,21 +1,21 @@ |
| require File.expand_path('../../test_helper', File.dirname(__FILE__)) | |
| class CmsAdmin::LayoutsControllerTest < ActionController::TestCase | |
| - | |
| + | |
| def test_get_index | |
| get :index | |
| assert_response :success | |
| assert assigns(:cms_layouts) | |
| assert_template :index | |
| end | |
| - | |
| + | |
| def test_get_index_with_no_layouts | |
| CmsLayout.delete_all | |
| get :index | |
| assert_response :redirect | |
| assert_redirected_to :action => :new | |
| end | |
| - | |
| + | |
| def test_get_new | |
| get :new | |
| assert_response :success | |
| @@ | @@ -24,7 +24,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_template :new | |
| assert_select 'form[action=/cms-admin/layouts]' | |
| end | |
| - | |
| + | |
| def test_get_edit | |
| layout = cms_layouts(:default) | |
| get :edit, :id => layout | |
| @@ | @@ -33,15 +33,30 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_template :edit | |
| assert_select "form[action=/cms-admin/layouts/#{layout.id}]" | |
| end | |
| - | |
| + | |
| def test_get_edit_failure | |
| get :edit, :id => 'not_found' | |
| assert_response :redirect | |
| assert_redirected_to :action => :index | |
| assert_equal 'Layout not found', flash[:error] | |
| end | |
| - | |
| - | def test_creation |
| + | |
| + | def test_creation_with_commit |
| + | assert_difference 'CmsLayout.count' do |
| + | post :create, :cms_layout => { |
| + | :label => 'Test Layout', |
| + | :slug => 'test', |
| + | :content => 'Test {{cms:page:content}}' |
| + | }, :commit => 'Create Layout' |
| + | assert_response :redirect |
| + | layout = CmsLayout.last |
| + | assert_equal cms_sites(:default), layout.cms_site |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'Layout created', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_creation_without_comiit |
| assert_difference 'CmsLayout.count' do | |
| post :create, :cms_layout => { | |
| :label => 'Test Layout', | |
| @@ | @@ -55,7 +70,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_equal 'Layout created', flash[:notice] | |
| end | |
| end | |
| - | |
| + | |
| def test_creation_failure | |
| assert_no_difference 'CmsLayout.count' do | |
| post :create, :cms_layout => { } | |
| @@ | @@ -64,7 +79,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_equal 'Failed to create layout', flash[:error] | |
| end | |
| end | |
| - | |
| + | |
| def test_update | |
| layout = cms_layouts(:default) | |
| put :update, :id => layout, :cms_layout => { | |
| @@ | @@ -78,7 +93,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_equal 'New Label', layout.label | |
| assert_equal 'New {{cms:page:content}}', layout.content | |
| end | |
| - | |
| + | |
| def test_update_failure | |
| layout = cms_layouts(:default) | |
| put :update, :id => layout, :cms_layout => { | |
| @@ | @@ -90,7 +105,7 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_not_equal '', layout.label | |
| assert_equal 'Failed to update layout', flash[:error] | |
| end | |
| - | |
| + | |
| def test_destroy | |
| assert_difference 'CmsLayout.count', -1 do | |
| delete :destroy, :id => cms_layouts(:default) | |
| @@ | @@ -99,5 +114,5 @@ class CmsAdmin::LayoutsControllerTest < ActionController::TestCase |
| assert_equal 'Layout deleted', flash[:notice] | |
| end | |
| end | |
| - | |
| + | |
| end | |
| \ No newline at end of file | |