Order crops case-insensitively by default.

This commit is contained in:
Miles Gould
2013-01-25 11:19:15 +00:00
parent 8d2fe8809d
commit dc1ab0912f
2 changed files with 9 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ class Crop < ActiveRecord::Base
attr_accessible :en_wikipedia_url, :system_name
has_many :scientific_names
has_many :plantings
default_scope order("lower(system_name) asc")
def Crop.random
@crop = Crop.offset(rand(Crop.count)).first

View File

@@ -42,4 +42,12 @@ describe Crop do
@rand_crop.system_name.should == 'Tomato'
end
end
context 'ordering' do
it "should be sorted case-insensitively" do
uppercase = FactoryGirl.create(:uppercasecrop)
lowercase = FactoryGirl.create(:lowercasecrop)
Crop.first.should == lowercase
end
end
end