Skip to content

Commit 2bfdc57

Browse files
committed
Finish proofreading alex
1 parent d1ba508 commit 2bfdc57

11 files changed

+115
-153
lines changed

rails6/en/chapter00-before.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMP
3131
****
3232

3333
"API on Rails 6" by https://github.com/madeindjs/api_on_rails[Alexandre Rousseau] is shared according to http://creativecommons.org/licenses/by-sa/4.0/[Creative Commons Attribution - Attribution-ShareAlike 4.0 International]. Built upon this book http://apionrails.icalialabs.com/book/.
34+
35+
Book's cover picture use a beautiful photo shot by https://unsplash.com/@siloine?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText[Yoann Siloine] who published it on https://unsplash.com[Unsplash].

rails6/en/chapter02-api.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,18 @@ It is important you feel comfortable with this ones and understand them.
314314
// end
315315
// ----
316316

317-
// If everything went well it is now time to add a `spec` directory under `lib` and add the `api_constraints_spec.rb`:
317+
// If everything went well it is now time to add a `spec` directory under `lib` and add the `api_constraints_test.rb`:
318318

319319
// [source,bash]
320320
// ----
321321
// $ mkdir lib/spec
322-
// $ touch lib/spec/api_constraints_spec.rb
322+
// $ touch lib/spec/api_constraints_test.rb
323323
// ----
324324

325325
//Then we add a bunch of specs describing our class:
326326

327327
// [source,ruby]
328-
// .lib/spec/api_constraints_spec.rb
328+
// .lib/spec/api_constraints_test.rb
329329
// ----
330330
// require 'spec_helper'
331331
// require './lib/api_constraints'
@@ -390,7 +390,7 @@ It is important you feel comfortable with this ones and understand them.
390390

391391
// [source,bash]
392392
// ----
393-
// $ bundle exec rspec lib/spec/api_constraints_spec.rb
393+
// $ bundle exec rspec lib/spec/api_constraints_test.rb
394394
// ..
395395

396396
// Finished in 0.00294 seconds (files took 0.06292 seconds to load)

rails6/en/chapter04-athentification.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ The solution is quite simple. We will add a `before_action` which will call the
524524
Here is the implementation:
525525

526526
[source,ruby]
527-
.spec/controllers/api/v1/users_controller_spec.rb
527+
.spec/controllers/api/v1/users_controller_test.rb
528528
----
529529
class Api::V1::UsersController < ApplicationController
530530
before_action :set_user, only: %i[show update destroy]

rails6/en/chapter06-improve-json.adoc

Lines changed: 44 additions & 54 deletions
Large diffs are not rendered by default.

rails6/en/chapter07-placing-orders.adoc

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
[#chapter07-placing-orders]
22
= Placing Orders
33

4-
In previous chapter we handle associations between product and user models, and how to serialize them in order to scale fast and easy. Now it is time to start placing orders which is going to be a more complex situation. We will handle associations between three models and we have to be smart enough to handle the JSON output we are delivering.
4+
In previous chapter we handle associations between products and users and how serialize them in order to scale fast and easy. Now it is time to start placing orders which is going to be a more complex situation. We will handle associations between thesesthree models. We have to be smart enough to handle the JSON output we are delivering.
55

66
In this chapter we will make several things which I list below:
77

88
* Create an `Order` model with its corresponding specs
99
* Handle JSON output association between the order user and product models
1010
* Send a confirmation email with the order summary
1111
12-
So now everything is clear, we can get our hands dirty. You can clone the project up to this point with:
12+
So now everything is clear we can get our hands dirty. You can clone the project up to this point with:
1313

1414
[source,bash]
1515
----
1616
$ git checkout tags/checkpoint_chapter07
1717
----
18+
1819
Let’s create a branch to start working:
1920

2021
[source,bash]
@@ -24,23 +25,23 @@ $ git checkout -b chapter07
2425

2526
== Modeling order
2627

27-
If you remember associations model, the `Order` model is associated with users and products at the same time. It is actually really simply to achieve this in Rails. The tricky part is when comes to serializing this objects. I'll talk more about this in a next section.
28+
If you remember associations model, `Order` model is associated with users and products at the same time. It is actually really simply to achieve this in Rails. The tricky part is when comes to serializing this objects. I'll talk more about this in a next section.
2829

29-
Let’s start by creating the order model, with a special form:
30+
Let’s start by creating the order model with a special form:
3031

3132
[source,bash]
3233
----
3334
$ rails generate model order user:belongs_to total:decimal
3435
----
3536

36-
The command above will generate the order model, but I’m taking advantage of the `references` method to create the corresponding foreign key for the order to belong to a user, it also adds the `belongs_to` directive into the order model. Let’s migrate the database.
37+
The command above will generate the order model but I’m taking advantage of the `references` method to create the corresponding foreign key for the order to belong to a user. It also adds the `belongs_to` directive into the order model. Let’s migrate the database.
3738

3839
[source,bash]
3940
----
4041
$ rake db:migrate
4142
----
4243

43-
Now it is time to drop some tests into the `order_test.rb` file:
44+
Now it is time to write some tests into the `order_test.rb` file:
4445

4546
[source,ruby]
4647
.test/models/order_test.rb
@@ -79,13 +80,13 @@ class User < ApplicationRecord
7980
# ...
8081
end
8182
----
83+
8284
Tests should pass:
8385

8486
[source,bash]
8587
----
8688
$ rake test
8789
..................................
88-
34 runs, 50 assertions, 0 failures, 0 errors, 0 skips
8990
----
9091

9192
And _commit_ all this:
@@ -98,7 +99,7 @@ $ git add . && git commit -m "Generate orders"
9899

99100
=== Orders and Products
100101

101-
We need to setup the association between the `order` and the `product` and this is build with a `has-many-to-many` association. As many products will be placed on many orders and the orders will have multiple products. So in this case we need a model in the middle which will join these two other objects and map the appropriate association.
102+
We need to setup the association between the `order` and the `product` and this is build with a *has-many-to-many* association. As many products will be placed on many orders and the orders will have multiple products. So in this case we need a model in the middle which will join these two other objects and map the appropriate association.
102103

103104
Let’s generate this model:
104105

@@ -107,14 +108,14 @@ Let’s generate this model:
107108
$ rails generate model placement order:belongs_to product:belongs_to
108109
----
109110

110-
Let’s migrate the database:
111+
Let’s run migration on database:
111112

112113
[source,bash]
113114
----
114115
$ rake db:migrate
115116
----
116117

117-
The implementation is like so:
118+
Implementation is like so:
118119

119120
[source,ruby]
120121
.app/models/product.rb
@@ -138,7 +139,7 @@ end
138139
----
139140

140141

141-
If you have been following the tutorial so far the implementation is already there because of the `references` type we pass on the model command generator. We should add the inverse option to the `placement` model for each `belongs_to` call. This gives a little boost when referencing the parent object.
142+
If you have been following the tutorial so far the implementation is already there because of the `references` type we pass on the model command generator. We should add `inverse_of` option to the `placement` model for each `belongs_to` call. This gives a little boost when referencing the parent object.
142143

143144
[source,ruby]
144145
.app/models/placement.rb
@@ -155,7 +156,6 @@ Let’s run the _models_ spec and make sure everything is green:
155156
----
156157
$ rake test
157158
..................................
158-
34 runs, 50 assertions, 0 failures, 0 errors, 0 skips
159159
----
160160

161161
Now that everything is nice and green let’s commit the changes and continue.
@@ -185,7 +185,7 @@ $ rails generate controller api::v1::orders
185185

186186
Up to this point and before start typing some code we have to ask ourselves:
187187

188-
> Should I leave my order endpoints nested into the `UsersController`, or should I isolate them?
188+
> Should I leave my order endpoints nested into the `UsersController` or should I isolate them?
189189

190190
The answer is really simple: it depends on the amount of information you want to expose to the developer.
191191

@@ -217,7 +217,7 @@ class Api::V1::OrdersControllerTest < ActionDispatch::IntegrationTest
217217
end
218218
----
219219

220-
If we run the test suite now, as you may expect, both tests will fail, because they have not even set the correct routes, nor the action. So let’s start by adding the routes:
220+
If we run the test suite now both tests should fail as you may expect. This is because they have not even set the correct routes nor actions. So let’s start by adding the routes:
221221

222222
[source,ruby]
223223
.config/routes.rb
@@ -232,7 +232,6 @@ Rails.application.routes.draw do
232232
end
233233
----
234234

235-
236235
Now it is time for the orders controller implementation:
237236

238237
[source,bash]
@@ -266,8 +265,6 @@ class Api::V1::OrdersController < ApplicationController
266265
end
267266
----
268267

269-
270-
271268
And now all of our tests should pass:
272269

273270
[source,bash]
@@ -286,12 +283,12 @@ $ git add . && git commit -m "Adds the show action for order"
286283

287284
=== Render a single order
288285

289-
As you can already imagine, this route is very easy. We only have to set up a few configurations (routes, controller action) and this section will be over. We will also include products related to this order in the output JSON.
286+
As you can already imagine this route is very easy. We only have to set up a few configurations (routes, controller action) and this section will be over. We will also include products related to this order in the output JSON.
290287

291288
Let's start by adding some tests:
292289

293290
[source,ruby]
294-
.spec/controllers/api/v1/orders_controller_spec.rb
291+
.spec/controllers/api/v1/orders_controller_test.rb
295292
----
296293
# ...
297294
class Api::V1::OrdersControllerTest < ActionDispatch::IntegrationTest
@@ -310,8 +307,6 @@ As you can see, the second part of the test verifies the product is included in
310307

311308
Let's add the implementation to run our tests. On the `routes.rb` file add the `show` action to the command routes:
312309

313-
314-
315310
[source,ruby]
316311
.config/routes.rb
317312
----
@@ -323,7 +318,7 @@ Rails.application.routes.draw do
323318
end
324319
----
325320

326-
And the implementation should look like this:
321+
And implementation should look like this:
327322

328323
[source,ruby]
329324
.app/controllers/api/v1/orders_controller.rb
@@ -344,7 +339,6 @@ class Api::V1::OrdersController < ApplicationController
344339
end
345340
----
346341

347-
348342
Our tests should be all green:
349343

350344
[source,bash]
@@ -371,9 +365,15 @@ Before launching this feature, let's take the time to think about the implicatio
371365
* decrease in product inventory
372366
* add some validation for order placement to ensure that there are enough products at the time the order is placed
373367

374-
It seems like there's still a lot to do, but believe me: you're closer than you think and it's not as hard as it looks. For now, let's keep it simple and assume that we still have enough products to place any number of orders. We're just concerned about the server's response at the moment.
368+
It seems like there's still a lot to do but believe me: you're closer than you think and it's not as hard as it looks. For now let's keep it simple and assume that we still have enough products to place any number of orders. We're just concerned about the server's response at the moment.
369+
370+
If you remember order model we need three things:
375371

376-
If you remember order model, we need three things: a total for the order, user who places the order and products for the order. Based on this information, we can start adding some tests:
372+
* a total for the order
373+
* user who places the order
374+
* products for the order
375+
376+
Based on this information we can start adding some tests:
377377

378378
[source,ruby]
379379
.test/controllers/api/v1/orders_controller_test.rb
@@ -409,7 +409,7 @@ class Api::V1::OrdersControllerTest < ActionDispatch::IntegrationTest
409409
end
410410
----
411411

412-
As you can see we are creating a `order_params` variable with the order data. Can you see the problem here? If not, I’ll explain it later. Let’s just add the necessary code to make this test pass.
412+
As you can see we are creating a `order_params` variable with the order data. Can you see the problem here? If not I’ll explain it later. Let’s just add the necessary code to make this test pass.
413413

414414
First we need to add the action to the resources on the routes file:
415415

@@ -503,19 +503,6 @@ class Order < ApplicationRecord
503503
end
504504
----
505505

506-
Just before you run your tests, we need to update the `order` factory, just to make it more useful:
507-
508-
[source,ruby]
509-
.spec/factories/orders.rb
510-
----
511-
FactoryBot.define do
512-
factory :order do
513-
user { nil }
514-
total { 0.0 }
515-
end
516-
end
517-
----
518-
519506
We can now hook the `set_total!` method to a `before_validation` callback to make sure it has the correct total before is validated.
520507

521508
[source,ruby]
@@ -527,7 +514,7 @@ class Order < ApplicationRecord
527514
end
528515
----
529516

530-
At this point, we are making sure the total is always present and bigger or equal to zero, meaning we can remove those validations and remove the specs. I’ll wait. Our tests should be passing by now:
517+
At this point we are making sure the total is always present and bigger or equal to zero. This means we can remove those validations and remove the specs. I’ll wait. Our tests should be passing by now:
531518

532519
[source,bash]
533520
----
@@ -593,7 +580,7 @@ class OrderMailerTest < ActionMailer::TestCase
593580
end
594581
----
595582

596-
I simply copied/pasted the tests from the documentation and adapted them to our needs. We must now ensure that these tests pass.
583+
I simply copied/pasted tests from the documentation and adapted them to our needs. We must now ensure that these tests pass.
597584

598585
First, we add the method `OrderMailer#send_confirmation`:
599586

@@ -610,7 +597,7 @@ class OrderMailer < ApplicationMailer
610597
end
611598
----
612599

613-
After adding this code, we must now add the corresponding views. It is a good practice including a text version in addition to the HTML version.
600+
After adding this code we must add corresponding views. It is a good practice to include a text version in addition to the HTML version.
614601

615602

616603
[source,erb]
@@ -691,9 +678,9 @@ $ git merge chapter07
691678

692679
== Conclusion
693680

694-
That's it! You did it! You can applaud yourself. I know it's been a long time, but it's almost over, believe me.
681+
That's it! You did it! You can applaud yourself. I know it's been a long time but believe me it's almost over.
695682

696-
In next chapters, we will continue working on the order template to add validations when placing an order. Some scenarios are:
683+
In next chapters we will continue working on the order template to add validations when placing an order. Some scenarios are:
697684

698685
* What happens when products are not available?
699686
* Decrease the quantity of the product in progress when placing an order

0 commit comments

Comments
 (0)