different 404 handling
Oleg
committed Mar 15, 2012
commit 602e51b9fa1728572ad8e8518cda1abe01063f6f
Showing 5
changed files with
25 additions
and 18 deletions
README.md
+1
-1
| @@ | @@ -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 | |
app/controllers/cms_content_controller.rb
+2
-2
| @@ | @@ -54,7 +54,7 @@ protected |
| 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 @@ protected |
| 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 | |
test/functional/cms_content_controller_test.rb
+10
-8
| @@ | @@ -38,9 +38,9 @@ class CmsContentControllerTest < ActionController::TestCase |
| 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 @@ class CmsContentControllerTest < ActionController::TestCase |
| 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 @@ class CmsContentControllerTest < ActionController::TestCase |
| 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 | |
test/integration/routing_extensions_test.rb
+6
-4
| @@ | @@ -11,8 +11,9 @@ class RoutingExtensionsTest < ActionDispatch::IntegrationTest |
| 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 @@ class RoutingExtensionsTest < ActionDispatch::IntegrationTest |
| 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 | |
test/integration/sites_test.rb
+6
-3
| @@ | @@ -32,9 +32,14 @@ class SitesTest < ActionDispatch::IntegrationTest |
| 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 @@ class SitesTest < ActionDispatch::IntegrationTest |
| %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 @@ class SitesTest < ActionDispatch::IntegrationTest |
| %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 | |