Skip to content

Commit d0f6061

Browse files
committed
Merge branch 'master' of github.com:madeindjs/api_on_rails
2 parents 7635dfc + f570eae commit d0f6061

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

rails6/en/chapter05-user-products.adoc

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,7 @@ end
137137

138138
You just have to modify the `User` model and specify the `has_many` relationship with the `depend: :destroy` option. We will see later what this method does in more detail.
139139

140-
.test/models/user_test.rb
141-
[source,ruby]
142-
----
143-
# ...
144-
class User < ApplicationRecord
145-
# ...
146-
has_many :products, dependent: :destroy
147-
end
148-
----
149-
150-
.test/models/user_test.rb
140+
.app/models/user.rb
151141
[source,ruby]
152142
----
153143
# ...
@@ -156,7 +146,7 @@ class User < ApplicationRecord
156146
has_many :products, dependent: :destroy
157147
end
158148
----
159-
149+
<<<
160150
And that's it. Now make a _commit_:
161151

162152
[source,bash]
@@ -177,7 +167,7 @@ Also an important thing about validation is to validate that every product has a
177167
----
178168
# ...
179169
class ProductTest < ActiveSupport::TestCase
180-
test "Should have a positive price" do
170+
test "should have a positive price" do
181171
product = products(:one)
182172
product.price = -1
183173
assert_not product.valid?
@@ -605,7 +595,7 @@ class Api::V1::ProductsControllerTest < ActionDispatch::IntegrationTest
605595
assert_response :no_content
606596
end
607597

608-
test "should forbid destroy user" do
598+
test "should forbid destroy product" do
609599
assert_no_difference('Product.count') do
610600
delete api_v1_user_url(@product), headers: { Authorization: JsonWebToken.encode(user_id: users(:two).id) }, as: :json
611601
end
@@ -759,7 +749,6 @@ $ git commit -am "Create a seed to populate database"
759749
760750
And as we get to the end of our chapter, it's time to apply all our modifications to the master branch by making a _merge_:
761751
762-
Then we create a bunch of product objects with the `FactoryBot` gem:
763752
[source,bash]
764753
----
765754
$ git checkout master
@@ -770,5 +759,5 @@ $ git merge chapter05
770759
771760
I hope you have enjoyed this chapter. It's a long one but the code we put together is an excellent base for the core app.
772761
773-
In the next chapter, we will focus on customizing the output of user and product models using the gem https://github.com/Netflix/fast_jsonapi_jsonapi[fast_jsonapi]. It will allow us to easily filter the attributes to display and manage associations such as embedded objects for example.
762+
In the next chapter, we will focus on customizing the output of user and product models using the gem https://github.com/Netflix/fast_jsonapi[fast_jsonapi]. It will allow us to easily filter the attributes to display and manage associations such as embedded objects for example.
774763

0 commit comments

Comments
 (0)