2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-03 12:03:01 -05:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe ReviewableSerializer do
|
|
|
|
|
|
|
|
let(:reviewable) { Fabricate(:reviewable_queued_post) }
|
|
|
|
let(:admin) { Fabricate(:admin) }
|
|
|
|
|
|
|
|
it "serializes all the fields" do
|
2019-04-10 05:25:45 -04:00
|
|
|
json = described_class.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
2019-01-03 12:03:01 -05:00
|
|
|
|
|
|
|
expect(json[:id]).to eq(reviewable.id)
|
|
|
|
expect(json[:status]).to eq(reviewable.status)
|
|
|
|
expect(json[:type]).to eq(reviewable.type)
|
|
|
|
expect(json[:created_at]).to eq(reviewable.created_at)
|
|
|
|
expect(json[:category_id]).to eq(reviewable.category_id)
|
|
|
|
expect(json[:can_edit]).to eq(true)
|
|
|
|
expect(json[:version]).to eq(0)
|
2019-04-10 05:25:45 -04:00
|
|
|
expect(json[:removed_topic_id]).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'Includes the removed topic id when the topis was deleted' do
|
|
|
|
reviewable.topic.trash!(admin)
|
|
|
|
|
|
|
|
json = described_class.new(reviewable.reload, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
|
|
|
|
expect(json[:removed_topic_id]).to eq reviewable.topic_id
|
2019-01-03 12:03:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "will not throw an error when the payload is `nil`" do
|
|
|
|
reviewable.payload = nil
|
|
|
|
json = ReviewableQueuedPostSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
|
|
|
|
expect(json['payload']).to be_blank
|
|
|
|
end
|
|
|
|
end
|