diff --git a/app/models/crop.rb b/app/models/crop.rb index 158cad97a..75b2a1ffb 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -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 diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index a1dbcb236..02ab2079e 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -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: diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 9e609a177..aad4f3b95 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -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