tests are almost clean. time to change how public site is loaded

Oleg committed Jun 23, 2011
commit e338db72873338a09b6be2bbd75396a2ab94f629
Showing 2 changed files with 16 additions and 62 deletions
app/controllers/cms_admin/base_controller.rb +5 -7
@@ @@ -16,18 +16,16 @@ class CmsAdmin::BaseController < ApplicationController
path = ComfortableMexicanSofa.config.admin_route_redirect
return redirect_to(path) unless path.blank?
load_admin_site
- redirect_to cms_admin_site_pages_path(@site)
+ redirect_to cms_admin_site_pages_path(@site) if @site
end
protected
def load_admin_site
- @site = Cms::Site.find(params[:site_id])
- rescue ActiveRecord::RecordNotFound => e
- raise e unless @site = Cms::Site.first
- rescue ActiveRecord::RecordNotFound
- flash[:error] = 'Site not found'
- return redirect_to(cms_admin_sites_path)
+ unless (@site = Cms::Site.find_by_id(params[:site_id]) || Cms::Site.first)
+ flash[:error] = 'Site not found'
+ return redirect_to(new_cms_admin_site_path)
+ end
end
def load_fixtures
test/integration/sites_test.rb +11 -55
@@ @@ -2,59 +2,23 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
class SitesTest < ActionDispatch::IntegrationTest
- def test_get_admin
- http_auth :get, cms_admin_pages_path
- assert_response :success
+ def test_get_admin_with_single_site
+ http_auth :get, cms_admin_path
+ assert assigns(:site)
+ assert_equal cms_sites(:default), assigns(:site)
+ assert_response :redirect
+ assert_redirected_to cms_admin_site_pages_path(assigns(:site))
end
def test_get_admin_with_no_site
Cms::Site.delete_all
- assert_difference 'Cms::Site.count' do
- http_auth :get, cms_admin_pages_path
- assert_response :redirect
- assert_redirected_to new_cms_admin_page_path
- site = Cms::Site.first
- assert_equal 'test.host', site.hostname
- assert_equal 'Default Site', site.label
- end
- end
-
- def test_get_admin_with_wrong_site
- site = cms_sites(:default)
- site.update_attribute(:hostname, 'remote.host')
- assert_no_difference 'Cms::Site.count' do
- http_auth :get, cms_admin_pages_path
- assert_response :success
- site.reload
- assert_equal 'test.host', site.hostname
- end
+ http_auth :get, cms_admin_path
+ assert_response :redirect
+ assert_redirected_to new_cms_admin_site_path
+ assert_equal 'Site not found', flash[:error]
end
- def test_get_admin_with_two_wrong_sites
- ComfortableMexicanSofa.config.enable_multiple_sites = true
- Cms::Site.delete_all
- Cms::Site.create!(:label => 'Site1', :hostname => 'site1.host')
- Cms::Site.create!(:label => 'Site2', :hostname => 'site2.host')
- assert_no_difference 'Cms::Site.count' do
- http_auth :get, cms_admin_pages_path
- assert_response :redirect
- assert_redirected_to cms_admin_sites_path
- assert_equal 'No Site defined for this hostname. Create it now.', flash[:error]
- end
- end
-
- def test_get_admin_with_no_site_and_multiple_sites_enabled
- ComfortableMexicanSofa.config.enable_multiple_sites = true
- Cms::Site.delete_all
- assert_no_difference 'Cms::Site.count' do
- http_auth :get, cms_admin_pages_path
- assert_response :redirect
- assert_redirected_to cms_admin_sites_path
- assert_equal 'No Site defined for this hostname. Create it now.', flash[:error]
- end
- end
-
- def test_get_public_page_for_wrong_host_with_single_site
+ def test_get_public_page_with_single_site
host! 'bogus.host'
get '/'
assert_response :success
@@ @@ -62,12 +26,4 @@ class SitesTest < ActionDispatch::IntegrationTest
assert_equal 'test.host', assigns(:cms_site).hostname
end
- def test_get_public_page_for_wrong_host_with_mutiple_sites
- ComfortableMexicanSofa.config.enable_multiple_sites = true
- host! 'bogus.host'
- get '/'
- assert_response 404
- assert_equal 'Site Not Found', response.body
- end
-
end
\ No newline at end of file