discourse/spec/serializers/pending_post_serializer_spec.rb
Selase Krakani 9f42a235ab
FIX: Attribute pending post to author in PendingPostSerialier (#23369)
This fixes a regression introduced by an earlier change which changed `ReviewableQueuedPost`
record creation to use the more appropriate `target_created_by_id` for the  author of the post
being queued instead of setting it to the creator(system user) of the `ReviewableQueuedPost` record.
2023-09-03 22:14:51 +00:00

58 lines
1.6 KiB
Ruby

# frozen_string_literal: true
RSpec.describe PendingPostSerializer do
subject(:serializer) { described_class.new(post, scope: guardian, root: false) }
let(:guardian) { Guardian.new(author) }
let(:author) { post.target_created_by }
before { freeze_time }
context "when creating a new topic" do
let(:post) { Fabricate(:reviewable_queued_post_topic) }
let(:expected_attributes) do
{
id: post.id,
avatar_template: author.avatar_template,
category_id: post.category_id,
created_at: Time.current,
created_by_id: author.id,
name: author.name,
raw_text: post.payload["raw"],
title: post.payload["title"],
topic_id: nil,
topic_url: nil,
username: author.username,
}
end
it "serializes a pending post properly" do
expect(serializer.as_json).to match expected_attributes
end
end
context "when not creating a new topic" do
let(:post) { Fabricate(:reviewable_queued_post) }
let(:topic) { post.topic }
let(:expected_attributes) do
{
id: post.id,
avatar_template: author.avatar_template,
category_id: post.category_id,
created_at: Time.current,
created_by_id: author.id,
name: author.name,
raw_text: post.payload["raw"],
title: topic.title,
topic_id: topic.id,
topic_url: topic.url,
username: author.username,
}
end
it "serializes a pending post properly" do
expect(serializer.as_json).to match expected_attributes
end
end
end