adding functinal stiff for sites
Oleg
committed Oct 15, 2010
commit 435b47017bdfd902c6f6a7900997282d779cb988
Showing 9
changed files with
210 additions
and 57 deletions
app/controllers/cms_admin/sites_controller.rb
+26
-9
| @@ | @@ -1,36 +1,53 @@ |
| class CmsAdmin::SitesController < CmsAdmin::BaseController | |
| - | before_filter :load_site, :only => [:edit, :update, :destroy] |
| + | before_filter :build_cms_site, :only => [:new, :create] |
| + | before_filter :load_cms_site, :only => [:edit, :update, :destroy] |
| def index | |
| - | |
| + | @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 |
| + | 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 |
| + | 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 load_site |
| + | def build_cms_site |
| + | @cms_site = CmsSite.new(params[:cms_site]) |
| + | end |
| + | |
| + | def load_cms_site |
| @cms_site = CmsSite.find(params[:id]) | |
| - | rescue ActiveRecord::RecordInvalid |
| + | rescue ActiveRecord::RecordNotFound |
| flash[:error] = 'Site not found' | |
| redirect_to :action => :index | |
| end | |
app/controllers/cms_admin/snippets_controller.rb
+15
-11
| @@ | @@ -1,32 +1,35 @@ |
| class CmsAdmin::SnippetsController < CmsAdmin::BaseController | |
| - | before_filter :build_cms_snippet, |
| - | :only => [:new, :create] |
| - | before_filter :load_cms_snippet, |
| - | :only => [:edit, :update, :destroy] |
| - | |
| + | |
| + | before_filter :build_cms_snippet, :only => [:new, :create] |
| + | before_filter :load_cms_snippet, :only => [:edit, :update, :destroy] |
| + | |
| def index | |
| @cms_snippets = CmsSnippet.all(:order => 'label') | |
| end | |
| def new | |
| + | render |
| + | end |
| + | |
| + | def edit |
| + | render |
| end | |
| def create | |
| @cms_snippet.save! | |
| - | flash[:notice] = 'Snippet saved' |
| + | flash[:notice] = 'Snippet created' |
| redirect_to :action => :edit, :id => @cms_snippet | |
| rescue ActiveRecord::RecordInvalid | |
| + | flash.now[:error] = 'Failed to create snippet' |
| render :action => :new | |
| end | |
| - | def edit |
| - | end |
| - | |
| def update | |
| @cms_snippet.update_attributes!(params[:cms_snippet]) | |
| - | flash[:notice] = 'Snippet saved' |
| + | flash[:notice] = 'Snippet updated' |
| redirect_to :action => :edit, :id => @cms_snippet | |
| rescue ActiveRecord::RecordInvalid | |
| + | flash.now[:error] = 'Failed to update snippet' |
| render :action => :edit | |
| end | |
| @@ | @@ -35,8 +38,9 @@ class CmsAdmin::SnippetsController < CmsAdmin::BaseController |
| flash[:notice] = 'Snippet deleted' | |
| redirect_to :action => :index | |
| end | |
| - | |
| + | |
| protected | |
| + | |
| def build_cms_snippet | |
| @cms_snippet = CmsSnippet.new(params[:cms_snippet]) | |
| end | |
app/views/cms_admin/sites/_form.html.erb
+2
-0
| @@ | @@ -0,0 +1,2 @@ |
| + | <%= form.text_field :label %> |
| + | <%= form.text_field :hostname %> |
| \ No newline at end of file | |
app/views/cms_admin/sites/edit.html.erb
+6
-0
| @@ | @@ -0,0 +1,6 @@ |
| + | <h1> Editing Site </h1> |
| + | |
| + | <%= cms_form_for @cms_site, :url => {:action => :update} do |form| %> |
| + | <%= render :partial => 'form', :object => form %> |
| + | <%= form.submit 'Update Site' %> |
| + | <% end %> |
| \ No newline at end of file | |
app/views/cms_admin/sites/index.html.erb
+4
-0
| @@ | @@ -0,0 +1,4 @@ |
| + | <%= link_to span_tag('Create New Site'), new_cms_admin_site_path, :class => 'big_button' %> |
| + | <h1>Sites</h1> |
| + | |
| + | <%= debug @cms_sites %> |
| \ No newline at end of file | |
app/views/cms_admin/sites/new.html.erb
+6
-0
| @@ | @@ -0,0 +1,6 @@ |
| + | <h1> New Site </h1> |
| + | |
| + | <%= cms_form_for @cms_site, :url => {:action => :create} do |form| %> |
| + | <%= render :partial => 'form', :object => form %> |
| + | <%= form.submit 'Create Site' %> |
| + | <% end %> |
| \ No newline at end of file | |
app/views/layouts/cms_admin.html.erb
+1
-0
| @@ | @@ -12,6 +12,7 @@ |
| <div class='body_wrapper'> | |
| <div class='left_column'> | |
| <div class='left_column_content'> | |
| + | <%= active_link_to 'Sites', cms_admin_sites_path %> |
| <%= active_link_to 'Layouts', cms_admin_layouts_path %> | |
| <%= active_link_to 'Pages', cms_admin_pages_path %> | |
| <%= active_link_to 'Snippets', cms_admin_snippets_path %> | |
test/functional/cms_admin/sites_controller_test.rb
+91
-0
| @@ | @@ -0,0 +1,91 @@ |
| + | require File.dirname(__FILE__) + '/../../test_helper' |
| + | |
| + | 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_new |
| + | get :new |
| + | assert_response :success |
| + | assert assigns(:cms_site) |
| + | assert_template :new |
| + | assert_select 'form[action=/cms-admin/sites]' |
| + | end |
| + | |
| + | def test_get_edit |
| + | site = cms_sites(:default) |
| + | get :edit, :id => site |
| + | assert_response :success |
| + | assert assigns(:cms_site) |
| + | 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 |
| + | assert_difference 'CmsSite.count' do |
| + | post :create, :cms_site => { |
| + | :label => 'Test Site', |
| + | :hostname => 'test.site.local' |
| + | } |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :edit, :id => CmsSite.last |
| + | assert_equal 'Site created', flash[:notice] |
| + | end |
| + | end |
| + | |
| + | def test_creation_failure |
| + | assert_no_difference 'CmsSite.count' do |
| + | post :create, :cms_site => { } |
| + | assert_response :success |
| + | assert_template :new |
| + | assert_equal 'Failed to create site', flash[:error] |
| + | end |
| + | end |
| + | |
| + | def test_update |
| + | site = cms_sites(:default) |
| + | put :update, :id => site, :cms_site => { |
| + | :label => 'New Site', |
| + | :hostname => 'new.site.local' |
| + | } |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :edit, :id => site |
| + | 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_failure |
| + | site = cms_sites(:default) |
| + | put :update, :id => site, :cms_site => { |
| + | :label => '' |
| + | } |
| + | assert_response :success |
| + | assert_template :edit |
| + | site.reload |
| + | 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) |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'Site deleted', flash[:notice] |
| + | end |
| + | end |
| + | end |
| \ No newline at end of file | |
test/functional/cms_admin/snippets_controller_test.rb
+59
-37
| @@ | @@ -2,69 +2,91 @@ require File.dirname(__FILE__) + '/../../test_helper' |
| class CmsAdmin::SnippetsControllerTest < ActionController::TestCase | |
| - | def test_index |
| + | def test_get_index |
| get :index | |
| assert_response :success | |
| - | assert_template 'index' |
| + | assert assigns(:cms_snippets) |
| + | assert_template :index |
| end | |
| - | def test_new |
| + | def test_get_new |
| get :new | |
| assert_response :success | |
| - | assert_template 'new' |
| + | assert assigns(:cms_snippet) |
| + | assert_template :new |
| + | assert_select 'form[action=/cms-admin/snippets]' |
| end | |
| - | def test_create |
| - | assert_difference 'CmsSnippet.count', 1 do |
| - | post :create, :cms_snippet => cms_snippet_params |
| - | end |
| - | assert_equal 'Snippet saved', flash[:notice] |
| - | assert_redirected_to edit_cms_admin_snippet_path(assigns(:cms_snippet)) |
| + | def test_get_edit |
| + | snippet = cms_snippets(:default) |
| + | get :edit, :id => snippet |
| + | assert_response :success |
| + | assert assigns(:cms_snippet) |
| + | assert_template :edit |
| + | assert_select "form[action=/cms-admin/snippets/#{snippet.id}]" |
| end | |
| - | def test_create_fails |
| - | assert_no_difference 'CmsSnippet.count' do |
| - | post :create, :cms_snippet => cms_snippet_params(:label => '') |
| + | def test_get_edit_failure |
| + | get :edit, :id => 'not_found' |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'Snippet not found', flash[:error] |
| + | end |
| + | |
| + | def test_creation |
| + | assert_difference 'CmsSnippet.count' do |
| + | post :create, :cms_snippet => { |
| + | :label => 'Test-Snippet', |
| + | :content => 'Test Content' |
| + | } |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :edit, :id => CmsSnippet.last |
| + | assert_equal 'Snippet created', flash[:notice] |
| end | |
| - | assert_response :success |
| - | assert_template 'new' |
| end | |
| - | def test_edit |
| - | get :edit, :id => cms_snippets(:default) |
| - | assert_response :success |
| - | assert_template 'edit' |
| + | def test_creation_failure |
| + | assert_no_difference 'CmsSnippet.count' do |
| + | post :create, :cms_snippet => { } |
| + | assert_response :success |
| + | assert_template :new |
| + | assert_equal 'Failed to create snippet', flash[:error] |
| + | end |
| end | |
| def test_update | |
| snippet = cms_snippets(:default) | |
| - | put :update, :id => snippet, :cms_snippet => {:label => 'new-label'} |
| - | assert_equal 'Snippet saved', flash[:notice] |
| - | assert_redirected_to edit_cms_admin_snippet_path(assigns(:cms_snippet)) |
| - | assert_equal 'new-label', assigns(:cms_snippet).label |
| + | put :update, :id => snippet, :cms_snippet => { |
| + | :label => 'New-Snippet', |
| + | :content => 'New Content' |
| + | } |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :edit, :id => snippet |
| + | assert_equal 'Snippet updated', flash[:notice] |
| + | snippet.reload |
| + | assert_equal 'New-Snippet', snippet.label |
| + | assert_equal 'New Content', snippet.content |
| end | |
| - | def test_update_fails |
| + | def test_update_failure |
| snippet = cms_snippets(:default) | |
| - | put :update, :id => snippet, :cms_snippet => {:label => ''} |
| + | put :update, :id => snippet, :cms_snippet => { |
| + | :label => '' |
| + | } |
| assert_response :success | |
| - | assert_template 'edit' |
| - | assert_equal 'default', snippet.label |
| + | assert_template :edit |
| + | snippet.reload |
| + | assert_not_equal '', snippet.label |
| + | assert_equal 'Failed to update snippet', flash[:error] |
| end | |
| def test_destroy | |
| assert_difference 'CmsSnippet.count', -1 do | |
| delete :destroy, :id => cms_snippets(:default) | |
| + | assert_response :redirect |
| + | assert_redirected_to :action => :index |
| + | assert_equal 'Snippet deleted', flash[:notice] |
| end | |
| - | assert_equal 'Snippet deleted', flash[:notice] |
| - | assert_redirected_to cms_admin_snippets_path |
| - | end |
| - | |
| - | protected |
| - | def cms_snippet_params(options = {}) |
| - | { |
| - | :label => 'snippet-label', |
| - | :content => 'Lorem ipsum dolor sit amet, consectetur adipisicing elit' |
| - | }.merge(options) |
| end | |
| + | |
| end | |
| \ No newline at end of file | |