Commit d00cb00d authored by Robert Speicher's avatar Robert Speicher

Rename NoMilestone to Milestone::None

Also refactors IssuableFinder to avoid redundant title check.
parent cfd81340
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# state: 'open' or 'closed' or 'all' # state: 'open' or 'closed' or 'all'
# group_id: integer # group_id: integer
# project_id: integer # project_id: integer
# milestone_id: integer # milestone_title: string
# assignee_id: integer # assignee_id: integer
# search: string # search: string
# label_name: string # label_name: string
...@@ -76,7 +76,7 @@ class IssuableFinder ...@@ -76,7 +76,7 @@ class IssuableFinder
return @milestones if defined?(@milestones) return @milestones if defined?(@milestones)
@milestones = @milestones =
if milestones? && params[:milestone_title] != NoMilestone.title if milestones? && params[:milestone_title] != Milestone::None.title
Milestone.where(title: params[:milestone_title]) Milestone.where(title: params[:milestone_title])
else else
nil nil
...@@ -183,12 +183,7 @@ class IssuableFinder ...@@ -183,12 +183,7 @@ class IssuableFinder
def by_milestone(items) def by_milestone(items)
if milestones? if milestones?
# `milestone_title` will still be present when "No Milestone" is selected
if params[:milestone_title] != NoMilestone.title
items = items.where(milestone_id: milestones.try(:pluck, :id)) items = items.where(milestone_id: milestones.try(:pluck, :id))
else
items = items.where(milestone_id: NoMilestone.id)
end
end end
items items
......
...@@ -29,7 +29,7 @@ module MilestonesHelper ...@@ -29,7 +29,7 @@ module MilestonesHelper
end.active end.active
grouped_milestones = Milestones::GroupService.new(milestones).execute grouped_milestones = Milestones::GroupService.new(milestones).execute
grouped_milestones.unshift(NoMilestone) grouped_milestones.unshift(Milestone::None)
options_from_collection_for_select(grouped_milestones, 'title', 'title', params[:milestone_title]) options_from_collection_for_select(grouped_milestones, 'title', 'title', params[:milestone_title])
end end
......
...@@ -14,6 +14,10 @@ ...@@ -14,6 +14,10 @@
# #
class Milestone < ActiveRecord::Base class Milestone < ActiveRecord::Base
# Represents a "No Milestone" state used for filtering Issues and Merge
# Requests that have no milestone assigned.
None = Struct.new(:title).new('No Milestone')
include InternalId include InternalId
include Sortable include Sortable
......
# NoMilestone
#
# Represents a "No Milestone" state used for filtering Issues and Merge Requests
# that have no milestone assigned.
class NoMilestone
def self.id
nil
end
def self.title
'No Milestone'
end
end
...@@ -13,7 +13,7 @@ feature 'Issue filtering by Milestone' do ...@@ -13,7 +13,7 @@ feature 'Issue filtering by Milestone' do
create(:issue, project: project) create(:issue, project: project)
visit_issues visit_issues
filter_by_milestone(NoMilestone.title) filter_by_milestone(Milestone::None.title)
expect(page).to have_css('.issue-title', count: 1) expect(page).to have_css('.issue-title', count: 1)
end end
......
...@@ -13,7 +13,7 @@ feature 'Merge Request filtering by Milestone' do ...@@ -13,7 +13,7 @@ feature 'Merge Request filtering by Milestone' do
create(:merge_request, :simple, source_project: project) create(:merge_request, :simple, source_project: project)
visit_merge_requests visit_merge_requests
filter_by_milestone(NoMilestone.title) filter_by_milestone(Milestone::None.title)
expect(page).to have_css('.merge-request-title', count: 1) expect(page).to have_css('.merge-request-title', count: 1)
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