提交 3bf2a4c0 编写于 作者: V Vijay Dev

Merge branch 'master' of github.com:rails/docrails

Conflicts:
	guides/source/testing.md
......@@ -182,7 +182,8 @@ def response_body=(body)
body = [body] unless body.nil? || body.respond_to?(:each)
super
end
# Tests if render or redirect has already happened.
def performed?
response_body || (response && response.committed?)
end
......
......@@ -267,23 +267,6 @@ This is equivalent to writing:
Client.where(first_name: 'does not exist').take!
```
#### `last!`
`Model.last!` finds the last record ordered by the primary key. For example:
```ruby
client = Client.last!
# => #<Client id: 221, first_name: "Russel">
```
The SQL equivalent of the above is:
```sql
SELECT * FROM clients ORDER BY clients.id DESC LIMIT 1
```
`Model.last!` raises `ActiveRecord::RecordNotFound` if no matching record is found.
### Retrieving Multiple Objects in Batches
We often need to iterate over a large set of records, as when we send a newsletter to a large set of users, or when we export data.
......@@ -293,7 +276,7 @@ This may appear straightforward:
```ruby
# This is very inefficient when the users table has thousands of rows.
User.all.each do |user|
NewsLetter.weekly_deliver(user)
NewsMailer.weekly(user).deliver
end
```
......@@ -333,7 +316,7 @@ The `:batch_size` option allows you to specify the number of records to be retri
```ruby
User.find_each(batch_size: 5000) do |user|
NewsLetter.weekly_deliver(user)
NewsMailer.weekly(user).deliver
end
```
......@@ -345,7 +328,7 @@ For example, to send newsletters only to users with the primary key starting fro
```ruby
User.find_each(start: 2000, batch_size: 5000) do |user|
NewsLetter.weekly_deliver(user)
NewsMailer.weekly(user).deliver
end
```
......
......@@ -909,7 +909,7 @@ And then finally, add the view for this action, located at
</table>
```
Now if you go to `http://localhost:3000/articles` you will see a list of all the
Now if you go to <http://localhost:3000/articles> you will see a list of all the
articles that you have created.
### Adding links
......@@ -1105,7 +1105,7 @@ standout.
Now you'll get a nice error message when saving an article without title when
you attempt to do just that on the new article form
[(http://localhost:3000/articles/new)](http://localhost:3000/articles/new).
<http://localhost:3000/articles/new>:
![Form With Errors](images/getting_started/form_with_errors.png)
......
......@@ -364,13 +364,8 @@ Ideally, you would like to include a test for everything which could possibly br
By now you've caught a glimpse of some of the assertions that are available. Assertions are the worker bees of testing. They are the ones that actually perform the checks to ensure that things are going as planned.
There are a bunch of different types of assertions you can use. Here's an
extract of the
[assertions](http://docs.seattlerb.org/minitest/Minitest/Assertions.html) you
can use with [minitest](https://github.com/seattlerb/minitest), the default
testing library used by Rails. The `[msg]` parameter is an optional string
message you can specify to make your test failure messages clearer. It's not
required.
There are a bunch of different types of assertions you can use.
Here's an extract of the assertions you can use with [`Minitest`](https://github.com/seattlerb/minitest), the default testing library used by Rails. The `[msg]` parameter is an optional string message you can specify to make your test failure messages clearer. It's not required.
| Assertion | Purpose |
| ---------------------------------------------------------------- | ------- |
......@@ -406,6 +401,8 @@ required.
| `assert_send( array, [msg] )` | Ensures that executing the method listed in `array[1]` on the object in `array[0]` with the parameters of `array[2 and up]` is true. This one is weird eh?|
| `flunk( [msg] )` | Ensures failure. This is useful to explicitly mark a test that isn't finished yet.|
The above are subset of assertions that minitest supports. For an exhaustive & more up-to-date list, please check [Minitest API documentation](http://docs.seattlerb.org/minitest/), specifically [`Minitest::Assertions`](http://docs.seattlerb.org/minitest/Minitest/Assertions.html)
Because of the modular nature of the testing framework, it is possible to create your own assertions. In fact, that's exactly what Rails does. It includes some specialized assertions to make your life easier.
NOTE: Creating your own assertions is an advanced topic that we won't cover in this tutorial.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册