Last active
December 18, 2015 14:49
-
-
Save sanjayginde/5799903 to your computer and use it in GitHub Desktop.
Example to 'disable' layouts in a Rails controller test. Uses an 'empty' layout, which can allow for testing that the the title tag and javascript is properly added...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# Empty layout used as layout replacement for testing... | |
!!! 5 | |
!= html5_haml_tag(:lang => 'en') do | |
%head | |
%meta{:content => "text/html; charset=utf-8", "http-equiv" => "Content-Type"}/ | |
%title=h ((title=yield(:title)).blank?) ? "Contently" : "#{title} : Contently".html_safe | |
%body | |
=yield | |
=yield :javascript | |
=yield :jstemplates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe PostsController | |
# Helper method... | |
def disable_layout | |
@controller.instance_eval do | |
def _process_options(options) | |
options[:layout] = '/layouts/empty.html' | |
end | |
end | |
end | |
# Call the helper method and render views... | |
before do | |
disable_layout | |
end | |
render_views | |
describe :show do | |
... | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment