summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-02-19 09:37:50 +0000
committerGo MAEDA <maeda@farend.jp>2019-02-19 09:37:50 +0000
commit087309ae1a34d34cd6e783d6c220a1a4c41a6f91 (patch)
tree0beae9c5041335b5a5e43005fdbc50773b030635
parent797c83f7c8ebb943208b20b27e9d89cb2186f255 (diff)
downloadredmine-087309ae1a34d34cd6e783d6c220a1a4c41a6f91.tar.gz
redmine-087309ae1a34d34cd6e783d6c220a1a4c41a6f91.zip
Merged r17881 from trunk to 3.4-stable (#30818).
git-svn-id: http://svn.redmine.org/redmine/branches/3.4-stable@17886 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/auto_completes_controller.rb20
-rw-r--r--test/functional/auto_completes_controller_test.rb10
2 files changed, 25 insertions, 5 deletions
diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb
index 293ac201e..2d707f929 100644
--- a/app/controllers/auto_completes_controller.rb
+++ b/app/controllers/auto_completes_controller.rb
@@ -19,7 +19,7 @@ class AutoCompletesController < ApplicationController
before_action :find_project
def issues
- @issues = []
+ issues = []
q = (params[:q] || params[:term]).to_s.strip
status = params[:status].to_s
issue_id = params[:issue_id].to_s
@@ -32,13 +32,14 @@ class AutoCompletesController < ApplicationController
scope = scope.where.not(:id => issue_id.to_i)
end
if q.match(/\A#?(\d+)\z/)
- @issues << scope.find_by_id($1.to_i)
+ issues << scope.find_by_id($1.to_i)
end
- @issues += scope.like(q).order(:id => :desc).limit(10).to_a
- @issues.compact!
+ issues += scope.like(q).order(:id => :desc).limit(10).to_a
+ issues.compact!
end
- render :layout => false
+
+ render :json => format_issues_json(issues)
end
private
@@ -50,4 +51,13 @@ class AutoCompletesController < ApplicationController
rescue ActiveRecord::RecordNotFound
render_404
end
+
+ def format_issues_json(issues)
+ issues.map {|issue| {
+ 'id' => issue.id,
+ 'label' => "#{issue.tracker} ##{issue.id}: #{issue.subject.to_s.truncate(60)}",
+ 'value' => issue.id
+ }
+ }
+ end
end
diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb
index f4f8b4fbf..4be188140 100644
--- a/test/functional/auto_completes_controller_test.rb
+++ b/test/functional/auto_completes_controller_test.rb
@@ -138,4 +138,14 @@ class AutoCompletesControllerTest < Redmine::ControllerTest
assert_include "issue", response.body
assert_not_include "Bug #12: Closed issue on a locked version", response.body
end
+
+ def test_auto_complete_should_return_json_content_type_response
+ get :issues, :params => {
+ :project_id => 'subproject1',
+ :q => '#13'
+ }
+
+ assert_response :success
+ assert_include 'application/json', response.headers['Content-Type']
+ end
end