@@ -20,25 +20,23 class AutoCompletesController < ApplicationController | |||
|
20 | 20 | |
|
21 | 21 | def issues |
|
22 | 22 | @issues = [] |
|
23 | q = (params[:q] || params[:term]).to_s | |
|
24 | query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues | |
|
25 | if q.match(/^\d+$/) | |
|
26 | @issues << query.visible.find_by_id(q.to_i) | |
|
23 | q = (params[:q] || params[:term]).to_s.strip | |
|
24 | if q.present? | |
|
25 | scope = (params[:scope] == "all" ? Issue : @project.issues).visible | |
|
26 | if q.match(/^\d+$/) | |
|
27 | @issues << scope.find_by_id(q.to_i) | |
|
28 | end | |
|
29 | @issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%").order("#{Issue.table_name}.id DESC").limit(10).all | |
|
30 | @issues.compact! | |
|
27 | 31 | end |
|
28 | unless q.blank? | |
|
29 | @issues += query.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10) | |
|
30 | end | |
|
31 | @issues.compact! | |
|
32 | 32 | render :layout => false |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | private |
|
36 | 36 | |
|
37 | 37 | def find_project |
|
38 |
project |
|
|
39 | @project = Project.find(project_id) | |
|
38 | @project = Project.find(params[:project_id]) | |
|
40 | 39 | rescue ActiveRecord::RecordNotFound |
|
41 | 40 | render_404 |
|
42 | 41 | end |
|
43 | ||
|
44 | 42 | end |
@@ -9,6 +9,6 | |||
|
9 | 9 | <%= toggle_link l(:button_cancel), 'new-relation-form'%> |
|
10 | 10 | </p> |
|
11 | 11 | |
|
12 |
<%= javascript_tag "observeAutocompleteField('relation_issue_to_id', '#{escape_javascript auto_complete_issues_path(: |
|
|
12 | <%= javascript_tag "observeAutocompleteField('relation_issue_to_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (Setting.cross_project_issue_relations? ? 'all' : nil))}')" %> | |
|
13 | 13 | |
|
14 | 14 | <%= javascript_tag "setPredecessorFieldsVisibility();" %> |
@@ -43,7 +43,7 | |||
|
43 | 43 | <div class="splitcontentright"> |
|
44 | 44 | <% if @issue.safe_attribute? 'parent_issue_id' %> |
|
45 | 45 | <p id="parent_issue"><%= f.text_field :parent_issue_id, :size => 10, :required => @issue.required_attribute?('parent_issue_id') %></p> |
|
46 |
<%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(: |
|
|
46 | <%= javascript_tag "observeAutocompleteField('issue_parent_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @issue.project)}')" %> | |
|
47 | 47 | <% end %> |
|
48 | 48 | |
|
49 | 49 | <% if @issue.safe_attribute? 'start_date' %> |
@@ -19,6 +19,13 class AutoCompletesControllerTest < ActionController::TestCase | |||
|
19 | 19 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | def test_issues_should_accept_term_param | |
|
23 | get :issues, :project_id => 'ecookbook', :term => 'ReCiPe' | |
|
24 | assert_response :success | |
|
25 | assert_not_nil assigns(:issues) | |
|
26 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} | |
|
27 | end | |
|
28 | ||
|
22 | 29 | def test_issues_should_return_issue_with_given_id |
|
23 | 30 | get :issues, :project_id => 'subproject1', :q => '13' |
|
24 | 31 | assert_response :success |
@@ -26,18 +33,28 class AutoCompletesControllerTest < ActionController::TestCase | |||
|
26 | 33 | assert assigns(:issues).include?(Issue.find(13)) |
|
27 | 34 | end |
|
28 | 35 | |
|
29 |
def test_auto_complete_with_scope_all_ |
|
|
30 | Setting.cross_project_issue_relations = '1' | |
|
36 | def test_auto_complete_with_scope_all_should_search_other_projects | |
|
31 | 37 | get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' |
|
32 | 38 | assert_response :success |
|
33 | 39 | assert_not_nil assigns(:issues) |
|
34 | 40 | assert assigns(:issues).include?(Issue.find(13)) |
|
35 | 41 | end |
|
36 | 42 | |
|
37 |
def test_auto_complete_with_scope_all_ |
|
|
38 | Setting.cross_project_issue_relations = '0' | |
|
39 | get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' | |
|
43 | def test_auto_complete_without_scope_all_should_not_search_other_projects | |
|
44 | get :issues, :project_id => 'ecookbook', :q => '13' | |
|
40 | 45 | assert_response :success |
|
41 | 46 | assert_equal [], assigns(:issues) |
|
42 | 47 | end |
|
48 | ||
|
49 | def test_issues_should_return_json | |
|
50 | get :issues, :project_id => 'subproject1', :q => '13' | |
|
51 | assert_response :success | |
|
52 | json = ActiveSupport::JSON.decode(response.body) | |
|
53 | assert_kind_of Array, json | |
|
54 | issue = json.first | |
|
55 | assert_kind_of Hash, issue | |
|
56 | assert_equal 13, issue['id'] | |
|
57 | assert_equal 13, issue['value'] | |
|
58 | assert_equal 'Bug #13: Subproject issue two', issue['label'] | |
|
59 | end | |
|
43 | 60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now