Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
dhp-venshop
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hoang Phuc Do
dhp-venshop
Commits
bd5bb37b
Commit
bd5bb37b
authored
Jul 04, 2017
by
Hoang Phuc Do
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RSpec for Order model
parent
07fd62c6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
2 deletions
+14
-2
app/controllers/orders_controller.rb
+2
-1
app/models/product_item.rb
+0
-1
spec/models/order_spec.rb
+12
-0
No files found.
app/controllers/orders_controller.rb
View file @
bd5bb37b
...
...
@@ -43,8 +43,9 @@ class OrdersController < ApplicationController
def
save_order_items
(
order
)
@cart
.
product_items
.
values
.
each
do
|
attrs
|
order
.
product_items
.
create
(
product:
attrs
[
:product
],
product_item
=
order
.
product_items
.
create
(
product:
attrs
[
:product
],
quantity:
attrs
[
:quantity
])
product_item
.
update_product_quantity
end
end
...
...
app/models/product_item.rb
View file @
bd5bb37b
class
ProductItem
<
ApplicationRecord
belongs_to
:product
,
optional:
true
belongs_to
:order
,
optional:
true
after_create
:update_product_quantity
validates
:quantity
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
...
...
spec/models/order_spec.rb
View file @
bd5bb37b
...
...
@@ -15,4 +15,16 @@ RSpec.describe Order, type: :model do
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
have_many
(
:product_items
)
}
end
context
'custom methods'
do
it
'has valid total_price'
do
user
=
create
(
:user
)
order
=
create
(
:order
,
user:
user
)
product
=
create
(
:product
,
quantity:
3
,
price:
10
)
ProductItem
.
create
(
quantity:
2
,
product_id:
product
.
id
,
order:
order
)
expect
(
order
.
total_price
).
to
eq
20
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment