Skip to content

Commit 622647b

Browse files
authored
Chapter 03 corrigé Lorène
1 parent b79423e commit 622647b

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

rails6/en/chapter03-presenting-users.adoc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ invoke active_record
5151
create test/fixtures/users.yml
5252
----
5353

54-
NOTE: In the MVC design patern, the model is the element that contains the data as well as the logic related to the data: validation, reading and recording. So first we will create this part.
54+
NOTE: In the MVC design patern, the model is the element containing the data as well as the logic related to the data: validation, reading and recording. So first we will create this part.
5555

5656
This command generates a lot of files! Don't worry, we'll review them one by one.
5757

@@ -74,7 +74,7 @@ end
7474

7575
NOTE: inserted date at the beginning of the migration file name should be different for you since it corresponds to the migration creation date.
7676

77-
We will modify a small this migration in order to add some database validations. With Rails it is common practice to make these verifications directly in the Ruby model but it is good practice to do so also in the database schema.
77+
We will modify a little bit this migration in order to add some database validations. With Rails it is common practice to make these verifications directly in the Ruby model but it is good practice to do so also in the database schema.
7878

7979
We will therefore add two additional constraints:
8080

@@ -111,7 +111,7 @@ NOTE: This command will convert our migration into a SQL query that will update
111111

112112
==== Model
113113

114-
We need to first add the `devise` gem into the `Gemfile`
114+
First we need to add the `devise` gem into the `Gemfile`
115115

116116
[source,ruby]
117117
.Gemfile
@@ -164,7 +164,7 @@ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
164164
gem 'devise'
165165
----
166166

167-
Then run the `bundle install` command to install it. Once the bundle command finishes, we need to run the devise install generator:
167+
Then run the `bundle install` command to install it. Once the bundle command finishes, we need runing the devise install generator:
168168

169169
[source,bash]
170170
----
@@ -262,7 +262,7 @@ RSpec.describe User, type: :model do
262262
end
263263
----
264264

265-
Because we previously prepare the test database, with `rake db:test:prepare`, we just simply run the tests:
265+
Because we previously prepare the test database, with `rake db:test:prepare`, we just simply run tests:
266266

267267
[source,bash]
268268
----
@@ -299,20 +299,20 @@ This command will create a `users_controller_spec.rb`. Before we get into that,
299299

300300
.Most common http codes
301301
****
302-
The first digit of the status code specifies one of five classes of response; the bare minimum for an HTTP client is that it recognize these five classes. A common list of used http codes is presented below:
302+
The first digit of the status code specifies one of five classes of responss. The bare minimum for an HTTP client is that it recognize these five classes. A common list of used http codes is presented below:
303303
304304
* `200`: Standard response for successful HTTP requests (It is commonly on GET requests)
305305
* `201`: The request has been fulfilled and resulted in a new resource being created (After POST requests)
306306
* `204`: The server successfully processed the request, but is not returning any content (It is usually a successful DELETE request)
307307
* `400`: The request cannot be fulfilled due to bad syntax.
308-
* `401`: Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided
308+
* `401`: Similar to 403 Forbidden, but specifically used when authentication is required and has failed or has not yet been provided
309309
* `404`: The requested resource could not be found but may be available again in the future (Usually GET requests)
310310
* `500`: A generic error message, given when an unexpected condition was encountered and no more specific message is suitable.
311311
312312
For a full list of HTTP method check out the article on http://en.wikipedia.org/wiki/List_of_HTTP_status_codes[Wikipedia] talking about it
313313
****
314314

315-
To keep our code nicely organized, we will create some directories under the controller specs directory in order to be consistent with our current setup. There is also another set up out there which uses instead of the `controllers` directory a `request` or `integration` directory, I this case I like to be consistent with the `app/controllers` directory.
315+
To keep our code nicely organized, we will create some directories under the controller specs directory in order to be consistent with our current setup. There is also another set up out there which uses instead of the `controllers` directory a `request` or `integration` directory, In this case I like being consistent with the `app/controllers` directory.
316316

317317
[source,bash]
318318
----
@@ -355,7 +355,7 @@ RSpec.describe Api::V1::UsersController, type: :controller do
355355
end
356356
----
357357

358-
So far, the tests look good, we just need to add the implementation. It is extremely simple:
358+
So far, tests look good, we just need to add the implementation. It is extremely simple:
359359

360360
[source,ruby]
361361
.app/controllers/api/v1/users_controller.rb
@@ -444,7 +444,7 @@ $ git commit -m "Adds show action the users controller"
444444

445445
=== Testing endpoints with CURL
446446

447-
So we finally have an endpoint to test. There are plenty of options to start playing with. The first that come to my mind is using http://curl.haxx.se/[cURL] because is built-in on almost any Linux distribution and of course on your Mac OSX. So let’s try it out:
447+
So we finally have an endpoint to test. There are plenty of options to start playing with. The first coming to my mind is using http://curl.haxx.se/[cURL] because is built-in on almost any Linux distribution and of course on your Mac OSX. So let’s try it out:
448448

449449
NOTE: Remember our base URI is `api.market_place_api.dev`.
450450

@@ -453,7 +453,7 @@ NOTE: Remember our base URI is `api.market_place_api.dev`.
453453
$ curl -H 'Accept: application/vnd.marketplace.v1' http://api.market_place_api.dev/users/1
454454
----
455455

456-
This will throw us an error. Well you might expect that already because we don’t have a user with `id` equals to 1. Let’s create it first through the terminal:
456+
This will throw us an error. Well you might expect that because we don’t have an user with `id` equals to 1. Let’s create it first through the terminal:
457457

458458
[source,bash]
459459
----
@@ -493,9 +493,9 @@ $ git commit -m "Updates application controller to prevent CSRF exception from b
493493

494494
=== Creating users
495495

496-
Now that we have a better understanding on how to build endpoints and how they work, it’s time to add more abilities to the API. One of the most important is letting the users actually create a profile on our application. As usual we will write tests before implementing our code extending our testing suite.
496+
Now that we have a better understanding on how to build endpoints and how they work, it’s time to add more abilities to the API. One of the most important is letting the users create a profile on our application. As usual we will write tests before implementing our code extending our testing suite.
497497

498-
Creating records in Rails as you may know is really easy, the trick when building an api is which is the best fit for the HTTP codes to send on the response, as well as the actual `json response`. If you don’t totally get this it will probably be more easy on the code:
498+
Creating records in Rails as you may know is really easy, the trick when building an api is the best fit for the HTTP codes to send on the response, as well as the actual `json response`. If you don’t totally get this it will probably be more easy on the code:
499499

500500
*Make sure your repository is clean and that you don’t have any commits left, if so place them so we can start fresh.*
501501

@@ -548,7 +548,7 @@ end
548548

549549
There is a lot of code up there but don’t worry I’ll walk you through it:
550550

551-
* We need to validate to states on which the record can be, valid or invalid. In this case we are using the `context` clause to achieve this scenarios.
551+
* We need to validate states on which the record can be, valid or invalid. In this case we are using the `context` clause to achieve this scenarios.
552552
* In case everything goes smooth, we should return a `201` HTTP code which means a record just got `created`, as well as the JSON representation of that object.
553553
* In case of any errors, we have to return a `422` HTTP code which stands for `Unprocessable Entity` meaning the server could save the record. We also return a JSON representation of why the resource could not be saved.
554554

@@ -620,7 +620,7 @@ $ git commit -m "Adds the user create endpoint"
620620
The pattern for *updating* users is very similar as *creating* new ones. If you are an experienced Rails developer you may already know the differences between these two actions:
621621

622622
* The `update` action responds to a PUT/PATCH request.
623-
* Only the `current_user` should be able to update their information, meaning we have to enforce a user to be authenticated. We will cover that on next chapters
623+
* Only the `current_user` should be able to update their information, meaning we have to enforce an user to be authenticated. We will cover that on next chapters
624624

625625
As usual we start by writing our tests:
626626

@@ -673,9 +673,9 @@ RSpec.describe Api::V1::UsersController, type: :controller do
673673
end
674674
----
675675

676-
Getting the tests to pass requires us to build the `update` action on the `users_controller.rb` file as well as adding it to the `routes.rb`. As you can see we have to much code duplicated, we’ll refactor our tests in next chapter.
676+
Getting the tests pass requires us to build the `update` action on the `users_controller.rb` file as well as adding it to the `routes.rb`. As you can see we have too much code duplicated, we’ll refactor our tests in next chapter.
677677

678-
First we add the action the `routes.rb` file
678+
First we add the action in the `routes.rb` file
679679

680680
[source,ruby]
681681
.config/routes.rb

0 commit comments

Comments
 (0)