mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #6950 from andrewpbrett/fix-nil-enterprise-category
Fix #6949: Add default icon value if enterprise.category is nil
This commit is contained in:
@@ -129,7 +129,7 @@ module Api
|
||||
producer_shop: "map_003-producer-shop.svg",
|
||||
producer: "map_001-producer-only.svg",
|
||||
}
|
||||
"/map_icons/" + icons[enterprise.category]
|
||||
"/map_icons/" + (icons[enterprise.category] || "map_001-producer-only.svg")
|
||||
end
|
||||
|
||||
# Choose regular icon font for enterprises.
|
||||
|
||||
@@ -19,7 +19,7 @@ module Api
|
||||
producer_shop: "map_003-producer-shop.svg",
|
||||
producer: "map_001-producer-only.svg",
|
||||
}
|
||||
"/map_icons/" + icons[enterprise.category]
|
||||
"/map_icons/" + (icons[enterprise.category] || "map_001-producer-only.svg")
|
||||
end
|
||||
|
||||
def icon_font
|
||||
|
||||
@@ -97,4 +97,26 @@ describe Api::CachedEnterpriseSerializer do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#icon' do
|
||||
context "enterpise has a unrecognized category" do
|
||||
before do
|
||||
allow(enterprise).to receive(:category) { "unknown_category" }
|
||||
end
|
||||
|
||||
it "returns the map producer icon" do
|
||||
expect(cached_enterprise_serializer.icon).to eq("/map_icons/map_001-producer-only.svg")
|
||||
end
|
||||
end
|
||||
|
||||
context "enterpise has a nil category" do
|
||||
before do
|
||||
allow(enterprise).to receive(:category) { nil }
|
||||
end
|
||||
|
||||
it "returns the map producer icon" do
|
||||
expect(cached_enterprise_serializer.icon).to eq("/map_icons/map_001-producer-only.svg")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,4 +19,26 @@ describe Api::EnterpriseShopfrontListSerializer do
|
||||
it "serializes icons" do
|
||||
expect(serializer.to_json).to match "map_005-hub.svg"
|
||||
end
|
||||
|
||||
describe '#icon' do
|
||||
context "enterpise has a unrecognized category" do
|
||||
before do
|
||||
allow(enterprise).to receive(:category) { "unknown_category" }
|
||||
end
|
||||
|
||||
it "returns the map producer icon" do
|
||||
expect(serializer.icon).to eq("/map_icons/map_001-producer-only.svg")
|
||||
end
|
||||
end
|
||||
|
||||
context "enterpise has a nil category" do
|
||||
before do
|
||||
allow(enterprise).to receive(:category) { nil }
|
||||
end
|
||||
|
||||
it "returns the map producer icon" do
|
||||
expect(serializer.icon).to eq("/map_icons/map_001-producer-only.svg")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user