Fix extra nil added to assigned investment IDs
When `valuator_group` was `nil`, `[valuator_group&.investment_ids]` is evaluated to `nil`, and so we were adding an extra element to the array. We could add a `compact` call to the resulting array, but I find it easier to convert `nil` to an array using `to_a`.
This commit is contained in:
@@ -18,7 +18,7 @@ class Valuator < ApplicationRecord
|
||||
end
|
||||
|
||||
def assigned_investment_ids
|
||||
investment_ids + [valuator_group&.investment_ids].flatten
|
||||
investment_ids + valuator_group&.investment_ids.to_a
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -28,8 +28,8 @@ describe Valuator do
|
||||
investment2.valuators << valuator
|
||||
|
||||
assigned_investment_ids = valuator.assigned_investment_ids
|
||||
expect(assigned_investment_ids).to include investment1.id
|
||||
expect(assigned_investment_ids).to include investment2.id
|
||||
|
||||
expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
|
||||
expect(assigned_investment_ids).not_to include investment3.id
|
||||
end
|
||||
|
||||
@@ -45,8 +45,8 @@ describe Valuator do
|
||||
investment2.valuator_groups << group
|
||||
|
||||
assigned_investment_ids = valuator.assigned_investment_ids
|
||||
expect(assigned_investment_ids).to include investment1.id
|
||||
expect(assigned_investment_ids).to include investment2.id
|
||||
|
||||
expect(assigned_investment_ids).to match_array [investment1.id, investment2.id]
|
||||
expect(assigned_investment_ids).not_to include investment3.id
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user