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
Hide 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
...
@@ -12,7 +12,7 @@ class CardsController < ApplicationController
if
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'remove'
if
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'remove'
# Nothing to delete
# Nothing to delete
if
@card_infos
.
empty?
if
@card_infos
.
empty?
redirect_to
cards_path
redirect_to
cards_path
and
return
else
else
card_items
=
@card_infos
[
:card_items
]
card_items
=
@card_infos
[
:card_items
]
found
=
false
found
=
false
...
@@ -25,20 +25,20 @@ class CardsController < ApplicationController
...
@@ -25,20 +25,20 @@ class CardsController < ApplicationController
found
=
true
found
=
true
end
end
flash
[
:error
]
=
"Invalid request (product not exist in card)"
if
!
found
flash
[
:error
]
=
"Invalid request (product not exist in card)"
if
!
found
redirect_to
cards_path
redirect_to
cards_path
and
return
end
end
end
end
elsif
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'update'
elsif
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'update'
# Nothing to update
# Nothing to update
if
@card_infos
.
empty?
if
@card_infos
.
empty?
flash
[
:error
]
=
"Invalid request"
flash
[
:error
]
=
"Invalid request"
redirect_to
cards_path
redirect_to
cards_path
and
return
else
else
quantity
=
params
[
:quantity
]
quantity
=
params
[
:quantity
]
# Invalid request
# Invalid request
if
quantity
.
nil?
||
quantity
.
to_i
<=
0
if
quantity
.
nil?
||
quantity
.
to_i
<=
0
flash
[
:error
]
=
"Invalid quantity"
flash
[
:error
]
=
"Invalid quantity"
redirect_to
cards_path
redirect_to
cards_path
and
return
else
else
card_items
=
@card_infos
[
:card_items
]
card_items
=
@card_infos
[
:card_items
]
card_items
.
each_with_index
do
|
card_item
,
key
|
card_items
.
each_with_index
do
|
card_item
,
key
|
...
@@ -50,7 +50,7 @@ class CardsController < ApplicationController
...
@@ -50,7 +50,7 @@ class CardsController < ApplicationController
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
end
end
end
end
redirect_to
cards_path
redirect_to
cards_path
and
return
end
end
end
end
else
else
...
@@ -63,7 +63,7 @@ class CardsController < ApplicationController
...
@@ -63,7 +63,7 @@ class CardsController < ApplicationController
customer_info
=
Hash
.
new
customer_info
=
Hash
.
new
@card_infos
=
{
card_items:
card_items
,
customer_info:
customer_info
}
@card_infos
=
{
card_items:
card_items
,
customer_info:
customer_info
}
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
redirect_to
cards_path
redirect_to
cards_path
and
return
else
else
card_items
=
@card_infos
[
:card_items
]
card_items
=
@card_infos
[
:card_items
]
found
=
false
found
=
false
...
@@ -81,12 +81,12 @@ class CardsController < ApplicationController
...
@@ -81,12 +81,12 @@ class CardsController < ApplicationController
@card_infos
=
{
card_items:
card_items
,
customer_info:
customer_info
}
@card_infos
=
{
card_items:
card_items
,
customer_info:
customer_info
}
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
session
[
:SHOPPING_CARD_SESSION_NAME
]
=
@card_infos
end
end
redirect_to
cards_path
redirect_to
cards_path
and
return
end
end
end
end
else
else
flash
[
:error
]
=
"Invalid product"
flash
[
:error
]
=
"Invalid product"
redirect_to
products_path
redirect_to
products_path
and
return
end
end
end
end
end
end
...
...
venshop_app/spec/requests/card_pages_spec.rb
View file @
973f4051
...
@@ -4,21 +4,28 @@ describe "CardPages" do
...
@@ -4,21 +4,28 @@ describe "CardPages" do
subject
{
page
}
subject
{
page
}
describe
"step 1"
do
describe
"step 1"
do
before
(
:
each
)
do
before
(
:
all
)
do
@product_category
=
FactoryGirl
.
create
(
:product_category
)
@product_category
=
FactoryGirl
.
create
(
:product_category
)
@user
=
FactoryGirl
.
create
(
:user
)
@user
=
FactoryGirl
.
create
(
:user
)
end
before
(
:each
)
do
5
.
times
{
FactoryGirl
.
create
(
:product
,
product_category_id:
@product_category
.
id
,
user_id:
@user
.
id
)
}
5
.
times
{
FactoryGirl
.
create
(
:product
,
product_category_id:
@product_category
.
id
,
user_id:
@user
.
id
)
}
Product
.
all
.
each
do
|
product
|
Product
.
all
.
each
do
|
product
|
visit
product_path
(
product
)
visit
product_path
(
product
)
page
.
find
(
'.product-detail'
).
click_link
(
'Order'
)
page
.
find
(
'.product-detail'
).
click_link
(
'Order'
)
end
end
end
end
after
(
:each
)
do
Product
.
delete_all
after
(
:all
)
do
User
.
delete_all
User
.
delete_all
ProductCategory
.
delete_all
ProductCategory
.
delete_all
end
end
after
(
:each
)
do
Product
.
delete_all
end
describe
"when update quantity"
do
describe
"when update quantity"
do
describe
"with invalid information"
do
describe
"with invalid information"
do
describe
"when product not exist"
do
describe
"when product not exist"
do
...
@@ -85,35 +92,24 @@ describe "CardPages" do
...
@@ -85,35 +92,24 @@ describe "CardPages" do
describe
"when remove a product"
do
describe
"when remove a product"
do
describe
"with invalid information"
do
describe
"with invalid information"
do
# let(:product) { Product.first }
# before { visit cards_path(product_id: product.id) }
describe
"when product not exist"
do
describe
"when product not exist"
do
#
before do
before
do
# visit cards_path(card_action: 'update', product_id: 0, quantity: "abc"
)
visit
cards_path
(
card_action:
'update'
,
product_id:
0
)
#
end
end
#
it { should have_selector('.alert.alert-error', text: 'Invalid') }
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
end
end
# it "when product exist in db, but not exist in card" do
describe
"when product exist in db, but not exist in card"
do
# product = Product.first
let
(
:product_not_in_card
)
{
FactoryGirl
.
create
(
:product
,
product_category_id:
@product_category
.
id
,
user_id:
@user
.
id
)
}
# 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
# describe "when product exist in db, but not exist in card" do
# let(:product_not_in_card) { Product.last }
#
before do
before
do
#
visit cards_path(card_action: 'remove', product_id: product_not_in_card.id)
visit
cards_path
(
card_action:
'remove'
,
product_id:
product_not_in_card
.
id
)
#
end
end
#
it { should have_selector('.alert.alert-error', text: 'Invalid') }
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
#
end
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