diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 31ae2b3ee2..0840a53df3 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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) && diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 65571e3da7..4fa6e2b3f6 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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)