Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

different 404 handling

  • Loading branch information...
commit 602e51b9fa1728572ad8e8518cda1abe01063f6f 1 parent 6da93cb
@GBH GBH authored
View
2  README.md
@@ -5,7 +5,7 @@ ComfortableMexicanSofa is a powerful CMS Engine for your Rails 3 applications.
Features
--------
-* Simple integration with Rails 3.0 and 3.1 apps
+* Simple integration with Rails 3 apps (with or without assets pipeline)
* Build your application in Rails, not in CMS
* Powerful page templating capability using [Tags](https://github.com/comfy/comfortable-mexican-sofa/wiki/Tags)
* [Multiple Sites](https://github.com/comfy/comfortable-mexican-sofa/wiki/Sites) from a single installation
View
4 app/controllers/cms_content_controller.rb
@@ -54,7 +54,7 @@ def load_cms_site
I18n.locale = @cms_site.locale
else
I18n.locale = I18n.default_locale
- render :text => I18n.t('cms.content.site_not_found'), :status => 404
+ raise ActionController::RoutingError.new('Site Not Found')
end
end
@@ -66,7 +66,7 @@ def load_cms_page
if @cms_page = @cms_site.pages.published.find_by_full_path('/404')
render_html(404)
else
- render :text => I18n.t('cms.content.page_not_found'), :status => 404
+ raise ActionController::RoutingError.new('Page Not Found')
end
end
View
18 test/functional/cms_content_controller_test.rb
@@ -38,9 +38,9 @@ def test_render_page_with_xhr
end
def test_render_page_not_found
- get :render_html, :cms_path => 'doesnotexist'
- assert_response 404
- assert_equal 'Page Not Found', response.body
+ assert_exception_raised ActionController::RoutingError, 'Page Not Found' do
+ get :render_html, :cms_path => 'doesnotexist'
+ end
end
def test_render_page_not_found_with_custom_404
@@ -66,9 +66,9 @@ def test_render_page_not_found_with_custom_404
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
+ assert_exception_raised ActionController::RoutingError, 'Site Not Found' do
+ get :render_html, :cms_path => ''
+ end
end
def test_render_page_with_no_layout
@@ -90,8 +90,10 @@ def test_render_page_with_redirect
def test_render_page_unpublished
page = cms_pages(:default)
page.update_attribute(:is_published, false)
- get :render_html, :cms_path => ''
- assert_response 404
+
+ assert_exception_raised ActionController::RoutingError, 'Page Not Found' do
+ get :render_html, :cms_path => ''
+ end
end
def test_render_page_with_irb_disabled
View
10 test/integration/routing_extensions_test.rb
@@ -11,8 +11,9 @@ def test_get_admin_with_admin_route_prefix
ComfortableMexicanSofa.config.admin_route_prefix = 'custom-admin'
Rails.application.reload_routes!
- http_auth :get, '/cms-admin/sites'
- assert_response 404
+ assert_exception_raised ActionController::RoutingError, 'Page Not Found' do
+ http_auth :get, '/cms-admin/sites'
+ end
http_auth :get, '/custom-admin/sites'
assert_response :success
@@ -31,8 +32,9 @@ def test_get_admin_with_admin_route_prefix_disabled
ComfortableMexicanSofa.config.admin_route_prefix = ''
Rails.application.reload_routes!
- http_auth :get, '/cms-admin'
- assert_response 404
+ assert_exception_raised ActionController::RoutingError, 'Page Not Found' do
+ http_auth :get, '/cms-admin'
+ end
end
def test_get_admin_with_all_routes_disabled
View
9 test/integration/sites_test.rb
@@ -32,9 +32,14 @@ def test_get_public_page_with_sites_with_different_paths
site_b = Cms::Site.create!(:identifier => 'site-b', :hostname => 'test.host', :path => 'path-b')
site_c = Cms::Site.create!(:identifier => 'site-c', :hostname => 'test.host', :path => 'path-c/child')
+ [site_a, site_b, site_c].each do |site|
+ layout = site.layouts.create!(:identifier => 'test')
+ site.pages.create!(:label => 'index', :layout => layout)
+ site.pages.create!(:label => '404', :slug => '404', :layout => layout)
+ end
+
%w(/ /path-a /path-a/child /path-c).each do |path|
get path
- assert_response 404
assert assigns(:cms_site), path
assert_equal site_a, assigns(:cms_site)
assert_equal path.gsub(/^\//, ''), @controller.params[:cms_path].to_s
@@ -42,7 +47,6 @@ def test_get_public_page_with_sites_with_different_paths
%w(/path-b /path-b/child).each do |path|
get path
- assert_response 404
assert assigns(:cms_site), path
assert_equal site_b, assigns(:cms_site)
assert_equal path.gsub(/^\/path-b/, '').gsub(/^\//, ''), @controller.params[:cms_path].to_s
@@ -50,7 +54,6 @@ def test_get_public_page_with_sites_with_different_paths
%w(/path-c/child /path-c/child/child).each do |path|
get path
- assert_response 404
assert assigns(:cms_site), path
assert_equal site_c, assigns(:cms_site)
assert_equal path.gsub(/^\/path-c\/child/, '').gsub(/^\//, ''), @controller.params[:cms_path].to_s
Please sign in to comment.
Something went wrong with that request. Please try again.