mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 03:13:47 +08:00
222c8d9b6a
A bit of a mixed bag, this addresses several edge areas of bookmarks and makes them compatible with polymorphic bookmarks (hidden behind the `use_polymorphic_bookmarks` site setting). The main ones are: * ExportUserArchive compatibility * SyncTopicUserBookmarked job compatibility * Sending different notifications for the bookmark reminders based on the bookmarkable type * Import scripts compatibility * BookmarkReminderNotificationHandler compatibility This PR also refactors the `register_bookmarkable` API so it accepts a class descended from a `BaseBookmarkable` class instead. This was done because we kept having to add more and more lambdas/properties inline and it was very messy, so a factory pattern is cleaner. The classes can be tested independently as well. Some later PRs will address some other areas like the discourse narrative bot, advanced search, reports, and the .ics endpoint for bookmarks.
49 lines
1.5 KiB
Ruby
49 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserBookmarkList do
|
|
let(:params) { {} }
|
|
fab!(:user) { Fabricate(:user) }
|
|
let(:list) { UserBookmarkList.new(user: user, guardian: Guardian.new(user), params: params) }
|
|
|
|
context "for non-polymorphic bookmarks" do
|
|
before do
|
|
22.times do
|
|
bookmark = Fabricate(:bookmark, user: user)
|
|
Fabricate(:topic_user, topic: bookmark.topic, user: user)
|
|
end
|
|
end
|
|
|
|
it "defaults to 20 per page" do
|
|
expect(list.per_page).to eq(20)
|
|
end
|
|
|
|
context "when the per_page param is too high" do
|
|
let(:params) { { per_page: 1000 } }
|
|
|
|
it "does not allow more than X bookmarks to be requested per page" do
|
|
expect(list.load.count).to eq(20)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "for polymorphic bookmarks" do
|
|
before do
|
|
SiteSetting.use_polymorphic_bookmarks = true
|
|
register_test_bookmarkable
|
|
|
|
Fabricate(:topic_user, user: user, topic: post_bookmark.bookmarkable.topic)
|
|
Fabricate(:topic_user, user: user, topic: topic_bookmark.bookmarkable)
|
|
user_bookmark
|
|
end
|
|
|
|
let(:post_bookmark) { Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:post)) }
|
|
let(:topic_bookmark) { Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:topic)) }
|
|
let(:user_bookmark) { Fabricate(:bookmark, user: user, bookmarkable: Fabricate(:user)) }
|
|
|
|
it "returns all types of bookmarks" do
|
|
list.load
|
|
expect(list.bookmarks.map(&:id)).to match_array([post_bookmark.id, topic_bookmark.id, user_bookmark.id])
|
|
end
|
|
end
|
|
end
|