Skip to content

Commit

Permalink
nil memoized tz variable on reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts committed Sep 2, 2024
1 parent 48377fc commit 1d7fd3c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
6 changes: 6 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ def time_zone
@time_zone ||= (pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[pref.time_zone])
end

def reload(*)
@time_zone = nil

super
end

def wants_comments_in_reverse_order?
pref.comments_in_reverse_order?
end
Expand Down
7 changes: 0 additions & 7 deletions modules/meeting/app/mailers/meeting_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def icalendar_notification(meeting, user, _actor, **)
set_headers @meeting

with_attached_ics(meeting, user) do
timezone = Time.zone || Time.zone_default
@formatted_timezone = format_timezone_offset timezone, @meeting.start_time
subject = "[#{@meeting.project.name}] #{@meeting.title}"
mail(to: user, subject:)
end
Expand Down Expand Up @@ -95,9 +93,4 @@ def set_headers(meeting)
headers["Content-Type"] = 'text/calendar; charset=utf-8; method="PUBLISH"; name="meeting.ics"'
headers["Content-Transfer-Encoding"] = "8bit"
end

def format_timezone_offset(timezone, time)
offset = ::ActiveSupport::TimeZone.seconds_to_utc_offset time.utc_offest_for_timezone(timezone), true
"(GMT#{offset}) #{timezone.name}"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<p><%= t(:text_notificiation_invited) %></p>

<ul>
<li><%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> <%= @formatted_timezone %></li>
<li><%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)</li>
<li><%=Meeting.human_attribute_name(:location) %>: <%= @meeting.location %></li>
<li><%=Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %></li>
<li><%=Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= t(:text_notificiation_invited) %>
<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> <%= @formatted_timezone %>
<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
<%=Meeting.human_attribute_name(:location) %>: <%= @meeting.location %>
<%=Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %>
<%=Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %>
2 changes: 1 addition & 1 deletion modules/meeting/app/views/meeting_mailer/invited.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ See COPYRIGHT and LICENSE files for more details.
<td style="<%= placeholder_text_styles %>">
<%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>
-
<%= format_time @meeting.end_time, include_date: false %> <%= Time.zone %>
<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
</td>
</tr>
<% if @meeting.location.present? %>
Expand Down
2 changes: 1 addition & 1 deletion modules/meeting/app/views/meeting_mailer/invited.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= @meeting.project.name %>: <%= @meeting.title %> (<%= meeting_url(@meeting) %>)
<%= @meeting.author %>
<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> <%= Time.zone %>
<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
<%= Meeting.human_attribute_name(:location) %>: <%= @meeting.location %>
<%= Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %>
<%= Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %>
4 changes: 2 additions & 2 deletions modules/meeting/app/views/meeting_mailer/rescheduled.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ See COPYRIGHT and LICENSE files for more details.
<s>
<%= format_time_as_date @changes[:old_start] %> <%= format_time @changes[:old_start], include_date: false %>
-
<%= format_time (@changes[:old_start] + @changes[:old_duration].hours), include_date: false %> <%= formatted_time_zone_offset %>
<%= format_time (@changes[:old_start] + @changes[:old_duration].hours), include_date: false %> (<%= formatted_time_zone_offset %>)
</s>
</td>
</tr>
Expand All @@ -59,7 +59,7 @@ See COPYRIGHT and LICENSE files for more details.
<td style="<%= placeholder_text_styles('font-weight': 'bold') %>">
<%= format_time_as_date @changes[:new_start] %> <%= format_time @changes[:new_start], include_date: false %>
-
<%= format_time (@changes[:new_start] + @changes[:new_duration].hours), include_date: false %> <%= formatted_time_zone_offset %>
<%= format_time (@changes[:new_start] + @changes[:new_duration].hours), include_date: false %> (<%= formatted_time_zone_offset %>)
</td>
</tr>
<% if @meeting.location.present? %>
Expand Down
4 changes: 2 additions & 2 deletions modules/meeting/app/views/meeting_mailer/rescheduled.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details.
title: @meeting.title) %>
<%= t('meeting.email.rescheduled.old_date_time') %>:
<%= format_time_as_date @changes[:old_start] %> <%= format_time @changes[:old_start], include_date: false %> - <%= format_time (@changes[:old_start] + @changes[:old_duration]), include_date: false %> <%= Time.zone %>
<%= format_time_as_date @changes[:old_start] %> <%= format_time @changes[:old_start], include_date: false %> - <%= format_time (@changes[:old_start] + @changes[:old_duration]), include_date: false %> (<%= formatted_time_zone_offset %>}

<%= t('meeting.email.rescheduled.new_date_time') %>:
<%= format_time_as_date @changes[:new_start] %> <%= format_time @changes[:new_start], include_date: false %> - <%= format_time (@changes[:new_start] + @changes[:new_duration]), include_date: false %> <%= Time.zone %>
<%= format_time_as_date @changes[:new_start] %> <%= format_time @changes[:new_start], include_date: false %> - <%= format_time (@changes[:new_start] + @changes[:new_duration]), include_date: false %> (<%= formatted_time_zone_offset %>}
35 changes: 18 additions & 17 deletions modules/meeting/spec/mailers/meeting_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
let(:meeting_agenda) do
create(:meeting_agenda, meeting:)
end
let(:tokyo_offset) { "UTC#{ActiveSupport::TimeZone['Asia/Tokyo'].now.formatted_offset}" }
let(:berlin_offset) { "UTC#{ActiveSupport::TimeZone['Europe/Berlin'].now.formatted_offset}" }

before do
User.current = author
Expand Down Expand Up @@ -88,11 +90,9 @@
context "with a recipient with another time zone" do
let!(:preference) { watcher1.pref.update(time_zone: "Asia/Tokyo") }

it "renders the mail with the correcet locale" do
expect(mail.text_part.body).to include("Tokyo")
expect(mail.text_part.body).to include("GMT+09:00")
expect(mail.html_part.body).to include("Tokyo")
expect(mail.html_part.body).to include("GMT+09:00")
it "renders the mail with the correct locale" do
expect(mail.text_part.body).to include(tokyo_offset)
expect(mail.html_part.body).to include(tokyo_offset)

expect(mail.to).to contain_exactly(watcher1.mail)
end
Expand All @@ -111,8 +111,8 @@

it "renders the mail with the correct locale" do
expect(mail.html_part.body).to include("11/09/2021 11:00 PM")
expect(mail.html_part.body).to include("12:00 AM (GMT+01:00) Europe/Berlin")
expect(mail.text_part.body).to include("11/09/2021 11:00 PM-12:00 AM (GMT+01:00) Europe/Berlin")
expect(mail.html_part.body).to include("12:00 AM (#{berlin_offset})")
expect(mail.text_part.body).to include("11/09/2021 11:00 PM-12:00 AM (#{berlin_offset})")

expect(mail.to).to contain_exactly(author.mail)
end
Expand All @@ -124,9 +124,9 @@

it "renders the mail with the correct locale" do
expect(mail.html_part.body).to include("11/10/2021 07:00 AM")
expect(mail.html_part.body).to include("08:00 AM (GMT+09:00) Asia/Tokyo")
expect(mail.html_part.body).to include("08:00 AM (#{tokyo_offset})")

expect(mail.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo")
expect(mail.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (#{tokyo_offset})")

expect(mail.to).to contain_exactly(watcher1.mail)
end
Expand Down Expand Up @@ -160,7 +160,7 @@
expect(body).to include(meeting.project.name)
expect(body).to include(meeting.title)
expect(body).to include(meeting.location)
expect(body).to include("01/19/2021 11:00 AM-12:00 PM (GMT+01:00) Europe/Berlin")
expect(body).to include("01/19/2021 11:00 AM-12:00 PM (#{berlin_offset})")
expect(body).to include(meeting.participants[0].name)
expect(body).to include(meeting.participants[1].name)
end
Expand All @@ -174,7 +174,7 @@
expect(body).to include(meeting.title)
expect(body).to include(meeting.location)
expect(body).to include("01/19/2021 11:00 AM")
expect(body).to include("12:00 PM (GMT+01:00) Europe/Berlin")
expect(body).to include("12:00 PM (#{berlin_offset})")
expect(body).to include(meeting.participants[0].name)
expect(body).to include(meeting.participants[1].name)
end
Expand Down Expand Up @@ -207,9 +207,9 @@
let(:mail) { described_class.icalendar_notification(meeting, watcher1, author) }

it "renders the mail with the correct locale" do
expect(mail.text_part.body).to include("01/19/2021 07:00 PM-08:00 PM (GMT+09:00) Asia/Tokyo")
expect(mail.text_part.body).to include("01/19/2021 07:00 PM-08:00 PM (#{tokyo_offset})")
expect(mail.html_part.body).to include("01/19/2021 07:00 PM")
expect(mail.html_part.body).to include("08:00 PM (GMT+09:00) Asia/Tokyo")
expect(mail.html_part.body).to include("08:00 PM (#{tokyo_offset})")

expect(mail.to).to contain_exactly(watcher1.mail)
end
Expand All @@ -227,9 +227,9 @@
let(:mail) { described_class.icalendar_notification(meeting, author, author) }

it "renders the mail with the correct locale" do
expect(mail.text_part.body).to include("11/09/2021 11:00 PM-12:00 AM (GMT+01:00) Europe/Berlin")
expect(mail.text_part.body).to include("11/09/2021 11:00 PM-12:00 AM (#{berlin_offset})")
expect(mail.html_part.body).to include("11/09/2021 11:00 PM")
expect(mail.html_part.body).to include("12:00 AM (GMT+01:00) Europe/Berlin")
expect(mail.html_part.body).to include("12:00 AM (#{berlin_offset})")

expect(mail.to).to contain_exactly(author.mail)
end
Expand All @@ -240,8 +240,8 @@
let!(:preference) { watcher1.pref.update(time_zone: "Asia/Tokyo") }

it "renders the mail with the correct locale" do
expect(mail.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo")
expect(mail.html_part.body).to include("11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo")
expect(mail.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (#{tokyo_offset})")
expect(mail.html_part.body).to include("11/10/2021 07:00 AM-08:00 AM (#{tokyo_offset})")

expect(mail.to).to contain_exactly(watcher1.mail)
end
Expand All @@ -255,6 +255,7 @@ def check_meeting_mail_content(body)
expect(body).to include(i18n.format_date(meeting.start_date))
expect(body).to include(i18n.format_time(meeting.start_time, include_date: false))
expect(body).to include(i18n.format_time(meeting.end_time, include_date: false))
expect(body).to include(i18n.formatted_time_zone_offset)
expect(body).to include(meeting.participants[0].name)
expect(body).to include(meeting.participants[1].name)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
context "without a timezone set" do
let(:preference) { build(:user_preference, time_zone: "") }

it "shows the timeZone as nil" do
expect(subject).to be_json_eql(nil.to_json).at_path("timeZone")
it "shows the timeZone as utc" do
expect(subject).to be_json_eql("Etc/UTC".to_json).at_path("timeZone")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/deleted_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end

describe "#time_zone" do
it { expect(user.time_zone).to be_nil }
it { expect(user.time_zone).to eql ActiveSupport::TimeZone["Etc/UTC"] }
end

describe "#rss_key" do
Expand Down
4 changes: 2 additions & 2 deletions spec/models/users/default_timezone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
let(:user) { create(:user) }

context "with no system default set" do
it "is not set" do
expect(user.pref.time_zone).to be_nil
it "is still set to Etc/UTC as that will be calculated with internally" do
expect(user.pref.time_zone).to eq "Etc/UTC"
end
end

Expand Down

0 comments on commit 1d7fd3c

Please sign in to comment.