mirror of
https://github.com/discourse/discourse.git
synced 2025-05-29 00:37:44 +08:00
FIX: respect user timezone in emails about silencing and suspending (#16918)
This commit is contained in:

committed by
GitHub

parent
0c590963c3
commit
25e4095c9c
@ -1184,4 +1184,68 @@ describe UserNotifications do
|
||||
"[admin](http://test.localhost/u/admin)")
|
||||
end
|
||||
end
|
||||
|
||||
describe ".account_silenced" do
|
||||
fab!(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:silence_user]) }
|
||||
|
||||
it "adds the silenced_till date in user's timezone" do
|
||||
user.user_option.timezone = "Asia/Tbilisi" # GMT+4
|
||||
user.silenced_till = DateTime.parse("May 25, 2020, 12:00pm")
|
||||
|
||||
mail = UserNotifications.account_silenced(user, { user_history: user_history })
|
||||
|
||||
expect(mail.body).to include("May 25, 2020, 4:00pm")
|
||||
end
|
||||
|
||||
context "user doesn't have timezone set" do
|
||||
before do
|
||||
user.user_option.timezone = nil
|
||||
end
|
||||
|
||||
it "doesn't raise error" do
|
||||
expect { UserNotifications.account_silenced(user) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "adds the silenced_till date in UTC" do
|
||||
date = "May 25, 2020, 12:00pm"
|
||||
user.silenced_till = DateTime.parse(date)
|
||||
|
||||
mail = UserNotifications.account_silenced(user, { user_history: user_history })
|
||||
|
||||
expect(mail.body).to include(date)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".account_suspended" do
|
||||
fab!(:user_history) { Fabricate(:user_history, action: UserHistory.actions[:suspend_user]) }
|
||||
|
||||
it "adds the suspended_till date in user's timezone" do
|
||||
user.user_option.timezone = "Asia/Tbilisi" # GMT+4
|
||||
user.suspended_till = DateTime.parse("May 25, 2020, 12:00pm")
|
||||
|
||||
mail = UserNotifications.account_suspended(user, { user_history: user_history })
|
||||
|
||||
expect(mail.body).to include("May 25, 2020, 4:00pm")
|
||||
end
|
||||
|
||||
context "user doesn't have timezone set" do
|
||||
before do
|
||||
user.user_option.timezone = nil
|
||||
end
|
||||
|
||||
it "doesn't raise error" do
|
||||
expect { UserNotifications.account_suspended(user) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "adds the suspended_till date in UTC" do
|
||||
date = "May 25, 2020, 12:00pm"
|
||||
user.suspended_till = DateTime.parse(date)
|
||||
|
||||
mail = UserNotifications.account_suspended(user, { user_history: user_history })
|
||||
|
||||
expect(mail.body).to include(date)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user