Fix: NoMethodError (MAYBE-RAILS-D1) #1688
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This error occurs because the
weight
method in Account::Holding attempts to calculate a percentage based on the account's balance, but the account association is nil in the test data. The original intent of the test was to verify that balance calculation works correctly with investment holdings, but it failed to properly set up the test data with the required account association.Key changes made:
account: @account
to each Account::Holding.new call in the test data setup to ensure the account association is properly setThe test is verifying that:
The fix ensures that when the weight calculation is performed in Account::Holding#weight (which divides amount by account.balance), it has access to a valid account object and its balance. This maintains the original intent of calculating the holding's percentage of the total account value while preventing the nil reference error.
The test itself is part of a comprehensive suite testing balance calculations under various scenarios (transactions, valuations, multi-currency, etc.), and this particular test focuses on investment-specific balance calculations where both cash and security holdings need to be considered.
Tip
You can make revisions or ask questions of Revise.dev by using
/revise
in any comment or review!/revise Add a comment above the method to explain why we're making this change.
/revise Why did you choose to make this change specifically?
Important
If something doesn't look right, click to retry this interaction.