annotate .svn/pristine/31/3155f8295657e15516d6d855aaf7eefbf749a747.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

Fix failure to interpret Javascript when autocompleting members for project
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Thu, 11 Sep 2014 10:24:38 +0100
parents e248c7af89ec
children
rev   line source
Chris@1494 1 # Redmine - project management software
Chris@1494 2 # Copyright (C) 2006-2014 Jean-Philippe Lang
Chris@1494 3 #
Chris@1494 4 # This program is free software; you can redistribute it and/or
Chris@1494 5 # modify it under the terms of the GNU General Public License
Chris@1494 6 # as published by the Free Software Foundation; either version 2
Chris@1494 7 # of the License, or (at your option) any later version.
Chris@1494 8 #
Chris@1494 9 # This program is distributed in the hope that it will be useful,
Chris@1494 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1494 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1494 12 # GNU General Public License for more details.
Chris@1494 13 #
Chris@1494 14 # You should have received a copy of the GNU General Public License
Chris@1494 15 # along with this program; if not, write to the Free Software
Chris@1494 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1494 17
Chris@1494 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1494 19
Chris@1494 20 class WatchersControllerTest < ActionController::TestCase
Chris@1494 21 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
Chris@1494 22 :issues, :trackers, :projects_trackers, :issue_statuses, :enumerations, :watchers
Chris@1494 23
Chris@1494 24 def setup
Chris@1494 25 User.current = nil
Chris@1494 26 end
Chris@1494 27
Chris@1494 28 def test_watch_a_single_object
Chris@1494 29 @request.session[:user_id] = 3
Chris@1494 30 assert_difference('Watcher.count') do
Chris@1494 31 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
Chris@1494 32 assert_response :success
Chris@1494 33 assert_include '$(".issue-1-watcher")', response.body
Chris@1494 34 end
Chris@1494 35 assert Issue.find(1).watched_by?(User.find(3))
Chris@1494 36 end
Chris@1494 37
Chris@1494 38 def test_watch_a_collection_with_a_single_object
Chris@1494 39 @request.session[:user_id] = 3
Chris@1494 40 assert_difference('Watcher.count') do
Chris@1494 41 xhr :post, :watch, :object_type => 'issue', :object_id => ['1']
Chris@1494 42 assert_response :success
Chris@1494 43 assert_include '$(".issue-1-watcher")', response.body
Chris@1494 44 end
Chris@1494 45 assert Issue.find(1).watched_by?(User.find(3))
Chris@1494 46 end
Chris@1494 47
Chris@1494 48 def test_watch_a_collection_with_multiple_objects
Chris@1494 49 @request.session[:user_id] = 3
Chris@1494 50 assert_difference('Watcher.count', 2) do
Chris@1494 51 xhr :post, :watch, :object_type => 'issue', :object_id => ['1', '3']
Chris@1494 52 assert_response :success
Chris@1494 53 assert_include '$(".issue-bulk-watcher")', response.body
Chris@1494 54 end
Chris@1494 55 assert Issue.find(1).watched_by?(User.find(3))
Chris@1494 56 assert Issue.find(3).watched_by?(User.find(3))
Chris@1494 57 end
Chris@1494 58
Chris@1494 59 def test_watch_should_be_denied_without_permission
Chris@1494 60 Role.find(2).remove_permission! :view_issues
Chris@1494 61 @request.session[:user_id] = 3
Chris@1494 62 assert_no_difference('Watcher.count') do
Chris@1494 63 xhr :post, :watch, :object_type => 'issue', :object_id => '1'
Chris@1494 64 assert_response 403
Chris@1494 65 end
Chris@1494 66 end
Chris@1494 67
Chris@1494 68 def test_watch_invalid_class_should_respond_with_404
Chris@1494 69 @request.session[:user_id] = 3
Chris@1494 70 assert_no_difference('Watcher.count') do
Chris@1494 71 xhr :post, :watch, :object_type => 'foo', :object_id => '1'
Chris@1494 72 assert_response 404
Chris@1494 73 end
Chris@1494 74 end
Chris@1494 75
Chris@1494 76 def test_watch_invalid_object_should_respond_with_404
Chris@1494 77 @request.session[:user_id] = 3
Chris@1494 78 assert_no_difference('Watcher.count') do
Chris@1494 79 xhr :post, :watch, :object_type => 'issue', :object_id => '999'
Chris@1494 80 assert_response 404
Chris@1494 81 end
Chris@1494 82 end
Chris@1494 83
Chris@1494 84 def test_unwatch
Chris@1494 85 @request.session[:user_id] = 3
Chris@1494 86 assert_difference('Watcher.count', -1) do
Chris@1494 87 xhr :delete, :unwatch, :object_type => 'issue', :object_id => '2'
Chris@1494 88 assert_response :success
Chris@1494 89 assert_include '$(".issue-2-watcher")', response.body
Chris@1494 90 end
Chris@1494 91 assert !Issue.find(1).watched_by?(User.find(3))
Chris@1494 92 end
Chris@1494 93
Chris@1494 94 def test_unwatch_a_collection_with_multiple_objects
Chris@1494 95 @request.session[:user_id] = 3
Chris@1494 96 Watcher.create!(:user_id => 3, :watchable => Issue.find(1))
Chris@1494 97 Watcher.create!(:user_id => 3, :watchable => Issue.find(3))
Chris@1494 98
Chris@1494 99 assert_difference('Watcher.count', -2) do
Chris@1494 100 xhr :delete, :unwatch, :object_type => 'issue', :object_id => ['1', '3']
Chris@1494 101 assert_response :success
Chris@1494 102 assert_include '$(".issue-bulk-watcher")', response.body
Chris@1494 103 end
Chris@1494 104 assert !Issue.find(1).watched_by?(User.find(3))
Chris@1494 105 assert !Issue.find(3).watched_by?(User.find(3))
Chris@1494 106 end
Chris@1494 107
Chris@1494 108 def test_new
Chris@1494 109 @request.session[:user_id] = 2
Chris@1494 110 xhr :get, :new, :object_type => 'issue', :object_id => '2'
Chris@1494 111 assert_response :success
Chris@1494 112 assert_match /ajax-modal/, response.body
Chris@1494 113 end
Chris@1494 114
Chris@1494 115 def test_new_for_new_record_with_project_id
Chris@1494 116 @request.session[:user_id] = 2
Chris@1494 117 xhr :get, :new, :project_id => 1
Chris@1494 118 assert_response :success
Chris@1494 119 assert_equal Project.find(1), assigns(:project)
Chris@1494 120 assert_match /ajax-modal/, response.body
Chris@1494 121 end
Chris@1494 122
Chris@1494 123 def test_new_for_new_record_with_project_identifier
Chris@1494 124 @request.session[:user_id] = 2
Chris@1494 125 xhr :get, :new, :project_id => 'ecookbook'
Chris@1494 126 assert_response :success
Chris@1494 127 assert_equal Project.find(1), assigns(:project)
Chris@1494 128 assert_match /ajax-modal/, response.body
Chris@1494 129 end
Chris@1494 130
Chris@1494 131 def test_create
Chris@1494 132 @request.session[:user_id] = 2
Chris@1494 133 assert_difference('Watcher.count') do
Chris@1494 134 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'}
Chris@1494 135 assert_response :success
Chris@1494 136 assert_match /watchers/, response.body
Chris@1494 137 assert_match /ajax-modal/, response.body
Chris@1494 138 end
Chris@1494 139 assert Issue.find(2).watched_by?(User.find(4))
Chris@1494 140 end
Chris@1494 141
Chris@1494 142 def test_create_multiple
Chris@1494 143 @request.session[:user_id] = 2
Chris@1494 144 assert_difference('Watcher.count', 2) do
Chris@1494 145 xhr :post, :create, :object_type => 'issue', :object_id => '2', :watcher => {:user_ids => ['4', '7']}
Chris@1494 146 assert_response :success
Chris@1494 147 assert_match /watchers/, response.body
Chris@1494 148 assert_match /ajax-modal/, response.body
Chris@1494 149 end
Chris@1494 150 assert Issue.find(2).watched_by?(User.find(4))
Chris@1494 151 assert Issue.find(2).watched_by?(User.find(7))
Chris@1494 152 end
Chris@1494 153
Chris@1494 154 def test_autocomplete_on_watchable_creation
Chris@1494 155 @request.session[:user_id] = 2
Chris@1494 156 xhr :get, :autocomplete_for_user, :q => 'mi', :project_id => 'ecookbook'
Chris@1494 157 assert_response :success
Chris@1494 158 assert_select 'input', :count => 4
Chris@1494 159 assert_select 'input[name=?][value=1]', 'watcher[user_ids][]'
Chris@1494 160 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
Chris@1494 161 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
Chris@1494 162 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
Chris@1494 163 end
Chris@1494 164
Chris@1494 165 def test_autocomplete_on_watchable_update
Chris@1494 166 @request.session[:user_id] = 2
Chris@1494 167 xhr :get, :autocomplete_for_user, :q => 'mi', :object_id => '2' , :object_type => 'issue', :project_id => 'ecookbook'
Chris@1494 168 assert_response :success
Chris@1494 169 assert_select 'input', :count => 3
Chris@1494 170 assert_select 'input[name=?][value=2]', 'watcher[user_ids][]'
Chris@1494 171 assert_select 'input[name=?][value=8]', 'watcher[user_ids][]'
Chris@1494 172 assert_select 'input[name=?][value=9]', 'watcher[user_ids][]'
Chris@1494 173
Chris@1494 174 end
Chris@1494 175
Chris@1494 176 def test_append
Chris@1494 177 @request.session[:user_id] = 2
Chris@1494 178 assert_no_difference 'Watcher.count' do
Chris@1494 179 xhr :post, :append, :watcher => {:user_ids => ['4', '7']}, :project_id => 'ecookbook'
Chris@1494 180 assert_response :success
Chris@1494 181 assert_include 'watchers_inputs', response.body
Chris@1494 182 assert_include 'issue[watcher_user_ids][]', response.body
Chris@1494 183 end
Chris@1494 184 end
Chris@1494 185
Chris@1494 186 def test_remove_watcher
Chris@1494 187 @request.session[:user_id] = 2
Chris@1494 188 assert_difference('Watcher.count', -1) do
Chris@1494 189 xhr :delete, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3'
Chris@1494 190 assert_response :success
Chris@1494 191 assert_match /watchers/, response.body
Chris@1494 192 end
Chris@1494 193 assert !Issue.find(2).watched_by?(User.find(3))
Chris@1494 194 end
Chris@1494 195 end