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
d0280375
Commit
d0280375
authored
Jul 05, 2017
by
Hoang Phuc Do
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix merge request
parent
d2fa4e8c
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
7 deletions
+15
-7
app/models/product.rb
+1
-0
spec/models/order_spec.rb
+1
-1
spec/models/product_item_spec.rb
+2
-2
spec/models/product_spec.rb
+11
-4
No files found.
app/models/product.rb
View file @
d0280375
...
@@ -10,6 +10,7 @@ class Product < ApplicationRecord
...
@@ -10,6 +10,7 @@ class Product < ApplicationRecord
validates
:user_id
,
presence:
true
validates
:user_id
,
presence:
true
def
in_stock?
(
required_quantity
)
def
in_stock?
(
required_quantity
)
return
false
if
required_quantity
<=
0
quantity
>=
required_quantity
.
to_i
quantity
>=
required_quantity
.
to_i
end
end
...
...
spec/models/order_spec.rb
View file @
d0280375
...
@@ -23,7 +23,7 @@ RSpec.describe Order, type: :model do
...
@@ -23,7 +23,7 @@ RSpec.describe Order, type: :model do
let!
(
:product_item
)
{
create
(
:product_item
,
product:
product
,
order:
order
)
}
let!
(
:product_item
)
{
create
(
:product_item
,
product:
product
,
order:
order
)
}
it
'has valid total_price'
do
it
'has valid total_price'
do
expect
(
order
.
total_price
).
to
eq
10
expect
(
order
.
total_price
).
to
eq
product
.
price
*
product_item
.
quantity
end
end
end
end
end
end
spec/models/product_item_spec.rb
View file @
d0280375
...
@@ -21,12 +21,12 @@ RSpec.describe ProductItem, type: :model do
...
@@ -21,12 +21,12 @@ RSpec.describe ProductItem, type: :model do
let!
(
:product_item
)
{
create
(
:product_item
,
product:
product
)
}
let!
(
:product_item
)
{
create
(
:product_item
,
product:
product
)
}
it
'has valid total_price'
do
it
'has valid total_price'
do
expect
(
product_item
.
total_price
).
to
eq
10
expect
(
product_item
.
total_price
).
to
eq
product
.
price
*
product_item
.
quantity
end
end
it
'has valid update_product_quantity'
do
it
'has valid update_product_quantity'
do
product_item
.
update_product_quantity
product_item
.
update_product_quantity
expect
(
product
.
quantity
).
to
eq
2
expect
(
product
.
quantity
).
to
eq
product
.
quantity
end
end
end
end
end
end
spec/models/product_spec.rb
View file @
d0280375
...
@@ -27,12 +27,19 @@ RSpec.describe Product, type: :model do
...
@@ -27,12 +27,19 @@ RSpec.describe Product, type: :model do
let!
(
:other_user
)
{
create
(
:user
)
}
let!
(
:other_user
)
{
create
(
:user
)
}
let!
(
:product
)
{
create
(
:product
,
quantity:
3
,
user:
user
)
}
let!
(
:product
)
{
create
(
:product
,
quantity:
3
,
user:
user
)
}
it
'has valid in_stock?'
do
it
'product quantity in stock?'
do
expect
(
product
.
in_stock?
(
2
)).
to
be_truthy
instock_quantity
=
2
expect
(
product
.
in_stock?
(
instock_quantity
)).
to
be_truthy
end
end
it
'has invalid in_stock?'
do
it
'product quantity out of stock?'
do
expect
(
product
.
in_stock?
(
4
)).
not_to
be_truthy
out_of_stock_quantity
=
4
expect
(
product
.
in_stock?
(
out_of_stock_quantity
)).
not_to
be_truthy
end
it
'product quantity invalid?'
do
invalid_quantity
=
-
1
expect
(
product
.
in_stock?
(
invalid_quantity
)).
not_to
be_truthy
end
end
it
'has valid belongs_to_user?'
do
it
'has valid belongs_to_user?'
do
...
...
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