Showing plantings on crops page. Ugly for now, but works.

This commit is contained in:
Skud
2013-01-17 15:35:30 +11:00
parent c1c218a2f3
commit 1da6c83fa1
3 changed files with 18 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ class Crop < ActiveRecord::Base
friendly_id :system_name, use: :slugged
attr_accessible :en_wikipedia_url, :system_name
has_many :scientific_names
has_many :plantings
def Crop.random
@crop = Crop.offset(rand(Crop.count)).first

View File

@@ -11,10 +11,13 @@
=link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-large btn-primary'
%h2 Who's growing this?
- (1..5).each do
.well
%h4 Some person
%p These blocks would contain recent posts from members who are growing this crop.
- @crop.plantings.each do |p|
%p
= p.quantity ? p.quantity : nil
= link_to p.crop.system_name, p.crop
in
= link_to p.location, p.garden
= p.planted_at ? "planted at #{p.planted_at}" : nil
.span3
%h3 Scientific names:

View File

@@ -5,6 +5,12 @@ describe "crops/show" do
@crop = assign(:crop, FactoryGirl.create(:maize,
:scientific_names => [ FactoryGirl.create(:zea_mays) ]
))
@owner = FactoryGirl.create(:member)
@garden = FactoryGirl.create(:garden, :owner => @owner)
@planting = FactoryGirl.create(:planting,
:garden => @garden,
:crop => @crop
)
end
it "shows the wikipedia URL" do
@@ -28,6 +34,10 @@ describe "crops/show" do
assert_select("a[href=#{new_planting_path}?crop_id=#{@crop.id}]")
end
it "links to people who are growing this crop" do
rendered.should contain "member1"
end
context "logged out" do
it "doesn't show the edit links if logged out" do
render