Adding an active scope and test to Enterprise

This commit is contained in:
Will Marshall
2014-04-30 12:02:11 +10:00
parent 137c265885
commit 563976c084
2 changed files with 9 additions and 0 deletions

View File

@@ -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.*') }

View File

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