mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Adding a taxon collection mechanism to Enterprise
This commit is contained in:
@@ -106,6 +106,7 @@ class Enterprise < ActiveRecord::Base
|
||||
count(distinct: true)
|
||||
end
|
||||
|
||||
|
||||
def self.find_near(suburb)
|
||||
enterprises = []
|
||||
|
||||
@@ -137,6 +138,13 @@ class Enterprise < ActiveRecord::Base
|
||||
Spree::Variant.joins(:product => :product_distributions).where('product_distributions.distributor_id=?', self.id)
|
||||
end
|
||||
|
||||
# Return all taxons for all distributed products
|
||||
def taxons
|
||||
Spree::Product.in_distributor(self).map do |p|
|
||||
p.taxons
|
||||
end.flatten.uniq
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def initialize_country
|
||||
|
||||
@@ -383,4 +383,17 @@ describe Enterprise do
|
||||
Enterprise.find_near(@suburb_in_nsw).count.should eql(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "taxons" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:taxon1) { create(:taxon) }
|
||||
let(:taxon2) { create(:taxon) }
|
||||
let(:product1) { create(:simple_product, taxons: [taxon1]) }
|
||||
let(:product2) { create(:simple_product, taxons: [taxon1, taxon2]) }
|
||||
|
||||
it "gets all taxons of all products" do
|
||||
Spree::Product.stub(:in_distributor).and_return [product1, product2]
|
||||
distributor.taxons.should == [taxon1, taxon2]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user