comparison test/functional/.svn/text-base/users_controller_test.rb.svn-base @ 0:513646585e45

* Import Redmine trunk SVN rev 3859
author Chris Cannam
date Fri, 23 Jul 2010 15:52:44 +0100
parents
children 1d32c0a0efbf
comparison
equal deleted inserted replaced
-1:000000000000 0:513646585e45
1 # redMine - project management software
2 # Copyright (C) 2006-2007 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.dirname(__FILE__) + '/../test_helper'
19 require 'users_controller'
20
21 # Re-raise errors caught by the controller.
22 class UsersController; def rescue_action(e) raise e end; end
23
24 class UsersControllerTest < ActionController::TestCase
25 include Redmine::I18n
26
27 fixtures :users, :projects, :members, :member_roles, :roles
28
29 def setup
30 @controller = UsersController.new
31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new
33 User.current = nil
34 @request.session[:user_id] = 1 # admin
35 end
36
37 def test_index
38 get :index
39 assert_response :success
40 assert_template 'index'
41 end
42
43 def test_index
44 get :index
45 assert_response :success
46 assert_template 'index'
47 assert_not_nil assigns(:users)
48 # active users only
49 assert_nil assigns(:users).detect {|u| !u.active?}
50 end
51
52 def test_index_with_name_filter
53 get :index, :name => 'john'
54 assert_response :success
55 assert_template 'index'
56 users = assigns(:users)
57 assert_not_nil users
58 assert_equal 1, users.size
59 assert_equal 'John', users.first.firstname
60 end
61
62 def test_show
63 @request.session[:user_id] = nil
64 get :show, :id => 2
65 assert_response :success
66 assert_template 'show'
67 assert_not_nil assigns(:user)
68 end
69
70 def test_show_should_not_fail_when_custom_values_are_nil
71 user = User.find(2)
72
73 # Create a custom field to illustrate the issue
74 custom_field = CustomField.create!(:name => 'Testing', :field_format => 'text')
75 custom_value = user.custom_values.build(:custom_field => custom_field).save!
76
77 get :show, :id => 2
78 assert_response :success
79 end
80
81 def test_show_inactive
82 @request.session[:user_id] = nil
83 get :show, :id => 5
84 assert_response 404
85 end
86
87 def test_show_should_not_reveal_users_with_no_visible_activity_or_project
88 @request.session[:user_id] = nil
89 get :show, :id => 9
90 assert_response 404
91 end
92
93 def test_show_inactive_by_admin
94 @request.session[:user_id] = 1
95 get :show, :id => 5
96 assert_response 200
97 assert_not_nil assigns(:user)
98 end
99
100 def test_edit
101 ActionMailer::Base.deliveries.clear
102 post :edit, :id => 2, :user => {:firstname => 'Changed'}
103 assert_equal 'Changed', User.find(2).firstname
104 assert ActionMailer::Base.deliveries.empty?
105 end
106
107 def test_edit_with_activation_should_send_a_notification
108 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
109 u.login = 'foo'
110 u.status = User::STATUS_REGISTERED
111 u.save!
112 ActionMailer::Base.deliveries.clear
113 Setting.bcc_recipients = '1'
114
115 post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
116 assert u.reload.active?
117 mail = ActionMailer::Base.deliveries.last
118 assert_not_nil mail
119 assert_equal ['foo.bar@somenet.foo'], mail.bcc
120 assert mail.body.include?(ll('fr', :notice_account_activated))
121 end
122
123 def test_edit_with_password_change_should_send_a_notification
124 ActionMailer::Base.deliveries.clear
125 Setting.bcc_recipients = '1'
126
127 u = User.find(2)
128 post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
129 assert_equal User.hash_password('newpass'), u.reload.hashed_password
130
131 mail = ActionMailer::Base.deliveries.last
132 assert_not_nil mail
133 assert_equal [u.mail], mail.bcc
134 assert mail.body.include?('newpass')
135 end
136
137 def test_edit_membership
138 post :edit_membership, :id => 2, :membership_id => 1,
139 :membership => { :role_ids => [2]}
140 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
141 assert_equal [2], Member.find(1).role_ids
142 end
143
144 def test_destroy_membership
145 post :destroy_membership, :id => 2, :membership_id => 1
146 assert_redirected_to :action => 'edit', :id => '2', :tab => 'memberships'
147 assert_nil Member.find_by_id(1)
148 end
149 end