From e7dd50c3f18abbbad3fd2bbc81ea3efee5aef18a Mon Sep 17 00:00:00 2001 From: Skud Date: Sat, 30 Aug 2014 09:28:02 +1000 Subject: [PATCH] Added scopes for finished and current plantings --- app/models/planting.rb | 2 ++ spec/models/planting_spec.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/app/models/planting.rb b/app/models/planting.rb index afeeb2137..270a827d2 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -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, diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 65e7b890e..13b910d22 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -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