comparison .svn/pristine/70/704aed8cd1d0bda41857f825de04eaafa665a7f0.svn-base @ 1296:038ba2d95de8 redmine-2.2

Fix redmine-2.2 branch update (add missing svn files)
author Chris Cannam
date Fri, 14 Jun 2013 09:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1296:038ba2d95de8
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'watchers_controller'
20
21 # Re-raise errors caught by the controller.
22 class WatchersController; def rescue_action(e) raise e end; end
23
24 class WatchersControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
27
28 def setup
29 @controller = WatchersController.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
32 User.current = nil
33 end
34
35 def test_watch
36 @request.session[:user_id] = 3
37 assert_difference('Watcher.count') do
38 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
39 assert_response :success
40 assert_include '$(".issue-1-watcher")', response.body
41 end
42 assert Issue.find(1).watched_by?(User.find(3))
43 end
44
45 def test_watch_should_be_denied_without_permission
46 Role.find(2).remove_permission! :view_issues
47 @request.session[:user_id] = 3
48 assert_no_difference('Watcher.count') do
49 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
50 assert_response 403
51 end
52 end
53
54 def test_watch_invalid_class_should_respond_with_404
55 @request.session[:user_id] = 3
56 assert_no_difference('Watcher.count') do
57 xhr :post, :watch, :object_type => 'foo', :object_id => '1'
58 assert_response 404
59 end
60 end
61
62 def test_watch_invalid_object_should_respond_with_404
63 @request.session[:user_id] = 3
64 assert_no_difference('Watcher.count') do
65 xhr :post, :watch, :object_type => 'issue', :object_id => '999'
66 assert_response 404
67 end
68 end
69
70 def test_unwatch
71 @request.session[:user_id] = 3
72 assert_difference('Watcher.count', -1) do
73 xhr :post, :unwatch, :object_type => 'issue', :object_id => '2'
74 assert_response :success
75 assert_include '$(".issue-2-watcher")', response.body
76 end
77 assert !Issue.find(1).watched_by?(User.find(3))
78 end
79
80 def test_new
81 @request.session[:user_id] = 2
82 xhr :get, :new, :object_type => 'issue', :object_id => '2'
83 assert_response :success
84 assert_match /ajax-modal/, response.body
85 end
86
87 def test_new_for_new_record_with_id
88 @request.session[:user_id] = 2
89 xhr :get, :new, :project_id => 1
90 assert_response :success
91 assert_equal Project.find(1), assigns(:project)
92 assert_match /ajax-modal/, response.body
93 end
94
95 def test_new_for_new_record_with_identifier
96 @request.session[:user_id] = 2
97 xhr :get, :new, :project_id => 'ecookbook'
98 assert_response :success
99 assert_equal Project.find(1), assigns(:project)
100 assert_match /ajax-modal/, response.body
101 end
102
103 def test_create
104 @request.session[:user_id] = 2
105 assert_difference('Watcher.count') do
106 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
107 assert_response :success
108 assert_match /watchers/, response.body
109 assert_match /ajax-modal/, response.body
110 end
111 assert Issue.find(2).watched_by?(User.find(4))
112 end
113
114 def test_create_multiple
115 @request.session[:user_id] = 2
116 assert_difference('Watcher.count', 2) do
117 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
118 assert_response :success
119 assert_match /watchers/, response.body
120 assert_match /ajax-modal/, response.body
121 end
122 assert Issue.find(2).watched_by?(User.find(4))
123 assert Issue.find(2).watched_by?(User.find(7))
124 end
125
126 def test_autocomplete_on_watchable_creation
127 xhr :get, :autocomplete_for_user, :q => 'mi'
128 assert_response :success
129 assert_select 'input', :count => 4
130 assert_select 'input[name=?][value=1]', 'watcher[user_ids][]'
131 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
132 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
133 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
134 end
135
136 def test_autocomplete_on_watchable_update
137 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue'
138 assert_response :success
139 assert_select 'input', :count => 3
140 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
141 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
142 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
143
144 end
145
146 def test_append
147 @request.session[:user_id] = 2
148 assert_no_difference 'Watcher.count' do
149 xhr :post, :append, :watcher => {:user_ids => ['4', '7']}
150 assert_response :success
151 assert_include 'watchers_inputs', response.body
152 assert_include 'issue[watcher_user_ids][]', response.body
153 end
154 end
155
156 def test_remove_watcher
157 @request.session[:user_id] = 2
158 assert_difference('Watcher.count', -1) do
159 xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
160 assert_response :success
161 assert_match /watchers/, response.body
162 end
163 assert !Issue.find(2).watched_by?(User.find(3))
164 end
165 end