mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
DEV: UserOption.user_tzinfo (#14088)
Provides a safe way to retrieve the timezone of a user. This is not used in core yet, but used in multiple plugins.
This commit is contained in:
@ -166,4 +166,28 @@ describe UserOption do
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe '.user_tzinfo' do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
|
||||
context 'user with valid timezone given' do
|
||||
before do
|
||||
user.user_option.update(timezone: 'Europe/Paris')
|
||||
end
|
||||
|
||||
it 'returns the expect timezone' do
|
||||
expect(UserOption.user_tzinfo(user.id)).to eq(ActiveSupport::TimeZone.find_tzinfo('Europe/Paris'))
|
||||
end
|
||||
end
|
||||
|
||||
context 'user with invalid timezone given' do
|
||||
before do
|
||||
user.user_option.update(timezone: 'Catopia/Catcity')
|
||||
end
|
||||
|
||||
it 'fallbacks to UTC' do
|
||||
expect(UserOption.user_tzinfo(user.id)).to eq(ActiveSupport::TimeZone.find_tzinfo('UTC'))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user