docbrown/spec/serializers/search/podcast_episode_serializer_spec.rb
Jeremy Friesen a65954107f
Refactoring to add helper method (#16064)
* Refactoring to add helper method

Prior to this commit, we made view level calls to service modules.  This
refactor provides convenience methods on the model.

Furthermore, it addresses a few Rubocop violations that "come along for
the ride."

* Ensuring cached entity squaks like User

* Fixing broken spec

* Fixing typo
2022-01-12 11:21:44 -05:00

22 lines
936 B
Ruby

require "rails_helper"
RSpec.describe Search::PodcastEpisodeSerializer do
let(:pce) { create(:podcast_episode) }
it "serializes a PodcastEpisode" do
data_hash = described_class.new(pce).serializable_hash.dig(:data, :attributes)
expect(data_hash.keys).to include(
:id, :body_text, :comments_count, :path, :published_at, :quote, :reactions_count, :subtitle,
:summary, :title, :website_url, :class_name, :highlight, :hotness_score, :main_image,
:podcast, :public_reactions_count, :published, :search_score, :slug, :user
)
end
it "serializes podcast" do
podcast = described_class.new(pce).serializable_hash.dig(:data, :attributes, :podcast)
expect(podcast.keys).to include(:slug, :image_url, :title)
expect(podcast[:slug]).to eq(pce.podcast_slug)
expect(podcast[:image_url]).to eq(pce.podcast.profile_image_url_for(length: 90))
expect(podcast[:title]).to eq(pce.title)
end
end