[#802] Change WatchersController to allow groups
This commit is contained in:
parent
e6e6a06fff
commit
65e7995682
|
@ -53,7 +53,7 @@ class WatchersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
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|
|
respond_to do |format|
|
||||||
format.html { redirect_to :back }
|
format.html { redirect_to :back }
|
||||||
format.js do
|
format.js do
|
||||||
|
|
|
@ -132,6 +132,21 @@ class WatchersControllerTest < ActionController::TestCase
|
||||||
assert Issue.find(2).watched_by?(User.find(7))
|
assert Issue.find(2).watched_by?(User.find(7))
|
||||||
end
|
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
|
def test_remove_watcher
|
||||||
@request.session[:user_id] = 2
|
@request.session[:user_id] = 2
|
||||||
assert_difference('Watcher.count', -1) do
|
assert_difference('Watcher.count', -1) do
|
||||||
|
@ -141,4 +156,23 @@ class WatchersControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
assert !Issue.find(2).watched_by?(User.find(3))
|
assert !Issue.find(2).watched_by?(User.find(3))
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -42,7 +42,7 @@ module Redmine
|
||||||
|
|
||||||
# Removes user from the watchers list
|
# Removes user from the watchers list
|
||||||
def remove_watcher(user)
|
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}"
|
Watcher.delete_all "watchable_type = '#{self.class}' AND watchable_id = #{self.id} AND user_id = #{user.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue