Skip to content

Commit

Permalink
bring back that test and make it pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jagthedrummer committed Nov 20, 2024
1 parent ead98a3 commit cc654d9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bullet_train/app/models/concerns/users/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions bullet_train/test/models/team_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", 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: "[email protected]", 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

0 comments on commit cc654d9

Please sign in to comment.