From 8e3d4da376a737b3c9cf2e7018d7318450ecbed9 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 19 Apr 2011 12:03:55 -0700 Subject: [PATCH] [#802] Show groups in the watchers partial and users autocomplete --- app/controllers/auto_completes_controller.rb | 8 +++++++- app/views/watchers/_watchers.rhtml | 4 ++-- test/functional/auto_completes_controller_test.rb | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/controllers/auto_completes_controller.rb b/app/controllers/auto_completes_controller.rb index 27226ea8..f1fe99c7 100644 --- a/app/controllers/auto_completes_controller.rb +++ b/app/controllers/auto_completes_controller.rb @@ -48,8 +48,14 @@ class AutoCompletesController < ApplicationController end @removed_users ||= [] + + if params[:include_groups] + user_finder = Principal + else + user_finder = User + end - @users = User.active.like(params[:q]).find(:all, :limit => 100) - @removed_users + @users = user_finder.active.like(params[:q]).find(:all, :limit => 100) - @removed_users render :layout => false end diff --git a/app/views/watchers/_watchers.rhtml b/app/views/watchers/_watchers.rhtml index 741366cd..00b4954c 100644 --- a/app/views/watchers/_watchers.rhtml +++ b/app/views/watchers/_watchers.rhtml @@ -12,12 +12,12 @@ :object_id => watched}, :method => :post, :html => {:id => 'new-watcher-form', :style => 'display:none;'}) do |f| %> - <% users = User.active.find(:all, :limit => 25) - watched.watcher_users %> + <% users = Principal.active.find(:all, :limit => 25) - watched.watcher_users %>

<%= label_tag "user_search", l(:label_user_search) %><%= text_field_tag 'user_search', nil, :style => "width:98%;" %>

<%= observe_field(:user_search, :frequency => 0.5, :update => :users, - :url => auto_complete_users_path(:remove_watchers => watched.id, :klass => watched.class), + :url => auto_complete_users_path(:remove_watchers => watched.id, :klass => watched.class, :include_groups => true), :with => 'q') %> diff --git a/test/functional/auto_completes_controller_test.rb b/test/functional/auto_completes_controller_test.rb index 4ee6482d..5881862d 100644 --- a/test/functional/auto_completes_controller_test.rb +++ b/test/functional/auto_completes_controller_test.rb @@ -92,6 +92,20 @@ class AutoCompletesControllerTest < ActionController::TestCase end end + context "including groups" do + setup do + @group = Group.generate(:lastname => 'Complete Group').reload + get :users, :q => 'complete', :include_groups => true + end + + should_respond_with :success + + should "include matching groups" do + assert_select "input[type=checkbox][value=?]", @group.id + end + + end + context "restrict by removing group members" do setup do @group = Group.first