Skip to content

Commit

Permalink
different 404 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg committed Mar 15, 2012
1 parent 6da93cb commit 602e51b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/cms_content_controller.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down
18 changes: 10 additions & 8 deletions test/functional/cms_content_controller_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 6 additions & 4 deletions test/integration/routing_extensions_test.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 6 additions & 3 deletions test/integration/sites_test.rb
Expand Up @@ -32,25 +32,28 @@ 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
end

%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
end

%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
Expand Down

0 comments on commit 602e51b

Please sign in to comment.