Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
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
0
Merge Requests
0
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
huanvl
venshop
Commits
5fd64555
Commit
5fd64555
authored
Nov 01, 2013
by
vulehuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rspec: card - remove product with invalid information
parent
eda24c21
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
4 deletions
+28
-4
venshop_app/app/controllers/cards_controller.rb
+4
-1
venshop_app/spec/factories.rb
+1
-1
venshop_app/spec/requests/card_pages_spec.rb
+23
-2
No files found.
venshop_app/app/controllers/cards_controller.rb
View file @
5fd64555
...
@@ -15,14 +15,17 @@ class CardsController < ApplicationController
...
@@ -15,14 +15,17 @@ class CardsController < ApplicationController
redirect_to
cards_path
redirect_to
cards_path
else
else
card_items
=
@card_infos
[
:card_items
]
card_items
=
@card_infos
[
:card_items
]
found
=
false
card_items
.
each
do
|
card_item
|
card_items
.
each
do
|
card_item
|
# if a product exist in card
# if a product exist in card
if
card_item
[
:product_id
]
==
params
[
:product_id
]
if
card_item
[
:product_id
]
==
params
[
:product_id
]
card_items
.
delete
(
card_item
)
card_items
.
delete
(
card_item
)
@card_infos
=
{
card_items:
card_items
,
customer_info:
@card_infos
[
:customer_info
]
}
@card_infos
=
{
card_items:
card_items
,
customer_info:
@card_infos
[
:customer_info
]
}
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
redirect_to
cards_path
found
=
true
end
end
flash
[
:error
]
=
"Invalid request (product not exist in card)"
if
!
found
redirect_to
cards_path
end
end
end
end
elsif
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'update'
elsif
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'update'
...
...
venshop_app/spec/factories.rb
View file @
5fd64555
...
@@ -26,7 +26,7 @@ FactoryGirl.define do
...
@@ -26,7 +26,7 @@ FactoryGirl.define do
review_rate
0
review_rate
0
review_count
0
review_count
0
price_currency
'USD'
price_currency
'USD'
price
0
price
99.99
product_category_id
0
product_category_id
0
user_id
0
user_id
0
status
true
status
true
...
...
venshop_app/spec/requests/card_pages_spec.rb
View file @
5fd64555
...
@@ -61,19 +61,40 @@ describe "CardPages" do
...
@@ -61,19 +61,40 @@ describe "CardPages" do
it
"with valid information"
do
it
"with valid information"
do
amount
=
99
amount
=
99
product
=
Product
.
first
product
=
Product
.
first
visit
cards_path
(
product_id:
product
.
id
)
visit
cards_path
(
card_action:
'update'
,
product_id:
product
.
id
,
quantity:
amount
)
visit
cards_path
(
card_action:
'update'
,
product_id:
product
.
id
,
quantity:
amount
)
page
.
should
have_xpath
(
"//input[@id='cart-quantity-
#{
product
.
id
}
'][@value='
#{
amount
}
']"
)
page
.
should
have_xpath
(
"//input[@id='cart-quantity-
#{
product
.
id
}
'][@value='
#{
amount
}
']"
)
page
.
should
have_selector
(
".cart-unit-price-
#{
product
.
id
}
"
,
text:
ActionController
::
Base
.
helpers
.
number_with_delimiter
(
product
.
price
))
page
.
should
have_selector
(
".cart-unit-price-
#{
product
.
id
}
"
,
text:
ActionController
::
Base
.
helpers
.
number_with_delimiter
(
product
.
price
))
page
.
should
have_selector
(
".cart-total-price-
#{
product
.
id
}
"
,
text:
ActionController
::
Base
.
helpers
.
number_with_delimiter
(
product
.
price
*
amount
))
page
.
should
have_selector
(
".cart-total-price-
#{
product
.
id
}
"
,
text:
ActionController
::
Base
.
helpers
.
number_with_delimiter
(
product
.
price
*
amount
))
end
end
end
end
describe
"when remove a product"
do
describe
"when remove a product"
do
describe
"when product is not exist in card"
do
describe
"with invalid information"
do
describe
"when product not exist"
do
before
do
visit
cards_path
(
card_action:
'update'
,
product_id:
0
,
quantity:
"abc"
)
end
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
end
end
it
"when product exist in db, but not exist in card"
do
product
=
Product
.
first
product_not_in_card
=
Product
.
last
visit
cards_path
(
product_id:
product
.
id
)
visit
cards_path
(
card_action:
'remove'
,
product_id:
product_not_in_card
.
id
)
page
.
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
end
end
describe
"when product exist in card"
do
describe
"when product exist in card"
do
describe
"calculate price"
do
describe
"calculate price"
do
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