To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / functional / watchers_controller_test.rb @ 441:cbce1fd3b1b7
History | View | Annotate | Download (3.15 KB)
| 1 | 0:513646585e45 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | 441:cbce1fd3b1b7 | Chris | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
| 3 | 0:513646585e45 | Chris | #
|
| 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 | 119:8661b858af72 | Chris | require File.expand_path('../../test_helper', __FILE__) |
| 19 | 0:513646585e45 | Chris | 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_get_watch_should_be_invalid |
||
| 36 | @request.session[:user_id] = 3 |
||
| 37 | get :watch, :object_type => 'issue', :object_id => '1' |
||
| 38 | assert_response 405
|
||
| 39 | end
|
||
| 40 | |||
| 41 | def test_watch |
||
| 42 | @request.session[:user_id] = 3 |
||
| 43 | assert_difference('Watcher.count') do |
||
| 44 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
||
| 45 | assert_response :success
|
||
| 46 | 441:cbce1fd3b1b7 | Chris | assert @response.body.include?('$$(".issue-1-watcher")') |
| 47 | 0:513646585e45 | Chris | end
|
| 48 | assert Issue.find(1).watched_by?(User.find(3)) |
||
| 49 | end
|
||
| 50 | |||
| 51 | def test_watch_should_be_denied_without_permission |
||
| 52 | Role.find(2).remove_permission! :view_issues |
||
| 53 | @request.session[:user_id] = 3 |
||
| 54 | assert_no_difference('Watcher.count') do |
||
| 55 | xhr :post, :watch, :object_type => 'issue', :object_id => '1' |
||
| 56 | assert_response 403
|
||
| 57 | end
|
||
| 58 | end
|
||
| 59 | |||
| 60 | def test_unwatch |
||
| 61 | @request.session[:user_id] = 3 |
||
| 62 | assert_difference('Watcher.count', -1) do |
||
| 63 | xhr :post, :unwatch, :object_type => 'issue', :object_id => '2' |
||
| 64 | assert_response :success
|
||
| 65 | 441:cbce1fd3b1b7 | Chris | assert @response.body.include?('$$(".issue-2-watcher")') |
| 66 | 0:513646585e45 | Chris | end
|
| 67 | assert !Issue.find(1).watched_by?(User.find(3)) |
||
| 68 | end
|
||
| 69 | |||
| 70 | def test_new_watcher |
||
| 71 | @request.session[:user_id] = 2 |
||
| 72 | assert_difference('Watcher.count') do |
||
| 73 | xhr :post, :new, :object_type => 'issue', :object_id => '2', :watcher => {:user_id => '4'} |
||
| 74 | assert_response :success
|
||
| 75 | assert_select_rjs :replace_html, 'watchers' |
||
| 76 | end
|
||
| 77 | assert Issue.find(2).watched_by?(User.find(4)) |
||
| 78 | end
|
||
| 79 | |||
| 80 | def test_remove_watcher |
||
| 81 | @request.session[:user_id] = 2 |
||
| 82 | assert_difference('Watcher.count', -1) do |
||
| 83 | xhr :post, :destroy, :object_type => 'issue', :object_id => '2', :user_id => '3' |
||
| 84 | assert_response :success
|
||
| 85 | assert_select_rjs :replace_html, 'watchers' |
||
| 86 | end
|
||
| 87 | assert !Issue.find(2).watched_by?(User.find(3)) |
||
| 88 | end
|
||
| 89 | end |