docbrown/spec/serializers/homepage/article_serializer_spec.rb
Jeremy Friesen c5bf4bf880
Extracting duplicate logic (#16035)
Prior to this commit, we had two places that need to know the nuances
ofquerying for tag flares and what we should include in our queries for
serialization.

With this commit, we're factoring towards a common source of knowledge
and providing a much needed test for the expected output of this
serialization.

Loosely related to #15916, #15983, #15994, and #16032.
2022-01-10 15:19:04 -05:00

20 lines
792 B
Ruby

require "rails_helper"
RSpec.describe Homepage::ArticleSerializer, type: :serializer do
describe "#serialized_collection_from" do
let(:user) { create(:user, name: "\"Rowdy\" Roddy Piper \\:/") }
let(:organization) { create(:organization) }
let(:tag) { create(:tag, name: "ama", bg_color_hex: "#f3f3f3", text_color_hex: "#cccccc") }
let(:article) { create(:article, user: user, organization: organization, tags: tag.name) }
before do
article
stub_const("FlareTag::FLARE_TAG_IDS_HASH", { "ama" => tag.id })
end
it "is parseable as JSON (once converted to_json)" do
response = described_class.serialized_collection_from(relation: Article.all)
expect(JSON.parse(response.to_json)[0].dig("user", "name")).to eq(user.name)
end
end
end