mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Make helper methods private
Otherwise next dev might think these are attributes of the resulting JSON serialized object. They just made the refactoring a bit easier.
This commit is contained in:
@@ -74,14 +74,6 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
ids_to_objs options[:data].supplied_taxons[object.id]
|
||||
end
|
||||
|
||||
def product_properties
|
||||
enterprise.supplied_products.flat_map(&:properties)
|
||||
end
|
||||
|
||||
def producer_properties
|
||||
enterprise.properties
|
||||
end
|
||||
|
||||
def supplied_properties
|
||||
(product_properties + producer_properties).uniq do |property_object|
|
||||
property_object.property.presentation
|
||||
@@ -149,6 +141,14 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
|
||||
private
|
||||
|
||||
def product_properties
|
||||
enterprise.supplied_products.flat_map(&:properties)
|
||||
end
|
||||
|
||||
def producer_properties
|
||||
enterprise.properties
|
||||
end
|
||||
|
||||
def enterprise
|
||||
object
|
||||
end
|
||||
|
||||
@@ -4,29 +4,6 @@ describe Api::CachedEnterpriseSerializer do
|
||||
let(:cached_enterprise_serializer) { described_class.new(enterprise) }
|
||||
let(:enterprise) { create(:enterprise) }
|
||||
|
||||
describe '#product_properties' do
|
||||
let(:property) { create(:property) }
|
||||
|
||||
before do
|
||||
product = create(:product, properties: [property])
|
||||
enterprise.supplied_products << product
|
||||
end
|
||||
|
||||
it 'returns the properties of the products supplied by the enterprise' do
|
||||
expect(cached_enterprise_serializer.product_properties).to eq([property])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#producer_properties' do
|
||||
let(:property) { create(:property) }
|
||||
|
||||
before { enterprise.properties << property }
|
||||
|
||||
it 'returns the properties of the enterprise' do
|
||||
expect(cached_enterprise_serializer.producer_properties).to eq([property])
|
||||
end
|
||||
end
|
||||
|
||||
describe '#supplied_properties' do
|
||||
let(:property) { create(:property, presentation: 'One') }
|
||||
let(:duplicate_property) { create(:property, presentation: 'One') }
|
||||
@@ -42,8 +19,8 @@ describe Api::CachedEnterpriseSerializer do
|
||||
end
|
||||
|
||||
it "removes duplicate product and producer properties" do
|
||||
merge = cached_enterprise_serializer.supplied_properties
|
||||
expect(merge).to eq([property, different_property])
|
||||
properties = cached_enterprise_serializer.supplied_properties
|
||||
expect(properties).to eq([property, different_property])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user