diff --git a/app/controllers/solidus_paypal_braintree/transactions_controller.rb b/app/controllers/solidus_paypal_braintree/transactions_controller.rb index 2423c7c7..9ed3ce93 100644 --- a/app/controllers/solidus_paypal_braintree/transactions_controller.rb +++ b/app/controllers/solidus_paypal_braintree/transactions_controller.rb @@ -1,4 +1,6 @@ class SolidusPaypalBraintree::TransactionsController < Spree::StoreController + class InvalidTransactionError < StandardError; end + PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [ :nonce, :payment_type, @@ -23,7 +25,8 @@ def create return redirect_to spree.checkout_state_path(import.order.state) end else - render text: transaction.errors + raise InvalidTransactionError, + "Transaction invalid: #{transaction.errors.full_messages.join(', ')}" end end diff --git a/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb b/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb index c3d63080..140271fa 100644 --- a/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb +++ b/spec/controllers/solidus_paypal_braintree/transactions_controller_spec.rb @@ -78,9 +78,11 @@ context "when the transaction is invalid" do before { params[:transaction].delete(:phone) } - it "displays the errors object" do - subject - expect(response.body).to match(/^#$/) + it "raises an error" do + expect { post_create }.to raise_error( + SolidusPaypalBraintree::TransactionsController::InvalidTransactionError, + "Transaction invalid: Phone can't be blank" + ) end end end