Preload enterprise logos and promo images for shops page

This commit is contained in:
Joseph Johansen
2024-08-01 11:55:20 +01:00
parent 53e3621e04
commit ffe4603f2f
2 changed files with 44 additions and 0 deletions

View File

@@ -19,5 +19,7 @@ class ShopsListService
.includes(address: [:state, :country])
.includes(:properties)
.includes(supplied_products: :properties)
.with_attached_promo_image
.with_attached_logo
end
end

View File

@@ -0,0 +1,42 @@
# frozen_string_literal: true
require "spec_helper"
RSpec.describe ShopsListService do
subject { described_class.new }
before do
create_list :enterprise, 3, :with_logo_image, :with_promo_image
create_list :distributor_enterprise, 3,
:with_logo_image,
:with_promo_image,
with_payment_and_shipping: true
end
let(:shop) { subject.open_shops.first }
describe "#open_shops" do
it "preloads promo images" do
expect(shop.association(:promo_image_attachment).loaded?).to be true
expect(shop.promo_image.association(:blob).loaded?).to be true
end
it "preloads logos" do
expect(shop.association(:logo_attachment).loaded?).to be true
expect(shop.logo.association(:blob).loaded?).to be true
end
end
describe "#closed_shops" do
let(:shop) { subject.closed_shops.first }
it "preloads promo images" do
expect(shop.association(:promo_image_attachment).loaded?).to be true
expect(shop.promo_image.association(:blob).loaded?).to be true
end
it "preloads logos" do
expect(shop.association(:logo_attachment).loaded?).to be true
expect(shop.logo.association(:blob).loaded?).to be true
end
end
end