Permalink
Browse files

add should_render_with_layout and should_render_without_layout

  • Loading branch information...
1 parent 99b1189 commit 2d858c0b08ca5e93e389730bfc591c3cce39b9f9 @mjankowski mjankowski committed with Tammer Saleh Sep 15, 2008
@@ -148,7 +148,7 @@ def should_respond_with_content_type(content_type)
end
end
end
-
+
# Macro that creates a test asserting that a value returned from the session is correct.
# The given string is evaled to produce the resulting redirect path. All of the instance variables
# set by the controller are available to the evaled string.
@@ -175,6 +175,24 @@ def should_render_template(template)
end
end
+ # Macro that creates a test asserting that the controller rendered with the given layout.
+ # Example:
+ #
+ # should_render_with_layout 'special'
+ def should_render_with_layout(expected_layout = 'application')
+ expected_layout ||= false
+ should "render with #{expected_layout} layout" do
+ response_layout = @response.layout.blank? ? false : @response.layout.split('/').last
+ assert_equal expected_layout, response_layout, "Expected #{expected_layout} but was #{response_layout}"
+ end
+ end
+
+ # Macro that creates a test asserting that the controller rendered without a layout.
+ # Same as @should_render_with_layout false@
+ def should_render_without_layout
+ should_render_with_layout nil
+ end
+
# Macro that creates a test asserting that the controller returned a redirect to the given path.
# The given string is evaled to produce the resulting redirect path. All of the instance variables
# set by the controller are available to the evaled string.
@@ -82,6 +82,16 @@ def setup
should_assign_to :user, :posts
should_not_assign_to :foo, :bar
end
+
+ context "viewing a post on GET to #show" do
+ setup { get :show, :user_id => users(:first), :id => posts(:first) }
+ should_render_with_layout 'wide'
+ end
+
+ context "on GET to #new" do
+ setup { get :new, :user_id => users(:first) }
+ should_render_without_layout
+ end
end
end
@@ -21,13 +21,14 @@ def show
@post = @user.posts.find(params[:id])
respond_to do |format|
- format.html # show.rhtml
+ format.html { render :layout => 'wide' }
format.xml { render :xml => @post.to_xml }
end
end
def new
@post = @user.posts.build
+ render :layout => false
end
def edit
@@ -0,0 +1 @@
+<html><%= yield %></html>

0 comments on commit 2d858c0

Please sign in to comment.