From f9296a1f389e2e70e16c6a297941409af9f3c262 Mon Sep 17 00:00:00 2001 From: Rodrigo Souto Date: Wed, 29 Aug 2012 20:33:49 +0000 Subject: [PATCH] [performance] Rendering nothing on some not_founds --- app/controllers/public/not_found_controller.rb | 4 ++++ config/routes.rb | 14 +++++++------- test/integration/routing_test.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/app/controllers/public/not_found_controller.rb b/app/controllers/public/not_found_controller.rb index 1f0a87d..54cc049 100644 --- a/app/controllers/public/not_found_controller.rb +++ b/app/controllers/public/not_found_controller.rb @@ -2,4 +2,8 @@ class NotFoundController < ApplicationController def index render_not_found end + + def nothing + render :nothing => true, :status => 404 + end end diff --git a/config/routes.rb b/config/routes.rb index cdd8265..26ba71d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -22,13 +22,13 @@ ActionController::Routing::Routes.draw do |map| map.connect '', :controller => "home", :conditions => { :if => lambda { |env| !Domain.hosting_profile_at(env[:host]) } } map.home 'site/:action', :controller => 'home' - map.connect 'images/*stuff', :controller => 'not_found', :action => 'index' - map.connect 'stylesheets/*stuff', :controller => 'not_found', :action => 'index' - map.connect 'designs/*stuff', :controller => 'not_found', :action => 'index' - map.connect 'articles/*stuff', :controller => 'not_found', :action => 'index' - map.connect 'javascripts/*stuff', :controller => 'not_found', :action => 'index' - map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'index' - map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'index' + map.connect 'images/*stuff', :controller => 'not_found', :action => 'nothing' + map.connect 'stylesheets/*stuff', :controller => 'not_found', :action => 'nothing' + map.connect 'designs/*stuff', :controller => 'not_found', :action => 'nothing' + map.connect 'articles/*stuff', :controller => 'not_found', :action => 'nothing' + map.connect 'javascripts/*stuff', :controller => 'not_found', :action => 'nothing' + map.connect 'thumbnails/*stuff', :controller => 'not_found', :action => 'nothing' + map.connect 'user_themes/*stuff', :controller => 'not_found', :action => 'nothing' # online documentation map.doc 'doc', :controller => 'doc', :action => 'index' diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 79f899c..7bd847d 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -221,4 +221,32 @@ class RoutingTest < ActionController::IntegrationTest assert_routing('/chat/avatar/chemical-brothers', :controller => 'chat', :action => 'avatar', :id => 'chemical-brothers') end + def test_not_found_images_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/images/aksdhf') + end + + def test_not_found_stylesheets_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/stylesheets/aksdhf') + end + + def test_not_found_designs_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/designs/aksdhf') + end + + def test_not_found_articles_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/articles/aksdhf') + end + + def test_not_found_javascripts_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/javascripts/aksdhf') + end + + def test_not_found_thumbnails_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/thumbnails/aksdhf') + end + + def test_not_found_user_themes_on_nothing + assert_recognizes({:controller => 'not_found', :action => 'nothing', :stuff => ['aksdhf']}, '/user_themes/aksdhf') + end + end -- libgit2 0.21.2