From e6cd00b0c4c1540489d0ad6ef2d3d0000efadcf5 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 25 Aug 2017 14:33:01 +0200 Subject: [PATCH 1/7] Reorganize coupon code feature specs It will be easier to add other context, like checking out with logged in user. --- frontend/spec/features/coupon_code_spec.rb | 77 +++++++++++----------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/frontend/spec/features/coupon_code_spec.rb b/frontend/spec/features/coupon_code_spec.rb index 50215fb1672..ea77a529821 100644 --- a/frontend/spec/features/coupon_code_spec.rb +++ b/frontend/spec/features/coupon_code_spec.rb @@ -11,7 +11,7 @@ let!(:payment_method) { create(:check_payment_method) } let!(:product) { create(:product, name: "RoR Mug", price: 20) } - context "visitor makes checkout as guest without registration" do + context "visitor makes checkout" do def create_basic_coupon_promotion(code) promotion = create( :promotion, @@ -34,50 +34,51 @@ def create_basic_coupon_promotion(code) let!(:promotion) { create_basic_coupon_promotion("onetwo") } - # OrdersController context "on the payment page" do - before do - visit spree.root_path - click_link "RoR Mug" - click_button "add-to-cart-button" - click_button "Checkout" - fill_in "order_email", with: "spree@example.com" - fill_in "First Name", with: "John" - fill_in "Last Name", with: "Smith" - fill_in "Street Address", with: "1 John Street" - fill_in "City", with: "City of John" - fill_in "Zip", with: "01337" - select country.name, from: "Country" - select state.name, from: "order[bill_address_attributes][state_id]" - fill_in "Phone", with: "555-555-5555" - - # To shipping method screen - click_button "Save and Continue" - # To payment screen - click_button "Save and Continue" - end - - it "informs about an invalid coupon code" do - fill_in "order_coupon_code", with: "coupon_codes_rule_man" - click_button "Save and Continue" - expect(page).to have_content(I18n.t('spree.coupon_code_not_found')) - end + context "as guest without registration" do + before do + visit spree.root_path + click_link "RoR Mug" + click_button "add-to-cart-button" + click_button "Checkout" + fill_in "order_email", with: "spree@example.com" + fill_in "First Name", with: "John" + fill_in "Last Name", with: "Smith" + fill_in "Street Address", with: "1 John Street" + fill_in "City", with: "City of John" + fill_in "Zip", with: "01337" + select country.name, from: "Country" + select state.name, from: "order[bill_address_attributes][state_id]" + fill_in "Phone", with: "555-555-5555" + + # To shipping method screen + click_button "Save and Continue" + # To payment screen + click_button "Save and Continue" + end - it "can enter an invalid coupon code, then a real one" do - fill_in "order_coupon_code", with: "coupon_codes_rule_man" - click_button "Save and Continue" - expect(page).to have_content(I18n.t('spree.coupon_code_not_found')) - fill_in "order_coupon_code", with: "onetwo" - click_button "Save and Continue" - expect(page).to have_content("Promotion (Onetwo) -$10.00") - end + it "informs about an invalid coupon code" do + fill_in "order_coupon_code", with: "coupon_codes_rule_man" + click_button "Save and Continue" + expect(page).to have_content(I18n.t('spree.coupon_code_not_found')) + end - context "with a promotion" do - it "applies a promotion to an order" do + it "can enter an invalid coupon code, then a real one" do + fill_in "order_coupon_code", with: "coupon_codes_rule_man" + click_button "Save and Continue" + expect(page).to have_content(I18n.t('spree.coupon_code_not_found')) fill_in "order_coupon_code", with: "onetwo" click_button "Save and Continue" expect(page).to have_content("Promotion (Onetwo) -$10.00") end + + context "with a promotion" do + it "applies a promotion to an order" do + fill_in "order_coupon_code", with: "onetwo" + click_button "Save and Continue" + expect(page).to have_content("Promotion (Onetwo) -$10.00") + end + end end end From 4465e16477f335f1390014514be68b24081f8995 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 6 Oct 2017 16:58:36 +0200 Subject: [PATCH 2/7] Add controller specs for coupon application Both in checkout and orders controller. This feature was not tested at controller level. Adding specs will allow more confidence for future changes on this part. --- .../spree/checkout_controller_spec.rb | 37 +++++++++++++++++++ .../spree/orders_controller_spec.rb | 35 ++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/frontend/spec/controllers/spree/checkout_controller_spec.rb b/frontend/spec/controllers/spree/checkout_controller_spec.rb index 06c7de20346..f46035c2e2c 100644 --- a/frontend/spec/controllers/spree/checkout_controller_spec.rb +++ b/frontend/spec/controllers/spree/checkout_controller_spec.rb @@ -478,4 +478,41 @@ def post_address post :update, params: { state: "payment" } }.to change { order.line_items.to_a.size }.from(1).to(0) end + + context 'trying to apply a coupon code' do + let(:order) { create(:order_with_line_items, state: 'payment', guest_token: 'a token') } + let(:coupon_code) { "coupon_code" } + + before { cookies.signed[:guest_token] = order.guest_token } + + context "when coupon code is applied" do + let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') } + + it "continues checkout flow normally" do + expect(Spree::PromotionHandler::Coupon) + .to receive_message_chain(:new, :apply) + .and_return(promotion_handler) + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + + expect(response).to redirect_to(spree.checkout_state_path('confirm')) + expect(flash.now[:success]).to eq('Coupon Applied!') + end + + context "when coupon code is not applied" do + let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: 'Some error', success: false) } + + it "render cart with coupon error" do + expect(Spree::PromotionHandler::Coupon) + .to receive_message_chain(:new, :apply) + .and_return(promotion_handler) + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + + expect(response).to render_template :edit + expect(flash.now[:error]).to eq('Some error') + end + end + end + end end diff --git a/frontend/spec/controllers/spree/orders_controller_spec.rb b/frontend/spec/controllers/spree/orders_controller_spec.rb index 7f8c4672245..0a5a4ac1a4f 100644 --- a/frontend/spec/controllers/spree/orders_controller_spec.rb +++ b/frontend/spec/controllers/spree/orders_controller_spec.rb @@ -128,6 +128,41 @@ put :update, params: { checkout: true } expect(response).to redirect_to checkout_state_path('address') end + + context 'trying to apply a coupon code' do + let(:order) { create(:order_with_line_items, state: 'cart') } + let(:coupon_code) { "coupon_code" } + + context "when coupon code is applied" do + let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') } + + it "continues checkout flow normally" do + expect(Spree::PromotionHandler::Coupon) + .to receive_message_chain(:new, :apply) + .and_return(promotion_handler) + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + + expect(response).to redirect_to(spree.cart_path) + expect(flash.now[:success]).to eq('Coupon Applied!') + end + + context "when coupon code is not applied" do + let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: 'Some error', success: false) } + + it "render cart with coupon error" do + expect(Spree::PromotionHandler::Coupon) + .to receive_message_chain(:new, :apply) + .and_return(promotion_handler) + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + + expect(response).to render_template :edit + expect(flash.now[:error]).to eq('Some error') + end + end + end + end end end From 8032c973883fb76188bf6000655281557f6459e6 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 6 Oct 2017 17:23:47 +0200 Subject: [PATCH 3/7] Do not try to apply coupon code when field is empty There's no need to try to apply coupon code when its params is empty. Right now, submitting every form that have the coupon code field (cart and checkout payment), even with the field empty, it is uselessy calling the Spree::PromotionHandler::Coupon `new` and `apply`. --- frontend/app/controllers/spree/store_controller.rb | 2 +- .../controllers/spree/checkout_controller_spec.rb | 12 ++++++++++++ .../spec/controllers/spree/orders_controller_spec.rb | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/app/controllers/spree/store_controller.rb b/frontend/app/controllers/spree/store_controller.rb index 57a3e8039d4..f4edb6b0e90 100644 --- a/frontend/app/controllers/spree/store_controller.rb +++ b/frontend/app/controllers/spree/store_controller.rb @@ -20,7 +20,7 @@ def cart_link # and OrdersController can both reference it (or any other controller # which needs it) def apply_coupon_code - if params[:order] && params[:order][:coupon_code] + if params[:order] && params[:order][:coupon_code].present? @order.coupon_code = params[:order][:coupon_code] handler = PromotionHandler::Coupon.new(@order).apply diff --git a/frontend/spec/controllers/spree/checkout_controller_spec.rb b/frontend/spec/controllers/spree/checkout_controller_spec.rb index f46035c2e2c..6f46a7636fd 100644 --- a/frontend/spec/controllers/spree/checkout_controller_spec.rb +++ b/frontend/spec/controllers/spree/checkout_controller_spec.rb @@ -485,6 +485,18 @@ def post_address before { cookies.signed[:guest_token] = order.guest_token } + context "when coupon code is empty" do + let(:coupon_code) { "" } + + it 'does not try to apply coupon code' do + expect(Spree::PromotionHandler::Coupon).not_to receive :new + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + + expect(response).to redirect_to(spree.checkout_state_path('confirm')) + end + end + context "when coupon code is applied" do let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') } diff --git a/frontend/spec/controllers/spree/orders_controller_spec.rb b/frontend/spec/controllers/spree/orders_controller_spec.rb index 0a5a4ac1a4f..9191f1ebb56 100644 --- a/frontend/spec/controllers/spree/orders_controller_spec.rb +++ b/frontend/spec/controllers/spree/orders_controller_spec.rb @@ -133,6 +133,18 @@ let(:order) { create(:order_with_line_items, state: 'cart') } let(:coupon_code) { "coupon_code" } + context "when coupon code is empty" do + let(:coupon_code) { "" } + + it 'does not try to apply coupon code' do + expect(Spree::PromotionHandler::Coupon).not_to receive :new + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + + expect(response).to redirect_to(spree.cart_path) + end + end + context "when coupon code is applied" do let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: nil, success: 'Coupon Applied!') } From 2daa602febf6183f172f263d72c86d9bbc95afce Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Sat, 14 Oct 2017 20:18:30 +0200 Subject: [PATCH 4/7] Duplicate apply_coupon_code into controllers that use it This method is used into Checkout and Order controllers, but they need some different behavior which now would be hard to add in a non-hacky way. --- .../controllers/spree/checkout_controller.rb | 15 +++++++++++++++ .../app/controllers/spree/orders_controller.rb | 15 +++++++++++++++ .../app/controllers/spree/store_controller.rb | 18 ------------------ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/frontend/app/controllers/spree/checkout_controller.rb b/frontend/app/controllers/spree/checkout_controller.rb index 987b33026f8..1e44350c086 100644 --- a/frontend/app/controllers/spree/checkout_controller.rb +++ b/frontend/app/controllers/spree/checkout_controller.rb @@ -166,6 +166,21 @@ def completion_route spree.order_path(@order) end + def apply_coupon_code + if params[:order] && params[:order][:coupon_code].present? + @order.coupon_code = params[:order][:coupon_code] + + handler = PromotionHandler::Coupon.new(@order).apply + + if handler.error.present? + flash.now[:error] = handler.error + respond_with(@order) { |format| format.html { render :edit } } && return + elsif handler.success + flash[:success] = handler.success + end + end + end + def setup_for_current_state method_name = :"before_#{@order.state}" send(method_name) if respond_to?(method_name, true) diff --git a/frontend/app/controllers/spree/orders_controller.rb b/frontend/app/controllers/spree/orders_controller.rb index e6b1e38a853..013f1195a3b 100644 --- a/frontend/app/controllers/spree/orders_controller.rb +++ b/frontend/app/controllers/spree/orders_controller.rb @@ -120,5 +120,20 @@ def assign_order redirect_to(root_path) && return end end + + def apply_coupon_code + if params[:order] && params[:order][:coupon_code].present? + @order.coupon_code = params[:order][:coupon_code] + + handler = PromotionHandler::Coupon.new(@order).apply + + if handler.error.present? + flash.now[:error] = handler.error + respond_with(@order) { |format| format.html { render :edit } } && return + elsif handler.success + flash[:success] = handler.success + end + end + end end end diff --git a/frontend/app/controllers/spree/store_controller.rb b/frontend/app/controllers/spree/store_controller.rb index f4edb6b0e90..af47daffbd8 100644 --- a/frontend/app/controllers/spree/store_controller.rb +++ b/frontend/app/controllers/spree/store_controller.rb @@ -16,24 +16,6 @@ def cart_link private - # This method is placed here so that the CheckoutController - # and OrdersController can both reference it (or any other controller - # which needs it) - def apply_coupon_code - if params[:order] && params[:order][:coupon_code].present? - @order.coupon_code = params[:order][:coupon_code] - - handler = PromotionHandler::Coupon.new(@order).apply - - if handler.error.present? - flash.now[:error] = handler.error - respond_with(@order) { |format| format.html { render :edit } } && return - elsif handler.success - flash[:success] = handler.success - end - end - end - def config_locale Spree::Frontend::Config[:locale] end From c7c47b233bbf4bfc144f0e5598758ccda0a74c36 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Sat, 14 Oct 2017 21:13:06 +0200 Subject: [PATCH 5/7] Setup checkout step view correctly on coupon errors When coupon code handler has errors checkout controller needs an extra setup for current step views or it will not render correctly. --- .../controllers/spree/checkout_controller.rb | 1 + .../spree/checkout_controller_spec.rb | 9 +++++ frontend/spec/features/coupon_code_spec.rb | 39 +++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/frontend/app/controllers/spree/checkout_controller.rb b/frontend/app/controllers/spree/checkout_controller.rb index 1e44350c086..58c340d850d 100644 --- a/frontend/app/controllers/spree/checkout_controller.rb +++ b/frontend/app/controllers/spree/checkout_controller.rb @@ -173,6 +173,7 @@ def apply_coupon_code handler = PromotionHandler::Coupon.new(@order).apply if handler.error.present? + setup_for_current_state flash.now[:error] = handler.error respond_with(@order) { |format| format.html { render :edit } } && return elsif handler.success diff --git a/frontend/spec/controllers/spree/checkout_controller_spec.rb b/frontend/spec/controllers/spree/checkout_controller_spec.rb index 6f46a7636fd..9a079275134 100644 --- a/frontend/spec/controllers/spree/checkout_controller_spec.rb +++ b/frontend/spec/controllers/spree/checkout_controller_spec.rb @@ -514,6 +514,15 @@ def post_address context "when coupon code is not applied" do let(:promotion_handler) { instance_double('Spree::PromotionHandler::Coupon', error: 'Some error', success: false) } + it "setups the current step correctly before rendering" do + expect(Spree::PromotionHandler::Coupon) + .to receive_message_chain(:new, :apply) + .and_return(promotion_handler) + expect(controller).to receive(:setup_for_current_state) + + put :update, params: { state: order.state, order: { coupon_code: coupon_code } } + end + it "render cart with coupon error" do expect(Spree::PromotionHandler::Coupon) .to receive_message_chain(:new, :apply) diff --git a/frontend/spec/features/coupon_code_spec.rb b/frontend/spec/features/coupon_code_spec.rb index ea77a529821..465ef51bfac 100644 --- a/frontend/spec/features/coupon_code_spec.rb +++ b/frontend/spec/features/coupon_code_spec.rb @@ -80,6 +80,45 @@ def create_basic_coupon_promotion(code) end end end + + context 'as logged user' do + let!(:user) { create(:user, bill_address: create(:address), ship_address: create(:address)) } + + before do + allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user) + allow_any_instance_of(Spree::OrdersController).to receive_messages(try_spree_current_user: user) + end + + context 'with saved credit card' do + let(:bogus) { create(:credit_card_payment_method) } + let!(:credit_card) do + create(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: "BGS-WEFWF") + end + + before do + user.wallet.add(credit_card) + + visit spree.root_path + click_link "RoR Mug" + click_button "add-to-cart-button" + # To Cart + click_button "Checkout" + # To shipping method screen, address is auto-populated + # with user's saved addresses + click_button "Save and Continue" + # To payment screen + click_button "Save and Continue" + end + + it "shows wallet payments on coupon code errors" do + fill_in "order_coupon_code", with: "coupon_codes_rule_man" + click_button "Save and Continue" + + expect(page).to have_content("The coupon code you entered doesn't exist. Please try again.") + expect(page).to have_content("Use an existing card") + end + end + end end # CheckoutController From 4497ef5c15d5a9f0d62aec0cceb3d5b83f603320 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Sat, 21 Oct 2017 15:34:25 +0200 Subject: [PATCH 6/7] Move checkout coupon code section into summary This commit moves the coupon code application section of checkout into the summary box, still visible in payment step only. It also wraps the coupon code input + button into a real form so it still works if, for some reason, JS is not working, falling back to submitting a simple order form for now. --- .../spree/frontend/checkout/coupon-code.js | 1 + .../spree/frontend/screen.css.scss | 28 ++++++++++++++++++- .../controllers/spree/checkout_controller.rb | 5 ++-- .../spree/checkout/_coupon_code.html.erb | 12 ++++++++ .../views/spree/checkout/_payment.html.erb | 10 ------- .../views/spree/checkout/_summary.html.erb | 4 +++ .../spree/checkout_controller_spec.rb | 2 +- frontend/spec/features/coupon_code_spec.rb | 10 +++---- 8 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 frontend/app/views/spree/checkout/_coupon_code.html.erb diff --git a/frontend/app/assets/javascripts/spree/frontend/checkout/coupon-code.js b/frontend/app/assets/javascripts/spree/frontend/checkout/coupon-code.js index 1b086d87477..48eb66cf001 100644 --- a/frontend/app/assets/javascripts/spree/frontend/checkout/coupon-code.js +++ b/frontend/app/assets/javascripts/spree/frontend/checkout/coupon-code.js @@ -1,4 +1,5 @@ Spree.onCouponCodeApply = function(e) { + e.preventDefault(); var couponCodeField = $("#order_coupon_code"); var couponCode = $.trim(couponCodeField.val()); if (couponCode === "") { diff --git a/frontend/app/assets/stylesheets/spree/frontend/screen.css.scss b/frontend/app/assets/stylesheets/spree/frontend/screen.css.scss index 5a78fac412e..bba385519bc 100644 --- a/frontend/app/assets/stylesheets/spree/frontend/screen.css.scss +++ b/frontend/app/assets/stylesheets/spree/frontend/screen.css.scss @@ -948,9 +948,35 @@ p[data-hook="use_billing"] { padding: 5px; } +.coupon-code { + margin-top: 20px; + padding: 10px; + + form { + display: flex; + flex-flow: row wrap; + } + + label { + flex: 1 100%; + text-align: left; + } + + input[type="text"] { + flex: 3 0; + width: 100%; + margin-right: 5px; + } + + &-apply-button { + white-space: nowrap; + } +} + #coupon_status { + margin-top: 10px; font-weight: bold; - font-size: 125%; + font-size: 100%; &.success { color: $c_green; } diff --git a/frontend/app/controllers/spree/checkout_controller.rb b/frontend/app/controllers/spree/checkout_controller.rb index 58c340d850d..312efe835d8 100644 --- a/frontend/app/controllers/spree/checkout_controller.rb +++ b/frontend/app/controllers/spree/checkout_controller.rb @@ -173,12 +173,13 @@ def apply_coupon_code handler = PromotionHandler::Coupon.new(@order).apply if handler.error.present? - setup_for_current_state flash.now[:error] = handler.error - respond_with(@order) { |format| format.html { render :edit } } && return elsif handler.success flash[:success] = handler.success end + + setup_for_current_state + respond_with(@order) { |format| format.html { render :edit } } && return end end diff --git a/frontend/app/views/spree/checkout/_coupon_code.html.erb b/frontend/app/views/spree/checkout/_coupon_code.html.erb new file mode 100644 index 00000000000..795260c13a5 --- /dev/null +++ b/frontend/app/views/spree/checkout/_coupon_code.html.erb @@ -0,0 +1,12 @@ +
+ <%= form_for order, url: update_checkout_path(order.state) do |form| %> + <%= form.label :coupon_code %> + <%= form.text_field :coupon_code, placeholder: :coupon_code %> + + + <% end %> + +
+
diff --git a/frontend/app/views/spree/checkout/_payment.html.erb b/frontend/app/views/spree/checkout/_payment.html.erb index 8f182c06802..07b19a54f5f 100644 --- a/frontend/app/views/spree/checkout/_payment.html.erb +++ b/frontend/app/views/spree/checkout/_payment.html.erb @@ -56,16 +56,6 @@ <% end %>
-

- <%= form.label :coupon_code %> - <%= form.text_field :coupon_code %> - - -

-
- diff --git a/frontend/app/views/spree/checkout/_summary.html.erb b/frontend/app/views/spree/checkout/_summary.html.erb index 8a91261f783..233298213ae 100644 --- a/frontend/app/views/spree/checkout/_summary.html.erb +++ b/frontend/app/views/spree/checkout/_summary.html.erb @@ -70,3 +70,7 @@ + +<% if order.state == 'payment' %> + <%= render 'coupon_code', order: order %> +<% end %> diff --git a/frontend/spec/controllers/spree/checkout_controller_spec.rb b/frontend/spec/controllers/spree/checkout_controller_spec.rb index 9a079275134..d764a030f17 100644 --- a/frontend/spec/controllers/spree/checkout_controller_spec.rb +++ b/frontend/spec/controllers/spree/checkout_controller_spec.rb @@ -507,7 +507,7 @@ def post_address put :update, params: { state: order.state, order: { coupon_code: coupon_code } } - expect(response).to redirect_to(spree.checkout_state_path('confirm')) + expect(response).to render_template :edit expect(flash.now[:success]).to eq('Coupon Applied!') end diff --git a/frontend/spec/features/coupon_code_spec.rb b/frontend/spec/features/coupon_code_spec.rb index 465ef51bfac..fc95390be56 100644 --- a/frontend/spec/features/coupon_code_spec.rb +++ b/frontend/spec/features/coupon_code_spec.rb @@ -59,23 +59,23 @@ def create_basic_coupon_promotion(code) it "informs about an invalid coupon code" do fill_in "order_coupon_code", with: "coupon_codes_rule_man" - click_button "Save and Continue" + click_button "Apply Code" expect(page).to have_content(I18n.t('spree.coupon_code_not_found')) end it "can enter an invalid coupon code, then a real one" do fill_in "order_coupon_code", with: "coupon_codes_rule_man" - click_button "Save and Continue" + click_button "Apply Code" expect(page).to have_content(I18n.t('spree.coupon_code_not_found')) fill_in "order_coupon_code", with: "onetwo" - click_button "Save and Continue" + click_button "Apply Code" expect(page).to have_content("Promotion (Onetwo) -$10.00") end context "with a promotion" do it "applies a promotion to an order" do fill_in "order_coupon_code", with: "onetwo" - click_button "Save and Continue" + click_button "Apply Code" expect(page).to have_content("Promotion (Onetwo) -$10.00") end end @@ -112,7 +112,7 @@ def create_basic_coupon_promotion(code) it "shows wallet payments on coupon code errors" do fill_in "order_coupon_code", with: "coupon_codes_rule_man" - click_button "Save and Continue" + click_button "Apply Code" expect(page).to have_content("The coupon code you entered doesn't exist. Please try again.") expect(page).to have_content("Use an existing card") From 212287a97c1b14e59c173b80a37f396376e163eb Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 11 May 2018 11:02:01 +0200 Subject: [PATCH 7/7] Use permitted attributes to retrieve coupon code --- frontend/app/controllers/spree/checkout_controller.rb | 4 ++-- frontend/app/controllers/spree/orders_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/app/controllers/spree/checkout_controller.rb b/frontend/app/controllers/spree/checkout_controller.rb index 312efe835d8..98261af11e3 100644 --- a/frontend/app/controllers/spree/checkout_controller.rb +++ b/frontend/app/controllers/spree/checkout_controller.rb @@ -167,8 +167,8 @@ def completion_route end def apply_coupon_code - if params[:order] && params[:order][:coupon_code].present? - @order.coupon_code = params[:order][:coupon_code] + if update_params[:coupon_code].present? + @order.coupon_code = update_params[:coupon_code] handler = PromotionHandler::Coupon.new(@order).apply diff --git a/frontend/app/controllers/spree/orders_controller.rb b/frontend/app/controllers/spree/orders_controller.rb index 013f1195a3b..d88028d9242 100644 --- a/frontend/app/controllers/spree/orders_controller.rb +++ b/frontend/app/controllers/spree/orders_controller.rb @@ -122,8 +122,8 @@ def assign_order end def apply_coupon_code - if params[:order] && params[:order][:coupon_code].present? - @order.coupon_code = params[:order][:coupon_code] + if order_params[:coupon_code].present? + @order.coupon_code = order_params[:coupon_code] handler = PromotionHandler::Coupon.new(@order).apply