discourse/plugins/discourse-rewind/spec/services/toggle_share_spec.rb
Martin Brennan c4d4ed890f
FEATURE: Share Rewind reports publicly by default and allow for making them private (#36587)
This commit introduces a toggle which is enabled by default
to share the Discourse Rewind report publicly.

**IMPORTANT NOTES**:

*  Users with "Hide my public profile" enabled
**will not** have their Rewind shared publicly by default,
and will not be able to unless they disable "Hide my public
profile" first.
* This commit also excludes personal messages from best
   posts and best topics reports so sensitive message data
   will never be shown, but other report data like reaction
   counts may still be based off of PM data

Other users who cannot see the rewind will see an error.

We always show a message saying which  user you are looking
at when viewing another user's Rewind.

Users can also unshare their rewind from Rewind preferences.
2025-12-16 09:29:35 +10:00

48 lines
1.4 KiB
Ruby

# frozen_string_literal: true
RSpec.describe(DiscourseRewind::ToggleShare) do
describe ".call" do
subject(:result) { described_class.call(**dependencies) }
fab!(:user)
let(:guardian) { Guardian.new(user) }
let(:dependencies) { { guardian: } }
context "when discourse_rewind_share_publicly is false" do
before { user.user_option.update!(discourse_rewind_share_publicly: false) }
it "toggles to true" do
expect { result }.to change {
user.user_option.reload.discourse_rewind_share_publicly
}.from(false).to(true)
end
context "when user has hide_profile set to true" do
before { user.user_option.update!(hide_profile: true) }
it { is_expected.to fail_a_policy(:user_not_hiding_profile) }
end
end
context "when discourse_rewind_share_publicly is true" do
before { user.user_option.update!(discourse_rewind_share_publicly: true) }
it "toggles to false" do
expect { result }.to change {
user.user_option.reload.discourse_rewind_share_publicly
}.from(true).to(false)
end
context "when user has hide_profile set to true" do
before { user.user_option.update!(hide_profile: true) }
it "toggles to false" do
expect { result }.to change {
user.user_option.reload.discourse_rewind_share_publicly
}.from(true).to(false)
end
end
end
end
end