summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/auto_completes_controller.rb25
-rw-r--r--app/controllers/issues_controller.rb14
-rw-r--r--app/views/auto_completes/issues.html.erb (renamed from app/views/issues/auto_complete.html.erb)0
-rw-r--r--app/views/issues/_form.rhtml5
-rw-r--r--config/routes.rb3
-rw-r--r--lib/redmine.rb3
-rw-r--r--test/functional/auto_completes_controller_test.rb20
-rw-r--r--test/functional/issues_controller_test.rb14
-rw-r--r--test/integration/routing_test.rb2
9 files changed, 52 insertions, 34 deletions
diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb
new file mode 100644
index 000000000..1438106f6
--- /dev/null
+++ b/app/controllers/auto_completes_controller.rb
@@ -0,0 +1,25 @@
+class AutoCompletesController < ApplicationController
+ before_filter :find_project
+
+ def issues
+ @issues = []
+ q = params[:q].to_s
+ if q.match(/^\d+$/)
+ @issues << @project.issues.visible.find_by_id(q.to_i)
+ end
+ unless q.blank?
+ @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
+ end
+ render :layout => false
+ end
+
+ private
+
+ def find_project
+ project_id = (params[:issue] && params[:issue][:project_id]) || params[:project_id]
+ @project = Project.find(project_id)
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
+end
diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb
index eaa6dbc35..4981f43ee 100644
--- a/app/controllers/issues_controller.rb
+++ b/app/controllers/issues_controller.rb
@@ -21,7 +21,7 @@ class IssuesController < ApplicationController
before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issues, :only => [:bulk_edit, :move, :perform_move, :destroy]
- before_filter :find_project, :only => [:new, :create, :update_form, :preview, :auto_complete]
+ before_filter :find_project, :only => [:new, :create, :update_form, :preview]
before_filter :authorize, :except => [:index, :changes, :preview, :context_menu]
before_filter :find_optional_project, :only => [:index, :changes]
before_filter :check_for_default_issue_status, :only => [:new, :create]
@@ -316,18 +316,6 @@ class IssuesController < ApplicationController
render :layout => false
end
- def auto_complete
- @issues = []
- q = params[:q].to_s
- if q.match(/^\d+$/)
- @issues << @project.issues.visible.find_by_id(q.to_i)
- end
- unless q.blank?
- @issues += @project.issues.visible.find(:all, :conditions => ["LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%"], :limit => 10)
- end
- render :layout => false
- end
-
private
def find_issue
@issue = Issue.find(params[:id], :include => [:project, :tracker, :status, :author, :priority, :category])
diff --git a/app/views/issues/auto_complete.html.erb b/app/views/auto_completes/issues.html.erb
index b130159eb..b130159eb 100644
--- a/app/views/issues/auto_complete.html.erb
+++ b/app/views/auto_completes/issues.html.erb
diff --git a/app/views/issues/_form.rhtml b/app/views/issues/_form.rhtml
index 1e3beaf85..ccb7a55a3 100644
--- a/app/views/issues/_form.rhtml
+++ b/app/views/issues/_form.rhtml
@@ -9,10 +9,7 @@
<% unless (@issue.new_record? && @issue.parent_issue_id.nil?) || !User.current.allowed_to?(:manage_subtasks, @project) %>
<p><%= f.text_field :parent_issue_id, :size => 10 %></p>
<div id="parent_issue_candidates" class="autocomplete"></div>
-<%= javascript_tag "observeParentIssueField('#{url_for(:controller => :issues,
- :action => :auto_complete,
- :id => @issue,
- :project_id => @project) }')" %>
+<%= javascript_tag "observeParentIssueField('#{auto_complete_issues_path(:id => @issue, :project_id => @project) }')" %>
<% end %>
<p><%= f.text_area :description,
diff --git a/config/routes.rb b/config/routes.rb
index 08cd10055..910087ab9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -104,7 +104,8 @@ ActionController::Routing::Routes.draw do |map|
end
map.resources :issue_moves, :only => [:new, :create], :path_prefix => '/issues', :as => 'move'
-
+ map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
+
map.with_options :controller => 'issues' do |issues_routes|
issues_routes.with_options :conditions => {:method => :get} do |issues_views|
issues_views.connect 'issues', :action => 'index'
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 073e52d2d..aa9fe75d1 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -58,7 +58,8 @@ Redmine::AccessControl.map do |map|
map.permission :manage_categories, {:projects => :settings, :issue_categories => [:new, :edit, :destroy]}, :require => :member
# Issues
map.permission :view_issues, {:projects => :roadmap,
- :issues => [:index, :changes, :show, :context_menu, :auto_complete],
+ :issues => [:index, :changes, :show, :context_menu],
+ :auto_complete => [:issues],
:versions => [:show, :status_by],
:queries => :index,
:reports => [:issue_report, :issue_report_details]}
diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb
new file mode 100644
index 000000000..25e75fc4b
--- /dev/null
+++ b/test/functional/auto_completes_controller_test.rb
@@ -0,0 +1,20 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class AutoCompletesControllerTest < ActionController::TestCase
+ fixtures :all
+
+ def test_issues_should_not_be_case_sensitive
+ get :issues, :project_id => 'ecookbook', :q => 'ReCiPe'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
+ end
+
+ def test_issues_should_return_issue_with_given_id
+ get :issues, :project_id => 'subproject1', :q => '13'
+ assert_response :success
+ assert_not_nil assigns(:issues)
+ assert assigns(:issues).include?(Issue.find(13))
+ end
+
+end
diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb
index 0c1172f60..948cf8598 100644
--- a/test/functional/issues_controller_test.rb
+++ b/test/functional/issues_controller_test.rb
@@ -1123,20 +1123,6 @@ class IssuesControllerTest < ActionController::TestCase
assert_not_nil assigns(:notes)
end
- def test_auto_complete_should_not_be_case_sensitive
- get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe'
- assert_response :success
- assert_not_nil assigns(:issues)
- assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
- end
-
- def test_auto_complete_should_return_issue_with_given_id
- get :auto_complete, :project_id => 'subproject1', :q => '13'
- assert_response :success
- assert_not_nil assigns(:issues)
- assert assigns(:issues).include?(Issue.find(13))
- end
-
def test_destroy_issue_with_no_time_entries
assert_nil TimeEntry.find_by_issue_id(2)
@request.session[:user_id] = 2
diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb
index b9eac552e..607df5b06 100644
--- a/test/integration/routing_test.rb
+++ b/test/integration/routing_test.rb
@@ -100,7 +100,7 @@ class RoutingTest < ActionController::IntegrationTest
should_route :get, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
should_route :post, "/projects/project-name/issues/gantt", :controller => 'gantts', :action => 'show', :project_id => 'project-name'
- should_route :get, "/issues/auto_complete", :controller => 'issues', :action => 'auto_complete'
+ should_route :get, "/issues/auto_complete", :controller => 'auto_completes', :action => 'issues'
end
context "issue categories" do