mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
6e161d3e75
The most common thing that we do with fab! is: fab!(:thing) { Fabricate(:thing) } This commit adds a shorthand for this which is just simply: fab!(:thing) i.e. If you omit the block, then, by default, you'll get a `Fabricate`d object using the fabricator of the same name.
34 lines
1.2 KiB
Ruby
34 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe UserBookmarkListSerializer do
|
|
fab!(: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
|
|
|
|
after { DiscoursePluginRegistry.reset! }
|
|
|
|
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))
|
|
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(
|
|
%w[UserTestBookmarkSerializer UserTopicBookmarkSerializer UserPostBookmarkSerializer],
|
|
)
|
|
end
|
|
end
|
|
end
|