Patch #31994 » 0001-Issue-auto-complete-should-return-last-10-updated-is.patch
| app/controllers/auto_completes_controller.rb | ||
|---|---|---|
| 25 | 25 |
q = (params[:q] || params[:term]).to_s.strip |
| 26 | 26 |
status = params[:status].to_s |
| 27 | 27 |
issue_id = params[:issue_id].to_s |
| 28 | ||
| 29 |
scope = Issue.cross_project_scope(@project, params[:scope]).visible |
|
| 30 |
scope = scope.open(status == 'o') if status.present? |
|
| 31 |
scope = scope.where.not(:id => issue_id.to_i) if issue_id.present? |
|
| 28 | 32 |
if q.present? |
| 29 |
scope = Issue.cross_project_scope(@project, params[:scope]).visible |
|
| 30 |
if status.present? |
|
| 31 |
scope = scope.open(status == 'o') |
|
| 32 |
end |
|
| 33 |
if issue_id.present? |
|
| 34 |
scope = scope.where.not(:id => issue_id.to_i) |
|
| 35 |
end |
|
| 36 | 33 |
if q.match(/\A#?(\d+)\z/) |
| 37 | 34 |
issues << scope.find_by_id($1.to_i) |
| 38 | 35 |
end |
| 39 | ||
| 40 | 36 |
issues += scope.like(q).order(:id => :desc).limit(10).to_a |
| 41 | 37 |
issues.compact! |
| 38 |
else |
|
| 39 |
issues += scope.order(:id => :desc).limit(10).to_a |
|
| 42 | 40 |
end |
| 43 | 41 | |
| 44 | 42 |
render :json => format_issues_json(issues) |
| test/functional/auto_completes_controller_test.rb | ||
|---|---|---|
| 150 | 150 |
assert_response :success |
| 151 | 151 |
assert_include 'application/json', response.headers['Content-Type'] |
| 152 | 152 |
end |
| 153 | ||
| 154 |
def test_auto_complete_without_term_should_return_last_10_updated_issues |
|
| 155 |
# There are 9 issues generated by fixtures |
|
| 156 |
# and we need two more to test the 10 limit |
|
| 157 |
%w(1..2).each do |
|
| 158 |
Issue.generate! |
|
| 159 |
end |
|
| 160 | ||
| 161 |
get :issues |
|
| 162 | ||
| 163 |
assert_response :success |
|
| 164 |
json = ActiveSupport::JSON.decode(response.body) |
|
| 165 | ||
| 166 |
assert_equal 10, json.count |
|
| 167 |
assert_equal Issue.last.id, json.first['id'].to_i |
|
| 168 |
end |
|
| 153 | 169 |
end |
- « Previous
- 1
- 2
- Next »