if request.post?
@user.admin = params[:user][:admin] if params[:user][:admin]
@user.login = params[:user][:login] if params[:user][:login]
- @user.password, @user.password_confirmation = params[:password], params[:password_confirmation] unless params[:password].nil? or params[:password].empty? or @user.auth_source_id
+ if params[:password].present? && (@user.auth_source_id.nil? || params[:user][:auth_source_id].blank?)
+ @user.password, @user.password_confirmation = params[:password], params[:password_confirmation]
+ end
@user.group_ids = params[:user][:group_ids] if params[:user][:group_ids]
@user.attributes = params[:user]
# Was the account actived ? (do it before User#save clears the change)
assert_equal [u.mail], mail.bcc
assert mail.body.include?('newpass')
end
+
+ test "POST :edit with a password change to an AuthSource user switching to Internal authentication" do
+ # Configure as auth source
+ u = User.find(2)
+ u.auth_source = AuthSource.find(1)
+ u.save!
+
+ post :edit, :id => u.id, :user => {:auth_source_id => ''}, :password => 'newpass', :password_confirmation => 'newpass'
+
+ assert_equal nil, u.reload.auth_source
+ assert_equal User.hash_password('newpass'), u.reload.hashed_password
+ end
def test_edit_membership
post :edit_membership, :id => 2, :membership_id => 1,