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