@@ -0,0 +1,26 | |||||
|
1 | require "#{File.dirname(__FILE__)}/../test_helper" | |||
|
2 | ||||
|
3 | class LayoutTest < ActionController::IntegrationTest | |||
|
4 | fixtures :all | |||
|
5 | ||||
|
6 | test "browsing to a missing page should render the base layout" do | |||
|
7 | get "/users/100000000" | |||
|
8 | ||||
|
9 | assert_response :not_found | |||
|
10 | ||||
|
11 | # UsersController uses the admin layout by default | |||
|
12 | assert_select "#admin-menu", :count => 0 | |||
|
13 | end | |||
|
14 | ||||
|
15 | test "browsing to an unauthorized page should render the base layout" do | |||
|
16 | user = User.find(9) | |||
|
17 | user.password, user.password_confirmation = 'test', 'test' | |||
|
18 | user.save! | |||
|
19 | ||||
|
20 | log_user('miscuser9','test') | |||
|
21 | ||||
|
22 | get "/admin" | |||
|
23 | assert_response :forbidden | |||
|
24 | assert_select "#admin-menu", :count => 0 | |||
|
25 | end | |||
|
26 | end |
@@ -258,7 +258,7 class ApplicationController < ActionController::Base | |||||
258 | def render_403 |
|
258 | def render_403 | |
259 | @project = nil |
|
259 | @project = nil | |
260 | respond_to do |format| |
|
260 | respond_to do |format| | |
261 |
format.html { render :template => "common/403", :layout => |
|
261 | format.html { render :template => "common/403", :layout => use_layout, :status => 403 } | |
262 | format.atom { head 403 } |
|
262 | format.atom { head 403 } | |
263 | format.xml { head 403 } |
|
263 | format.xml { head 403 } | |
264 | format.js { head 403 } |
|
264 | format.js { head 403 } | |
@@ -269,7 +269,7 class ApplicationController < ActionController::Base | |||||
269 |
|
269 | |||
270 | def render_404 |
|
270 | def render_404 | |
271 | respond_to do |format| |
|
271 | respond_to do |format| | |
272 |
format.html { render :template => "common/404", :layout => |
|
272 | format.html { render :template => "common/404", :layout => use_layout, :status => 404 } | |
273 | format.atom { head 404 } |
|
273 | format.atom { head 404 } | |
274 | format.xml { head 404 } |
|
274 | format.xml { head 404 } | |
275 | format.js { head 404 } |
|
275 | format.js { head 404 } | |
@@ -282,7 +282,7 class ApplicationController < ActionController::Base | |||||
282 | respond_to do |format| |
|
282 | respond_to do |format| | |
283 | format.html { |
|
283 | format.html { | |
284 | flash.now[:error] = msg |
|
284 | flash.now[:error] = msg | |
285 |
render :text => '', :layout => |
|
285 | render :text => '', :layout => use_layout, :status => 500 | |
286 | } |
|
286 | } | |
287 | format.atom { head 500 } |
|
287 | format.atom { head 500 } | |
288 | format.xml { head 500 } |
|
288 | format.xml { head 500 } | |
@@ -290,6 +290,13 class ApplicationController < ActionController::Base | |||||
290 | format.json { head 500 } |
|
290 | format.json { head 500 } | |
291 | end |
|
291 | end | |
292 | end |
|
292 | end | |
|
293 | ||||
|
294 | # Picks which layout to use based on the request | |||
|
295 | # | |||
|
296 | # @return [boolean, string] name of the layout to use or false for no layout | |||
|
297 | def use_layout | |||
|
298 | request.xhr? ? false : 'base' | |||
|
299 | end | |||
293 |
|
300 | |||
294 | def invalid_authenticity_token |
|
301 | def invalid_authenticity_token | |
295 | if api_request? |
|
302 | if api_request? |
General Comments 0
You need to be logged in to leave comments.
Login now