mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-26 20:56:48 +00:00
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.
64 lines
1.8 KiB
Ruby
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
|