Commit a823ed3d by vulehuan

rspec: card - update 'update quantity' test syntax

parent ef76ace2
...@@ -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 99.99 price 111
product_category_id 0 product_category_id 0
user_id 0 user_id 0
status true status true
......
...@@ -4,7 +4,7 @@ describe "CardPages" do ...@@ -4,7 +4,7 @@ describe "CardPages" do
subject { page } subject { page }
describe "step 1" do describe "step 1" do
before(:all) { before(:each) do
@product_category = FactoryGirl.create(:product_category) @product_category = FactoryGirl.create(:product_category)
@user = FactoryGirl.create(:user) @user = FactoryGirl.create(:user)
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) }
...@@ -12,8 +12,8 @@ describe "CardPages" do ...@@ -12,8 +12,8 @@ describe "CardPages" do
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
after(:all) do after(:each) do
Product.delete_all Product.delete_all
User.delete_all User.delete_all
ProductCategory.delete_all ProductCategory.delete_all
...@@ -58,54 +58,81 @@ describe "CardPages" do ...@@ -58,54 +58,81 @@ describe "CardPages" do
end end
end end
it "with valid information" do describe "with valid information" do
amount = 99 let(:amount) { 99 }
product = Product.first let(:product) { Product.first }
visit cards_path(product_id: product.id) before do
visit cards_path(card_action: 'update', product_id: product.id , quantity: amount) visit cards_path(card_action: 'update', product_id: product.id , quantity: amount)
end
page.should have_xpath("//input[@id='cart-quantity-#{product.id}'][@value='#{amount}']") it do
page.should have_selector(".cart-unit-price-#{product.id}", text: ActionController::Base.helpers.number_with_delimiter(product.price)) should have_xpath("//input[@id='cart-quantity-#{product.id}'][@value='#{amount}']")
page.should have_selector(".cart-total-price-#{product.id}", text: ActionController::Base.helpers.number_with_delimiter(product.price * amount)) should have_selector(".cart-unit-price-#{product.id}", text: ActionController::Base.helpers.number_with_delimiter(product.price))
should have_selector(".cart-total-price-#{product.id}", text: ActionController::Base.helpers.number_with_delimiter(product.price * amount))
total = 0 total = 0
Product.all.each do |obj| Product.all.each do |obj|
total += obj.price total += obj.price
end end
total += (amount - 1) * product.price total += (amount - 1) * product.price
page.should have_selector('#card-must-paid', text: ActionController::Base.helpers.number_with_delimiter(total)) should have_selector('#card-must-paid', text: ActionController::Base.helpers.number_with_delimiter(total))
end
end end
end end
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, quantity: "abc")
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 # it "when product exist in db, but not exist in card" do
product = Product.first # product = Product.first
product_not_in_card = Product.last # product_not_in_card = Product.last
visit cards_path(product_id: product.id) # visit cards_path(product_id: product.id)
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)
page.should have_selector('.alert.alert-error', text: 'Invalid') # page.should have_selector('.alert.alert-error', text: 'Invalid')
end # end
# describe "when product exist in db, but not exist in card" do
# let(:product_not_in_card) { Product.last }
# 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
end end
describe "when product exist in card" do describe "when product exist in card" do
describe "calculate price" do # it "calculate price" do
end # product = Product.first
# total = 0
# # Add to cart all
# Product.all.each do |obj|
# visit cards_path(product_id: product.id)
# total += obj.price
# end
# visit cards_path(card_action: 'remove', product_id: product.id)
# total -= product.price
# page.should have_selector('#card-must-paid', text: ActionController::Base.helpers.number_with_delimiter(total + 1))
# end
end end
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