Commit b5132118 authored by Ahmad Sherif's avatar Ahmad Sherif

Ensure milestones passed to GlobalMilestone is an ActiveRecord::Relation

parent b8bfe50a
...@@ -8,7 +8,8 @@ class GlobalMilestone ...@@ -8,7 +8,8 @@ class GlobalMilestone
milestones = milestones.group_by(&:title) milestones = milestones.group_by(&:title)
milestones.map do |title, milestones| milestones.map do |title, milestones|
new(title, milestones) milestones_relation = Milestone.where(id: milestones.map(&:id))
new(title, milestones_relation)
end end
end end
...@@ -61,11 +62,11 @@ class GlobalMilestone ...@@ -61,11 +62,11 @@ class GlobalMilestone
end end
def participants def participants
@participants ||= milestones_relation.includes(:participants).map(&:participants).flatten.compact.uniq @participants ||= milestones.includes(:participants).map(&:participants).flatten.compact.uniq
end end
def labels def labels
@labels ||= GlobalLabel.build_collection(milestones_relation.includes(:labels).map(&:labels).flatten) @labels ||= GlobalLabel.build_collection(milestones.includes(:labels).map(&:labels).flatten)
.sort_by!(&:title) .sort_by!(&:title)
end end
...@@ -89,14 +90,4 @@ class GlobalMilestone ...@@ -89,14 +90,4 @@ class GlobalMilestone
end end
end end
end end
private
def milestones_relation
@milestones_relation ||= if milestones.is_a?(ActiveRecord::Relation)
milestones
else
Milestone.where(id: milestones.map(&:id))
end
end
end end
...@@ -50,8 +50,9 @@ describe GlobalMilestone, models: true do ...@@ -50,8 +50,9 @@ describe GlobalMilestone, models: true do
milestone1_project2, milestone1_project2,
milestone1_project3, milestone1_project3,
] ]
milestones_relation = Milestone.where(id: milestones.map(&:id))
@global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones) @global_milestone = GlobalMilestone.new(milestone1_project1.title, milestones_relation)
end end
it 'has exactly one group milestone' do it 'has exactly one group milestone' do
...@@ -67,7 +68,7 @@ describe GlobalMilestone, models: true do ...@@ -67,7 +68,7 @@ describe GlobalMilestone, models: true do
let(:milestone) { create(:milestone, title: "git / test", project: project1) } let(:milestone) { create(:milestone, title: "git / test", project: project1) }
it 'strips out slashes and spaces' do it 'strips out slashes and spaces' do
global_milestone = GlobalMilestone.new(milestone.title, [milestone]) global_milestone = GlobalMilestone.new(milestone.title, Milestone.where(id: milestone.id))
expect(global_milestone.safe_title).to eq('git-test') expect(global_milestone.safe_title).to eq('git-test')
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment