Skip to content

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

Fix time zone dependent test

Christophe Bliarde342d47a7e1a
diff --git a/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb b/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
index b4bb40d8199..bce686ea6c9 100644
--- a/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_date_alerts_spec.rb
@@ -5,9 +5,22 @@ require 'features/page_objects/notification'
describe "Notification center date alerts", js: true, with_settings: { journal_aggregation_time_minutes: 0 } do
include ActiveSupport::Testing::TimeHelpers
- shared_let(:time_zone) { ActiveSupport::TimeZone['Europe/Berlin'] }
+ def ensure_assignable_time_zone!(time_zone)
+ assignable_time_zones = UserPreferences::UpdateContract.assignable_time_zones
+ if assignable_time_zones.exclude?(time_zone)
+ raise "Unable to use local timezone '#{time_zone}'. Acceptable values are #{assignable_time_zones.inspect}"
+ end
+ end
+
+ shared_let(:time_zone) do
+ # use host timezone, deduced from the gmt offset
+ offset = Time.now.gmt_offset # rubocop:disable Rails/TimeZone
+ time_zone = ActiveSupport::TimeZone[offset]
+ ensure_assignable_time_zone!(time_zone)
+ time_zone
+ end
shared_let(:user) do
- create(:user, preferences: { time_zone: time_zone.name }).tap do |user|
+ create(:user, preferences: { time_zone: time_zone.tzinfo.name }).tap do |user|
user.notification_settings.first.update(
start_date: 7,
due_date: 3,
@@ -172,10 +185,14 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
timezone.now.change(time_hash(time))
end
+ # early in the morning, a bit after 1:00 AM local time, the notifications get
+ # created by the job
+ let(:notifications_creation_time) { timezone_time('1:04', time_zone) }
+
def run_create_date_alerts_notifications_job
create_date_alerts_service = Notifications::ScheduleDateAlertsNotificationsJob::Service
.new([timezone_time('1:00', time_zone)])
- travel_to(timezone_time('1:04', time_zone))
+ travel_to(notifications_creation_time)
create_date_alerts_service.call
travel_back
end
@@ -251,7 +268,7 @@ describe "Notification center date alerts", js: true, with_settings: { journal_a
activity_tab.expect_notification_count 1
# When a work package is updated to a different date
- wp_double_notification.update_column(:due_date, 5.days.from_now)
+ wp_double_notification.update_column(:due_date, time_zone.now + 5.days)
page.driver.refresh
center.expect_item(notification_wp_double_date_alert, 'Finish date is in 5 days')