aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-03-27 21:26:37 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-03-27 21:26:37 +0530
commitb42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4 (patch)
treedd296efc489c22850d6cc7fa8d7a69da5e122b54 /guides/source
parent888fcca01b736b7f91041b7a6a1b162af6688f7a (diff)
parentae040ed6d8c48bf0cd6d5d6b434d60c9c8c27f81 (diff)
downloadrails-b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4.tar.gz
rails-b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4.tar.bz2
rails-b42fbd3ecbc3e2c55987e0ae6331443dfd68d5b4.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/command_line.textile6
-rw-r--r--guides/source/engines.textile4
-rw-r--r--guides/source/testing.textile38
3 files changed, 46 insertions, 2 deletions
diff --git a/guides/source/command_line.textile b/guides/source/command_line.textile
index 463c2b172b..858ce47db1 100644
--- a/guides/source/command_line.textile
+++ b/guides/source/command_line.textile
@@ -278,6 +278,12 @@ The +console+ command lets you interact with your Rails application from the com
You can also use the alias "c" to invoke the console: <tt>rails c</tt>.
+You can specify the environment in which the +console+ command should operate using the +-e+ switch.
+
+<shell>
+$ rails console -e staging
+</shell>
+
If you wish to test out some code without changing any data, you can do that by invoking +rails console --sandbox+.
<shell>
diff --git a/guides/source/engines.textile b/guides/source/engines.textile
index 501d48eab8..047f9afd76 100644
--- a/guides/source/engines.textile
+++ b/guides/source/engines.textile
@@ -219,7 +219,7 @@ By default, the scaffold styling is not applied to the engine as the engine's la
<%= stylesheet_link_tag "scaffold" %>
</erb>
-You can see what the engine has so far by running +rake db:migrate+ at the root of our engine to run the migration generated by the scaffold generator, and then running +rails server+. When you open +http://localhost:3000/blorgh/posts+ you will see the default scaffold that has been generated.
+You can see what the engine has so far by running +rake db:migrate+ at the root of our engine to run the migration generated by the scaffold generator, and then running +rails server+ in +test/dummy+. When you open +http://localhost:3000/blorgh/posts+ you will see the default scaffold that has been generated.
!images/engines_scaffold.png(Blank engine scaffold)!
@@ -263,7 +263,7 @@ create test/fixtures/blorgh/comments.yml
This generator call will generate just the necessary model files it needs, namespacing the files under a +blorgh+ directory and creating a model class called +Blorgh::Comment+.
-To show the comments on a post, edit +app/views/posts/show.html.erb+ and add this line before the "Edit" link:
+To show the comments on a post, edit +app/views/blorgh/posts/show.html.erb+ and add this line before the "Edit" link:
<erb>
<h3>Comments</h3>
diff --git a/guides/source/testing.textile b/guides/source/testing.textile
index c367f532ae..60b0aa89b9 100644
--- a/guides/source/testing.textile
+++ b/guides/source/testing.textile
@@ -524,6 +524,44 @@ You also have access to three instance variables in your functional tests:
* +@request+ - The request
* +@response+ - The response
+h4. Testing Templates and Layouts
+
+If you want to make sure that the response rendered the correct template and layout, you can use the +assert_template+
+method:
+
+<ruby>
+test "index should render correct template and layout" do
+ get :index
+ assert_template :index
+ assert_template :layout => "layouts/application"
+end
+</ruby>
+
+Note that you cannot test for template and layout at the same time, with one call to +assert_template+ method.
+Also, for the +layout+ test, you can give a regular expression instead of a string, but using the string, makes
+things clearer. On the other hand, you have to include the "layouts" directory name even if you save your layout
+file in this standard layout directory. Hence,
+
+<ruby>
+assert_template :layout => "application"
+</ruby>
+
+will not work.
+
+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+: