From 0ba64689386dfc7fd6b0d77223c8f55f2a556a01 Mon Sep 17 00:00:00 2001 From: Artem Biserov Date: Mon, 7 Oct 2013 17:57:08 +0400 Subject: [PATCH] do not render layout in xhr request --- .../api_taster/application_controller.rb | 2 +- .../api_taster/routes_controller_spec.rb | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/api_taster/application_controller.rb b/app/controllers/api_taster/application_controller.rb index d5654d9..76f491c 100644 --- a/app/controllers/api_taster/application_controller.rb +++ b/app/controllers/api_taster/application_controller.rb @@ -1,6 +1,6 @@ module ApiTaster class ApplicationController < ActionController::Base - layout proc { |controller| controller.request.xhr? ? nil : 'api_taster/application' } + layout proc { |controller| controller.request.xhr? ? false : 'api_taster/application' } before_filter :reload_routes diff --git a/spec/controllers/api_taster/routes_controller_spec.rb b/spec/controllers/api_taster/routes_controller_spec.rb index 87c8bc2..7c09df9 100644 --- a/spec/controllers/api_taster/routes_controller_spec.rb +++ b/spec/controllers/api_taster/routes_controller_spec.rb @@ -41,5 +41,25 @@ module ApiTaster assigns(:obsolete_definitions).should be_kind_of(Array) end + + context 'layout' do + context 'when request is not XHR' do + it 'renders application layout' do + get :index, :use_route => :api_taster + + response.should render_template('api_taster/application') + end + end + + context 'when request is XHR' do + before { request.stub(:xhr?) { true } } + + it 'does not render layout' do + get :index, :use_route => :api_taster + + response.should_not render_template('api_taster/application') + end + end + end end end