Return the persisted line in add_investment
This method was returning a boolean value and caused a `Naming/PredicateMethod` when upgrading rubocop. So, instead, we're returning the created line when it was successfully created, and `nil` when it wasn't. Having said that, I'm not sure why we added the `.persisted?` back in commit3eb22ab7bsince as far as I can tell we don't use the return value for anything. The test added in commitda43e9e2efor this change passes if we simply return `lines.create(investment: investment)`. For now I'm leaving the `persisted?` check just in case, but removing it might be fine.
This commit is contained in:
@@ -10,7 +10,9 @@ class Budget
|
||||
has_many :headings, -> { distinct }, through: :groups
|
||||
|
||||
def add_investment(investment)
|
||||
lines.create(investment: investment).persisted?
|
||||
line = lines.create(investment: investment)
|
||||
|
||||
line if line.persisted?
|
||||
end
|
||||
|
||||
def total_amount_spent
|
||||
|
||||
Reference in New Issue
Block a user