A platform for community discussion. Free, open, simple.
DEV: Freeze time in gamification scorable specs (#43658)
Gabriel Grubba3b82052d10c8
diff --git a/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb b/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rbindex 14ba4d73fec..59772ea1837 100755--- a/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb+++ b/plugins/discourse-gamification/spec/lib/scorables/shared_scorables_spec.rb@@ -1,5 +1,9 @@# frozen_string_literal: true+# Scores are read through a materialized view that filters on PostgreSQL's+# CURRENT_DATE, which is pinned to the start of the test transaction. Fixtures+# created from the wall clock fall outside it when a run straddles UTC midnight,+# so every shared example freezes the clock.RSpec.shared_examples "Scorable Type" dofab!(:leaderboard, :gamification_leaderboard)let(:current_user) { Fabricate(:user) }@@ -7,6 +11,8 @@ RSpec.shared_examples "Scorable Type" dolet(:third_user) { Fabricate(:user) }let(:expected_score) { expected_score }+ before { freeze_time DateTime.parse("2024-01-01 12:00") }+describe "#{described_class} updates gamification score" doit "has correct total score" doDiscourseGamification::GamificationLeaderboardScore.calculate_scores(@@ -30,6 +36,8 @@ RSpec.shared_examples "Category Scoped Scorable Type" dolet(:expected_score) { described_class.score_multiplier }let(:after_create_hook) { nil }+ before { freeze_time DateTime.parse("2024-01-01 12:00") }+describe "updates gamification score" dolet!(:create_score) { class_action_fabricator }let!(:trigger_after_create_hook) { after_create_hook }@@ -70,6 +78,8 @@ RSpec.shared_examples "No Score Value" dolet(:class_action_fabricator_for_themselves) { nil }let(:after_create_hook) { nil }+ before { freeze_time DateTime.parse("2024-01-01 12:00") }+describe "#{described_class} awards no score value" dolet!(:create_score_for_deleted_object) { class_action_fabricator_for_deleted_object }let!(:create_score_for_pm) { class_action_fabricator_for_pm }