OSDN Git Service

Allow filtering by issues with no assigned... assignee
authorRobert Speicher <rspeicher@gmail.com>
Tue, 14 Aug 2012 00:49:18 +0000 (20:49 -0400)
committerRobert Speicher <rspeicher@gmail.com>
Tue, 14 Aug 2012 00:49:18 +0000 (20:49 -0400)
Continues #1222

app/controllers/issues_controller.rb
app/helpers/issues_helper.rb
app/views/issues/index.html.haml
spec/requests/issues_spec.rb

index e7396be..889a7d9 100644 (file)
@@ -144,14 +144,19 @@ class IssuesController < ApplicationController
               else @project.issues.opened
               end
 
-    @issues = @issues.where(assignee_id: params[:assignee_id]) if params[:assignee_id].present?
     @issues = @issues.tagged_with(params[:label_name]) if params[:label_name].present?
     @issues = @issues.includes(:author, :project).order("updated_at")
 
+    # Filter by specific assignee_id (or lack thereof)?
+    if params[:assignee_id].present?
+      @issues = @issues.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id]))
+    end
+
     # Filter by specific milestone_id (or lack thereof)?
     if params[:milestone_id].present?
       @issues = @issues.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id]))
     end
+
     @issues
   end
 
index 53ceec4..452611f 100644 (file)
@@ -42,4 +42,8 @@ module IssuesHelper
   def unassigned_milestone
     OpenStruct.new(id: 0, title: 'Unspecified')
   end
+
+  def unassigned_issue
+    OpenStruct.new(id: 0, name: 'Unassigned')
+  end
 end
index 5ce097f..fbc2fe7 100644 (file)
@@ -49,7 +49,7 @@
         .right
           = form_tag project_issues_path(@project), method: :get, class: :right  do
             = select_tag(:label_name, options_for_select(issue_tags, params[:label_name]), prompt: "Labels")
-            = select_tag(:assignee_id, options_from_collection_for_select(@project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee")
+            = select_tag(:assignee_id, options_from_collection_for_select([unassigned_issue] + @project.users.all, "id", "name", params[:assignee_id]), prompt: "Assignee")
             = select_tag(:milestone_id, options_from_collection_for_select([unassigned_milestone] + @project.milestones.order("id desc").all, "id", "title", params[:milestone_id]), prompt: "Milestone")
             = hidden_field_tag :f, params[:f]
         .clearfix
index 1acac7d..15ee5d1 100644 (file)
@@ -102,6 +102,7 @@ describe "Issues" do
 
       @issue = Issue.first
       @issue.milestone = Factory(:milestone, project: project)
+      @issue.assignee = nil
       @issue.save
     end
 
@@ -120,5 +121,21 @@ describe "Issues" do
       page.should_not have_content 'barbaz'
       page.should_not have_content 'gitlab'
     end
+
+    it "should allow filtering by issues with no specified assignee" do
+      visit project_issues_path(project, assignee_id: '0')
+
+      page.should have_content 'foobar'
+      page.should_not have_content 'barbaz'
+      page.should_not have_content 'gitlab'
+    end
+
+    it "should allow filtering by a specified assignee" do
+      visit project_issues_path(project, assignee_id: @user.id)
+
+      page.should_not have_content 'foobar'
+      page.should have_content 'barbaz'
+      page.should have_content 'gitlab'
+    end
   end
 end