Fix duplicate records in investments by tag

When an investment had been assigned a user tag and a valuation tag with
the same name, it appeared twice when filtering by tag.

This is because by design, in order to provide compatibility with scopes
using "select" or "distinct", the method `tagged_with` doesn't select
unique records.

Forcing the query to return unique records solves the issue.
This commit is contained in:
Javi Martín
2020-04-08 14:36:04 +02:00
parent b5682362b7
commit 958d373247
4 changed files with 27 additions and 2 deletions

View File

@@ -0,0 +1,17 @@
require "rails_helper"
describe BudgetExecutionsHelper do
describe "#options_for_milestone_tags" do
let(:budget) { create(:budget) }
it "does not return duplicate records for tags in different contexts" do
create(:budget_investment, :winner, budget: budget, milestone_tag_list: ["Multiple"])
create(:budget_investment, :winner, budget: budget, milestone_tag_list: ["Multiple"])
create(:budget_investment, :winner, budget: budget, milestone_tag_list: ["Dup"], tag_list: ["Dup"])
@budget = budget
expect(options_for_milestone_tags).to eq [["Dup (1)", "Dup"], ["Multiple (2)", "Multiple"]]
end
end
end