mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-03 22:47:07 -05:00
Added scopes for finished and current plantings
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user