discourse/spec/serializers/reviewable_serializer_spec.rb
Robin Ward b58867b6e9 FEATURE: New 'Reviewable' model to make reviewable items generic
Includes support for flags, reviewable users and queued posts, with REST API
backwards compatibility.

Co-Authored-By: romanrizzi <romanalejandro@gmail.com>
Co-Authored-By: jjaffeux <j.jaffeux@gmail.com>
2019-03-28 12:45:10 -04:00

27 lines
874 B
Ruby

require 'rails_helper'
describe ReviewableSerializer do
let(:reviewable) { Fabricate(:reviewable_queued_post) }
let(:admin) { Fabricate(:admin) }
it "serializes all the fields" do
json = ReviewableSerializer.new(reviewable, scope: Guardian.new(admin), root: nil).as_json
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)
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