@@ -20,25 +20,23 class AutoCompletesController < ApplicationController | |||||
20 |
|
20 | |||
21 | def issues |
|
21 | def issues | |
22 | @issues = [] |
|
22 | @issues = [] | |
23 | q = (params[:q] || params[:term]).to_s |
|
23 | q = (params[:q] || params[:term]).to_s.strip | |
24 | query = (params[:scope] == "all" && Setting.cross_project_issue_relations?) ? Issue : @project.issues |
|
24 | if q.present? | |
25 | if q.match(/^\d+$/) |
|
25 | scope = (params[:scope] == "all" ? Issue : @project.issues).visible | |
26 | @issues << query.visible.find_by_id(q.to_i) |
|
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 | end |
|
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 | render :layout => false |
|
32 | render :layout => false | |
33 | end |
|
33 | end | |
34 |
|
34 | |||
35 | private |
|
35 | private | |
36 |
|
36 | |||
37 | def find_project |
|
37 | def find_project | |
38 |
project |
|
38 | @project = Project.find(params[:project_id]) | |
39 | @project = Project.find(project_id) |
|
|||
40 | rescue ActiveRecord::RecordNotFound |
|
39 | rescue ActiveRecord::RecordNotFound | |
41 | render_404 |
|
40 | render_404 | |
42 | end |
|
41 | end | |
43 |
|
||||
44 | end |
|
42 | end |
@@ -9,6 +9,6 | |||||
9 | <%= toggle_link l(:button_cancel), 'new-relation-form'%> |
|
9 | <%= toggle_link l(:button_cancel), 'new-relation-form'%> | |
10 | </p> |
|
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 | <%= javascript_tag "setPredecessorFieldsVisibility();" %> |
|
14 | <%= javascript_tag "setPredecessorFieldsVisibility();" %> |
@@ -43,7 +43,7 | |||||
43 | <div class="splitcontentright"> |
|
43 | <div class="splitcontentright"> | |
44 | <% if @issue.safe_attribute? 'parent_issue_id' %> |
|
44 | <% if @issue.safe_attribute? 'parent_issue_id' %> | |
45 | <p id="parent_issue"><%= f.text_field :parent_issue_id, :size => 10, :required => @issue.required_attribute?('parent_issue_id') %></p> |
|
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 | <% end %> |
|
47 | <% end %> | |
48 |
|
48 | |||
49 | <% if @issue.safe_attribute? 'start_date' %> |
|
49 | <% if @issue.safe_attribute? 'start_date' %> |
@@ -19,6 +19,13 class AutoCompletesControllerTest < ActionController::TestCase | |||||
19 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} |
|
19 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} | |
20 | end |
|
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 | def test_issues_should_return_issue_with_given_id |
|
29 | def test_issues_should_return_issue_with_given_id | |
23 | get :issues, :project_id => 'subproject1', :q => '13' |
|
30 | get :issues, :project_id => 'subproject1', :q => '13' | |
24 | assert_response :success |
|
31 | assert_response :success | |
@@ -26,18 +33,28 class AutoCompletesControllerTest < ActionController::TestCase | |||||
26 | assert assigns(:issues).include?(Issue.find(13)) |
|
33 | assert assigns(:issues).include?(Issue.find(13)) | |
27 | end |
|
34 | end | |
28 |
|
35 | |||
29 |
def test_auto_complete_with_scope_all_ |
|
36 | def test_auto_complete_with_scope_all_should_search_other_projects | |
30 | Setting.cross_project_issue_relations = '1' |
|
|||
31 | get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' |
|
37 | get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' | |
32 | assert_response :success |
|
38 | assert_response :success | |
33 | assert_not_nil assigns(:issues) |
|
39 | assert_not_nil assigns(:issues) | |
34 | assert assigns(:issues).include?(Issue.find(13)) |
|
40 | assert assigns(:issues).include?(Issue.find(13)) | |
35 | end |
|
41 | end | |
36 |
|
42 | |||
37 |
def test_auto_complete_with_scope_all_ |
|
43 | def test_auto_complete_without_scope_all_should_not_search_other_projects | |
38 | Setting.cross_project_issue_relations = '0' |
|
44 | get :issues, :project_id => 'ecookbook', :q => '13' | |
39 | get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' |
|
|||
40 | assert_response :success |
|
45 | assert_response :success | |
41 | assert_equal [], assigns(:issues) |
|
46 | assert_equal [], assigns(:issues) | |
42 | end |
|
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 | end |
|
60 | end |
General Comments 0
You need to be logged in to leave comments.
Login now