From 563976c084e5e11baf5eafa89b368fa9baa36717 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 30 Apr 2014 12:02:11 +1000 Subject: [PATCH] Adding an active scope and test to Enterprise --- app/models/enterprise.rb | 1 + spec/models/enterprise_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 85a3998c60..916111bf21 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -30,6 +30,7 @@ class Enterprise < ActiveRecord::Base after_validation :geocode_address scope :by_name, order('name') + scope :active, where(:active => true) 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 d9c1808e94..990829f1b1 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -47,6 +47,14 @@ describe Enterprise do end describe "scopes" do + + describe 'active' do + it 'find active enterprises' do + d1 = create(:distributor_enterprise, active: false) + s1 = create(:supplier_enterprise) + Enterprise.active.should == [s1] + end + end describe "distributors_with_active_order_cycles" do it "finds active distributors by order cycles" do