Skip to content
Snippets Groups Projects
Commit 5deae7eb authored by Eric Davis's avatar Eric Davis
Browse files

[#800 #801] Refactor AutoCompletesController#users to not be coupled to Groups

parent a110f104
Tags
No related merge requests found
......@@ -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)
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
context "with no restrictions" do
setup do
get :users, :q => 'complete'
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
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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment