Commit 5fd64555 by vulehuan

rspec: card - remove product with invalid information

parent eda24c21
...@@ -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'
......
...@@ -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
......
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment