mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-19 22:38:55 -04:00
Added toplevel scope for crops without a parent
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user