2022-04-21 18:23:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe UserPostBookmarkSerializer do
|
2022-06-29 20:18:12 -04:00
|
|
|
let(:whisperers_group) { Fabricate(:group) }
|
2022-04-21 18:23:42 -04:00
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:post) { Fabricate(:post, user: user, topic: topic) }
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
|
|
|
let!(:bookmark) { Fabricate(:bookmark, name: 'Test', user: user, bookmarkable: post) }
|
|
|
|
|
2022-06-29 20:18:12 -04:00
|
|
|
before do
|
|
|
|
SiteSetting.enable_whispers = true
|
|
|
|
SiteSetting.whispers_allowed_groups = "#{whisperers_group.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "uses the correct highest_post_number column based on whether the user is whisperer" do
|
2022-04-21 18:23:42 -04:00
|
|
|
Fabricate(:post, topic: topic)
|
|
|
|
Fabricate(:post, topic: topic)
|
|
|
|
Fabricate(:whisper, topic: topic)
|
|
|
|
topic.reload
|
|
|
|
bookmark.reload
|
|
|
|
serializer = UserPostBookmarkSerializer.new(bookmark, scope: Guardian.new(user))
|
|
|
|
|
|
|
|
expect(serializer.highest_post_number).to eq(3)
|
|
|
|
|
2022-06-29 20:18:12 -04:00
|
|
|
user.groups << whisperers_group
|
2022-04-21 18:23:42 -04:00
|
|
|
|
|
|
|
expect(serializer.highest_post_number).to eq(4)
|
|
|
|
end
|
|
|
|
end
|