Commit b1ea0b3c01f6d68834957a5f88b04329651802cc
1 parent
28d90385
Exists in
master
and in
4 other branches
Allow filtering by issues with no assigned milestone
Closes #1222
Showing
4 changed files
with
44 additions
and
2 deletions
Show diff stats
app/controllers/issues_controller.rb
... | ... | @@ -145,9 +145,13 @@ class IssuesController < ApplicationController |
145 | 145 | end |
146 | 146 | |
147 | 147 | @issues = @issues.where(assignee_id: params[:assignee_id]) if params[:assignee_id].present? |
148 | - @issues = @issues.where(milestone_id: params[:milestone_id]) if params[:milestone_id].present? | |
149 | 148 | @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present? |
150 | 149 | @issues = @issues.includes(:author, :project).order("updated_at") |
150 | + | |
151 | + # Filter by specific milestone_id (or lack thereof)? | |
152 | + if params[:milestone_id].present? | |
153 | + @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) | |
154 | + end | |
151 | 155 | @issues |
152 | 156 | end |
153 | 157 | ... | ... |
app/helpers/issues_helper.rb
... | ... | @@ -36,4 +36,10 @@ module IssuesHelper |
36 | 36 | def issue_tags |
37 | 37 | @project.issues.tag_counts_on(:labels).map(&:name) |
38 | 38 | end |
39 | + | |
40 | + # Returns a fake Milestone-like object that can be used in a | |
41 | + # <tt>select_tag</tt> to allow filtering by issues with no assigned milestone | |
42 | + def unassigned_milestone | |
43 | + OpenStruct.new(id: 0, title: 'Unspecified') | |
44 | + end | |
39 | 45 | end | ... | ... |
app/views/issues/index.html.haml
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | = form_tag project_issues_path(@project), method: :get, class: :right do |
51 | 51 | = select_tag(:label_name, options_for_select(issue_tags, params[:label_name]), prompt: "Labels") |
52 | 52 | = select_tag(:assignee_id, options_from_collection_for_select(@project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee") |
53 | - = select_tag(:milestone_id, options_from_collection_for_select(@project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") | |
53 | + = select_tag(:milestone_id, options_from_collection_for_select([unassigned_milestone] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone") | |
54 | 54 | = hidden_field_tag :f, params[:f] |
55 | 55 | .clearfix |
56 | 56 | ... | ... |
spec/requests/issues_spec.rb
... | ... | @@ -89,4 +89,36 @@ describe "Issues" do |
89 | 89 | page.should have_content 'gitlab' |
90 | 90 | end |
91 | 91 | end |
92 | + | |
93 | + describe "Filter issue" do | |
94 | + before do | |
95 | + ['foobar', 'barbaz', 'gitlab'].each do |title| | |
96 | + @issue = Factory :issue, | |
97 | + author: @user, | |
98 | + assignee: @user, | |
99 | + project: project, | |
100 | + title: title | |
101 | + end | |
102 | + | |
103 | + @issue = Issue.first | |
104 | + @issue.milestone = Factory(:milestone, project: project) | |
105 | + @issue.save | |
106 | + end | |
107 | + | |
108 | + it "should allow filtering by issues with no specified milestone" do | |
109 | + visit project_issues_path(project, milestone_id: '0') | |
110 | + | |
111 | + page.should_not have_content 'foobar' | |
112 | + page.should have_content 'barbaz' | |
113 | + page.should have_content 'gitlab' | |
114 | + end | |
115 | + | |
116 | + it "should allow filtering by a specified milestone" do | |
117 | + visit project_issues_path(project, milestone_id: @issue.milestone.id) | |
118 | + | |
119 | + page.should have_content 'foobar' | |
120 | + page.should_not have_content 'barbaz' | |
121 | + page.should_not have_content 'gitlab' | |
122 | + end | |
123 | + end | |
92 | 124 | end | ... | ... |