Skip to content

Add account_type validation for manual payments in Payment model#77

Merged
rsmoke merged 3 commits intomainfrom
staging
Mar 17, 2026
Merged

Add account_type validation for manual payments in Payment model#77
rsmoke merged 3 commits intomainfrom
staging

Conversation

@rsmoke
Copy link
Copy Markdown
Member

@rsmoke rsmoke commented Mar 17, 2026

This pull request strengthens validation for the account_type field in the Payment model, ensuring that it is required for manually entered payments. It also updates the admin interface and adds comprehensive tests to cover these scenarios.

Validation improvements for manual payments:

  • Added a conditional validation to require account_type when transaction_type is "ManuallyEntered" in the Payment model.
  • Introduced the manual_entry? helper method to encapsulate the logic for identifying manual entries.

Admin interface update:

  • Updated the account_type field in the ActiveAdmin payments form to be marked as required.

Test coverage enhancements:

  • Added model specs to verify that account_type is required for manual payments and optional otherwise.
  • Added a controller spec to ensure that payments can still be created via the gateway even if account_type is missing, as long as the payment is not manually entered.

rsmoke added 2 commits March 17, 2026 11:14
Enhance the Payment model by adding a presence validation for account_type when the transaction_type is 'ManuallyEntered'. Introduce a manual_entry? method to support this validation. Update the corresponding RSpec tests to ensure proper validation behavior for manual entries.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens Payment model validation so account_type is required for manually entered payments (transaction_type == "ManuallyEntered"), aligns the ActiveAdmin manual-payment form with that requirement, and adds specs to cover the updated behavior.

Changes:

  • Added conditional account_type presence validation for manual payments and introduced a manual_entry? predicate.
  • Updated ActiveAdmin Payment form to mark account_type as required for manual entry.
  • Added/expanded specs to verify manual-payment validation and ensure gateway-created payments still work without account_type.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
spec/models/payment_spec.rb Adds validation specs for manual payments requiring account_type.
spec/controllers/payments_controller_spec.rb Adds a controller spec ensuring gateway payments can be created without account_type.
app/models/payment.rb Introduces manual_entry? and uses it to conditionally require account_type.
app/admin/payments.rb Marks account_type as required in the ActiveAdmin manual-payment form.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/models/payment_spec.rb
Comment thread app/models/payment.rb
…ry? method

Update the manual_payment_decimal and check_manual_amount methods to utilize the new manual_entry? method for improved readability. Add a new test case to validate behavior when transaction_type is not 'ManuallyEntered'.
@rsmoke rsmoke merged commit 77d4bfe into main Mar 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants