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
d2fa4e8c
Commit
d2fa4e8c
authored
Jul 04, 2017
by
Hoang Phuc Do
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update RSpec for Product Item model
parent
5ef81a22
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
9 deletions
+37
-9
spec/factories/product_item.rb
+7
-0
spec/models/order_spec.rb
+6
-7
spec/models/product_item_spec.rb
+14
-0
spec/models/product_spec.rb
+10
-2
No files found.
spec/factories/product_item.rb
0 → 100644
View file @
d2fa4e8c
FactoryGirl
.
define
do
factory
:product_item
do
quantity
1
product
order
end
end
spec/models/order_spec.rb
View file @
d2fa4e8c
...
...
@@ -17,14 +17,13 @@ RSpec.describe Order, type: :model do
end
context
'custom methods'
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:order
)
{
create
(
:order
,
user:
user
)
}
let!
(
:product
)
{
create
(
:product
,
quantity:
3
,
price:
10
)
}
let!
(
:product_item
)
{
create
(
:product_item
,
product:
product
,
order:
order
)
}
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
expect
(
order
.
total_price
).
to
eq
10
end
end
end
spec/models/product_item_spec.rb
View file @
d2fa4e8c
...
...
@@ -15,4 +15,18 @@ RSpec.describe ProductItem, type: :model do
it
{
is_expected
.
to
belong_to
(
:order
)
}
it
{
is_expected
.
to
belong_to
(
:product
)
}
end
context
'custom methods'
do
let!
(
:product
)
{
create
(
:product
,
price:
10
,
quantity:
3
)
}
let!
(
:product_item
)
{
create
(
:product_item
,
product:
product
)
}
it
'has valid total_price'
do
expect
(
product_item
.
total_price
).
to
eq
10
end
it
'has valid update_product_quantity'
do
product_item
.
update_product_quantity
expect
(
product
.
quantity
).
to
eq
2
end
end
end
spec/models/product_spec.rb
View file @
d2fa4e8c
...
...
@@ -25,14 +25,22 @@ RSpec.describe Product, type: :model do
context
'custom methods'
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:other_user
)
{
create
(
:user
)
}
let!
(
:product
)
{
create
(
:product
,
quantity:
3
,
user:
other_
user
)
}
let!
(
:product
)
{
create
(
:product
,
quantity:
3
,
user:
user
)
}
it
'has valid in_stock?'
do
expect
(
product
.
in_stock?
(
2
)).
to
be_truthy
end
it
'has invalid in_stock?'
do
expect
(
product
.
in_stock?
(
4
)).
not_to
be_truthy
end
it
'has valid belongs_to_user?'
do
expect
(
product
.
belongs_to_user?
(
user
)).
not_to
be_truthy
expect
(
product
.
belongs_to_user?
(
user
)).
to
be_truthy
end
it
'has invalid belongs_to_user?'
do
expect
(
product
.
belongs_to_user?
(
other_user
)).
not_to
be_truthy
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