From cc654d99ba8ce97961a3af4713d9e1bacc7026c3 Mon Sep 17 00:00:00 2001 From: Jeremy Green Date: Wed, 20 Nov 2024 09:28:46 -0600 Subject: [PATCH] bring back that test and make it pass --- .../app/models/concerns/users/base.rb | 2 +- bullet_train/test/models/team_test.rb | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/bullet_train/app/models/concerns/users/base.rb b/bullet_train/app/models/concerns/users/base.rb index c75299c98..ddbf4d598 100644 --- a/bullet_train/app/models/concerns/users/base.rb +++ b/bullet_train/app/models/concerns/users/base.rb @@ -153,7 +153,7 @@ def developer? end def set_teams_time_zone - teams.where(time_zone: nil).each do |team| + teams.where(time_zone: [nil, "UTC"]).each do |team| team.update(time_zone: time_zone) if team.users.count == 1 end end diff --git a/bullet_train/test/models/team_test.rb b/bullet_train/test/models/team_test.rb index 1a8e95f80..8f111ad88 100644 --- a/bullet_train/test/models/team_test.rb +++ b/bullet_train/test/models/team_test.rb @@ -29,4 +29,34 @@ class TeamTest < ActiveSupport::TestCase team.reload assert_equal "UTC", team.time_zone end + + test "default UTC time_zone is overwritten once the first user sets a time zone" do + team = Team.create!(name: "new test team") + user = User.create!(email: "test@test.com", password: "password", password_confirmation: "password", time_zone: nil) + Membership.create!(team: team, user: user) + team.reload + assert_equal "UTC", team.time_zone + + user.time_zone = "Central Time (US & Canada)" + user.save + + team.reload + assert_equal "Central Time (US & Canada)", team.time_zone + end + + test "nil time_zone is overwritten once the first user sets a time zone" do + team = Team.create!(name: "new test team", time_zone: nil) + user = User.create!(email: "test@test.com", password: "password", password_confirmation: "password", time_zone: nil) + Membership.create!(team: team, user: user) + team.time_zone = nil + team.save + team.reload + assert_equal nil, team.time_zone + + user.time_zone = "Central Time (US & Canada)" + user.save + + team.reload + assert_equal "Central Time (US & Canada)", team.time_zone + end end