Bulk watch/unwatch issues from the context menu (#7159).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11339 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2013-02-10 10:31:12 +00:00
parent 7303cc416c
commit 856ef810b4
7 changed files with 164 additions and 40 deletions
+43 -6
View File
@@ -25,7 +25,7 @@ class WatchersControllerTest < ActionController::TestCase
User.current = nil
end
def test_watch
def test_watch_a_single_object
@request.session[:user_id] = 3
assert_difference('Watcher.count') do
xhr :post, :watch, :object_type => 'issue', :object_id => '1'
@@ -35,6 +35,27 @@ class WatchersControllerTest < ActionController::TestCase
assert Issue.find(1).watched_by?(User.find(3))
end
def test_watch_a_collection_with_a_single_object
@request.session[:user_id] = 3
assert_difference('Watcher.count') do
xhr :post, :watch, :object_type => 'issue', :object_id => ['1']
assert_response :success
assert_include '$(".issue-1-watcher")', response.body
end
assert Issue.find(1).watched_by?(User.find(3))
end
def test_watch_a_collection_with_multiple_objects
@request.session[:user_id] = 3
assert_difference('Watcher.count', 2) do
xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3']
assert_response :success
assert_include '$(".issue-bulk-watcher")', response.body
end
assert Issue.find(1).watched_by?(User.find(3))
assert Issue.find(3).watched_by?(User.find(3))
end
def test_watch_should_be_denied_without_permission
Role.find(2).remove_permission! :view_issues
@request.session[:user_id] = 3
@@ -70,6 +91,20 @@ class WatchersControllerTest < ActionController::TestCase
assert !Issue.find(1).watched_by?(User.find(3))
end
def test_unwatch_a_collection_with_multiple_objects
@request.session[:user_id] = 3
Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
Watcher.create!(:user_id => 3, :watchable => Issue.find(3))
assert_difference('Watcher.count', -2) do
xhr :post, :unwatch, :object_type => 'issue', :object_id => ['1', '3']
assert_response :success
assert_include '$(".issue-bulk-watcher")', response.body
end
assert !Issue.find(1).watched_by?(User.find(3))
assert !Issue.find(3).watched_by?(User.find(3))
end
def test_new
@request.session[:user_id] = 2
xhr :get, :new, :object_type => 'issue', :object_id => '2'
@@ -77,7 +112,7 @@ class WatchersControllerTest < ActionController::TestCase
assert_match /ajax-modal/, response.body
end
def test_new_for_new_record_with_id
def test_new_for_new_record_with_project_id
@request.session[:user_id] = 2
xhr :get, :new, :project_id => 1
assert_response :success
@@ -85,7 +120,7 @@ class WatchersControllerTest < ActionController::TestCase
assert_match /ajax-modal/, response.body
end
def test_new_for_new_record_with_identifier
def test_new_for_new_record_with_project_identifier
@request.session[:user_id] = 2
xhr :get, :new, :project_id => 'ecookbook'
assert_response :success
@@ -117,7 +152,8 @@ class WatchersControllerTest < ActionController::TestCase
end
def test_autocomplete_on_watchable_creation
xhr :get, :autocomplete_for_user, :q => 'mi'
@request.session[:user_id] = 2
xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook'
assert_response :success
assert_select 'input', :count => 4
assert_select 'input[name=?][value=1]', 'watcher[user_ids][]'
@@ -127,7 +163,8 @@ class WatchersControllerTest < ActionController::TestCase
end
def test_autocomplete_on_watchable_update
xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue'
@request.session[:user_id] = 2
xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue', :project_id => 'ecookbook'
assert_response :success
assert_select 'input', :count => 3
assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
@@ -139,7 +176,7 @@ class WatchersControllerTest < ActionController::TestCase
def test_append
@request.session[:user_id] = 2
assert_no_difference 'Watcher.count' do
xhr :post, :append, :watcher => {:user_ids => ['4', '7']}
xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook'
assert_response :success
assert_include 'watchers_inputs', response.body
assert_include 'issue[watcher_user_ids][]', response.body
+69
View File
@@ -0,0 +1,69 @@
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.expand_path('../../../test_helper', __FILE__)
class WatchersHelperTest < ActionView::TestCase
include WatchersHelper
include Redmine::I18n
fixtures :users, :issues
def setup
super
set_language_if_valid('en')
User.current = nil
end
test '#watcher_link with a non-watched object' do
expected = link_to(
"Watch",
"/watchers/watch?object_id=1&object_type=issue",
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
)
assert_equal expected, watcher_link(Issue.find(1), User.find(1))
end
test '#watcher_link with a single objet array' do
expected = link_to(
"Watch",
"/watchers/watch?object_id=1&object_type=issue",
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav-off"
)
assert_equal expected, watcher_link([Issue.find(1)], User.find(1))
end
test '#watcher_link with a multiple objets array' do
expected = link_to(
"Watch",
"/watchers/watch?object_id%5B%5D=1&object_id%5B%5D=3&object_type=issue",
:remote => true, :method => 'post', :class => "issue-bulk-watcher icon icon-fav-off"
)
assert_equal expected, watcher_link([Issue.find(1), Issue.find(3)], User.find(1))
end
test '#watcher_link with a watched object' do
Watcher.create!(:watchable => Issue.find(1), :user => User.find(1))
expected = link_to(
"Unwatch",
"/watchers/unwatch?object_id=1&object_type=issue",
:remote => true, :method => 'post', :class => "issue-1-watcher icon icon-fav"
)
assert_equal expected, watcher_link(Issue.find(1), User.find(1))
end
end