mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Add Enterprise#ready_for_checkout?
This commit is contained in:
@@ -277,6 +277,10 @@ class Enterprise < ActiveRecord::Base
|
||||
select('DISTINCT spree_taxons.*')
|
||||
end
|
||||
|
||||
def ready_for_checkout?
|
||||
shipping_methods.any? && payment_methods.available.any?
|
||||
end
|
||||
|
||||
def shop_trial_in_progress?
|
||||
!!shop_trial_start_date &&
|
||||
(shop_trial_start_date + SHOP_TRIAL_LENGTH.days > Time.now) &&
|
||||
|
||||
@@ -219,6 +219,32 @@ describe Enterprise do
|
||||
end
|
||||
end
|
||||
|
||||
describe "#ready_for_checkout?" do
|
||||
let!(:e) { create(:enterprise) }
|
||||
|
||||
it "returns false for enterprises with no payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
e.reload.should_not be_ready_for_checkout
|
||||
end
|
||||
|
||||
it "returns false for enterprises with no shipping methods" do
|
||||
create(:payment_method, distributors: [e])
|
||||
e.reload.should_not be_ready_for_checkout
|
||||
end
|
||||
|
||||
it "returns false for enterprises with unavailable payment methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e], active: false)
|
||||
e.reload.should_not be_ready_for_checkout
|
||||
end
|
||||
|
||||
it "returns true for enterprises with available payment and shipping methods" do
|
||||
create(:shipping_method, distributors: [e])
|
||||
create(:payment_method, distributors: [e])
|
||||
e.reload.should be_ready_for_checkout
|
||||
end
|
||||
end
|
||||
|
||||
describe "distributors_with_active_order_cycles" do
|
||||
it "finds active distributors by order cycles" do
|
||||
s = create(:supplier_enterprise)
|
||||
|
||||
Reference in New Issue
Block a user