Merge pull request #3967 from consul/duplicate_by_tag
Fix duplicate records in investments by tag
This commit is contained in:
@@ -5,7 +5,7 @@ module BudgetExecutionsHelper
|
||||
|
||||
def options_for_milestone_tags
|
||||
@budget.investments_milestone_tags.map do |tag|
|
||||
["#{tag} (#{@budget.investments.winners.tagged_with(tag).count})", tag]
|
||||
["#{tag} (#{@budget.investments.winners.by_tag(tag).count})", tag]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ class Budget
|
||||
scope :by_group, ->(group_id) { where(group_id: group_id) }
|
||||
scope :by_heading, ->(heading_id) { where(heading_id: heading_id) }
|
||||
scope :by_admin, ->(admin_id) { where(administrator_id: admin_id) }
|
||||
scope :by_tag, ->(tag_name) { tagged_with(tag_name) }
|
||||
scope :by_tag, ->(tag_name) { tagged_with(tag_name).distinct }
|
||||
|
||||
scope :for_render, -> { includes(:heading) }
|
||||
|
||||
|
||||
17
spec/helpers/budget_executions_helper_spec.rb
Normal file
17
spec/helpers/budget_executions_helper_spec.rb
Normal 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
|
||||
@@ -796,6 +796,14 @@ describe Budget::Investment do
|
||||
|
||||
expect(investment.valuation_tag_list).to match_array(%w[Code Test Refactor])
|
||||
end
|
||||
|
||||
describe ".by_tag" do
|
||||
it "does not return duplicate records for tags in different contexts" do
|
||||
investment = create(:budget_investment, tag_list: ["Same"], valuation_tag_list: ["Same"])
|
||||
|
||||
expect(Budget::Investment.by_tag("Same")).to eq [investment]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user