mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 08:52:14 -04:00
Randomly display 8 crops on the garden page
This commit is contained in:
@@ -1,2 +1,7 @@
|
||||
module ApplicationHelper
|
||||
|
||||
def random_crop
|
||||
Crop.random
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -3,4 +3,9 @@ class Crop < ActiveRecord::Base
|
||||
friendly_id :system_name, use: :slugged
|
||||
attr_accessible :en_wikipedia_url, :system_name
|
||||
has_many :scientific_names
|
||||
|
||||
def Crop.random
|
||||
@crop = Crop.offset(rand(Crop.count)).first
|
||||
return @crop
|
||||
end
|
||||
end
|
||||
|
||||
@@ -14,12 +14,14 @@
|
||||
.span9
|
||||
|
||||
%h2 What's planted here?
|
||||
%div.alert
|
||||
%button.close{:type => 'button', 'data-dismiss' => 'alert'} ×
|
||||
Note: these are a random selection, and don't represent actual plantings
|
||||
|
||||
%ul.thumbnails
|
||||
- (1..8).each do
|
||||
%li.span2
|
||||
.thumbnail
|
||||
= image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded')
|
||||
Crop name
|
||||
= render :partial => "crops/thumbnail", :locals => { :crop => random_crop }
|
||||
|
||||
%h2 Updates
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require 'spec_helper'
|
||||
rGkequire 'spec_helper'
|
||||
|
||||
describe Crop do
|
||||
context 'all fields present' do
|
||||
@@ -27,4 +27,18 @@ describe Crop do
|
||||
expect { @crop.save }.to raise_error ActiveRecord::StatementInvalid
|
||||
end
|
||||
end
|
||||
|
||||
context 'random' do
|
||||
before(:each) do
|
||||
@crop = Crop.new
|
||||
@crop.system_name = "Tomato"
|
||||
@crop.en_wikipedia_url = "http://en.wikipedia.org/wiki/Tomato"
|
||||
@crop.save
|
||||
end
|
||||
|
||||
it 'should find a random crop' do
|
||||
@rand_crop = Crop.random
|
||||
@rand_crop.system_name.should == 'Tomato'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user