This commit is contained in:
parent
a110f1041d
commit
5deae7ebe3
|
@ -34,10 +34,15 @@ class AutoCompletesController < ApplicationController
|
|||
end
|
||||
|
||||
def users
|
||||
@group = Group.find(params[:id])
|
||||
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @group.users
|
||||
if params[:remove_group_members].present?
|
||||
@group = Group.find(params[:remove_group_members])
|
||||
@removed_users = @group.users
|
||||
else
|
||||
@removed_users = []
|
||||
end
|
||||
|
||||
@users = User.active.like(params[:q]).find(:all, :limit => 100) - @removed_users
|
||||
render :layout => false
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<%= observe_field(:user_search,
|
||||
:frequency => 0.5,
|
||||
:update => :users,
|
||||
:url => auto_complete_users_path(:id => @group),
|
||||
:url => auto_complete_users_path(:remove_group_members => @group),
|
||||
:with => 'q')
|
||||
%>
|
||||
|
||||
|
|
|
@ -71,22 +71,43 @@ class AutoCompletesControllerTest < ActionController::TestCase
|
|||
@lastname = User.generate!(:lastname => 'Complete')
|
||||
@none = User.generate!(:login => 'hello', :firstname => 'ABC', :lastname => 'DEF')
|
||||
@inactive = User.generate!(:firstname => 'Complete', :status => User::STATUS_LOCKED)
|
||||
end
|
||||
|
||||
context "with no restrictions" do
|
||||
setup do
|
||||
get :users, :q => 'complete'
|
||||
end
|
||||
|
||||
get :users, :q => 'complete', :id => Group.first.id
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
context "restrict by removing group members" do
|
||||
setup do
|
||||
@group = Group.first
|
||||
@group.users << @login
|
||||
@group.users << @firstname
|
||||
get :users, :q => 'complete', :remove_group_members => @group.id
|
||||
end
|
||||
|
||||
should_respond_with :success
|
||||
|
||||
should "not include existing members of the Group" do
|
||||
assert_select "input[type=checkbox][value=?]", @lastname.id
|
||||
|
||||
assert_select "input[type=checkbox][value=?]", @login.id, :count => 0
|
||||
assert_select "input[type=checkbox][value=?]", @firstname.id, :count => 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue