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
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
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
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