Added continue functionality to sites.
DeLynn Berry
committed Apr 03, 2011
commit 4f5c8fba188d6ae71cb7fe01d4d65273ded50cab
Showing 4
changed files with
60 additions
and 28 deletions
app/controllers/cms_admin/sites_controller.rb
+14
-14
| @@ | @@ -1,59 +1,59 @@ |
| class CmsAdmin::SitesController < CmsAdmin::BaseController | |
| - | |
| + | |
| skip_before_filter :load_admin_cms_site | |
| - | |
| + | |
| before_filter :build_cms_site, :only => [:new, :create] | |
| before_filter :load_cms_site, :only => [:edit, :update, :destroy] | |
| - | |
| + | |
| def index | |
| return redirect_to :action => :new if CmsSite.count == 0 | |
| @cms_sites = CmsSite.all | |
| end | |
| - | |
| + | |
| def new | |
| render | |
| end | |
| - | |
| + | |
| def edit | |
| render | |
| end | |
| - | |
| + | |
| def create | |
| @cms_site.save! | |
| flash[:notice] = 'Site created' | |
| - | redirect_to :action => :edit, :id => @cms_site |
| + | redirect_to (params[:commit] ? {:action => :index} : {:action => :edit, :id => @cms_site}) |
| rescue ActiveRecord::RecordInvalid | |
| flash.now[:error] = 'Failed to create site' | |
| render :action => :new | |
| end | |
| - | |
| + | |
| def update | |
| @cms_site.update_attributes!(params[:cms_site]) | |
| flash[:notice] = 'Site updated' | |
| - | redirect_to :action => :edit, :id => @cms_site |
| + | redirect_to (params[:commit] ? {:action => :index} : {:action => :edit, :id => @cms_site}) |
| rescue ActiveRecord::RecordInvalid | |
| flash.now[:error] = 'Failed to update site' | |
| render :action => :edit | |
| end | |
| - | |
| + | |
| def destroy | |
| @cms_site.destroy | |
| flash[:notice] = 'Site deleted' | |
| redirect_to :action => :index | |
| end | |
| - | |
| + | |
| protected | |
| - | |
| + | |
| def build_cms_site | |
| @cms_site = CmsSite.new(params[:cms_site]) | |
| @cms_site.hostname ||= request.host.downcase | |
| end | |
| - | |
| + | |
| def load_cms_site | |
| @cms_site = CmsSite.find(params[:id]) | |
| rescue ActiveRecord::RecordNotFound | |
| flash[:error] = 'Site not found' | |
| redirect_to :action => :index | |
| end | |
| - | |
| + | |
| end | |
| \ No newline at end of file | |
app/views/cms_admin/sites/edit.html.erb
+4
-1
| @@ | @@ -2,5 +2,8 @@ |
| <%= cms_form_for @cms_site, :url => {:action => :update} do |form| %> | |
| <%= render :partial => 'form', :object => form %> | |
| - | <%= form.submit 'Update Site' %> |
| + | <%= form.simple_field nil, nil, :class => 'submit_element' do %> |
| + | <%= form.submit 'Update Site', :disable_builder => true %> |
| + | <%= form.submit 'Update & Edit'.html_safe, :name => "save", :disable_builder => true%> |
| + | <% end %> |
| <% end %> | |
| \ No newline at end of file | |
app/views/cms_admin/sites/new.html.erb
+4
-1
| @@ | @@ -2,5 +2,8 @@ |
| <%= cms_form_for @cms_site, :url => {:action => :create} do |form| %> | |
| <%= render :partial => 'form', :object => form %> | |
| - | <%= form.submit 'Create Site' %> |
| + | <%= form.simple_field nil, nil, :class => 'submit_element' do %> |
| + | <%= form.submit 'Create Site', :disable_builder => true %> |
| + | <%= form.submit 'Create & Edit'.html_safe, :name => "save", :disable_builder => true%> |
| + | <% end %> |
| <% end %> | |
| \ No newline at end of file | |
test/functional/cms_admin/sites_controller_test.rb
+38
-12
| @@ | @@ -1,21 +1,21 @@ |
| require File.expand_path('../../test_helper', File.dirname(__FILE__)) | |
| class CmsAdmin::SitesControllerTest < ActionController::TestCase | |
| - | |
| + | |
| def test_get_index | |
| get :index | |
| assert_response :success | |
| assert assigns(:cms_sites) | |
| assert_template :index | |
| end | |
| - | |
| + | |
| def test_get_index_with_no_sites | |
| CmsSite.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::SitesControllerTest < ActionController::TestCase |
| assert_template :new | |
| assert_select 'form[action=/cms-admin/sites]' | |
| end | |
| - | |
| + | |
| def test_get_edit | |
| site = cms_sites(:default) | |
| get :edit, :id => site | |
| @@ | @@ -33,15 +33,27 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase |
| assert_template :edit | |
| assert_select "form[action=/cms-admin/sites/#{site.id}]" | |
| end | |
| - | |
| + | |
| def test_get_edit_failure | |
| get :edit, :id => 'not_found' | |
| assert_response :redirect | |
| assert_redirected_to :action => :index | |
| assert_equal 'Site not found', flash[:error] | |
| end | |
| - | |
| - | def test_creation |
| + | |
| + | def test_create_with_commit |
| + | assert_difference 'CmsSite.count' do |
| + | post :create, :cms_site => { |
| + | :label => 'Test Site', |
| + | :hostname => 'test.site.local' |
| + | }, :commit => 'Create Site' |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'Site created', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_create_without_commit |
| assert_difference 'CmsSite.count' do | |
| post :create, :cms_site => { | |
| :label => 'Test Site', | |
| @@ | @@ -52,7 +64,7 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase |
| assert_equal 'Site created', flash[:notice] | |
| end | |
| end | |
| - | |
| + | |
| def test_creation_failure | |
| assert_no_difference 'CmsSite.count' do | |
| post :create, :cms_site => { } | |
| @@ | @@ -61,8 +73,22 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase |
| assert_equal 'Failed to create site', flash[:error] | |
| end | |
| end | |
| - | |
| - | def test_update |
| + | |
| + | def test_update_with_commit |
| + | site = cms_sites(:default) |
| + | put :update, :id => site, :cms_site => { |
| + | :label => 'New Site', |
| + | :hostname => 'new.site.local' |
| + | }, :commit => 'Update Site' |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'Site updated', flash[:notice] |
| + | site.reload |
| + | assert_equal 'New Site', site.label |
| + | assert_equal 'new.site.local', site.hostname |
| + | end |
| + | |
| + | def test_update_wthout_commit |
| site = cms_sites(:default) | |
| put :update, :id => site, :cms_site => { | |
| :label => 'New Site', | |
| @@ | @@ -75,7 +101,7 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase |
| assert_equal 'New Site', site.label | |
| assert_equal 'new.site.local', site.hostname | |
| end | |
| - | |
| + | |
| def test_update_failure | |
| site = cms_sites(:default) | |
| put :update, :id => site, :cms_site => { | |
| @@ | @@ -87,7 +113,7 @@ class CmsAdmin::SitesControllerTest < ActionController::TestCase |
| assert_not_equal '', site.label | |
| assert_equal 'Failed to update site', flash[:error] | |
| end | |
| - | |
| + | |
| def test_destroy | |
| assert_difference 'CmsSite.count', -1 do | |
| delete :destroy, :id => cms_sites(:default) | |