mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
fcc2e7ebbf
This commit migrates all bookmarks to be polymorphic (using the bookmarkable_id and bookmarkable_type) columns. It also deletes all the old code guarded behind the use_polymorphic_bookmarks setting and changes that setting to true for all sites and by default for the sake of plugins. No data is deleted in the migrations, the old post_id and for_topic columns for bookmarks will be dropped later on.
31 lines
1.2 KiB
Ruby
31 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserBookmarkListSerializer do
|
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
context "for polymorphic bookmarks" do
|
|
before do
|
|
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)) }
|
|
|
|
def run_serializer
|
|
bookmark_list = UserBookmarkList.new(user: user, guardian: Guardian.new(user), params: {})
|
|
bookmark_list.load
|
|
UserBookmarkListSerializer.new(bookmark_list)
|
|
end
|
|
|
|
it "chooses the correct class of serializer for all the bookmarkable types" do
|
|
serializer = run_serializer
|
|
expect(serializer.bookmarks.map(&:class).map(&:to_s)).to match_array(["UserTestBookmarkSerializer", "UserTopicBookmarkSerializer", "UserPostBookmarkSerializer"])
|
|
end
|
|
end
|
|
end
|