@@ -299,7 +299,7 @@ Now to get this test to pass we can add a model level validation for the _title_
...
@@ -299,7 +299,7 @@ Now to get this test to pass we can add a model level validation for the _title_
```ruby
```ruby
classPost<ActiveRecord::Base
classPost<ActiveRecord::Base
validates:title,:presence=>true
validates:title,presence:true
end
end
```
```
...
@@ -397,7 +397,7 @@ Rails adds some custom assertions of its own to the `test/unit` framework:
...
@@ -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_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_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_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.|
| `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.
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
...
@@ -457,7 +457,7 @@ Let us modify `test_should_create_post` test in `posts_controller_test.rb` so th
```ruby
```ruby
test"should create post"do
test"should create post"do
assert_difference('Post.count')do
assert_difference('Post.count')do
post:create,:post=>{:title=>'Some title'}
post:create,post: {title:'Some title'}
end
end
assert_redirected_topost_path(assigns(:post))
assert_redirected_topost_path(assigns(:post))
...
@@ -518,7 +518,7 @@ method:
...
@@ -518,7 +518,7 @@ method:
test"index should render correct template and layout"do
test"index should render correct template and layout"do
get:index
get:index
assert_template:index
assert_template:index
assert_template:layout=>"layouts/application"
assert_templatelayout:"layouts/application"
end
end
```
```
...
@@ -528,7 +528,7 @@ things clearer. On the other hand, you have to include the "layouts" directory n
...
@@ -528,7 +528,7 @@ things clearer. On the other hand, you have to include the "layouts" directory n