Skip to content

Commit

Permalink
Merge pull request #2130 from melissacarbone/ensure_validation_errors…
Browse files Browse the repository at this point in the history
…_are_returned_for_refund

Ensure validation error is returned when creating a refund without a …
  • Loading branch information
jhawthorn authored Aug 21, 2017
2 parents 39c8fd7 + 256cf4a commit d1441be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def create_log_entry
end

def amount_is_less_than_or_equal_to_allowed_amount
if amount > payment.credit_allowed
if payment && amount > payment.credit_allowed
errors.add(:amount, :greater_than_allowed)
end
end
Expand Down
8 changes: 8 additions & 0 deletions core/spec/models/spree/refund_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@
}
end
end

context 'when payment is not present' do
let(:refund) { build(:refund, payment: nil) }

it 'returns a validation error' do
expect { refund.save! }.to raise_error 'Validation failed: Payment can\'t be blank'
end
end
end

describe 'total_amount_reimbursed_for' do
Expand Down

0 comments on commit d1441be

Please sign in to comment.