mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
FEATURE: Add timezone to core user_options (#8380)
* Add timezone to user_options table * Also migrate existing timezone values from UserCustomField, which is where the discourse-calendar plugin is storing them * Allow user to change their core timezone from Profile * Auto guess & set timezone on login & invite accept & signup * Serialize user_options.timezone for group members. this is so discourse-group-timezones can access the core user timezone, as it is being removed in discourse-calendar. * Annotate user_option with timezone * Validate timezone values
This commit is contained in:
49
spec/lib/validators/timezone_validator_spec.rb
Normal file
49
spec/lib/validators/timezone_validator_spec.rb
Normal file
@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe TimezoneValidator do
|
||||
describe "#valid?" do
|
||||
context "when timezone is ok" do
|
||||
it "returns true" do
|
||||
expect(described_class.valid?("Australia/Brisbane")).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "when timezone is not ok" do
|
||||
it "returns false" do
|
||||
expect(described_class.valid?("Mars")).to eq(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#validate_each" do
|
||||
let(:record) { Fabricate(:active_user).user_option }
|
||||
|
||||
context "when timezone is ok" do
|
||||
it "adds no errors to the record" do
|
||||
record.timezone = "Australia/Melbourne"
|
||||
record.save
|
||||
expect(record.errors.full_messages.empty?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "when timezone is blank" do
|
||||
it "adds no errors to the record" do
|
||||
record.timezone = nil
|
||||
record.save
|
||||
expect(record.errors.full_messages.empty?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
context "when timezone is not ok" do
|
||||
it "adds errors to the record" do
|
||||
record.timezone = "Mars"
|
||||
record.save
|
||||
expect(record.errors.full_messages).to include(
|
||||
"Timezone 'Mars' is not a valid timezone"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user