From 43798231dd103a18863cb5c5aa4050244e4c7f37 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 4 Jun 2013 12:22:31 +1000 Subject: [PATCH 1/3] added crop photos and a new placeholder image --- app/assets/images/placeholder_150.png | Bin 0 -> 2501 bytes app/models/crop.rb | 5 ++ app/models/planting.rb | 4 ++ app/views/crops/_thumbnail.html.haml | 5 +- app/views/plantings/_thumbnail.html.haml | 59 ++++++++++++----------- app/views/plantings/show.html.haml | 35 ++++++++------ spec/models/crop_spec.rb | 10 ++++ spec/models/planting_spec.rb | 9 +++- spec/views/crops/index.html.haml_spec.rb | 15 ++++-- spec/views/crops/show.html.haml_spec.rb | 8 +++ 10 files changed, 98 insertions(+), 52 deletions(-) create mode 100644 app/assets/images/placeholder_150.png diff --git a/app/assets/images/placeholder_150.png b/app/assets/images/placeholder_150.png new file mode 100644 index 0000000000000000000000000000000000000000..c3d7f500c7aae1afefe290f43da7ba47b8dc802e GIT binary patch literal 2501 zcmcImc{J4T8voiFq?BwSOCpI%7|N2eHyVt}7W31fEMqXkU@X5dA|wevgi@lLXzYxL zXh>!>$uh%F)=3ymV{Bu&qx;vr=l*%`dC&7cpZ7WM@|@?K&+~p#9H7?wMCC*Q0N7`1 zV*%s&oLv*%!<&uyLMC~R4-K=v1XPk0=6H)eHzC#*z|QV?^0q9C7ZC}zaYX~b-b1^_ z2joAN-A+1mDs zgY%vJGQ7K#Z7nWdji4=#(w!bL_(-g(>PDhgnUG4kaC`}$;6)LFile+l$%kWLTV21v zz<{$abVJV1S(Y^v&MEa1pZk9IUQPGEo}#1myWd zK)K$?*y7%qF-A;c)e@W8VG8+yBMTi6A(U=NCwEBT)kGl{UMahv>z$Ba}*j(9KPFCQRiIuRNhw{Oxm!z?#h@HW*0{o;<039Wi$RFVKiiC@`N zJ=35lCUwhbd}7h0?cEe7czU{cZXrP6om|!%4YVPSBl$I5=KVHEhRGHq;rE zPdRcxf-3eLELQf??OGgunZqQm zCq)-cC{K>T-*O6qTRyqleU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1sGpWDW0C3*Zn}6IdfvNp7E5 zg|hSD)MV;&2?7T*j4Ne2aCdGuB@F2Wnw$=Bfew=Fk+bZ1LHdTml(x zWbVWr7H=zkmO1cTPXQ{wW4e0KeC6U}MbMGAuf1Q#O7aRyW)rCqcTDVCIgz6N%c|rMnON5_3_&B^+`w<8qq6r zq!6q%`+aG&&ApB4>OJ07{%=a){~`(gQ-G|8Z;4Ns5$^?*XSDGI6<})#wWz%GNBlnl Dbc?e@ literal 0 HcmV?d00001 diff --git a/app/models/crop.rb b/app/models/crop.rb index 105afe0b5..acb04d6d5 100644 --- a/app/models/crop.rb +++ b/app/models/crop.rb @@ -5,6 +5,7 @@ class Crop < ActiveRecord::Base has_many :scientific_names has_many :plantings + has_many :photos, :through => :plantings belongs_to :parent, :class_name => 'Crop' has_many :varieties, :class_name => 'Crop', :foreign_key => 'parent_id' @@ -38,4 +39,8 @@ class Crop < ActiveRecord::Base return plantings.count end + def default_photo + return photos.first + end + end diff --git a/app/models/planting.rb b/app/models/planting.rb index 1535c798b..7b68a272b 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -50,4 +50,8 @@ class Planting < ActiveRecord::Base def to_s self.crop_system_name + " in " + self.location end + + def default_photo + return photos.first + end end diff --git a/app/views/crops/_thumbnail.html.haml b/app/views/crops/_thumbnail.html.haml index 5e4c6cb63..1337b8f0d 100644 --- a/app/views/crops/_thumbnail.html.haml +++ b/app/views/crops/_thumbnail.html.haml @@ -1,6 +1,6 @@ .thumbnail(style='height: 220px') - if crop - = link_to image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded'), crop + = link_to image_tag((crop.default_photo ? crop.default_photo.thumbnail_url : 'placeholder_150.png'), :alt => crop.system_name, :class => 'img-rounded'), crop %p = link_to crop.system_name, crop - if crop.scientific_names.count > 0 @@ -12,6 +12,3 @@ %small Planted = pluralize(crop.plantings_count, "time") - - else - = image_tag('http://placehold.it/150x150', :alt => '', :class => 'img-rounded') - Sample crop diff --git a/app/views/plantings/_thumbnail.html.haml b/app/views/plantings/_thumbnail.html.haml index 2e6147f02..362cd03a5 100644 --- a/app/views/plantings/_thumbnail.html.haml +++ b/app/views/plantings/_thumbnail.html.haml @@ -1,32 +1,37 @@ .well - %h4 - - if defined?(title) && title == 'owner' - = link_to planting.owner, planting.owner - - else - = link_to planting.crop.system_name, planting + .row-fluid + .span3 + = link_to image_tag((planting.default_photo ? planting.default_photo.thumbnail_url : 'placeholder_150.png'), :alt => '', :class => 'img-rounded'), planting + + .span9 + %h4 + - if defined?(title) && title == 'owner' + = link_to planting.owner, planting.owner + - else + = link_to planting.crop.system_name, planting - %p - Planted - - if planting.planted_at - = planting.planted_at - in - = link_to planting.location, planting.garden + %p + Planted + - if planting.planted_at + = planting.planted_at + in + = link_to planting.location, planting.garden - %p - - if planting.quantity - Quantity: - = planting.quantity - - else -   + %p + - if planting.quantity + Quantity: + = planting.quantity + - else +   - - if planting.description && ! defined?(hide_description) - %div - :markdown - #{ planting.description } + - if planting.description && ! defined?(hide_description) + %div + :markdown + #{ planting.description } - - if can? :edit, planting or can? :destroy, planting - %p - - if can? :edit, planting - =link_to 'Edit', edit_planting_path(planting), :class => 'btn btn-mini' - - if can? :destroy, planting - =link_to 'Delete', planting, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini' + - if can? :edit, planting or can? :destroy, planting + %p + - if can? :edit, planting + =link_to 'Edit', edit_planting_path(planting), :class => 'btn btn-mini' + - if can? :destroy, planting + =link_to 'Delete', planting, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini' diff --git a/app/views/plantings/show.html.haml b/app/views/plantings/show.html.haml index 137ffaaa4..9d33ecf17 100644 --- a/app/views/plantings/show.html.haml +++ b/app/views/plantings/show.html.haml @@ -30,24 +30,27 @@ .span6 .well - %h3 - = link_to @planting.crop, @planting.crop - - if can? :edit, @planting - = link_to 'Plant another', new_planting_path, :class => 'btn btn-primary' - - elsif can? :create, Planting - = link_to 'Plant this', new_planting_path, :class => 'btn btn-primary' + .row-fluid + .span4 + = link_to image_tag((@planting.crop.default_photo ? @planting.crop.default_photo.thumbnail_url : 'placeholder_150.png'), :alt => '', :class => 'img-rounded'), @planting.crop + .span8 + %h3 + = link_to @planting.crop, @planting.crop + - if can? :edit, @planting + = link_to 'Plant another', new_planting_path, :class => 'btn btn-primary' + - elsif can? :create, Planting + = link_to 'Plant this', new_planting_path, :class => 'btn btn-primary' - %p - %b Scientific name: - = @planting.crop_default_scientific_name - %p - %b - Planted - = pluralize(@planting.crop_plantings_count, "time") - by #{Growstuff::Application.config.site_name} members + %p + %b Scientific name: + = @planting.crop_default_scientific_name + %p + %b + Planted + = pluralize(@planting.crop_plantings_count, "time") + by #{Growstuff::Application.config.site_name} members -%h2 - Notes +%h2 Notes :markdown #{ @planting.description != "" ? @planting.description : "No description given." } diff --git a/spec/models/crop_spec.rb b/spec/models/crop_spec.rb index bea69ed01..3184d236e 100644 --- a/spec/models/crop_spec.rb +++ b/spec/models/crop_spec.rb @@ -69,4 +69,14 @@ describe Crop do @tomato.varieties.should eq [@roma] end end + + context 'photos' do + it 'has a default photo' do + @crop = FactoryGirl.create(:tomato) + @planting = FactoryGirl.create(:planting, :crop => @crop) + @photo = FactoryGirl.create(:photo) + @planting.photos << @photo + @crop.default_photo.should be_an_instance_of Photo + end + end end diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 8a9a75e93..538d70fcd 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -87,12 +87,19 @@ describe Planting do end context 'photos' do - it 'has a photo' do + before(:each) do @planting = FactoryGirl.create(:planting) @photo = FactoryGirl.create(:photo) @planting.photos << @photo + end + + it 'has a photo' do @planting.photos.first.should eq @photo end + + it 'has a default photo' do + @planting.default_photo.should eq @photo + end end end diff --git a/spec/views/crops/index.html.haml_spec.rb b/spec/views/crops/index.html.haml_spec.rb index 8f926129a..d61d108be 100644 --- a/spec/views/crops/index.html.haml_spec.rb +++ b/spec/views/crops/index.html.haml_spec.rb @@ -6,11 +6,10 @@ describe "crops/index" do page = 1 per_page = 2 total_entries = 2 + @tomato = FactoryGirl.create(:tomato) + @maize = FactoryGirl.create(:maize) crops = WillPaginate::Collection.create(page, per_page, total_entries) do |pager| - pager.replace([ - FactoryGirl.create(:tomato), - FactoryGirl.create(:maize) - ]) + pager.replace([ @tomato, @maize ]) end assign(:crops, crops) end @@ -21,6 +20,14 @@ describe "crops/index" do assert_select "a", :text => "Tomato" end + it "shows photos where available" do + @planting = FactoryGirl.create(:planting, :crop => @tomato) + @photo = FactoryGirl.create(:photo) + @planting.photos << @photo + render + assert_select "img", :src => @photo.thumbnail_url + end + it "linkifies crop images" do render assert_select "img", :src => :tomato diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 0b34be50e..b1bfe26da 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -44,6 +44,14 @@ describe "crops/show" do rendered.should contain "Springfield Community Garden" end + it "shows photos where available" do + @planting = FactoryGirl.create(:planting, :crop => @crop) + @photo = FactoryGirl.create(:photo) + @planting.photos << @photo + render + assert_select "img", :src => @photo.thumbnail_url + end + context 'varieties' do before(:each) do @popcorn = FactoryGirl.create(:popcorn, :parent_id => @crop.id) From 2839d6bf665eee2e519243d94286a8c92067a3d3 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 4 Jun 2013 12:24:53 +1000 Subject: [PATCH 2/3] Fixed RSS bug where comments were showing up as "edited" Tried many ways to test this (assert_select, response.has_tag, etc), but couldn't get it to work. Have tested manually and it looks good. --- app/views/comments/index.rss.haml | 2 +- app/views/posts/show.rss.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/comments/index.rss.haml b/app/views/comments/index.rss.haml index 5e4b227c5..db2f7a54f 100644 --- a/app/views/comments/index.rss.haml +++ b/app/views/comments/index.rss.haml @@ -20,4 +20,4 @@ %pubDate= comment.created_at.to_s(:rfc822) %link= post_url(comment.post) - %guid= post_url(comment.post) + %guid= comment_url(comment) diff --git a/app/views/posts/show.rss.haml b/app/views/posts/show.rss.haml index 4f260a038..d5867dfb4 100644 --- a/app/views/posts/show.rss.haml +++ b/app/views/posts/show.rss.haml @@ -20,4 +20,4 @@ %pubDate= comment.created_at.to_s(:rfc822) %link= post_url(@post) - %guid= post_url(@post) + %guid= comment_url(comment) From a3d0f15fd5ae21fb2bec38056beb44089fd3d85d Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 4 Jun 2013 13:02:29 +1000 Subject: [PATCH 3/3] Delete photo from photos/show page --- app/models/photo.rb | 2 ++ app/models/planting.rb | 2 ++ app/views/photos/index.html.haml | 4 +++- app/views/photos/show.html.haml | 3 +++ spec/models/planting_spec.rb | 13 ++++++++++++- spec/views/photos/show.html.haml_spec.rb | 12 +++++++++++- 6 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index ac67273ab..e65617c87 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -2,7 +2,9 @@ class Photo < ActiveRecord::Base attr_accessible :flickr_photo_id, :owner_id, :title, :license_name, :license_url, :thumbnail_url, :fullsize_url, :link_url belongs_to :owner, :class_name => 'Member' + has_and_belongs_to_many :plantings + before_destroy {|photo| photo.plantings.clear} default_scope order("created_at desc") diff --git a/app/models/planting.rb b/app/models/planting.rb index 1535c798b..0bf5f6eb6 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -7,7 +7,9 @@ class Planting < ActiveRecord::Base belongs_to :garden belongs_to :crop + has_and_belongs_to_many :photos + before_destroy {|planting| planting.photos.clear} default_scope order("created_at desc") diff --git a/app/views/photos/index.html.haml b/app/views/photos/index.html.haml index 09a8e1bd7..94ff1539d 100644 --- a/app/views/photos/index.html.haml +++ b/app/views/photos/index.html.haml @@ -1,4 +1,6 @@ -- content_for :title, "Photos" +- content_for :title, "Photo Gallery" + +%p This page shows all your photos. %div.pagination = page_entries_info @photos, :model => "photos" diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 47a2b7ecc..d9166cfa1 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -15,6 +15,9 @@ %p = link_to "View on Flickr", @photo.link_url + - if can? :destroy, @photo + %p= link_to 'Delete Photo', @photo, method: :delete, data: { confirm: 'Are you sure?' }, :class => 'btn btn-mini' + .span6 - if @photo.plantings.count > 0 %p This photo depicts: diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 8a9a75e93..e0d04d569 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -86,13 +86,24 @@ describe Planting do @planting.errors[:sunniness].should include("not valid is not a valid sunniness value") end + # we decided that all the tests for the planting/photo association would + # be done on this side, not on the photos side context 'photos' do - it 'has a photo' do + before(:each) do @planting = FactoryGirl.create(:planting) @photo = FactoryGirl.create(:photo) @planting.photos << @photo + end + + it 'has a photo' do @planting.photos.first.should eq @photo end + + it 'deletes association with photos when photo is deleted' do + @photo.destroy + @planting.reload + @planting.photos.should be_empty + end end end diff --git a/spec/views/photos/show.html.haml_spec.rb b/spec/views/photos/show.html.haml_spec.rb index fa03e08d6..18a201590 100644 --- a/spec/views/photos/show.html.haml_spec.rb +++ b/spec/views/photos/show.html.haml_spec.rb @@ -1,9 +1,14 @@ require 'spec_helper' describe "photos/show" do + before(:each) do + @member = FactoryGirl.create(:member) + controller.stub(:current_user) { @member } + end + context "CC-licensed photo" do before(:each) do - @photo = assign(:photo, FactoryGirl.create(:photo)) + @photo = assign(:photo, FactoryGirl.create(:photo, :owner => @member)) render end @@ -23,6 +28,10 @@ describe "photos/show" do it "shows a link to the original image" do assert_select "a", :href => @photo.link_url, :text => "View on Flickr" end + + it "has a delete button" do + assert_select "a[href=#{photo_path(@photo)}]", 'Delete Photo' + end end context "unlicensed photo" do @@ -34,6 +43,7 @@ describe "photos/show" do it "contains the phrase 'All rights reserved'" do rendered.should contain "All rights reserved" end + end context "linked to a planting" do