[#800 #801] Refactor the user auto complete method to the AutoCompletesController

This commit is contained in:
Eric Davis 2010-12-03 13:59:23 -08:00
parent 111c7f47f7
commit a110f1041d
8 changed files with 41 additions and 17 deletions

View File

@ -13,7 +13,7 @@
#++
class AutoCompletesController < ApplicationController
before_filter :find_project
before_filter :find_project, :only => :issues
def issues
@issues = []
@ -33,6 +33,13 @@ class AutoCompletesController < ApplicationController
render :layout => false
end
def users
@group = Group.find(params[:id])
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
render :layout => false
end
private
def find_project

View File

@ -126,12 +126,6 @@ class GroupsController < ApplicationController
end
end
def autocomplete_for_user
@group = Group.find(params[:id])
@users = User.active.not_in_group(@group).like(params[:q]).all(:limit => 100)
render :layout => false
end
def edit_membership
@group = Group.find(params[:id])
@membership = Member.edit_membership(params[:membership_id], params[:membership], @group)

View File

@ -33,7 +33,7 @@
<%= observe_field(:user_search,
:frequency => 0.5,
:update => :users,
:url => { :controller => 'groups', :action => 'autocomplete_for_user', :id => @group },
:url => auto_complete_users_path(:id => @group),
:with => 'q')
%>

View File

@ -87,6 +87,7 @@ ActionController::Routing::Routes.draw do |map|
# Misc issue routes. TODO: move into resources
map.auto_complete_issues '/issues/auto_complete', :controller => 'auto_completes', :action => 'issues'
map.auto_complete_users '/users/auto_complete', :controller => 'auto_completes', :action => 'users'
map.preview_issue '/issues/preview/:id', :controller => 'previews', :action => 'issue' # TODO: would look nicer as /issues/:id/preview
map.issues_context_menu '/issues/context_menu', :controller => 'context_menus', :action => 'issues'
map.issue_changes '/issues/changes', :controller => 'journals', :action => 'index'

View File

@ -63,4 +63,30 @@ class AutoCompletesControllerTest < ActionController::TestCase
assert_response :success
assert_equal [], assigns(:issues)
end
context "GET :users" do
setup do
@login = User.generate!(:login => 'Acomplete')
@firstname = User.generate!(:firstname => 'Complete')
@lastname = User.generate!(:lastname => 'Complete')
@none = User.generate!(:login => 'hello', :firstname => 'ABC', :lastname => 'DEF')
@inactive = User.generate!(:firstname => 'Complete', :status => User::STATUS_LOCKED)
get :users, :q => 'complete', :id => Group.first.id
end
should_respond_with :success
should "render a list of matching users in checkboxes" do
assert_select "input[type=checkbox][value=?]", @login.id
assert_select "input[type=checkbox][value=?]", @firstname.id
assert_select "input[type=checkbox][value=?]", @lastname.id
assert_select "input[type=checkbox][value=?]", @none.id, :count => 0
end
should "only show active users" do
assert_select "input[type=checkbox][value=?]", @inactive.id, :count => 0
end
end
end

View File

@ -100,13 +100,4 @@ class GroupsControllerTest < ActionController::TestCase
post :destroy_membership, :id => 10, :membership_id => 6
end
end
def test_autocomplete_for_user
get :autocomplete_for_user, :id => 10, :q => 'mis'
assert_response :success
users = assigns(:users)
assert_not_nil users
assert users.any?
assert !users.include?(Group.find(10).users.first)
end
end

View File

@ -346,4 +346,9 @@ class RoutingTest < ActionController::IntegrationTest
context "administration panel" do
should_route :get, "/admin/projects", :controller => 'admin', :action => 'projects'
end
context "auto_completes" do
should_route :get, "/users/auto_complete", :controller => 'auto_completes', :action => 'users'
end
end