From f824afb4d307dd2c1e1aed2b8437470d87ffc3d0 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 15 Nov 2016 16:10:20 +0800 Subject: [PATCH] FEATURE: Allow date_of_field column to be updated. --- app/assets/javascripts/discourse/models/user.js.es6 | 3 ++- app/controllers/users_controller.rb | 2 +- app/services/user_updater.rb | 1 + spec/services/user_updater_spec.rb | 5 ++++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/models/user.js.es6 b/app/assets/javascripts/discourse/models/user.js.es6 index e4f92d6b340..83223e79725 100644 --- a/app/assets/javascripts/discourse/models/user.js.es6 +++ b/app/assets/javascripts/discourse/models/user.js.es6 @@ -211,7 +211,8 @@ const User = RestModel.extend({ 'muted_tags', 'tracked_tags', 'watched_tags', - 'watching_first_post_tags'); + 'watching_first_post_tags', + 'date_of_birth'); ['email_always', 'mailing_list_mode', diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 792369932ea..0c226d93b29 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -706,7 +706,7 @@ class UsersController < ApplicationController end def user_params - result = params.permit(:name, :email, :password, :username) + result = params.permit(:name, :email, :password, :username, :date_of_birth) .merge(ip_address: request.remote_ip, registration_ip_address: request.remote_ip, locale: user_locale) diff --git a/app/services/user_updater.rb b/app/services/user_updater.rb index 44d217e3bd1..0361ccf4d54 100644 --- a/app/services/user_updater.rb +++ b/app/services/user_updater.rb @@ -54,6 +54,7 @@ class UserUpdater user.name = attributes.fetch(:name) { user.name } user.locale = attributes.fetch(:locale) { user.locale } + user.date_of_birth = attributes.fetch(:date_of_birth) { user.date_of_birth } if guardian.can_grant_title?(user) user.title = attributes.fetch(:title) { user.title } diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rb index a9a69ef6d7d..aa5f6f5734b 100644 --- a/spec/services/user_updater_spec.rb +++ b/spec/services/user_updater_spec.rb @@ -64,6 +64,7 @@ describe UserUpdater do it 'updates various fields' do user = Fabricate(:user) updater = UserUpdater.new(acting_user, user) + date_of_birth = Time.zone.now val = updater.update(bio_raw: 'my new bio', email_always: 'true', @@ -72,7 +73,8 @@ describe UserUpdater do new_topic_duration_minutes: 100, auto_track_topics_after_msecs: 101, notification_level_when_replying: 3, - email_in_reply_to: false + email_in_reply_to: false, + date_of_birth: date_of_birth ) expect(val).to be_truthy @@ -86,6 +88,7 @@ describe UserUpdater do expect(user.user_option.auto_track_topics_after_msecs).to eq 101 expect(user.user_option.notification_level_when_replying).to eq 3 expect(user.user_option.email_in_reply_to).to eq false + expect(user.date_of_birth).to eq(date_of_birth.to_date) end context 'when sso overrides bio' do