Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate that Refunds have an associated Payment #2130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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