OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
increase time_zone robustness
ulferts4c61ce1bfccf
diff --git a/app/models/user.rb b/app/models/user.rbindex c88ad590823..4563f1086b9 100644--- a/app/models/user.rb+++ b/app/models/user.rb@@ -406,7 +406,7 @@ class User < Principalenddef time_zone- @time_zone ||= (pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[pref.time_zone])+ @time_zone ||= ActiveSupport::TimeZone[pref.time_zone] || ActiveSupport::TimeZone["Etc/UTC"]enddef reload(*)diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rbindex 2cb717f4e12..66d7db19d21 100644--- a/spec/models/user_spec.rb+++ b/spec/models/user_spec.rb@@ -823,6 +823,39 @@ RSpec.describe User doendend+ describe "#time_zone" do+ let(:user) { build(:user, preferences:) }++ context "with an existing time zone in the prefs" do+ let(:preferences) { { "time_zone" => "Europe/Athens" } }++ it "returns the matching ActiveSupport::TimeZone" do+ expect(user.time_zone)+ .to eql ActiveSupport::TimeZone["Europe/Athens"]+ end+ end++ context "with an invalid time zone" do+ # Would need to be Etc/UTC or UTC to be valid+ let(:preferences) { { "time_zone" => "utc" } }++ it "returns the utc ActiveSupport::TimeZone" do+ expect(user.time_zone)+ .to eql ActiveSupport::TimeZone["Etc/UTC"]+ end+ end++ context "without a time zone" do+ # Would need to be Etc/UTC or UTC to be valid+ let(:preferences) { {} }++ it "returns the utc ActiveSupport::TimeZone" do+ expect(user.time_zone)+ .to eql ActiveSupport::TimeZone["Etc/UTC"]+ end+ end+ end+describe "#find_by_mail" dolet!(:user1) { create(:user, mail: "[email protected]") }let!(:user2) { create(:user, mail: "[email protected]") }