when site is not defined, let's not crash

Oleg committed Apr 30, 2011
commit 86aeb7c6a0ffd84b7f40a2f8e25323e820aaa901
Showing 2 changed files with 10 additions and 3 deletions
app/controllers/cms_content_controller.rb +2 -3
@@ @@ -29,12 +29,11 @@ protected
def load_cms_site
@cms_site = if ComfortableMexicanSofa.config.enable_multiple_sites
- Cms::Site.find_by_hostname!(request.host.downcase)
+ Cms::Site.find_by_hostname(request.host.downcase)
else
Cms::Site.first
end
- rescue ActiveRecord::RecordNotFound
- render :text => 'Site Not Found', :status => 404
+ render :text => 'Site Not Found', :status => 404 if !@cms_site
end
def load_cms_page
test/functional/cms_content_controller_test.rb +8 -0
@@ @@ -52,6 +52,14 @@ class CmsContentControllerTest < ActionController::TestCase
assert_match /custom 404 page content/, response.body
end
+ def test_render_page_with_no_site
+ Cms::Site.destroy_all
+
+ get :render_html, :cms_path => ''
+ assert_response 404
+ assert_equal 'Site Not Found', response.body
+ end
+
def test_render_page_with_redirect
cms_pages(:child).update_attribute(:target_page, cms_pages(:default))
assert_equal cms_pages(:default), cms_pages(:child).target_page