diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index 4a4d1f0aca..1ccf66f27c 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -226,8 +226,9 @@ class SplitCheckoutController < ::BaseController adjustment = voucher.create_adjustment(voucher.code, @order) - if adjustment.nil? + if !adjustment.valid? @order.errors.add(:voucher, I18n.t('split_checkout.errors.add_voucher_error')) + adjustment.errors.each { |error| @order.errors.import(error) } return false end diff --git a/spec/controllers/split_checkout_controller_spec.rb b/spec/controllers/split_checkout_controller_spec.rb index db3571d81b..774be4ca76 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -279,14 +279,17 @@ describe SplitCheckoutController, type: :controller do context "when adding fails" do it "returns 422 and an error message" do - # Makes adding the voucher fails - allow(voucher).to receive(:create_adjustment).and_return(nil) + # Create a non valid adjustment + adjustment = build(:adjustment, label: nil) + allow(voucher).to receive(:create_adjustment).and_return(adjustment) allow(Voucher).to receive(:find_by).and_return(voucher) put :update, params: params expect(response.status).to eq 422 - expect(flash[:error]).to match "There was an error while adding the voucher" + expect(flash[:error]).to match( + "There was an error while adding the voucher and Label can't be blank" + ) end end