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
973f4051
Commit
973f4051
authored
Nov 01, 2013
by
vulehuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spec: card - remove product with invalid information
parent
a823ed3d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
33 deletions
+29
-33
venshop_app/app/controllers/cards_controller.rb
+8
-8
venshop_app/spec/requests/card_pages_spec.rb
+21
-25
No files found.
venshop_app/app/controllers/cards_controller.rb
View file @
973f4051
...
...
@@ -12,7 +12,7 @@ class CardsController < ApplicationController
if
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'remove'
# Nothing to delete
if
@card_infos
.
empty?
redirect_to
cards_path
redirect_to
cards_path
and
return
else
card_items
=
@card_infos
[
:card_items
]
found
=
false
...
...
@@ -25,20 +25,20 @@ class CardsController < ApplicationController
found
=
true
end
flash
[
:error
]
=
"Invalid request (product not exist in card)"
if
!
found
redirect_to
cards_path
redirect_to
cards_path
and
return
end
end
elsif
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'update'
# Nothing to update
if
@card_infos
.
empty?
flash
[
:error
]
=
"Invalid request"
redirect_to
cards_path
redirect_to
cards_path
and
return
else
quantity
=
params
[
:quantity
]
# Invalid request
if
quantity
.
nil?
||
quantity
.
to_i
<=
0
flash
[
:error
]
=
"Invalid quantity"
redirect_to
cards_path
redirect_to
cards_path
and
return
else
card_items
=
@card_infos
[
:card_items
]
card_items
.
each_with_index
do
|
card_item
,
key
|
...
...
@@ -50,7 +50,7 @@ class CardsController < ApplicationController
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
end
end
redirect_to
cards_path
redirect_to
cards_path
and
return
end
end
else
...
...
@@ -63,7 +63,7 @@ class CardsController < ApplicationController
customer_info
=
Hash
.
new
@card_infos
=
{
card_items:
card_items
,
customer_info:
customer_info
}
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
redirect_to
cards_path
redirect_to
cards_path
and
return
else
card_items
=
@card_infos
[
:card_items
]
found
=
false
...
...
@@ -81,12 +81,12 @@ class CardsController < ApplicationController
@card_infos
=
{
card_items:
card_items
,
customer_info:
customer_info
}
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
end
redirect_to
cards_path
redirect_to
cards_path
and
return
end
end
else
flash
[
:error
]
=
"Invalid product"
redirect_to
products_path
redirect_to
products_path
and
return
end
end
end
...
...
venshop_app/spec/requests/card_pages_spec.rb
View file @
973f4051
...
...
@@ -4,21 +4,28 @@ describe "CardPages" do
subject
{
page
}
describe
"step 1"
do
before
(
:
each
)
do
before
(
:
all
)
do
@product_category
=
FactoryGirl
.
create
(
:product_category
)
@user
=
FactoryGirl
.
create
(
:user
)
end
before
(
:each
)
do
5
.
times
{
FactoryGirl
.
create
(
:product
,
product_category_id:
@product_category
.
id
,
user_id:
@user
.
id
)
}
Product
.
all
.
each
do
|
product
|
visit
product_path
(
product
)
page
.
find
(
'.product-detail'
).
click_link
(
'Order'
)
end
end
after
(
:each
)
do
Product
.
delete_all
after
(
:all
)
do
User
.
delete_all
ProductCategory
.
delete_all
end
after
(
:each
)
do
Product
.
delete_all
end
describe
"when update quantity"
do
describe
"with invalid information"
do
describe
"when product not exist"
do
...
...
@@ -85,35 +92,24 @@ describe "CardPages" do
describe
"when remove a product"
do
describe
"with invalid information"
do
# let(:product) { Product.first }
# before { visit cards_path(product_id: product.id) }
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') }
before
do
visit
cards_path
(
card_action:
'update'
,
product_id:
0
)
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)
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
end
# page.should have_selector('.alert.alert-error', text: 'Invalid')
# end
# describe "when product exist in db, but not exist in card" do
# let(:product_not_in_card) { Product.last }
describe
"when product exist in db, but not exist in card"
do
let
(
:product_not_in_card
)
{
FactoryGirl
.
create
(
:product
,
product_category_id:
@product_category
.
id
,
user_id:
@user
.
id
)
}
#
before do
#
visit cards_path(card_action: 'remove', product_id: product_not_in_card.id)
#
end
before
do
visit
cards_path
(
card_action:
'remove'
,
product_id:
product_not_in_card
.
id
)
end
#
it { should have_selector('.alert.alert-error', text: 'Invalid') }
#
end
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
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