mirror of
https://github.com/discourse/discourse.git
synced 2024-11-30 20:04:16 +08:00
c9dab6fd08
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors. By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
58 lines
1.5 KiB
Ruby
58 lines
1.5 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.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
|