mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Rename Property#sold_by and ProducerProperty#sold_by to currently_sold_by
This commit is contained in:
@@ -8,7 +8,7 @@ class ProducerProperty < ActiveRecord::Base
|
||||
after_destroy :refresh_products_cache_from_destroy
|
||||
|
||||
|
||||
scope :sold_by, ->(shop) {
|
||||
scope :currently_sold_by, ->(shop) {
|
||||
joins(producer: {supplied_products: {variants: {exchanges: :order_cycle}}}).
|
||||
merge(Exchange.outgoing).
|
||||
merge(Exchange.to_enterprise(shop)).
|
||||
|
||||
@@ -8,7 +8,7 @@ module Spree
|
||||
where('spree_product_properties.product_id IN (?)', enterprise.supplied_product_ids)
|
||||
}
|
||||
|
||||
scope :sold_by, ->(shop) {
|
||||
scope :currently_sold_by, ->(shop) {
|
||||
joins(products: {variants: {exchanges: :order_cycle}}).
|
||||
merge(Exchange.outgoing).
|
||||
merge(Exchange.to_enterprise(shop)).
|
||||
|
||||
@@ -42,8 +42,8 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
|
||||
def distributed_properties
|
||||
# This results in 3 queries per enterprise
|
||||
product_properties = Spree::Property.sold_by(object)
|
||||
ids = ProducerProperty.sold_by(object).pluck(:property_id)
|
||||
product_properties = Spree::Property.currently_sold_by(object)
|
||||
ids = ProducerProperty.currently_sold_by(object).pluck(:property_id)
|
||||
producer_properties = Spree::Property.where(id: ids)
|
||||
|
||||
OpenFoodNetwork::PropertyMerge.merge product_properties, producer_properties
|
||||
|
||||
@@ -8,7 +8,7 @@ describe ProducerProperty do
|
||||
producer.set_producer_property 'Organic Certified', 'NASAA 54321'
|
||||
end
|
||||
|
||||
describe ".sold_by" do
|
||||
describe ".currently_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) }
|
||||
@@ -22,7 +22,7 @@ describe ProducerProperty do
|
||||
|
||||
describe "with an associated producer property" do
|
||||
it "returns the producer property" do
|
||||
expect(ProducerProperty.sold_by(shop)).to eq [pp]
|
||||
expect(ProducerProperty.currently_sold_by(shop)).to eq [pp]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ describe ProducerProperty 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.sold_by(shop)).not_to include pp_other
|
||||
expect(ProducerProperty.currently_sold_by(shop)).not_to include pp_other
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ describe ProducerProperty do
|
||||
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.sold_by(shop)).not_to include pp_other
|
||||
expect(ProducerProperty.currently_sold_by(shop)).not_to include pp_other
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ describe ProducerProperty do
|
||||
end
|
||||
|
||||
it "doesn't return the producer property" do
|
||||
expect(ProducerProperty.sold_by(shop)).not_to include pp
|
||||
expect(ProducerProperty.currently_sold_by(shop)).not_to include pp
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,7 +59,7 @@ describe ProducerProperty do
|
||||
let!(:oc) { create(:simple_order_cycle, distributors: [shop], variants: [product.variants.first, product2.variants.first]) }
|
||||
|
||||
it "doesn't return duplicates" do
|
||||
expect(ProducerProperty.sold_by(shop).to_a.count).to eq 1
|
||||
expect(ProducerProperty.currently_sold_by(shop).to_a.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
describe ".sold_by" do
|
||||
describe ".currently_sold_by" do
|
||||
let!(:shop) { create(:distributor_enterprise) }
|
||||
let!(:shop_other) { create(:distributor_enterprise) }
|
||||
let!(:product) { create(:simple_product) }
|
||||
@@ -54,19 +54,19 @@ module Spree
|
||||
end
|
||||
|
||||
it "returns the property" do
|
||||
expect(Property.sold_by(shop)).to eq [property]
|
||||
expect(Property.currently_sold_by(shop)).to eq [property]
|
||||
end
|
||||
|
||||
it "doesn't return the property from another exchange" do
|
||||
expect(Property.sold_by(shop)).not_to include property_other_ex
|
||||
expect(Property.currently_sold_by(shop)).not_to include property_other_ex
|
||||
end
|
||||
|
||||
it "doesn't return the property with no order cycle" do
|
||||
expect(Property.sold_by(shop)).not_to include property_no_oc
|
||||
expect(Property.currently_sold_by(shop)).not_to include property_no_oc
|
||||
end
|
||||
|
||||
it "doesn't return the property from a closed order cycle" do
|
||||
expect(Property.sold_by(shop)).not_to include property_closed_oc
|
||||
expect(Property.currently_sold_by(shop)).not_to include property_closed_oc
|
||||
end
|
||||
|
||||
context "with another product in the order cycle" do
|
||||
@@ -78,7 +78,7 @@ module Spree
|
||||
end
|
||||
|
||||
it "doesn't return duplicates" do
|
||||
expect(Property.sold_by(shop).to_a.count).to eq 1
|
||||
expect(Property.currently_sold_by(shop).to_a.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user