Add Enterprise#ready_for_checkout?

This commit is contained in:
Rohan Mitchell
2014-10-31 14:04:43 +11:00
parent 94d50f220f
commit abeabd5b1c
2 changed files with 30 additions and 0 deletions

View File

@@ -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) &&

View File

@@ -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)