discourse/spec/serializers/reviewable_flagged_post_serializer_spec.rb
Daniel Waterworth 6e161d3e75
DEV: Allow fab! without block (#24314)
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.
2023-11-09 16:47:59 -06:00

27 lines
879 B
Ruby

# frozen_string_literal: true
RSpec.describe ReviewableFlaggedPostSerializer do
fab!(:admin)
it "includes the user fields for review" do
p0 = Fabricate(:post)
reviewable = PostActionCreator.spam(Fabricate(:user), p0).reviewable
json =
ReviewableFlaggedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
expect(json[:cooked]).to eq(p0.cooked)
expect(json[:raw]).to eq(p0.raw)
expect(json[:target_url]).to eq(Discourse.base_url + p0.url)
expect(json[:created_from_flag]).to eq(true)
end
it "works when the topic is deleted" do
reviewable = Fabricate(:reviewable_queued_post)
reviewable.topic.update(deleted_at: Time.now)
reviewable.reload
json =
ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
expect(json[:id]).to be_present
end
end