Added scopes for finished and current plantings

This commit is contained in:
Skud
2014-08-30 09:28:02 +10:00
parent b07d9d8db0
commit e7dd50c3f1
2 changed files with 16 additions and 0 deletions

View File

@@ -14,6 +14,8 @@ class Planting < ActiveRecord::Base
before_destroy {|planting| planting.photos.clear}
default_scope order("created_at desc")
scope :finished, where(:finished => true)
scope :current, where(:finished => false)
delegate :name,
:en_wikipedia_url,

View File

@@ -215,6 +215,20 @@ describe Planting do
@planting.finished_at.should be_an_instance_of Date
end
it 'has finished scope' do
@p = FactoryGirl.create(:planting)
@f = FactoryGirl.create(:finished_planting)
Planting.finished.should include @f
Planting.finished.should_not include @p
end
it 'has current scope' do
@p = FactoryGirl.create(:planting)
@f = FactoryGirl.create(:finished_planting)
Planting.current.should include @p
Planting.current.should_not include @f
end
end
end