Skip to content

Refactor PaymentsController for current_user and enhance validations#87

Merged
rsmoke merged 4 commits intomainfrom
staging
Mar 23, 2026
Merged

Refactor PaymentsController for current_user and enhance validations#87
rsmoke merged 4 commits intomainfrom
staging

Conversation

@rsmoke
Copy link
Copy Markdown
Member

@rsmoke rsmoke commented Mar 23, 2026

This pull request refactors how the total application cost is calculated throughout the codebase by introducing a new subscription_cost method and updating the total_cost calculation to include the subscription fee when applicable. The changes ensure that all relevant controllers, admin views, and models consistently use the new logic, and adds comprehensive tests for these behaviors.

Key changes include:

Application Model Logic

  • Added a new subscription_cost method to Application, which returns the current subscription cost if the user has selected a subscription, or zero otherwise. The total_cost method now includes this subscription cost in its calculation.
  • Updated the balance_due_with_batch method to also include the subscription cost when computing the total.

Controller and Admin Usage

  • Refactored all usages of manual cost summing in ApplicationsController, PaymentsController, and app/admin/applications.rb to use the new total_cost and subscription_cost methods from the model, ensuring consistency and reducing code duplication.

Testing

  • Added and updated tests in application_spec.rb to cover the new subscription_cost logic, the updated total_cost calculation, and balance computations that include subscription fees.

rsmoke added 4 commits March 23, 2026 13:22
Updated the Application model to incorporate subscription costs in total cost and balance due calculations. Refactored the PaymentsController and ActiveAdmin views to utilize the new total_cost method, ensuring consistent handling of subscription scenarios across the application. Added tests to verify correct computation of total costs when subscriptions are selected.
Implemented new test cases for the `subscription_cost` method in the Application model to ensure accurate cost calculations based on subscription selection. The tests cover scenarios for unselected subscriptions, selected subscriptions with configured costs, and cases with missing settings. This enhances the overall test coverage for application cost calculations.
Updated the `total_cost` method in the PaymentsController to handle potential errors when computing the total cost for applications. Added logging for exceptions to aid in debugging, ensuring that the method returns a default value of 0.0 in case of errors. This enhancement improves the robustness of payment calculations.
Enhance application cost calculations to include subscription fees
@rsmoke rsmoke merged commit 267760d into main Mar 23, 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.

1 participant