diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index e385d2de9..efe130a59 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -8,11 +8,11 @@ class HomeController < ApplicationController @planting_count = Planting.count @garden_count = Garden.count - @crops = Crop.interesting(6) + @crops = Crop.interesting.first(6) @recent_crops = Crop.recent.limit(12) - @plantings = Planting.interesting(4) - @seeds = Seed.interesting(6) - @members = Member.interesting(6) + @plantings = Planting.interesting.first(4) + @seeds = Seed.interesting.first(6) + @members = Member.interesting.first(6) respond_to do |format| format.html # index.html.haml diff --git a/app/models/crop.rb b/app/models/crop.rb index 86c4a5ac0..45fac0bc7 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -78,9 +78,10 @@ class Crop < ActiveRecord::Base return planted_from end - # Crop.interesting(howmany) + # Crop.interesting # returns a list of interesting crops, for use on the homepage etc - def Crop.interesting(howmany=12) + def Crop.interesting + howmany = 12 # max number to find interesting_crops = Array.new min_plantings = 3 # needs this many plantings to be interesting min_photos = 3 # needs this many photos to be interesting diff --git a/app/models/member.rb b/app/models/member.rb index 6b4835c14..b8f64c0de 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -181,7 +181,8 @@ class Member < ActiveRecord::Base return sets end - def Member.interesting(howmany=12) + def Member.interesting + howmany = 12 # max number to find interesting_members = Array.new Member.confirmed.located.recently_signed_in.each do |m| break if interesting_members.length == howmany diff --git a/app/models/planting.rb b/app/models/planting.rb index fdee6f692..7fa267411 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -70,7 +70,8 @@ class Planting < ActiveRecord::Base # return a list of interesting plantings, for the homepage etc. # we can't do this via a scope (as far as we know) so sadly we have to # do it this way. - def Planting.interesting(howmany=10) + def Planting.interesting + howmany = 12 # max amount to collect interesting_plantings = Array.new seen_owners = Hash.new(false) # keep track of which owners we've seen already diff --git a/app/models/seed.rb b/app/models/seed.rb index d7fb25451..1879cfa29 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -30,9 +30,10 @@ class Seed < ActiveRecord::Base end end - # Seed.interesting(howmany) + # Seed.interesting # returns a list of interesting seeds, for use on the homepage etc - def Seed.interesting(howmany=8) + def Seed.interesting + howmany = 12 # max number to find interesting_seeds = Array.new Seed.tradable.each do |s| diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index 618e82500..b1363004a 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -221,31 +221,6 @@ describe Crop do Crop.interesting.length.should == 1 end - it 'only gives you as many as you ask for' do - # first, a couple of candidate crops - @crop1 = FactoryGirl.create(:crop, :system_name => 'aaa') - @crop2 = FactoryGirl.create(:crop, :system_name => 'zzz') - - # they need 3+ plantings each to be interesting - (1..3).each do - FactoryGirl.create(:planting, :crop => @crop1) - end - (1..3).each do - FactoryGirl.create(:planting, :crop => @crop2) - end - - # crops need 3+ photos to be interesting - @photo = FactoryGirl.create(:photo) - [@crop1, @crop2].each do |c| - (1..3).each do - c.plantings.first.photos << @photo - c.plantings.first.save - end - end - - Crop.interesting(1).length.should == 1 - end - end end diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index de2c24b65..d730414aa 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -204,24 +204,6 @@ describe Planting do Planting.interesting.should_not include @planting1 end - it 'only gives you as many as you ask for' do - # plantings have members created implicitly for them - # each member is different, hence these are all interesting - @planting1 = FactoryGirl.create(:planting, :created_at => 5.days.ago) - @planting2 = FactoryGirl.create(:planting, :created_at => 4.days.ago) - @planting3 = FactoryGirl.create(:planting, :created_at => 3.days.ago) - @planting4 = FactoryGirl.create(:planting, :created_at => 2.days.ago) - - # plantings need photos to be interesting - @photo = FactoryGirl.create(:photo) - [@planting1, @planting2, @planting3, @planting4].each do |p| - p.photos << @photo - p.save - end - - Planting.interesting(2).length.should == 2 - end - end end