From 16847025dd3ec454873794955fb4633a8eb8ee79 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 8 Aug 2014 11:14:50 +1000 Subject: [PATCH] Fix bug: local storage was not correctly keyed to user id --- .../checkout/checkout_controller.js.coffee | 2 +- .../consumer/shopping/checkout_auth_spec.rb | 16 +++++++++++++++- .../checkout/checkout_controller_spec.js.coffee | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee index a5966e503b..e77712eae6 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee @@ -3,7 +3,7 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu # Bind to local storage $scope.fieldsToBind = ["bill_address", "email", "payment_method_id", "shipping_method_id", "ship_address"] - prefix = "order_#{Checkout.order.id}#{Checkout.order.user_id}#{CurrentHub.hub.id}" + prefix = "order_#{Checkout.order.id}#{CurrentUser?.id}#{CurrentHub.hub.id}" for field in $scope.fieldsToBind storage.bind $scope, "Checkout.order.#{field}", diff --git a/spec/features/consumer/shopping/checkout_auth_spec.rb b/spec/features/consumer/shopping/checkout_auth_spec.rb index 81ee44fdcd..2e756879a9 100644 --- a/spec/features/consumer/shopping/checkout_auth_spec.rb +++ b/spec/features/consumer/shopping/checkout_auth_spec.rb @@ -12,7 +12,8 @@ feature "As a consumer I want to check out my cart", js: true do let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } let(:product) { create(:simple_product, supplier: supplier) } let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) } - let(:user) { create_enterprise_user } + let(:address) { create(:address, firstname: "Foo", lastname: "Bar") } + let(:user) { create(:user, bill_address: address, ship_address: address) } after { Warden.test_reset! } before do @@ -38,6 +39,19 @@ feature "As a consumer I want to check out my cart", js: true do page.should have_login_modal end + it "populates user details once logged in" do + visit checkout_path + within("section[role='main']") { click_button "Log in" } + page.should have_login_modal + fill_in "Email", with: user.email + fill_in "Password", with: user.password + within(".login-modal") { click_button 'Log in' } + toggle_details + + page.should have_field 'First Name', with: 'Foo' + page.should have_field 'Last Name', with: 'Bar' + end + it "allows user to checkout as guest" do visit checkout_path checkout_as_guest diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee index ceebc55eab..d56a7495ab 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee @@ -46,7 +46,7 @@ describe "CheckoutCtrl", -> describe "Local storage", -> it "binds to localStorage when given a scope", -> - prefix = "order_#{scope.order.id}#{scope.order.user_id}#{CurrentHubMock.hub.id}" + prefix = "order_#{scope.order.id}#{CurrentUser?.id}#{CurrentHubMock.hub.id}" field = scope.fieldsToBind[0] expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.order.#{field}", {storeName: "#{prefix}_#{field}"}) expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true})