diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b1c14c8bc..d22dd33cd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -93,11 +93,9 @@ class UsersController < ApplicationController @user.login = params[:user][:login] @user.password, @user.password_confirmation = params[:user][:password], params[:user][:password_confirmation] unless @user.auth_source_id - # TODO: Similar to My#account - @user.pref.attributes = params[:pref] - @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') - if @user.save + @user.pref.attributes = params[:pref] + @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') @user.pref.save @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 6adfc2757..ca805d4a1 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -194,6 +194,33 @@ class UsersControllerTest < ActionController::TestCase assert mail.body.include?('secret') end + def test_create_with_preferences + assert_difference 'User.count' do + post :create, + :user => { + :firstname => 'John', + :lastname => 'Doe', + :login => 'jdoe', + :password => 'secret', + :password_confirmation => 'secret', + :mail => 'jdoe@gmail.com', + :mail_notification => 'none' + }, + :pref => { + 'hide_mail' => '1', + 'time_zone' => 'Paris', + 'comments_sorting' => 'desc', + 'warn_on_leaving_unsaved' => '0' + } + end + user = User.first(:order => 'id DESC') + assert_equal 'jdoe', user.login + assert_equal true, user.pref.hide_mail + assert_equal 'Paris', user.pref.time_zone + assert_equal 'desc', user.pref[:comments_sorting] + assert_equal '0', user.pref[:warn_on_leaving_unsaved] + end + def test_create_with_failure assert_no_difference 'User.count' do post :create, :user => {}