From c76a3815c03eac35f02f611beda7aeb2038c8290 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 15 Oct 2014 15:45:47 +1100 Subject: [PATCH] Add unconfirmed scope --- app/models/enterprise.rb | 1 + spec/models/enterprise_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 977b35390b..954667f3e1 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -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.*') } diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 692509890d..7dc1d986a1 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -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)