]> source.dussan.org Git - redmine.git/commitdiff
Issue auto complete should return last 10 issues (#31994).
authorGo MAEDA <maeda@farend.jp>
Wed, 11 Sep 2019 06:39:00 +0000 (06:39 +0000)
committerGo MAEDA <maeda@farend.jp>
Wed, 11 Sep 2019 06:39:00 +0000 (06:39 +0000)
Patch by Marius BALTEANU.

git-svn-id: http://svn.redmine.org/redmine/trunk@18449 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/auto_completes_controller.rb
test/functional/auto_completes_controller_test.rb

index f6a1414ad62031b5119fca00791c72ebb4901a26..e83374c9bb3438e50459bf800f60b6f7aca73677 100644 (file)
@@ -25,20 +25,18 @@ class AutoCompletesController < ApplicationController
     q = (params[:q] || params[:term]).to_s.strip
     status = params[:status].to_s
     issue_id = params[:issue_id].to_s
+
+    scope = Issue.cross_project_scope(@project, params[:scope]).visible
+    scope = scope.open(status == 'o') if status.present?
+    scope = scope.where.not(:id => issue_id.to_i) if issue_id.present?
     if q.present?
-      scope = Issue.cross_project_scope(@project, params[:scope]).visible
-      if status.present?
-        scope = scope.open(status == 'o')
-      end
-      if issue_id.present?
-        scope = scope.where.not(:id => issue_id.to_i)
-      end
       if q.match(/\A#?(\d+)\z/)
         issues << scope.find_by_id($1.to_i)
       end
-
       issues += scope.like(q).order(:id => :desc).limit(10).to_a
       issues.compact!
+    else
+      issues += scope.order(:id => :desc).limit(10).to_a
     end
 
     render :json => format_issues_json(issues)
index 8d815267f3c9dd0c4b59d65a5dac6fb73ec071eb..825ebf8e94a5009edfc9ab87d044cf3fa46baac9 100644 (file)
@@ -150,4 +150,20 @@ class AutoCompletesControllerTest < Redmine::ControllerTest
     assert_response :success
     assert_include 'application/json', response.headers['Content-Type']
   end
+
+  def test_auto_complete_without_term_should_return_last_10_updated_issues
+    # There are 9 issues generated by fixtures
+    # and we need two more to test the 10 limit
+    %w(1..2).each do
+      Issue.generate!
+    end
+
+    get :issues
+
+    assert_response :success
+    json = ActiveSupport::JSON.decode(response.body)
+
+    assert_equal 10, json.count
+    assert_equal Issue.last.id, json.first['id'].to_i
+  end
 end