mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-08 15:54:43 -04:00
Added unpopular scope to crop
This commit is contained in:
@@ -7,7 +7,7 @@ class CropsController < ApplicationController
|
||||
# GET /crops
|
||||
# GET /crops.json
|
||||
def index
|
||||
@crops = Crop.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
@crops = Crop.popular.includes(:scientific_names, {:plantings => :photos}).paginate(:page => params[:page])
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
||||
@@ -17,7 +17,8 @@ class Crop < ActiveRecord::Base
|
||||
default_scope order("lower(name) asc")
|
||||
scope :recent, reorder("created_at desc")
|
||||
scope :toplevel, where(:parent_id => nil)
|
||||
scope :popular, reorder("plantings_count desc")
|
||||
scope :popular, where("plantings_count > 0").reorder("plantings_count desc, lower(name) asc")
|
||||
scope :unpopular, where(:plantings_count => nil)
|
||||
scope :randomized, reorder('random()') # ok on sqlite and psql, but not on mysql
|
||||
|
||||
validates :en_wikipedia_url,
|
||||
|
||||
@@ -56,6 +56,7 @@ describe Crop do
|
||||
before (:each) do
|
||||
@tomato = FactoryGirl.create(:tomato)
|
||||
@maize = FactoryGirl.create(:maize)
|
||||
@cucumber = FactoryGirl.create(:crop, :name => 'cucumber')
|
||||
(1..10).each do
|
||||
FactoryGirl.create(:planting, :crop => @maize)
|
||||
end
|
||||
@@ -72,6 +73,10 @@ describe Crop do
|
||||
Crop.popular.first.should eq @tomato
|
||||
end
|
||||
|
||||
it "finds unpopular crops" do
|
||||
Crop.unpopular.should eq [@cucumber]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it 'finds a default scientific name' do
|
||||
|
||||
Reference in New Issue
Block a user