forked from edavis10/redmine
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: move IssuesController#auto_complete to a new controller. #4382
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3945 e93f8b46-1217-0410-a6f0-8f06a7374b81
- Loading branch information
Showing
9 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters