* VRFS-3058 - fix uniqueness constraint on ShoppingCart and test

This commit is contained in:
Seth Call 2015-04-19 11:43:54 -05:00
parent 64836c1a44
commit fc99fbce6c
3 changed files with 26 additions and 3 deletions

View File

@ -12,7 +12,7 @@ module JamRuby
attr_accessible :quantity, :cart_type, :product_info
validates_uniqueness_of :cart_id, scope: :cart_type
validates_uniqueness_of :cart_id, scope: [:cart_type, :user_id, :anonymous_user_id]
belongs_to :user, :inverse_of => :shopping_carts, :class_name => "JamRuby::User", :foreign_key => "user_id"

View File

@ -1009,7 +1009,16 @@ module JamRuby
user.photo_url = photo_url
# copy over the shopping cart to the new user, if a shopping cart is provided
user.shopping_carts = any_user.shopping_carts if any_user
if any_user
user.shopping_carts = any_user.shopping_carts
if user.shopping_carts
user.shopping_carts.each do |shopping_cart|
shopping_cart.anonymous_user_id = nil # nil out the anonymous user ID; required for uniqeness constraint on ShoppingCart
end
end
end
unless fb_signup.nil?
user.update_fb_authorization(fb_signup)

View File

@ -618,6 +618,11 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
# attempt to checkout
find('a.button-orange', text: 'PROCEED TO CHECKOUT').trigger(:click)
shopping_carts = ShoppingCart.all
shopping_carts.count.should eq(1)
shopping_cart = shopping_carts[0]
shopping_cart.anonymous_user_id.should_not be_nil
shopping_cart.user_id.should be_nil
# we should now be on checkoutSignin
find('h3', text: 'ALREADY A MEMBER OF THE JAMKAZAM COMMUNITY?')
@ -654,13 +659,22 @@ describe "Checkout", :js => true, :type => :feature, :capybara_feature => true d
find('.order-items-value.taxes', text:'$0.00')
find('.order-items-value.grand-total', text:'$0.00')
guy = User.find_by_email('guy@jamkazam.com')
# verify that the shopping cart has user_id info updated
shopping_cart.reload
shopping_cart.anonymous_user_id.should be_nil
shopping_cart.user.should eq(guy)
# click the ORDER button
find('.place-order-center a.button-orange.place-order').trigger(:click)
# and now we should see confirmation, and a notice that we are in a normal browser
find('.thanks-detail.jam-tracks-in-browser')
guy = User.find_by_email('guy@jamkazam.com')
guy.reload
jam_track_right = jamtrack_acdc_backinblack.right_for_user(guy)
# make sure it appears the user actually bought the jamtrack!
jam_track_right.should_not be_nil