Switch to 1.9 hash syntax (guides)
This commit is contained in:
parent
8be3a1a9a4
commit
e258225c8a
@ -299,7 +299,7 @@ Now to get this test to pass we can add a model level validation for the _title_
|
||||
|
||||
```ruby
|
||||
class Post < ActiveRecord::Base
|
||||
validates :title, :presence => true
|
||||
validates :title, presence: true
|
||||
end
|
||||
```
|
||||
|
||||
@ -397,7 +397,7 @@ Rails adds some custom assertions of its own to the `test/unit` framework:
|
||||
| `assert_recognizes(expected_options, path, extras={}, message=nil)` | Asserts that the routing of the given path was handled correctly and that the parsed options (given in the expected_options hash) match path. Basically, it asserts that Rails recognizes the route given by expected_options.|
|
||||
| `assert_generates(expected_path, options, defaults={}, extras = {}, message=nil)` | Asserts that the provided options can be used to generate the provided path. This is the inverse of assert_recognizes. The extras parameter is used to tell the request the names and values of additional request parameters that would be in a query string. The message parameter allows you to specify a custom error message for assertion failures.|
|
||||
| `assert_response(type, message = nil)` | Asserts that the response comes with a specific status code. You can specify `:success` to indicate 200-299, `:redirect` to indicate 300-399, `:missing` to indicate 404, or `:error` to match the 500-599 range|
|
||||
| `assert_redirected_to(options = {}, message=nil)` | Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that `assert_redirected_to(:controller => "weblog")` will also match the redirection of `redirect_to(:controller => "weblog", :action => "show")` and so on.|
|
||||
| `assert_redirected_to(options = {}, message=nil)` | Assert that the redirection options passed in match those of the redirect called in the latest action. This match can be partial, such that `assert_redirected_to(controller: "weblog")` will also match the redirection of `redirect_to(controller: "weblog", action: "show")` and so on.|
|
||||
| `assert_template(expected = nil, message=nil)` | Asserts that the request was rendered with the appropriate template file.|
|
||||
|
||||
You'll see the usage of some of these assertions in the next chapter.
|
||||
@ -457,7 +457,7 @@ Let us modify `test_should_create_post` test in `posts_controller_test.rb` so th
|
||||
```ruby
|
||||
test "should create post" do
|
||||
assert_difference('Post.count') do
|
||||
post :create, :post => { :title => 'Some title'}
|
||||
post :create, post: {title: 'Some title'}
|
||||
end
|
||||
|
||||
assert_redirected_to post_path(assigns(:post))
|
||||
@ -518,7 +518,7 @@ method:
|
||||
test "index should render correct template and layout" do
|
||||
get :index
|
||||
assert_template :index
|
||||
assert_template :layout => "layouts/application"
|
||||
assert_template layout: "layouts/application"
|
||||
end
|
||||
```
|
||||
|
||||
@ -528,7 +528,7 @@ things clearer. On the other hand, you have to include the "layouts" directory n
|
||||
file in this standard layout directory. Hence,
|
||||
|
||||
```ruby
|
||||
assert_template :layout => "application"
|
||||
assert_template layout: "application"
|
||||
```
|
||||
|
||||
will not work.
|
||||
@ -541,7 +541,7 @@ Hence:
|
||||
```ruby
|
||||
test "new should render correct layout" do
|
||||
get :new
|
||||
assert_template :layout => "layouts/application", :partial => "_form"
|
||||
assert_template layout: "layouts/application", partial: "_form"
|
||||
end
|
||||
```
|
||||
|
||||
@ -554,7 +554,7 @@ Here's another example that uses `flash`, `assert_redirected_to`, and `assert_di
|
||||
```ruby
|
||||
test "should create post" do
|
||||
assert_difference('Post.count') do
|
||||
post :create, :post => { :title => 'Hi', :body => 'This is my first post.'}
|
||||
post :create, post: {title: 'Hi', body: 'This is my first post.'}
|
||||
end
|
||||
assert_redirected_to post_path(assigns(:post))
|
||||
assert_equal 'Post was successfully created.', flash[:notice]
|
||||
@ -686,7 +686,7 @@ class UserFlowsTest < ActionDispatch::IntegrationTest
|
||||
get "/login"
|
||||
assert_response :success
|
||||
|
||||
post_via_redirect "/login", :username => users(:avs).username, :password => users(:avs).password
|
||||
post_via_redirect "/login", username: users(:avs).username, password: users(:avs).password
|
||||
assert_equal '/welcome', path
|
||||
assert_equal 'Welcome avs!', flash[:notice]
|
||||
|
||||
@ -742,7 +742,7 @@ class UserFlowsTest < ActionDispatch::IntegrationTest
|
||||
sess.extend(CustomDsl)
|
||||
u = users(user)
|
||||
sess.https!
|
||||
sess.post "/login", :username => u.username, :password => u.password
|
||||
sess.post "/login", username: u.username, password: u.password
|
||||
assert_equal '/welcome', path
|
||||
sess.https!(false)
|
||||
end
|
||||
@ -803,13 +803,13 @@ class PostsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test "should show post" do
|
||||
get :show, :id => @post.id
|
||||
get :show, id: @post.id
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should destroy post" do
|
||||
assert_difference('Post.count', -1) do
|
||||
delete :destroy, :id => @post.id
|
||||
delete :destroy, id: @post.id
|
||||
end
|
||||
|
||||
assert_redirected_to posts_path
|
||||
@ -841,18 +841,18 @@ class PostsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test "should show post" do
|
||||
get :show, :id => @post.id
|
||||
get :show, id: @post.id
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update post" do
|
||||
patch :update, :id => @post.id, :post => { }
|
||||
patch :update, id: @post.id, post: {}
|
||||
assert_redirected_to post_path(assigns(:post))
|
||||
end
|
||||
|
||||
test "should destroy post" do
|
||||
assert_difference('Post.count', -1) do
|
||||
delete :destroy, :id => @post.id
|
||||
delete :destroy, id: @post.id
|
||||
end
|
||||
|
||||
assert_redirected_to posts_path
|
||||
@ -874,7 +874,7 @@ Like everything else in your Rails application, it is recommended that you test
|
||||
|
||||
```ruby
|
||||
test "should route to post" do
|
||||
assert_routing '/posts/1', { :controller => "posts", :action => "show", :id => "1" }
|
||||
assert_routing '/posts/1', {controller: "posts", action: "show", id: "1"}
|
||||
end
|
||||
```
|
||||
|
||||
@ -955,7 +955,7 @@ require 'test_helper'
|
||||
class UserControllerTest < ActionController::TestCase
|
||||
test "invite friend" do
|
||||
assert_difference 'ActionMailer::Base.deliveries.size', +1 do
|
||||
post :invite_friend, :email => 'friend@example.com'
|
||||
post :invite_friend, email: 'friend@example.com'
|
||||
end
|
||||
invite_email = ActionMailer::Base.deliveries.last
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user