summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Davis <edavis@littlestreamsoftware.com>2010-08-19 04:34:31 +0000
committerEric Davis <edavis@littlestreamsoftware.com>2010-08-19 04:34:31 +0000
commitd457f90fcd75ad2518601ff09fbf067648b367f5 (patch)
treed97a1478f042412b37847f4f3fe320e7082a0e5a
parentb9f23bedb74876552737a2385e450aca11eeff34 (diff)
downloadredmine-d457f90fcd75ad2518601ff09fbf067648b367f5.tar.gz
redmine-d457f90fcd75ad2518601ff09fbf067648b367f5.zip
Merged r3949 from trunk.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.0-stable@3999 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/application_controller.rb13
-rw-r--r--test/integration/layout_test.rb26
2 files changed, 36 insertions, 3 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index e5909e69b..725bde788 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -258,7 +258,7 @@ class ApplicationController < ActionController::Base
def render_403
@project = nil
respond_to do |format|
- format.html { render :template => "common/403", :layout => (request.xhr? ? false : 'base'), :status => 403 }
+ format.html { render :template => "common/403", :layout => use_layout, :status => 403 }
format.atom { head 403 }
format.xml { head 403 }
format.js { head 403 }
@@ -269,7 +269,7 @@ class ApplicationController < ActionController::Base
def render_404
respond_to do |format|
- format.html { render :template => "common/404", :layout => !request.xhr?, :status => 404 }
+ format.html { render :template => "common/404", :layout => use_layout, :status => 404 }
format.atom { head 404 }
format.xml { head 404 }
format.js { head 404 }
@@ -282,7 +282,7 @@ class ApplicationController < ActionController::Base
respond_to do |format|
format.html {
flash.now[:error] = msg
- render :text => '', :layout => !request.xhr?, :status => 500
+ render :text => '', :layout => use_layout, :status => 500
}
format.atom { head 500 }
format.xml { head 500 }
@@ -290,6 +290,13 @@ class ApplicationController < ActionController::Base
format.json { head 500 }
end
end
+
+ # Picks which layout to use based on the request
+ #
+ # @return [boolean, string] name of the layout to use or false for no layout
+ def use_layout
+ request.xhr? ? false : 'base'
+ end
def invalid_authenticity_token
if api_request?
diff --git a/test/integration/layout_test.rb b/test/integration/layout_test.rb
new file mode 100644
index 000000000..03d407d24
--- /dev/null
+++ b/test/integration/layout_test.rb
@@ -0,0 +1,26 @@
+require "#{File.dirname(__FILE__)}/../test_helper"
+
+class LayoutTest < ActionController::IntegrationTest
+ fixtures :all
+
+ test "browsing to a missing page should render the base layout" do
+ get "/users/100000000"
+
+ assert_response :not_found
+
+ # UsersController uses the admin layout by default
+ assert_select "#admin-menu", :count => 0
+ end
+
+ test "browsing to an unauthorized page should render the base layout" do
+ user = User.find(9)
+ user.password, user.password_confirmation = 'test', 'test'
+ user.save!
+
+ log_user('miscuser9','test')
+
+ get "/admin"
+ assert_response :forbidden
+ assert_select "#admin-menu", :count => 0
+ end
+end