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