2022-04-22 06:23:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
RSpec.describe UserPostBookmarkSerializer do
|
|
|
|
let(:user) { Fabricate(:user) }
|
|
|
|
let(:topic) { Fabricate(:topic) }
|
2022-08-08 22:24:04 +08:00
|
|
|
let(:post) { Fabricate(:post, user: user, topic: topic) }
|
2022-04-22 06:23:42 +08:00
|
|
|
let!(:bookmark) { Fabricate(:bookmark, name: 'Test', user: user, bookmarkable: post) }
|
|
|
|
|
2022-08-08 22:24:04 +08:00
|
|
|
describe "#highest_post_number" do
|
|
|
|
let(:whisperers_group) { Fabricate(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.whispers_allowed_groups = "#{whisperers_group.id}"
|
|
|
|
end
|
2022-06-30 08:18:12 +08:00
|
|
|
|
2022-08-08 22:24:04 +08: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-22 06:23:42 +08:00
|
|
|
|
2022-08-08 22:24:04 +08:00
|
|
|
expect(serializer.highest_post_number).to eq(3)
|
2022-04-22 06:23:42 +08:00
|
|
|
|
2022-08-08 22:24:04 +08:00
|
|
|
user.groups << whisperers_group
|
2022-04-22 06:23:42 +08:00
|
|
|
|
2022-08-08 22:24:04 +08:00
|
|
|
expect(serializer.highest_post_number).to eq(4)
|
|
|
|
end
|
2022-04-22 06:23:42 +08:00
|
|
|
end
|
|
|
|
end
|