From 7feec40b89ada892ca6f107ada27ceedde505d83 Mon Sep 17 00:00:00 2001 From: Senthil A Date: Sat, 24 Mar 2012 06:06:50 -0700 Subject: [ci skip] updated bin/rails code in Rails Initialization Process guide --- guides/source/initialization.textile | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'guides/source') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index 69e5c1edcc..b5e427b35c 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -21,14 +21,24 @@ The actual +rails+ command is kept in _bin/rails_: #!/usr/bin/env ruby +# +# This file was generated by RubyGems. +# +# The application 'railties' is installed as part of a gem, and +# this file is here to facilitate running it. +# -begin - require "rails/cli" -rescue LoadError - railties_path = File.expand_path('../../railties/lib', __FILE__) - $:.unshift(railties_path) - require "rails/cli" +require 'rubygems' + +version = ">= 0" + +if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then + version = $1 + ARGV.shift end + +gem 'railties', version +load Gem.bin_path('railties', 'rails', version) This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying. -- cgit v1.2.3 From 214b0ddee74b6b7af0f3f4cd4e36669895c17bd9 Mon Sep 17 00:00:00 2001 From: Panayotis Matsinopoulos Date: Sat, 24 Mar 2012 23:12:39 +0200 Subject: Testing Template and Layout Example --- guides/source/testing.textile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'guides/source') diff --git a/guides/source/testing.textile b/guides/source/testing.textile index c367f532ae..01b406172f 100644 --- a/guides/source/testing.textile +++ b/guides/source/testing.textile @@ -524,6 +524,31 @@ You also have access to three instance variables in your functional tests: * +@request+ - The request * +@response+ - The response +h4. Testing Template and Layout Example + +If you want to make sure that the response rendered the correct template and layout, you can use the +assert_template+ +method: + + +test "index should render correct template and layout" do + get :index + assert_template :index + assert_template :layout => "layouts/application" +end + + +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, + + +assert_template :layout => "application" + + +will not work. + + h4. A Fuller Functional Test Example Here's another example that uses +flash+, +assert_redirected_to+, and +assert_difference+: -- cgit v1.2.3 From 5b35664481bdc4f8c8970a8aade4b460fae1f065 Mon Sep 17 00:00:00 2001 From: Panayotis Matsinopoulos Date: Sat, 24 Mar 2012 23:16:55 +0200 Subject: Small layout correction --- guides/source/testing.textile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.textile b/guides/source/testing.textile index 01b406172f..d98082ea88 100644 --- a/guides/source/testing.textile +++ b/guides/source/testing.textile @@ -543,12 +543,11 @@ things clearer. On the other hand, you have to include the "layouts" directory n file in this standard layout directory. Hence, -assert_template :layout => "application" + assert_template :layout => "application" will not work. - h4. A Fuller Functional Test Example Here's another example that uses +flash+, +assert_redirected_to+, and +assert_difference+: -- cgit v1.2.3 From c12b88695536418f0db33604590d20ff84323ae3 Mon Sep 17 00:00:00 2001 From: Panayotis Matsinopoulos Date: Sat, 24 Mar 2012 23:33:41 +0200 Subject: Testing layout gotcha when view renders partial --- guides/source/testing.textile | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'guides/source') diff --git a/guides/source/testing.textile b/guides/source/testing.textile index d98082ea88..c1c7b2f341 100644 --- a/guides/source/testing.textile +++ b/guides/source/testing.textile @@ -548,6 +548,22 @@ file in this standard layout directory. Hence, will not work. +Gotcha: Watch out if your view renders any partial + +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: + + +test "new should render correct layout" do + get :new + assert_template :layout => "layouts/application", :partial => "_form" +end + + +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+: -- cgit v1.2.3 From 2314490547e7b864a387d4a71586373036beb35f Mon Sep 17 00:00:00 2001 From: schneems Date: Sat, 24 Mar 2012 17:17:21 -0500 Subject: document `-e` argument for rails console this adds documentation for -e flag which sets the environment of the rails console like the `rails server` command. --- guides/source/command_line.textile | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'guides/source') 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: rails c. +You can specify the environment in which the +console+ command should operate using the +-e+ switch. + + +$ rails console -e staging + + If you wish to test out some code without changing any data, you can do that by invoking +rails console --sandbox+. -- cgit v1.2.3 From 492e91cc3441a1d0fc8e959bf46b374d424b711e Mon Sep 17 00:00:00 2001 From: Dimitri De Frenne Date: Mon, 26 Mar 2012 11:28:12 +0200 Subject: Fixed typo in path --- guides/source/engines.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/engines.textile b/guides/source/engines.textile index 501d48eab8..23b1a2fcb8 100644 --- a/guides/source/engines.textile +++ b/guides/source/engines.textile @@ -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:

Comments

-- cgit v1.2.3 From ddab3df8d15a854e394623b8aee8c43395e77efe Mon Sep 17 00:00:00 2001 From: Dimitri De Frenne Date: Mon, 26 Mar 2012 11:28:55 +0200 Subject: Made it a bit more clear where to run rails/server --- guides/source/engines.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guides/source') diff --git a/guides/source/engines.textile b/guides/source/engines.textile index 23b1a2fcb8..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" %>
-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)! -- cgit v1.2.3 From 286259f2aaf2fb83a886061a4a70e3c9cb22fd42 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 27 Mar 2012 21:08:08 +0530 Subject: Revert "[ci skip] updated bin/rails code in Rails Initialization Process guide" This reverts commit 7feec40b89ada892ca6f107ada27ceedde505d83. Reason: The guide had the contents of railties/bin/rails and I don't see any reason to change it. --- guides/source/initialization.textile | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'guides/source') diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile index b5e427b35c..69e5c1edcc 100644 --- a/guides/source/initialization.textile +++ b/guides/source/initialization.textile @@ -21,24 +21,14 @@ The actual +rails+ command is kept in _bin/rails_: #!/usr/bin/env ruby -# -# This file was generated by RubyGems. -# -# The application 'railties' is installed as part of a gem, and -# this file is here to facilitate running it. -# -require 'rubygems' - -version = ">= 0" - -if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then - version = $1 - ARGV.shift +begin + require "rails/cli" +rescue LoadError + railties_path = File.expand_path('../../railties/lib', __FILE__) + $:.unshift(railties_path) + require "rails/cli" end - -gem 'railties', version -load Gem.bin_path('railties', 'rails', version) This file will attempt to load +rails/cli+. If it cannot find it then +railties/lib+ is added to the load path (+$:+) before retrying. -- cgit v1.2.3 From ae040ed6d8c48bf0cd6d5d6b434d60c9c8c27f81 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Tue, 27 Mar 2012 21:24:21 +0530 Subject: minor edits in testing guide [ci skip] --- guides/source/testing.textile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'guides/source') diff --git a/guides/source/testing.textile b/guides/source/testing.textile index c1c7b2f341..60b0aa89b9 100644 --- a/guides/source/testing.textile +++ b/guides/source/testing.textile @@ -524,7 +524,7 @@ You also have access to three instance variables in your functional tests: * +@request+ - The request * +@response+ - The response -h4. Testing Template and Layout Example +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: @@ -543,13 +543,11 @@ things clearer. On the other hand, you have to include the "layouts" directory n file in this standard layout directory. Hence, - assert_template :layout => "application" +assert_template :layout => "application" will not work. -Gotcha: Watch out if your view renders any partial - 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. -- cgit v1.2.3