Add unconfirmed scope

This commit is contained in:
Rob Harrington
2014-10-15 15:45:47 +11:00
parent 1bdc55cb33
commit c76a3815c0
2 changed files with 12 additions and 0 deletions

View File

@@ -62,6 +62,7 @@ class Enterprise < ActiveRecord::Base
scope :by_name, order('name')
scope :visible, where(:visible => true)
scope :confirmed, where('confirmed_at IS NOT NULL')
scope :unconfirmed, where('confirmed_at IS NULL')
scope :is_primary_producer, where(:is_primary_producer => true)
scope :is_distributor, where(:is_distributor => true)
scope :supplying_variant_in, lambda { |variants| joins(:supplied_products => :variants_including_master).where('spree_variants.id IN (?)', variants).select('DISTINCT enterprises.*') }

View File

@@ -132,6 +132,17 @@ describe Enterprise do
end
end
describe "unconfirmed" do
it "find enterprises without a confirmed date" do
s1 = create(:supplier_enterprise, confirmed_at: Time.now)
d1 = create(:distributor_enterprise, confirmed_at: Time.now)
s2 = create(:supplier_enterprise, confirmed_at: nil)
d2 = create(:distributor_enterprise, confirmed_at: nil)
expect(Enterprise.unconfirmed).to_not include s1, d1
expect(Enterprise.unconfirmed).to include s2, d2
end
end
describe "distributors_with_active_order_cycles" do
it "finds active distributors by order cycles" do
s = create(:supplier_enterprise)