0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/plugins/discourse-rewind/spec/serializers/current_user_serializer_spec.rb
Martin Brennan ee5abe0e7b
FIX: Do not show rewind for new users (#37205)
There is no point showing rewind for a user who is
less than a month old, they will have no data to see.

This hides the preferences, activity tab, and avatar
decorations for rewind.
2026-01-20 17:44:19 +10:00

53 lines
1.7 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe CurrentUserSerializer do
before { SiteSetting.discourse_rewind_enabled = true }
fab!(:user)
let(:serializer) { CurrentUserSerializer.new(user, scope: Guardian.new(user), root: false) }
describe "#is_rewind_active" do
context "when in December" do
before { freeze_time DateTime.parse("2024-12-15") }
it "returns true for users created more than a month ago" do
user.update!(created_at: 2.months.ago)
expect(serializer.as_json[:is_rewind_active]).to eq(true)
end
it "returns false for users created less than a month ago" do
user.update!(created_at: 2.weeks.ago)
expect(serializer.as_json[:is_rewind_active]).to eq(false)
end
it "returns true for users created exactly one month ago" do
user.update!(created_at: 1.month.ago)
expect(serializer.as_json[:is_rewind_active]).to eq(true)
end
end
context "when in January" do
before { freeze_time DateTime.parse("2025-01-15") }
it "returns true for users created more than a month ago" do
user.update!(created_at: 2.months.ago)
expect(serializer.as_json[:is_rewind_active]).to eq(true)
end
it "returns false for users created less than a month ago" do
user.update!(created_at: 2.weeks.ago)
expect(serializer.as_json[:is_rewind_active]).to eq(false)
end
end
context "when outside rewind period (e.g., November)" do
before { freeze_time DateTime.parse("2024-11-15") }
it "returns false regardless of user age" do
user.update!(created_at: 2.years.ago)
expect(serializer.as_json[:is_rewind_active]).to eq(false)
end
end
end
end