Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Raise an error when the transaction is invalid
Browse files Browse the repository at this point in the history
Instead of displaying the errors object's to_s, show the actual
validation errors.
  • Loading branch information
Luuk Veenis committed Sep 14, 2016
1 parent f7b0bb6 commit 505fe2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class SolidusPaypalBraintree::TransactionsController < Spree::StoreController
class InvalidTransactionError < StandardError; end

PERMITTED_BRAINTREE_TRANSACTION_PARAMS = [
:nonce,
:payment_type,
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(/^#<ActiveModel::Errors:0x[\w]{14}>$/)
it "raises an error" do
expect { post_create }.to raise_error(
SolidusPaypalBraintree::TransactionsController::InvalidTransactionError,
"Transaction invalid: Phone can't be blank"
)
end
end
end
Expand Down

0 comments on commit 505fe2f

Please sign in to comment.