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
eda24c21
Commit
eda24c21
authored
Oct 31, 2013
by
vulehuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rspec: card - update quantity
parent
89d66f64
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
8 deletions
+65
-8
venshop_app/app/controllers/cards_controller.rb
+2
-0
venshop_app/app/views/cards/_item_list.html.erb
+3
-3
venshop_app/app/views/cards/index.html.erb
+1
-0
venshop_app/log/sunspot-solr-development.log.lck
+0
-0
venshop_app/spec/requests/card_pages_spec.rb
+59
-5
No files found.
venshop_app/app/controllers/cards_controller.rb
View file @
eda24c21
...
...
@@ -28,11 +28,13 @@ class CardsController < ApplicationController
elsif
!
params
[
:card_action
].
nil?
&&
params
[
:card_action
]
==
'update'
# Nothing to update
if
@card_infos
.
empty?
flash
[
:error
]
=
"Invalid request"
redirect_to
cards_path
else
quantity
=
params
[
:quantity
]
# Invalid request
if
quantity
.
nil?
||
quantity
.
to_i
<=
0
flash
[
:error
]
=
"Invalid quantity"
redirect_to
cards_path
else
card_items
=
@card_infos
[
:card_items
]
...
...
venshop_app/app/views/cards/_item_list.html.erb
View file @
eda24c21
...
...
@@ -29,12 +29,12 @@
<td>
<%=
$i
%>
</td>
<td>
<%=
link_to
(
product
.
name
,
product_url
(
product
))
%>
</td>
<%
if
can_edit
%>
<td><input
type=
"text"
class=
"form-control txt-quantity"
value=
"
<%=
card_item
[
:quantity
]
%>
"
/></td>
<td><input
id=
"cart-quantity-
<%=
card_item
[
:product_id
]
%>
"
type=
"text"
class=
"form-control txt-quantity"
value=
"
<%=
card_item
[
:quantity
]
%>
"
/></td>
<%
else
%>
<td><div
class=
"text-right"
>
<%=
card_item
[
:quantity
]
%>
</div></td>
<%
end
%>
<td><div
class=
"text-right"
>
<%=
number_with_delimiter
(
product
.
price
)
%>
</div></td>
<td><div
class=
"text-right"
>
<%=
number_with_delimiter
(
product
.
price
*
card_item
[
:quantity
])
%>
</div></td>
<td><div
class=
"text-right
cart-unit-price-
<%=
card_item
[
:product_id
]
%>
"
>
<%=
number_with_delimiter
(
product
.
price
)
%>
</div></td>
<td><div
class=
"text-right
cart-total-price-
<%=
card_item
[
:product_id
]
%>
"
>
<%=
number_with_delimiter
(
product
.
price
*
card_item
[
:quantity
])
%>
</div></td>
<%
if
can_edit
%>
<td>
<div
class=
"text-center"
>
...
...
venshop_app/app/views/cards/index.html.erb
View file @
eda24c21
...
...
@@ -3,6 +3,7 @@
<h2
class=
"sprite-2"
>
Cards
<span
class=
"sprite-2"
></span>
</h2>
<div
id=
"block-message-visible"
class=
"hidden"
></div>
<%=
render
partial:
'cards/item_list'
,
locals:
{
card_infos:
@card_infos
,
can_edit:
true
}
%>
<div
class=
"clearfix"
></div>
</div>
venshop_app/log/sunspot-solr-development.log.lck
deleted
100644 → 0
View file @
89d66f64
venshop_app/spec/requests/card_pages_spec.rb
View file @
eda24c21
require
'spec_helper'
describe
"Cards Page"
do
describe
"CardPages"
do
subject
{
page
}
describe
"step 1"
do
before
(
:all
)
{
@product_category
=
FactoryGirl
.
create
(
:product_category
)
@user
=
FactoryGirl
.
create
(
:user
)
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
}
after
(
:all
)
do
Product
.
delete_all
User
.
delete_all
ProductCategory
.
delete_all
end
describe
"when update quantity"
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
describe
"when product exist"
do
describe
"when quantity is not a number"
do
before
do
product
=
Product
.
first
visit
cards_path
(
card_action:
'update'
,
product_id:
product
.
id
,
quantity:
"abc"
)
end
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
end
describe
"when quantity < 0"
do
before
do
product
=
Product
.
first
visit
cards_path
(
card_action:
'update'
,
product_id:
product
.
id
,
quantity:
-
1
)
end
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
end
describe
"when quantity = 0"
do
before
do
product
=
Product
.
first
visit
cards_path
(
card_action:
'update'
,
product_id:
product
.
id
,
quantity:
0
)
end
it
{
should
have_selector
(
'.alert.alert-error'
,
text:
'Invalid'
)
}
end
end
end
describe
"with valid information"
do
it
"with valid information"
do
amount
=
99
product
=
Product
.
first
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_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
))
end
end
...
...
@@ -23,6 +75,8 @@ describe "Cards Page" do
end
describe
"when product exist in card"
do
describe
"calculate price"
do
end
end
end
...
...
@@ -31,9 +85,6 @@ describe "Cards Page" do
describe
"when click product name"
do
end
describe
"calculate price"
do
end
end
describe
"step 2"
do
...
...
@@ -90,5 +141,8 @@ describe "Cards Page" do
end
describe
"step 4"
do
before
{
visit
url_for
(
controller:
'cards'
,
action:
'thankyou'
)
}
it
{
should
have_title
(
'Thank you'
)
}
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