Remove dead code

Dead since https://github.com/openfoodfoundation/openfoodnetwork/pull/3305
This commit is contained in:
Luis Ramos
2020-04-18 14:47:33 +01:00
parent 437c7367db
commit 43274ecb4f
4 changed files with 0 additions and 169 deletions

View File

@@ -4,18 +4,6 @@ class ProducerProperty < ActiveRecord::Base
default_scope { order("#{table_name}.position") }
scope :ever_sold_by, ->(shop) {
joins(producer: { supplied_products: { variants: { exchanges: :order_cycle } } }).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
select('DISTINCT producer_properties.*')
}
scope :currently_sold_by, ->(shop) {
ever_sold_by(shop).
merge(OrderCycle.active)
}
def property_name
property.name if property
end

View File

@@ -10,18 +10,6 @@ module Spree
scope :sorted, -> { order(:name) }
scope :ever_sold_by, ->(shop) {
joins(products: { variants: { exchanges: :order_cycle } }).
merge(Exchange.outgoing).
merge(Exchange.to_enterprise(shop)).
select('DISTINCT spree_properties.*')
}
scope :currently_sold_by, ->(shop) {
ever_sold_by(shop).
merge(OrderCycle.active)
}
def property
self
end

View File

@@ -1,74 +0,0 @@
require 'spec_helper'
describe ProducerProperty do
let(:producer) { create(:supplier_enterprise) }
let(:pp) { producer.producer_properties.first }
before do
producer.set_producer_property 'Organic Certified', 'NASAA 54321'
end
describe ".currently_sold_by and .ever_sold_by" do
let!(:shop) { create(:distributor_enterprise) }
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first]) }
let(:product) { create(:simple_product, supplier: producer) }
let(:producer_other) { create(:supplier_enterprise) }
let(:product_other) { create(:simple_product, supplier: producer_other) }
let(:pp_other) { producer_other.producer_properties.first }
before do
producer_other.set_producer_property 'Spiffy', 'Ya'
end
describe "with an associated producer property" do
it "returns the producer property" do
expect(ProducerProperty.currently_sold_by(shop)).to eq [pp]
expect(ProducerProperty.ever_sold_by(shop)).to eq [pp]
end
end
describe "with a producer property for a producer not carried by that shop" do
let!(:exchange) { create(:exchange, order_cycle: oc, incoming: true, sender: producer_other, receiver: oc.coordinator) }
it "doesn't return the producer property" do
expect(ProducerProperty.currently_sold_by(shop)).not_to include pp_other
expect(ProducerProperty.ever_sold_by(shop)).not_to include pp_other
end
end
describe "with a producer property for a product in a different shop" do
let(:shop_other) { create(:distributor_enterprise) }
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first]) }
let!(:exchange) { create(:exchange, order_cycle: oc, incoming: false, sender: oc.coordinator, receiver: shop_other, variants: [product_other.variants.first]) }
it "doesn't return the producer property" do
expect(ProducerProperty.currently_sold_by(shop)).not_to include pp_other
expect(ProducerProperty.ever_sold_by(shop)).not_to include pp_other
end
end
describe "with a producer property for a product in a closed order cycle" do
before do
oc.update_attributes! orders_open_at: 2.weeks.ago, orders_close_at: 1.week.ago
end
it "doesn't return the producer property for .currently_sold_by" do
expect(ProducerProperty.currently_sold_by(shop)).not_to include pp
end
it "returns the producer property for .ever_sold_by" do
expect(ProducerProperty.ever_sold_by(shop)).to include pp
end
end
describe "with a duplicate producer property" do
let(:product2) { create(:simple_product, supplier: producer) }
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first, product2.variants.first]) }
it "doesn't return duplicates" do
expect(ProducerProperty.currently_sold_by(shop).to_a.size).to eq 1
expect(ProducerProperty.ever_sold_by(shop).to_a.size).to eq 1
end
end
end
end

View File

@@ -1,71 +0,0 @@
require 'spec_helper'
module Spree
describe Property do
describe "scopes" do
describe ".currently_sold_by and .ever_sold_by" do
let!(:shop) { create(:distributor_enterprise) }
let!(:shop_other) { create(:distributor_enterprise) }
let!(:product) { create(:simple_product) }
let!(:product_other_ex) { create(:simple_product) }
let!(:product_no_oc) { create(:simple_product) }
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first]) }
let!(:exchange_other_shop) { create(:exchange, order_cycle: oc, sender: oc.coordinator, receiver: shop_other, variants: [product_other_ex.variants.first]) }
let(:property) { product.properties.last }
let(:property_other_ex) { product_other_ex.properties.last }
let(:property_no_oc) { product_no_oc.properties.last }
before do
product.set_property 'Organic', 'NASAA 12345'
product_other_ex.set_property 'Biodynamic', 'ASDF 12345'
product_no_oc.set_property 'Shiny', 'Very'
end
it "returns the property" do
expect(Property.currently_sold_by(shop)).to eq [property]
expect(Property.ever_sold_by(shop)).to eq [property]
end
it "doesn't return the property from another exchange" do
expect(Property.currently_sold_by(shop)).not_to include property_other_ex
expect(Property.ever_sold_by(shop)).not_to include property_other_ex
end
it "doesn't return the property with no order cycle" do
expect(Property.currently_sold_by(shop)).not_to include property_no_oc
expect(Property.ever_sold_by(shop)).not_to include property_no_oc
end
describe "closed order cyces" do
let!(:product_closed_oc) { create(:simple_product) }
let!(:oc_closed) { create(:closed_order_cycle, distributors: [shop], variants: [product_closed_oc.variants.first]) }
let(:property_closed_oc) { product_closed_oc.properties.last }
before { product_closed_oc.set_property 'Spiffy', 'Ooh yeah' }
it "doesn't return the property for .currently_sold_by" do
expect(Property.currently_sold_by(shop)).not_to include property_closed_oc
end
it "returns the property for .ever_sold_by" do
expect(Property.ever_sold_by(shop)).to include property_closed_oc
end
end
context "with another product in the order cycle" do
let!(:product2) { create(:simple_product) }
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first, product2.variants.first]) }
before do
product2.set_property 'Organic', 'NASAA 12345'
end
it "doesn't return duplicates" do
expect(Property.currently_sold_by(shop).to_a.size).to eq 1
expect(Property.ever_sold_by(shop).to_a.size).to eq 1
end
end
end
end
end
end