[#802] Change WatchersController to allow groups

This commit is contained in:
Eric Davis 2011-04-19 11:49:49 -07:00
parent e6e6a06fff
commit 65e7995682
3 changed files with 36 additions and 2 deletions

View File

@ -53,7 +53,7 @@ class WatchersController < ApplicationController
end
def destroy
@watched.set_watcher(User.find(params[:user_id]), false) if request.post?
@watched.set_watcher(Principal.find(params[:user_id]), false) if request.post?
respond_to do |format|
format.html { redirect_to :back }
format.js do

View File

@ -132,6 +132,21 @@ class WatchersControllerTest < ActionController::TestCase
assert Issue.find(2).watched_by?(User.find(7))
end
context "POST :new" do
should "add groups" do
@group = Group.generate!.reload
Member.generate!(:project => Project.find(1), :roles => [Role.find(1)], :principal => @group)
@request.session[:user_id] = 2
assert_difference('Watcher.count') do
xhr :post, :new, :object_type => 'issue', :object_id => '2', :user_ids => [@group.id.to_s]
assert_response :success
assert_select_rjs :replace_html, 'watchers'
end
assert Issue.find(2).watched_by?(@group)
end
end
def test_remove_watcher
@request.session[:user_id] = 2
assert_difference('Watcher.count', -1) do
@ -141,4 +156,23 @@ class WatchersControllerTest < ActionController::TestCase
end
assert !Issue.find(2).watched_by?(User.find(3))
end
context "POST :destroy" do
should "remove a group" do
@group = Group.generate!.reload
Member.generate!(:project => Project.find(1), :roles => [Role.find(1)], :principal => @group)
assert Issue.find(2).add_watcher(@group)
assert Issue.find(2).watched_by?(@group)
@request.session[:user_id] = 2
assert_difference('Watcher.count', -1) do
xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => @group.id.to_s
assert_response :success
assert_select_rjs :replace_html, 'watchers'
end
assert !Issue.find(2).watched_by?(@group)
end
end
end

View File

@ -42,7 +42,7 @@ module Redmine
# Removes user from the watchers list
def remove_watcher(user)
return nil unless user && user.is_a?(User)
return nil unless user && user.is_a?(Principal)
Watcher.delete_all "watchable_type = '#{self.class}' AND watchable_id = #{self.id} AND user_id = #{user.id}"
end