Skip to content

Commit

Permalink
Testing layout gotcha when view renders partial
Browse files Browse the repository at this point in the history
  • Loading branch information
pmatsinopoulos committed Mar 24, 2012
1 parent 5b35664 commit c12b886
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions guides/source/testing.textile
Expand Up @@ -548,6 +548,22 @@ file in this standard layout directory. Hence,

will not work.

<b>Gotcha: Watch out if your view renders any partial</b>

If your view renders any partial, when asserting for the layout, you have to assert for the partial at the same time.
Otherwise, assertion will fail.

Hence:

<ruby>
test "new should render correct layout" do
get :new
assert_template :layout => "layouts/application", :partial => "_form"
end
</ruby>

is the correct way to assert for the layout when the view renders a partial with name +_form+. Omitting the +:partial+ key in your +assert_template+ call will complain.

h4. A Fuller Functional Test Example

Here's another example that uses +flash+, +assert_redirected_to+, and +assert_difference+:
Expand Down

0 comments on commit c12b886

Please sign in to comment.