@@ -22,7 +22,7 class AutoCompletesController < ApplicationController | |||||
22 | @issues = [] |
|
22 | @issues = [] | |
23 | q = (params[:q] || params[:term]).to_s.strip |
|
23 | q = (params[:q] || params[:term]).to_s.strip | |
24 | if q.present? |
|
24 | if q.present? | |
25 | scope = (params[:scope] == "all" ? Issue : @project.issues).visible |
|
25 | scope = (params[:scope] == "all" || @project.nil? ? Issue : @project.issues).visible | |
26 | if q.match(/^\d+$/) |
|
26 | if q.match(/^\d+$/) | |
27 | @issues << scope.find_by_id(q.to_i) |
|
27 | @issues << scope.find_by_id(q.to_i) | |
28 | end |
|
28 | end | |
@@ -35,7 +35,9 class AutoCompletesController < ApplicationController | |||||
35 | private |
|
35 | private | |
36 |
|
36 | |||
37 | def find_project |
|
37 | def find_project | |
38 | @project = Project.find(params[:project_id]) |
|
38 | if params[:project_id].present? | |
|
39 | @project = Project.find(params[:project_id]) | |||
|
40 | end | |||
39 | rescue ActiveRecord::RecordNotFound |
|
41 | rescue ActiveRecord::RecordNotFound | |
40 | render_404 |
|
42 | render_404 | |
41 | end |
|
43 | end |
@@ -19,3 +19,5 | |||||
19 | <% end %> |
|
19 | <% end %> | |
20 | <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> |
|
20 | <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> | |
21 | </div> |
|
21 | </div> | |
|
22 | ||||
|
23 | <%= javascript_tag "observeAutocompleteField('time_entry_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))}')" %> |
@@ -40,6 +40,13 class AutoCompletesControllerTest < ActionController::TestCase | |||||
40 | assert assigns(:issues).include?(Issue.find(13)) |
|
40 | assert assigns(:issues).include?(Issue.find(13)) | |
41 | end |
|
41 | end | |
42 |
|
42 | |||
|
43 | def test_auto_complete_without_project_should_search_all_projects | |||
|
44 | get :issues, :q => '13' | |||
|
45 | assert_response :success | |||
|
46 | assert_not_nil assigns(:issues) | |||
|
47 | assert assigns(:issues).include?(Issue.find(13)) | |||
|
48 | end | |||
|
49 | ||||
43 | def test_auto_complete_without_scope_all_should_not_search_other_projects |
|
50 | def test_auto_complete_without_scope_all_should_not_search_other_projects | |
44 | get :issues, :project_id => 'ecookbook', :q => '13' |
|
51 | get :issues, :project_id => 'ecookbook', :q => '13' | |
45 | assert_response :success |
|
52 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now