Added toplevel scope for crops without a parent

This commit is contained in:
Skud
2013-09-02 11:52:01 +10:00
parent 772eec77a7
commit 4dbfecd315
2 changed files with 7 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ class Crop < ActiveRecord::Base
default_scope order("lower(system_name) asc")
scope :recent, reorder("created_at desc")
scope :toplevel, where(:parent_id => nil)
scope :randomized, reorder('random()') # ok on sqlite and psql, but not on mysql
validates :en_wikipedia_url,

View File

@@ -81,6 +81,12 @@ describe Crop do
@roma.parent.should eq @tomato
@tomato.varieties.should eq [@roma]
end
it 'toplevel scope works' do
@tomato = FactoryGirl.create(:tomato)
@roma = FactoryGirl.create(:roma, :parent_id => @tomato.id)
Crop.toplevel.should eq [ @tomato ]
end
end
context 'photos' do