Rename NoMilestone to Milestone::None

Also refactors IssuableFinder to avoid redundant title check.
This commit is contained in:
Robert Speicher 2015-06-28 16:12:32 -04:00
parent cfd813402d
commit d00cb00d6b
6 changed files with 10 additions and 24 deletions

View file

@ -10,7 +10,7 @@
# state: 'open' or 'closed' or 'all'
# group_id: integer
# project_id: integer
# milestone_id: integer
# milestone_title: string
# assignee_id: integer
# search: string
# label_name: string
@ -76,7 +76,7 @@ class IssuableFinder
return @milestones if defined?(@milestones)
@milestones =
if milestones? && params[:milestone_title] != NoMilestone.title
if milestones? && params[:milestone_title] != Milestone::None.title
Milestone.where(title: params[:milestone_title])
else
nil
@ -183,12 +183,7 @@ class IssuableFinder
def by_milestone(items)
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))
else
items = items.where(milestone_id: NoMilestone.id)
end
items = items.where(milestone_id: milestones.try(:pluck, :id))
end
items

View file

@ -29,7 +29,7 @@ module MilestonesHelper
end.active
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])
end

View file

@ -14,6 +14,10 @@
#
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 Sortable

View file

@ -1,13 +0,0 @@
# 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

View file

@ -13,7 +13,7 @@ feature 'Issue filtering by Milestone' do
create(:issue, project: project)
visit_issues
filter_by_milestone(NoMilestone.title)
filter_by_milestone(Milestone::None.title)
expect(page).to have_css('.issue-title', count: 1)
end

View file

@ -13,7 +13,7 @@ feature 'Merge Request filtering by Milestone' do
create(:merge_request, :simple, source_project: project)
visit_merge_requests
filter_by_milestone(NoMilestone.title)
filter_by_milestone(Milestone::None.title)
expect(page).to have_css('.merge-request-title', count: 1)
end