mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Test and implementation: dropping inclusion of product_distributions from active Distributors on front page - BugHerd#125
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
module TempLandingPageHelper
|
||||
def temp_landing_page_distributor_link_class(distributor)
|
||||
cart = current_order(true)
|
||||
@active_distributors ||= Enterprise.active_distributors
|
||||
@active_distributors ||= Enterprise.distributors_with_active_order_cycles
|
||||
|
||||
klass = "shop-distributor"
|
||||
klass += " empties-cart" unless cart.line_items.empty? || cart.distributor == distributor
|
||||
|
||||
@@ -47,6 +47,7 @@ class Enterprise < ActiveRecord::Base
|
||||
scope :with_order_cycles_outer,
|
||||
joins('LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id)').
|
||||
joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)')
|
||||
|
||||
scope :with_order_cycles_and_exchange_variants_outer,
|
||||
with_order_cycles_outer.
|
||||
joins('LEFT OUTER JOIN exchange_variants ON (exchange_variants.exchange_id = exchanges.id)').
|
||||
@@ -57,6 +58,13 @@ class Enterprise < ActiveRecord::Base
|
||||
where('(product_distributions.product_id IS NOT NULL AND spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0) OR (order_cycles.id IS NOT NULL AND order_cycles.orders_open_at <= ? AND order_cycles.orders_close_at >= ?)', Time.now, Time.now, Time.now).
|
||||
select('DISTINCT enterprises.*')
|
||||
}
|
||||
|
||||
scope :distributors_with_active_order_cycles, lambda {
|
||||
with_order_cycles_outer.
|
||||
merge(OrderCycle.active).
|
||||
select('DISTINCT enterprises.*')
|
||||
}
|
||||
|
||||
scope :distributing_product, lambda { |product|
|
||||
with_distributed_products_outer.with_order_cycles_and_exchange_variants_outer.
|
||||
where('product_distributions.product_id = ? OR spree_variants.product_id = ?', product, product).
|
||||
|
||||
@@ -58,7 +58,7 @@ feature %q{
|
||||
page.should have_link "PepperTree Place"
|
||||
end
|
||||
|
||||
it "should grey out hubs that have no products available for distribution and are not in an order cycle" do
|
||||
it "should grey out hubs that are not in an order cycle" do
|
||||
|
||||
create(:simple_order_cycle, distributors: [d1, d3])
|
||||
create(:simple_product, distributors: [d1, d2])
|
||||
@@ -66,7 +66,7 @@ feature %q{
|
||||
visit root_path
|
||||
|
||||
page.should have_selector 'a.shop-distributor.active', text: 'Murandaka'
|
||||
page.should have_selector 'a.shop-distributor.active', text: 'Ballantyne'
|
||||
page.should have_selector 'a.shop-distributor.inactive', text: 'Ballantyne'
|
||||
page.should have_selector 'a.shop-distributor.active', text: "O'Hea Street"
|
||||
page.should have_selector 'a.shop-distributor.inactive', text: 'PepperTree Place'
|
||||
end
|
||||
|
||||
@@ -47,6 +47,25 @@ describe Enterprise do
|
||||
end
|
||||
|
||||
describe "scopes" do
|
||||
|
||||
describe "distributors_with_active_order_cycles" do
|
||||
it "finds active distributors by order cycles" do
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product)
|
||||
create(:simple_order_cycle, suppliers: [s], distributors: [d], variants: [p.master])
|
||||
Enterprise.distributors_with_active_order_cycles.should == [d]
|
||||
end
|
||||
|
||||
it "should not find inactive distributors by order cycles" do
|
||||
s = create(:supplier_enterprise)
|
||||
d = create(:distributor_enterprise)
|
||||
p = create(:product)
|
||||
create(:simple_order_cycle, :orders_open_at => 10.days.from_now, suppliers: [s], distributors: [d], variants: [p.master])
|
||||
Enterprise.distributors_with_active_order_cycles.should_not include d
|
||||
end
|
||||
end
|
||||
|
||||
describe "active_distributors" do
|
||||
it "finds active distributors by product distributions" do
|
||||
d = create(:distributor_enterprise)
|
||||
@@ -88,28 +107,6 @@ describe Enterprise do
|
||||
Enterprise.active_distributors.should be_empty
|
||||
end
|
||||
|
||||
it "shows only enterprises for given user" do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
e1 = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
e1.enterprise_roles.build(user: user).save
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.count.should == 1
|
||||
enterprises.should include e1
|
||||
end
|
||||
|
||||
it "shows all enterprises for admin user" do
|
||||
user = create(:admin_user)
|
||||
e1 = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.count.should == 2
|
||||
enterprises.should include e1
|
||||
enterprises.should include e2
|
||||
end
|
||||
end
|
||||
|
||||
describe "with_distributed_active_products_on_hand" do
|
||||
@@ -199,6 +196,31 @@ describe Enterprise do
|
||||
Enterprise.distributing_any_product_of([p1, p2]).should == [d]
|
||||
end
|
||||
end
|
||||
|
||||
describe "managed_by" do
|
||||
it "shows only enterprises for given user" do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
e1 = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
e1.enterprise_roles.build(user: user).save
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.count.should == 1
|
||||
enterprises.should include e1
|
||||
end
|
||||
|
||||
it "shows all enterprises for admin user" do
|
||||
user = create(:admin_user)
|
||||
e1 = create(:enterprise)
|
||||
e2 = create(:enterprise)
|
||||
|
||||
enterprises = Enterprise.managed_by user
|
||||
enterprises.count.should == 2
|
||||
enterprises.should include e1
|
||||
enterprises.should include e2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "has_supplied_products_on_hand?" do
|
||||
|
||||
Reference in New Issue
Block a user