comparison test/functional/users_controller_test.rb @ 37:94944d00e43c

* Update to SVN trunk rev 4411
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 19 Nov 2010 13:24:41 +0000
parents 40f7cfd4df19
children af80e5618e9b
comparison
equal deleted inserted replaced
22:40f7cfd4df19 37:94944d00e43c
22 class UsersController; def rescue_action(e) raise e end; end 22 class UsersController; def rescue_action(e) raise e end; end
23 23
24 class UsersControllerTest < ActionController::TestCase 24 class UsersControllerTest < ActionController::TestCase
25 include Redmine::I18n 25 include Redmine::I18n
26 26
27 fixtures :users, :projects, :members, :member_roles, :roles 27 fixtures :users, :projects, :members, :member_roles, :roles, :auth_sources, :custom_fields, :custom_values
28 28
29 def setup 29 def setup
30 @controller = UsersController.new 30 @controller = UsersController.new
31 @request = ActionController::TestRequest.new 31 @request = ActionController::TestRequest.new
32 @response = ActionController::TestResponse.new 32 @response = ActionController::TestResponse.new
63 @request.session[:user_id] = nil 63 @request.session[:user_id] = nil
64 get :show, :id => 2 64 get :show, :id => 2
65 assert_response :success 65 assert_response :success
66 assert_template 'show' 66 assert_template 'show'
67 assert_not_nil assigns(:user) 67 assert_not_nil assigns(:user)
68
69 assert_tag 'li', :content => /Phone number/
70 end
71
72 def test_show_should_not_display_hidden_custom_fields
73 @request.session[:user_id] = nil
74 UserCustomField.find_by_name('Phone number').update_attribute :visible, false
75 get :show, :id => 2
76 assert_response :success
77 assert_template 'show'
78 assert_not_nil assigns(:user)
79
80 assert_no_tag 'li', :content => /Phone number/
68 end 81 end
69 82
70 def test_show_should_not_fail_when_custom_values_are_nil 83 def test_show_should_not_fail_when_custom_values_are_nil
71 user = User.find(2) 84 user = User.find(2)
72 85
105 assert_not_nil memberships 118 assert_not_nil memberships
106 project_ids = memberships.map(&:project_id) 119 project_ids = memberships.map(&:project_id)
107 assert project_ids.include?(2) #private project admin can see 120 assert project_ids.include?(2) #private project admin can see
108 end 121 end
109 122
110 def test_edit 123 context "GET :new" do
124 setup do
125 get :new
126 end
127
128 should_assign_to :user
129 should_respond_with :success
130 should_render_template :new
131 end
132
133 context "POST :create" do
134 context "when successful" do
135 setup do
136 post :create, :user => {
137 :firstname => 'John',
138 :lastname => 'Doe',
139 :login => 'jdoe',
140 :password => 'test',
141 :password_confirmation => 'test',
142 :mail => 'jdoe@gmail.com'
143 },
144 :notification_option => 'none'
145 end
146
147 should_assign_to :user
148 should_respond_with :redirect
149 should_redirect_to('user edit') { {:controller => 'users', :action => 'edit', :id => User.find_by_login('jdoe')}}
150
151 should 'set the users mail notification' do
152 user = User.last
153 assert_equal 'none', user.mail_notification
154 end
155 end
156
157 context "when unsuccessful" do
158 setup do
159 post :create, :user => {}
160 end
161
162 should_assign_to :user
163 should_respond_with :success
164 should_render_template :new
165 end
166
167 end
168
169 def test_update
111 ActionMailer::Base.deliveries.clear 170 ActionMailer::Base.deliveries.clear
112 post :edit, :id => 2, :user => {:firstname => 'Changed'} 171 put :update, :id => 2, :user => {:firstname => 'Changed'}, :notification_option => 'all', :pref => {:hide_mail => '1', :comments_sorting => 'desc'}
113 assert_equal 'Changed', User.find(2).firstname 172
173 user = User.find(2)
174 assert_equal 'Changed', user.firstname
175 assert_equal 'all', user.mail_notification
176 assert_equal true, user.pref[:hide_mail]
177 assert_equal 'desc', user.pref[:comments_sorting]
114 assert ActionMailer::Base.deliveries.empty? 178 assert ActionMailer::Base.deliveries.empty?
115 end 179 end
116 180
117 def test_edit_with_activation_should_send_a_notification 181 def test_update_with_activation_should_send_a_notification
118 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr') 182 u = User.new(:firstname => 'Foo', :lastname => 'Bar', :mail => 'foo.bar@somenet.foo', :language => 'fr')
119 u.login = 'foo' 183 u.login = 'foo'
120 u.status = User::STATUS_REGISTERED 184 u.status = User::STATUS_REGISTERED
121 u.save! 185 u.save!
122 ActionMailer::Base.deliveries.clear 186 ActionMailer::Base.deliveries.clear
123 Setting.bcc_recipients = '1' 187 Setting.bcc_recipients = '1'
124 188
125 post :edit, :id => u.id, :user => {:status => User::STATUS_ACTIVE} 189 put :update, :id => u.id, :user => {:status => User::STATUS_ACTIVE}
126 assert u.reload.active? 190 assert u.reload.active?
127 mail = ActionMailer::Base.deliveries.last 191 mail = ActionMailer::Base.deliveries.last
128 assert_not_nil mail 192 assert_not_nil mail
129 assert_equal ['foo.bar@somenet.foo'], mail.bcc 193 assert_equal ['foo.bar@somenet.foo'], mail.bcc
130 assert mail.body.include?(ll('fr', :notice_account_activated)) 194 assert mail.body.include?(ll('fr', :notice_account_activated))
131 end 195 end
132 196
133 def test_edit_with_password_change_should_send_a_notification 197 def test_updat_with_password_change_should_send_a_notification
134 ActionMailer::Base.deliveries.clear 198 ActionMailer::Base.deliveries.clear
135 Setting.bcc_recipients = '1' 199 Setting.bcc_recipients = '1'
136 200
137 u = User.find(2) 201 u = User.find(2)
138 post :edit, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1' 202 put :update, :id => u.id, :user => {}, :password => 'newpass', :password_confirmation => 'newpass', :send_information => '1'
139 assert_equal User.hash_password('newpass'), u.reload.hashed_password 203 assert_equal User.hash_password('newpass'), u.reload.hashed_password
140 204
141 mail = ActionMailer::Base.deliveries.last 205 mail = ActionMailer::Base.deliveries.last
142 assert_not_nil mail 206 assert_not_nil mail
143 assert_equal [u.mail], mail.bcc 207 assert_equal [u.mail], mail.bcc
144 assert mail.body.include?('newpass') 208 assert mail.body.include?('newpass')
145 end 209 end
146 210
147 test "POST :edit with a password change to an AuthSource user switching to Internal authentication" do 211 test "put :update with a password change to an AuthSource user switching to Internal authentication" do
148 # Configure as auth source 212 # Configure as auth source
149 u = User.find(2) 213 u = User.find(2)
150 u.auth_source = AuthSource.find(1) 214 u.auth_source = AuthSource.find(1)
151 u.save! 215 u.save!
152 216
153 post :edit, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass' 217 put :update, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass'
154 218
155 assert_equal nil, u.reload.auth_source 219 assert_equal nil, u.reload.auth_source
156 assert_equal User.hash_password('newpass'), u.reload.hashed_password 220 assert_equal User.hash_password('newpass'), u.reload.hashed_password
157 end 221 end
158 222