diff --git a/app/controllers/watchers_controller.rb b/app/controllers/watchers_controller.rb index 5d5d2d50..2325634a 100644 --- a/app/controllers/watchers_controller.rb +++ b/app/controllers/watchers_controller.rb @@ -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 diff --git a/test/functional/watchers_controller_test.rb b/test/functional/watchers_controller_test.rb index 858e807e..ad839bac 100644 --- a/test/functional/watchers_controller_test.rb +++ b/test/functional/watchers_controller_test.rb @@ -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 diff --git a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb index 5fba3d76..9d99d2b7 100644 --- a/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb +++ b/vendor/plugins/acts_as_watchable/lib/acts_as_watchable.rb @@ -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