From cab7348a3522ebce9cc295fc97050d697ec71540 Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 31 May 2013 23:13:47 +1000 Subject: [PATCH] show plantings on photo page --- app/models/planting.rb | 4 +++ app/views/photos/show.html.haml | 37 +++++++++++++++--------- spec/views/photos/show.html.haml_spec.rb | 21 ++++++++++++-- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/app/models/planting.rb b/app/models/planting.rb index d88668acb..1535c798b 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -46,4 +46,8 @@ class Planting < ActiveRecord::Base def planted_at_string=(str) self.planted_at = str == '' ? nil : Time.parse(str) end + + def to_s + self.crop_system_name + " in " + self.location + end end diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 6306f9994..cde879ecc 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -1,15 +1,26 @@ -= image_tag(@photo.fullsize_url, :alt => 'A plant', :class => 'img-rounded') +-content_for :title, @photo.title -%p - = link_to @photo.title, @photo.link_url - by - = succeed "." do - = link_to @photo.owner, @photo.owner - License: - - if @photo.license_url - = succeed "." do - = link_to @photo.license_name, @photo.license_url - - else - = succeed "." do - = @photo.license_name +.row + .span6 + %p + %strong Posted by: + = link_to @photo.owner, @photo.owner + %p + %strong License: + - if @photo.license_url + = link_to @photo.license_name, @photo.license_url + - else + = succeed "." do + = @photo.license_name + %p + = link_to "View on Flickr", @photo.link_url + + .span6 + - if @photo.plantings.count > 0 + %p This photo depicts: + %ul + - @photo.plantings.each do |p| + %li= link_to p, p + +%p= image_tag(@photo.fullsize_url, :alt => 'A plant', :class => 'img-rounded') diff --git a/spec/views/photos/show.html.haml_spec.rb b/spec/views/photos/show.html.haml_spec.rb index 5b8cebfbf..fa03e08d6 100644 --- a/spec/views/photos/show.html.haml_spec.rb +++ b/spec/views/photos/show.html.haml_spec.rb @@ -20,8 +20,8 @@ describe "photos/show" do :text => @photo.license_name end - it "shows the title as a link to the original image" do - assert_select "a", :href => @photo.link_url, :text => @photo.title + it "shows a link to the original image" do + assert_select "a", :href => @photo.link_url, :text => "View on Flickr" end end @@ -34,6 +34,21 @@ describe "photos/show" do it "contains the phrase 'All rights reserved'" do rendered.should contain "All rights reserved" end -end + end + + context "linked to a planting" do + before(:each) do + @photo = FactoryGirl.create(:photo) + @planting = FactoryGirl.create(:planting) + @planting.photos << @photo + @photo = assign(:photo, @photo) + render + end + + it "shows link to planting" do + assert_select "a[href=#{planting_path(@planting)}]" + end + + end end