Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lifo/docrails
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaydev committed Mar 27, 2012
2 parents 888fcca + ae040ed commit b42fbd3
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 6 deletions.
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/caching/actions.rb
Expand Up @@ -40,7 +40,7 @@ module Caching
#
# You can modify the default action cache path by passing a
# <tt>:cache_path</tt> option. This will be passed directly to
# <tt>ActionCachePath.path_for</tt>. This is handy for actions with
# <tt>ActionCachePath.new</tt>. This is handy for actions with
# multiple possible routes that should be cached differently. If a
# block is given, it is called with the current controller instance.
#
Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/action_controller/caching/pages.rb
Expand Up @@ -99,7 +99,7 @@ def cache_page(content, path, extension = nil, gzip = Zlib::BEST_COMPRESSION)
# caches_page :index
#
# # cache the index action except for JSON requests
# caches_page :index, :if => Proc.new { |c| !c.request.format.json? }
# caches_page :index, :if => Proc.new { !request.format.json? }
#
# # don't gzip images
# caches_page :image, :gzip => false
Expand Down
19 changes: 19 additions & 0 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -1135,6 +1135,25 @@ def resource(*resources, &block)
# comment PATCH/PUT /sekret/comments/:id(.:format)
# comment DELETE /sekret/comments/:id(.:format)
#
# [:shallow_prefix]
# Prefixes nested shallow route names with specified prefix.
#
# scope :shallow_prefix => "sekret" do
# resources :posts do
# resources :comments, :shallow => true
# end
# end
#
# The +comments+ resource here will have the following routes generated for it:
#
# post_comments GET /posts/:post_id/comments(.:format)
# post_comments POST /posts/:post_id/comments(.:format)
# new_post_comment GET /posts/:post_id/comments/new(.:format)
# edit_sekret_comment GET /comments/:id/edit(.:format)
# sekret_comment GET /comments/:id(.:format)
# sekret_comment PATCH/PUT /comments/:id(.:format)
# sekret_comment DELETE /comments/:id(.:format)
#
# === Examples
#
# # routes call <tt>Admin::PostsController</tt>
Expand Down
Expand Up @@ -174,7 +174,7 @@ def create_table(table_name, options = {})
end

# Creates a new join table with the name created using the lexical order of the first two
# arguments. These arguments can be be a String or a Symbol.
# arguments. These arguments can be a String or a Symbol.
#
# # Creates a table called 'assemblies_parts' with no id.
# create_join_table(:assemblies, :parts)
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/relation/calculations.rb
Expand Up @@ -174,7 +174,7 @@ def calculate(operation, column_name, options = {})
#
# Person.pluck(:id) # SELECT people.id FROM people
# Person.uniq.pluck(:role) # SELECT DISTINCT role FROM people
# Person.where(:confirmed => true).limit(5).pluck(:id)
# Person.where(:age => 21).limit(5).pluck(:id) # SELECT people.id FROM people WHERE people.age = 21 LIMIT 5
#
def pluck(column_name)
key = column_name.to_s.split('.', 2).last
Expand Down
6 changes: 6 additions & 0 deletions guides/source/command_line.textile
Expand Up @@ -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>
Expand Down
4 changes: 2 additions & 2 deletions guides/source/engines.textile
Expand Up @@ -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)!

Expand Down Expand Up @@ -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>
Expand Down
38 changes: 38 additions & 0 deletions guides/source/testing.textile
Expand Up @@ -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+:
Expand Down

0 comments on commit b42fbd3

Please sign in to comment.