diff options
author | Go MAEDA <maeda@farend.jp> | 2020-02-06 08:19:13 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2020-02-06 08:19:13 +0000 |
commit | b995014c495b36102f36ec80618f50f3763bcd6f (patch) | |
tree | 85c230cf16c300f51f9716299ff7bc48d300c4cf /test/unit | |
parent | 29433771b45319a0b50f182f0dcaf72db1275a30 (diff) | |
download | redmine-b995014c495b36102f36ec80618f50f3763bcd6f.tar.gz redmine-b995014c495b36102f36ec80618f50f3763bcd6f.zip |
Allow adding user groups as watchers for issues (#4511).
Patch by Yuichi HARADA.
git-svn-id: http://svn.redmine.org/redmine/trunk@19498 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/group_test.rb | 16 | ||||
-rw-r--r-- | test/unit/query_test.rb | 26 | ||||
-rw-r--r-- | test/unit/watcher_test.rb | 12 |
3 files changed, 35 insertions, 19 deletions
diff --git a/test/unit/group_test.rb b/test/unit/group_test.rb index 77f79500b..37626ac0e 100644 --- a/test/unit/group_test.rb +++ b/test/unit/group_test.rb @@ -23,10 +23,9 @@ class GroupTest < ActiveSupport::TestCase fixtures :projects, :trackers, :issue_statuses, :issues, :enumerations, :users, :projects_trackers, - :roles, - :member_roles, - :members, - :groups_users + :roles, :member_roles, :members, + :groups_users, + :watchers include Redmine::I18n @@ -128,14 +127,21 @@ class GroupTest < ActiveSupport::TestCase assert !User.find(8).member_of?(Project.find(5)) end - def test_destroy_should_unassign_issues + def test_destroy_should_unassign_and_unwatch_issues group = Group.find(10) Issue.where(:id => 1).update_all(["assigned_to_id = ?", group.id]) + issue = Issue.find(2) + issue.set_watcher(group) + issue.save + issue.reload + assert issue.watcher_user_ids.include?(10) assert group.destroy assert group.destroyed? assert_nil Issue.find(1).assigned_to_id + issue.reload + assert !issue.watcher_user_ids.include?(10) end def test_builtin_groups_should_be_created_if_missing diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 56ec82d14..e99923fab 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -421,8 +421,6 @@ class QueryTest < ActiveSupport::TestCase issues = find_issues_with_query(query) assert issues.any? assert_nil issues.detect {|issue| !issue.is_private?} - ensure - User.current = nil end def test_operator_is_not_on_is_private_field @@ -436,8 +434,6 @@ class QueryTest < ActiveSupport::TestCase issues = find_issues_with_query(query) assert issues.any? assert_nil issues.detect {|issue| issue.is_private?} - ensure - User.current = nil end def test_operator_greater_than @@ -950,7 +946,20 @@ class QueryTest < ActiveSupport::TestCase assert_not_nil result assert !result.empty? assert_equal Issue.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id) - User.current = nil + end + + def test_filter_watched_issues_with_groups_also + user = User.find(2) + group = Group.find(10) + group.users << user + Issue.find(3).add_watcher(user) + Issue.find(7).add_watcher(group) + User.current = user + query = IssueQuery.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}}) + result = find_issues_with_query(query) + assert_not_nil result + assert !result.empty? + assert_equal [3, 7], result.sort_by(&:id).pluck(:id) end def test_filter_unwatched_issues @@ -960,7 +969,6 @@ class QueryTest < ActiveSupport::TestCase assert_not_nil result assert !result.empty? assert_equal((Issue.visible - Issue.watched_by(User.current)).sort_by(&:id).size, result.sort_by(&:id).size) - User.current = nil end def test_filter_on_watched_issues_with_view_issue_watchers_permission @@ -974,9 +982,6 @@ class QueryTest < ActiveSupport::TestCase result = find_issues_with_query(query) assert_includes result, Issue.find(1) assert_includes result, Issue.find(3) - ensure - User.current.reload - User.current = nil end def test_filter_on_watched_issues_without_view_issue_watchers_permission @@ -990,9 +995,6 @@ class QueryTest < ActiveSupport::TestCase result = find_issues_with_query(query) assert_includes result, Issue.find(1) assert_not_includes result, Issue.find(3) - ensure - User.current.reload - User.current = nil end def test_filter_on_custom_field_should_ignore_projects_with_field_disabled diff --git a/test/unit/watcher_test.rb b/test/unit/watcher_test.rb index 761bf5a71..48e619807 100644 --- a/test/unit/watcher_test.rb +++ b/test/unit/watcher_test.rb @@ -40,9 +40,12 @@ class WatcherTest < ActiveSupport::TestCase end def test_watch + group = Group.find(10) + assert @issue.add_watcher(group) assert @issue.add_watcher(@user) @issue.reload assert @issue.watchers.detect {|w| w.user == @user} + assert @issue.watchers.detect {|w| w.user == group} end def test_cant_watch_twice @@ -103,12 +106,14 @@ class WatcherTest < ActiveSupport::TestCase def test_addable_watcher_users addable_watcher_users = @issue.addable_watcher_users assert_kind_of Array, addable_watcher_users - assert_kind_of User, addable_watcher_users.first + addable_watcher_users.each do |addable_watcher| + assert_equal true, addable_watcher.is_a?(User) || addable_watcher.is_a?(Group) + end end def test_addable_watcher_users_should_not_include_user_that_cannot_view_the_object issue = Issue.new(:project => Project.find(1), :is_private => true) - assert_nil issue.addable_watcher_users.detect {|user| !issue.visible?(user)} + assert_nil issue.addable_watcher_users.detect {|user| user.is_a?(User) && !issue.visible?(user)} end def test_any_watched_should_return_false_if_no_object_is_watched @@ -147,9 +152,12 @@ class WatcherTest < ActiveSupport::TestCase end def test_unwatch + group = Group.find(10) + assert @issue.add_watcher(group) assert @issue.add_watcher(@user) @issue.reload assert_equal 1, @issue.remove_watcher(@user) + assert_equal 1, @issue.remove_watcher(group) end def test_prune_with_user |