[#373] Adding test and fix for duplicates in issue autocompleter

This commit is contained in:
Gregor Schmidt 2011-05-04 19:01:15 +02:00
parent 7cd96b6a6f
commit 8509212991
2 changed files with 8 additions and 7 deletions

View File

@ -15,6 +15,7 @@ class AutoCompletesController < ApplicationController
:conditions => ["LOWER(#{Issue.table_name}.subject) LIKE :q OR CAST(#{Issue.table_name}.id AS CHAR(13)) LIKE :q", {:q => "%#{q.downcase}%" }])
end
@issues.compact!
@issues.uniq!
render :layout => false
end

View File

@ -20,19 +20,19 @@ class AutoCompletesControllerTest < ActionController::TestCase
test 'should return issues matching a given id' do
@project = Project.find('subproject1')
@issue_21 = Issue.generate_for_project!(@project, :id => 21)
@issue_101 = Issue.generate_for_project!(@project, :id => 101)
@issue_102 = Issue.generate_for_project!(@project, :id => 102)
@issue_with_subject = Issue.generate_for_project!(@project, :subject => 'This has 1 in the subject')
@issue_2101 = Issue.generate_for_project!(@project, :id => 2101)
@issue_2102 = Issue.generate_for_project!(@project, :id => 2102)
@issue_with_subject = Issue.generate_for_project!(@project, :subject => 'This has 21 in the subject')
get :issues, :project_id => @project.id, :q => '1'
get :issues, :project_id => @project.id, :q => '21'
assert_response :success
assert_not_nil assigns(:issues)
assert assigns(:issues).include?(Issue.find(13))
assert assigns(:issues).include?(@issue_21)
assert assigns(:issues).include?(@issue_101)
assert assigns(:issues).include?(@issue_102)
assert assigns(:issues).include?(@issue_2101)
assert assigns(:issues).include?(@issue_2102)
assert assigns(:issues).include?(@issue_with_subject)
assert_equal assigns(:issues).size, assigns(:issues).uniq.size, "Issues list includes duplicates"
end
def test_auto_complete_with_scope_all_and_cross_project_relations