Skip to content

Commit

Permalink
Make reports and subscriptions specs work without product.distributor…
Browse files Browse the repository at this point in the history
…s attribute
  • Loading branch information
luisramos0 committed Mar 3, 2019
1 parent f3fa32c commit 9f0a609
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
11 changes: 5 additions & 6 deletions app/controllers/spree/admin/reports_controller_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def order_cycle_management
my_distributors = Enterprise.is_distributor.managed_by(spree_current_user)
my_suppliers = Enterprise.is_primary_producer.managed_by(spree_current_user)

# My distributors and any distributors distributing products I supply
@distributors = my_distributors | Enterprise.with_distributed_products_outer.merge(Spree::Product.in_any_supplier(my_suppliers))
# My distributors
@distributors = my_distributors
# My suppliers and any suppliers supplying products I distribute
@suppliers = my_suppliers | my_distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq
@order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC')
Expand All @@ -72,8 +72,8 @@ def packing
my_distributors = Enterprise.is_distributor.managed_by(spree_current_user)
my_suppliers = Enterprise.is_primary_producer.managed_by(spree_current_user)

# My distributors and any distributors distributing products I supply
@distributors = my_distributors | Enterprise.with_distributed_products_outer.merge(Spree::Product.in_any_supplier(my_suppliers))
# My distributors
@distributors = my_distributors
# My suppliers and any suppliers supplying products I distribute
@suppliers = my_suppliers | my_distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq
@order_cycles = OrderCycle.active_or_complete.accessible_by(spree_current_user).order('orders_close_at DESC')
Expand Down Expand Up @@ -231,8 +231,7 @@ def load_data
# Load distributors either owned by the user or selling their enterprises products.
my_distributors = Enterprise.is_distributor.managed_by(spree_current_user)
my_suppliers = Enterprise.is_primary_producer.managed_by(spree_current_user)
distributors_of_my_products = Enterprise.with_distributed_products_outer.merge(Spree::Product.in_any_supplier(my_suppliers))
@distributors = my_distributors | distributors_of_my_products
@distributors = my_distributors
# Load suppliers either owned by the user or supplying products their enterprises distribute.
suppliers_of_products_i_distribute = my_distributors.map { |d| Spree::Product.in_distributor(d) }.flatten.map(&:supplier).uniq
@suppliers = my_suppliers | suppliers_of_products_i_distribute
Expand Down
6 changes: 3 additions & 3 deletions spec/controllers/spree/admin/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
let(:distributor1) { create(:distributor_enterprise) }
let(:distributor2) { create(:distributor_enterprise) }
let(:distributor3) { create(:distributor_enterprise) }
let(:product1) { create(:product, price: 12.34, distributors: [distributor1], supplier: supplier1) }
let(:product2) { create(:product, price: 23.45, distributors: [distributor2], supplier: supplier2) }
let(:product3) { create(:product, price: 34.56, distributors: [distributor3], supplier: supplier3) }
let(:product1) { create(:product, price: 12.34, supplier: supplier1) }
let(:product2) { create(:product, price: 23.45, supplier: supplier2) }
let(:product3) { create(:product, price: 34.56, supplier: supplier3) }

# Given two order cycles with both distributors
let(:ocA) { create(:simple_order_cycle, coordinator: coordinator1, distributors: [distributor1, distributor2], suppliers: [supplier1, supplier2, supplier3], variants: [product1.master, product3.master]) }
Expand Down
1 change: 0 additions & 1 deletion spec/features/admin/reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@
let(:distributor_address) { create(:address, :address1 => "distributor address", :city => 'The Shire', :zipcode => "1234") }
let(:distributor) { create(:distributor_enterprise, :address => distributor_address) }
let(:product) { create(:product) }
let(:product_distribution) { create(:product_distribution, :product => product, :distributor => distributor) }
let(:shipping_instructions) { "pick up on thursday please!" }
let(:order1) { create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions) }
let(:order2) { create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions) }
Expand Down
12 changes: 6 additions & 6 deletions spec/features/admin/subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@
let!(:customer_user) { create(:user) }
let!(:credit_card1) { create(:credit_card, user: customer_user, cc_type: 'visa', last_digits: 1111, month: 10, year: 2030) }
let!(:customer) { create(:customer, enterprise: shop, bill_address: address, user: customer_user, allow_charges: true) }
let!(:test_product) { create(:product, supplier: shop, distributors: []) }
let!(:test_product) { create(:product, supplier: shop) }
let!(:test_variant) { create(:variant, product: test_product, unit_value: "100", price: 12.00, option_values: []) }
let!(:shop_product) { create(:product, supplier: shop, distributors: [shop]) }
let!(:shop_product) { create(:product, supplier: shop) }
let!(:shop_variant) { create(:variant, product: shop_product, unit_value: "1000", price: 6.00, option_values: []) }
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
Expand Down Expand Up @@ -414,22 +414,22 @@
describe "allowed variants" do
let!(:customer) { create(:customer, enterprise: shop, allow_charges: true) }
let!(:credit_card) { create(:credit_card, user: customer.user) }
let!(:shop_product) { create(:product, supplier: shop, distributors: [shop]) }
let!(:shop_product) { create(:product, supplier: shop) }
let!(:shop_variant) { create(:variant, product: shop_product, unit_value: "2000") }
let!(:permitted_supplier) do
create(:supplier_enterprise).tap do |supplier|
create(:enterprise_relationship, child: shop, parent: supplier, permissions_list: [:add_to_order_cycle])
end
end
let!(:permitted_supplier_product) { create(:product, supplier: permitted_supplier, distributors: [shop]) }
let!(:permitted_supplier_product) { create(:product, supplier: permitted_supplier) }
let!(:permitted_supplier_variant) { create(:variant, product: permitted_supplier_product, unit_value: "2000") }
let!(:incoming_exchange_product) { create(:product, distributors: [shop]) }
let!(:incoming_exchange_product) { create(:product) }
let!(:incoming_exchange_variant) do
create(:variant, product: incoming_exchange_product, unit_value: "2000").tap do |variant|
create(:exchange, order_cycle: order_cycle, incoming: true, receiver: shop, variants: [variant])
end
end
let!(:outgoing_exchange_product) { create(:product, distributors: [shop]) }
let!(:outgoing_exchange_product) { create(:product) }
let!(:outgoing_exchange_variant) do
create(:variant, product: outgoing_exchange_product, unit_value: "2000").tap do |variant|
create(:exchange, order_cycle: order_cycle, incoming: false, receiver: shop, variants: [variant])
Expand Down
3 changes: 0 additions & 3 deletions spec/lib/open_food_network/group_buy_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module OpenFoodNetwork
@variant1 = create(:variant)
@variant1.product.supplier = @supplier1
@variant1.product.save!
product_distribution = create(:product_distribution, :product => @variant1.product, :distributor => distributor)
shipping_instructions = "pick up on thursday please!"

order1 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
Expand All @@ -28,7 +27,6 @@ module OpenFoodNetwork
@variant2 = create(:variant)
@variant2.product.supplier = @supplier1
@variant2.product.save!
product_distribution = create(:product_distribution, :product => @variant2.product, :distributor => distributor)

line_item22 = create(:line_item, :variant => @variant2, :order => order2)
order2.line_items << line_item22
Expand All @@ -38,7 +36,6 @@ module OpenFoodNetwork
@variant3 = create(:variant, :weight => nil)
@variant3.product.supplier = @supplier2
@variant3.product.save!
product_distribution = create(:product_distribution, :product => @variant3.product, :distributor => distributor)

order3 = create(:order, :distributor => distributor, :bill_address => bill_address, :special_instructions => shipping_instructions)
line_item31 = create(:line_item, :variant => @variant3, :order => order3)
Expand Down

0 comments on commit 9f0a609

Please sign in to comment.