summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaƂgorzata Ksionek <meksionek@gmail.com>2019-05-20 11:43:06 +0200
committerEzekiel Kigbo <ekigbo@gitlab.com>2019-07-10 13:03:36 +1000
commit7e0da49fc2b0a95465e0ec47e68aad2b7fe97503 (patch)
treed3c5ea0cbf6908a3a6572d7762b5a795ff7a24a3
parent07652637bfdb15cce4d2355c6c116e6a0838e1d0 (diff)
downloadgitlab-ce-61864-timezones-with-the-same-identifier-defaults-to-the-first-in-the-list.tar.gz
Add saving timezone_name field
-rw-r--r--app/controllers/profiles_controller.rb1
-rw-r--r--app/models/user.rb1
-rw-r--r--app/models/user_preference.rb1
-rw-r--r--db/migrate/20190519094008_add_timezone_name_to_user_preferences.rb20
-rw-r--r--db/schema.rb1
-rw-r--r--spec/models/user_preference_spec.rb6
-rw-r--r--spec/services/users/update_service_spec.rb3
7 files changed, 32 insertions, 1 deletions
diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index 1d16ddb1608..caad1dc6dcc 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -107,6 +107,7 @@ class ProfilesController < Profiles::ApplicationController
:private_profile,
:include_private_contributions,
:timezone,
+ :timezone_name,
status: [:emoji, :message]
)
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 26be197209a..212397deb3c 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -231,6 +231,7 @@ class User < ApplicationRecord
delegate :set_notes_filter, to: :user_preference
delegate :first_day_of_week, :first_day_of_week=, to: :user_preference
delegate :timezone, :timezone=, to: :user_preference
+ delegate :timezone_name, :timezone_name=, to: :user_preference
delegate :time_display_relative, :time_display_relative=, to: :user_preference
delegate :time_format_in_24h, :time_format_in_24h=, to: :user_preference
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index f1326f4c8cb..a34b16a5499 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -11,6 +11,7 @@ class UserPreference < ApplicationRecord
validates :issue_notes_filter, :merge_request_notes_filter, inclusion: { in: NOTES_FILTERS.values }, presence: true
default_value_for :timezone, value: Time.zone.tzinfo.name, allows_nil: false
+ default_value_for :timezone_name, value: Time.zone.name, allows_nil: false
default_value_for :time_display_relative, value: true, allows_nil: false
default_value_for :time_format_in_24h, value: false, allows_nil: false
diff --git a/db/migrate/20190519094008_add_timezone_name_to_user_preferences.rb b/db/migrate/20190519094008_add_timezone_name_to_user_preferences.rb
new file mode 100644
index 00000000000..9c0b1510cd3
--- /dev/null
+++ b/db/migrate/20190519094008_add_timezone_name_to_user_preferences.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddTimezoneNameToUserPreferences < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ disable_ddl_transaction!
+
+ DOWNTIME = false
+
+ def up
+ add_column(:user_preferences, :timezone_name, :string)
+ end
+
+ def down
+ remove_column(:user_preferences, :timezone_name)
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9a8b64689bd..12f88fb706f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -3301,6 +3301,7 @@ ActiveRecord::Schema.define(version: 20190703130053) do
t.string "timezone"
t.boolean "time_display_relative"
t.boolean "time_format_in_24h"
+ t.string "timezone_name"
t.integer "epic_notes_filter", limit: 2, default: 0, null: false
t.string "epics_sort"
t.integer "roadmap_epics_state"
diff --git a/spec/models/user_preference_spec.rb b/spec/models/user_preference_spec.rb
index e09c91e874a..434a4f71ec1 100644
--- a/spec/models/user_preference_spec.rb
+++ b/spec/models/user_preference_spec.rb
@@ -79,4 +79,10 @@ describe UserPreference do
expect(user_preference.timezone).to eq(Time.zone.tzinfo.name)
end
end
+
+ describe '#timezone_name' do
+ it 'returns server time as default' do
+ expect(user_preference.timezone_name).to eq(Time.zone.name)
+ end
+ end
end
diff --git a/spec/services/users/update_service_spec.rb b/spec/services/users/update_service_spec.rb
index bdb154d8df3..c14d24221bd 100644
--- a/spec/services/users/update_service_spec.rb
+++ b/spec/services/users/update_service_spec.rb
@@ -14,10 +14,11 @@ describe Users::UpdateService do
end
it 'updates time preferences' do
- result = update_user(user, timezone: 'Warsaw', time_display_relative: true, time_format_in_24h: false)
+ result = update_user(user, timezone: 'Warsaw', timezone_name: 'Europe/Warsaw', time_display_relative: true, time_format_in_24h: false)
expect(result).to eq(status: :success)
expect(user.reload.timezone).to eq('Warsaw')
+ expect(user.reload.timezone_name).to eq('Europe/Warsaw')
expect(user.time_display_relative).to eq(true)
expect(user.time_format_in_24h).to eq(false)
end