Files
openfoodnetwork/spec/serializers/api/admin/enterprise_serializer_spec.rb
Maikel Linke 4a0ed99919 Replace Paperclip on Enterprise model
We configured Paperclip to convert images to JPG in some cases but I
omitted that here because we don't need it. If an image is better
represented as PNG or another format then the user should be able to
choose that.

Some specs were also testing the generated URL but the Active Storage
URL doesn't contain a style name anymore and it's not helpful to test
the URL.
2022-06-01 17:16:55 +10:00

64 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require "spec_helper"
describe Api::Admin::EnterpriseSerializer do
include FileHelper
let(:enterprise) { create(:distributor_enterprise) }
it "serializes an enterprise" do
serializer = Api::Admin::EnterpriseSerializer.new enterprise
expect(serializer.to_json).to match enterprise.name
end
context "for logo" do
let(:enterprise) { create(:distributor_enterprise, logo: image) }
context "when there is a logo" do
let(:image) do
black_logo_file
end
it "includes URLs of image versions" do
serializer = Api::Admin::EnterpriseSerializer.new(enterprise)
expect(serializer.as_json[:logo]).to_not be_blank
expect(serializer.as_json[:logo][:medium]).to match(/logo-black.png/)
end
end
context "when there is no logo" do
let(:image) { nil }
it "includes URLs of image versions" do
serializer = Api::Admin::EnterpriseSerializer.new(enterprise)
expect(serializer.as_json[:logo]).to be_blank
end
end
end
context "for promo image" do
let(:enterprise) { create(:distributor_enterprise, promo_image: image) }
context "when there is a promo image" do
let(:image) do
black_logo_file
end
it "includes URLs of image versions" do
serializer = Api::Admin::EnterpriseSerializer.new(enterprise)
expect(serializer.as_json[:promo_image]).to_not be_blank
expect(serializer.as_json[:promo_image][:medium]).to match(/logo-black\.png$/)
end
end
context "when there is no promo image" do
let(:image) { nil }
it "includes URLs of image versions" do
serializer = Api::Admin::EnterpriseSerializer.new(enterprise)
expect(serializer.as_json[:promo_image]).to be_nil
end
end
end
end