annotate test/functional/.svn/text-base/watchers_controller_test.rb.svn-base @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children cbce1fd3b1b7
rev   line source
Chris@0 1 # Redmine - project management software
Chris@0 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
Chris@0 3 #
Chris@0 4 # This program is free software; you can redistribute it and/or
Chris@0 5 # modify it under the terms of the GNU General Public License
Chris@0 6 # as published by the Free Software Foundation; either version 2
Chris@0 7 # of the License, or (at your option) any later version.
Chris@0 8 #
Chris@0 9 # This program is distributed in the hope that it will be useful,
Chris@0 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 12 # GNU General Public License for more details.
Chris@0 13 #
Chris@0 14 # You should have received a copy of the GNU General Public License
Chris@0 15 # along with this program; if not, write to the Free Software
Chris@0 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@0 17
Chris@117 18 require File.expand_path('../../test_helper', __FILE__)
Chris@0 19 require 'watchers_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class WatchersController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class WatchersControllerTest < ActionController::TestCase
Chris@0 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
Chris@0 26 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
Chris@0 27
Chris@0 28 def setup
Chris@0 29 @controller = WatchersController.new
Chris@0 30 @request = ActionController::TestRequest.new
Chris@0 31 @response = ActionController::TestResponse.new
Chris@0 32 User.current = nil
Chris@0 33 end
Chris@0 34
Chris@0 35 def test_get_watch_should_be_invalid
Chris@0 36 @request.session[:user_id] = 3
Chris@0 37 get :watch, :object_type => 'issue', :object_id => '1'
Chris@0 38 assert_response 405
Chris@0 39 end
Chris@0 40
Chris@0 41 def test_watch
Chris@0 42 @request.session[:user_id] = 3
Chris@0 43 assert_difference('Watcher.count') do
Chris@0 44 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
Chris@0 45 assert_response :success
Chris@0 46 assert_select_rjs :replace_html, 'watcher'
Chris@0 47 end
Chris@0 48 assert Issue.find(1).watched_by?(User.find(3))
Chris@0 49 end
Chris@0 50
Chris@0 51 def test_watch_should_be_denied_without_permission
Chris@0 52 Role.find(2).remove_permission! :view_issues
Chris@0 53 @request.session[:user_id] = 3
Chris@0 54 assert_no_difference('Watcher.count') do
Chris@0 55 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
Chris@0 56 assert_response 403
Chris@0 57 end
Chris@0 58 end
Chris@0 59
Chris@0 60 def test_watch_with_multiple_replacements
Chris@0 61 @request.session[:user_id] = 3
Chris@0 62 assert_difference('Watcher.count') do
Chris@0 63 xhr :post, :watch, :object_type => 'issue', :object_id => '1', :replace => ['watch_item_1','watch_item_2']
Chris@0 64 assert_response :success
Chris@0 65 assert_select_rjs :replace_html, 'watch_item_1'
Chris@0 66 assert_select_rjs :replace_html, 'watch_item_2'
Chris@0 67 end
Chris@0 68 end
Chris@0 69
Chris@0 70 def test_unwatch
Chris@0 71 @request.session[:user_id] = 3
Chris@0 72 assert_difference('Watcher.count', -1) do
Chris@0 73 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
Chris@0 74 assert_response :success
Chris@0 75 assert_select_rjs :replace_html, 'watcher'
Chris@0 76 end
Chris@0 77 assert !Issue.find(1).watched_by?(User.find(3))
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_unwatch_with_multiple_replacements
Chris@0 81 @request.session[:user_id] = 3
Chris@0 82 assert_difference('Watcher.count', -1) do
Chris@0 83 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2', :replace => ['watch_item_1', 'watch_item_2']
Chris@0 84 assert_response :success
Chris@0 85 assert_select_rjs :replace_html, 'watch_item_1'
Chris@0 86 assert_select_rjs :replace_html, 'watch_item_2'
Chris@0 87 end
Chris@0 88 assert !Issue.find(1).watched_by?(User.find(3))
Chris@0 89 end
Chris@0 90
Chris@0 91 def test_new_watcher
Chris@0 92 @request.session[:user_id] = 2
Chris@0 93 assert_difference('Watcher.count') do
Chris@0 94 xhr :post, :new, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
Chris@0 95 assert_response :success
Chris@0 96 assert_select_rjs :replace_html, 'watchers'
Chris@0 97 end
Chris@0 98 assert Issue.find(2).watched_by?(User.find(4))
Chris@0 99 end
Chris@0 100
Chris@0 101 def test_remove_watcher
Chris@0 102 @request.session[:user_id] = 2
Chris@0 103 assert_difference('Watcher.count', -1) do
Chris@0 104 xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
Chris@0 105 assert_response :success
Chris@0 106 assert_select_rjs :replace_html, 'watchers'
Chris@0 107 end
Chris@0 108 assert !Issue.find(2).watched_by?(User.find(3))
Chris@0 109 end
Chris@0 110 end