From 8dcd3932fa0aec5fd017b1e197937e464232b3ac Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 29 Oct 2013 16:22:48 +1100 Subject: [PATCH 1/2] Added a partial to display a member's location. --- .../bootstrap_and_overrides.css.less | 9 +++++ app/views/members/_location.html.haml | 5 +++ .../views/members/_location.html.haml_spec.rb | 35 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 app/views/members/_location.html.haml create mode 100644 spec/views/members/_location.html.haml_spec.rb diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less index b64bca8d9..a0970bd89 100644 --- a/app/assets/stylesheets/bootstrap_and_overrides.css.less +++ b/app/assets/stylesheets/bootstrap_and_overrides.css.less @@ -155,6 +155,15 @@ p.stats { height: 500px; } +.member-location { + font-size: small; + font-style: italic; +} + +.member-location a { + color: @brown; +} + // Overrides applying only to mobile view @media only screen and (max-width: 767px) { diff --git a/app/views/members/_location.html.haml b/app/views/members/_location.html.haml new file mode 100644 index 000000000..195897d71 --- /dev/null +++ b/app/views/members/_location.html.haml @@ -0,0 +1,5 @@ +.member-location + - if member.location.blank? + unknown location + - else + = link_to member.location, place_path(:place => member.location) diff --git a/spec/views/members/_location.html.haml_spec.rb b/spec/views/members/_location.html.haml_spec.rb new file mode 100644 index 000000000..96c1e3b8d --- /dev/null +++ b/spec/views/members/_location.html.haml_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' + +describe "members/_location" do + context "member with location" do + before(:each) do + @member = FactoryGirl.create(:london_member) + render :partial => 'members/location', :locals => { :member => @member } + end + + it 'shows location if available' do + rendered.should contain @member.location + end + + it "links to the places page" do + assert_select "a", :href => place_path(@member.location) + end + end + + context "member with no location" do + before(:each) do + @member = FactoryGirl.create(:member) + render :partial => 'members/location', :locals => { :member => @member } + end + + it 'shows unknown location' do + rendered.should contain "unknown location" + end + + it "doesn't link anywhere" do + assert_select "a", false + end + + end + +end From 9917b3a4890332e6b4cdc117644fe8c9fd789f14 Mon Sep 17 00:00:00 2001 From: Skud Date: Tue, 29 Oct 2013 16:23:17 +1100 Subject: [PATCH 2/2] Show harvests in crop page sidebar Also tweaked seed display to make them more consistent. --- app/views/crops/_find_seeds.html.haml | 9 ++----- app/views/crops/_harvests.html.haml | 19 ++++++++++++++ app/views/crops/show.html.haml | 34 +++++++++++++++---------- spec/views/crops/show.html.haml_spec.rb | 19 +++++++++++--- 4 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 app/views/crops/_harvests.html.haml diff --git a/app/views/crops/_find_seeds.html.haml b/app/views/crops/_find_seeds.html.haml index 02d56b856..db7c5b4b7 100644 --- a/app/views/crops/_find_seeds.html.haml +++ b/app/views/crops/_find_seeds.html.haml @@ -6,13 +6,8 @@ %ul - crop.seeds.tradable.each do |seed| %li - = link_to seed.owner, seed.owner - - if seed.owner.location - in #{seed.owner.location} - - else - (location unknown) - will trade #{seed.tradable_to}. - = link_to "View details.", seed_path(seed) + = link_to "#{seed.owner} will trade #{seed.tradable_to}.", seed_path(seed) + = render :partial => 'members/location', :locals => { :member => seed.owner } - if current_member = link_to "List your seeds to trade.", new_seed_path() - else diff --git a/app/views/crops/_harvests.html.haml b/app/views/crops/_harvests.html.haml new file mode 100644 index 000000000..b8cb25447 --- /dev/null +++ b/app/views/crops/_harvests.html.haml @@ -0,0 +1,19 @@ +%h4 Harvests +- if crop.harvests.empty? + %p + Nobody has harvested this crop yet. +- else + %ul + - crop.harvests.each do |harvest| + %li + = link_to "#{harvest.owner} harvested #{display_quantity(harvest)}.", harvest_path(harvest) + = render :partial => 'members/location', :locals => { :member => harvest.owner } + %small + = distance_of_time_in_words(harvest.created_at, Time.zone.now) + ago. + +- if current_member + = link_to "Track your #{crop.name} harvests.", new_harvest_path() +- else + = render :partial => 'shared/signin_signup', :locals => { :to => "track your #{crop.name} harvests" } + diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index 9789eaefc..60e3e2e4e 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -2,20 +2,6 @@ .row-fluid .span9 - = render :partial => 'photos', :locals => { :crop => @crop } - - = render :partial => 'varieties', :locals => { :crop => @crop } - - = render :partial => 'planting_advice', :locals => { :crop => @crop } - - %p - - if @crop.plantings.size > 0 - Planted - = pluralize(@crop.plantings.size, "time") - by #{Growstuff::Application.config.site_name} members - - else - Nobody is growing this yet. You could be the first! - %p - if can? :create, Planting = link_to "Plant this", new_planting_path(:crop_id => @crop.id), :class => 'btn btn-primary' @@ -28,6 +14,25 @@ - if can? :create, Seed = link_to 'Add seeds to stash', new_seed_path(:params => { :crop_id => @crop.id }), :class => 'btn btn-primary' + = render :partial => 'photos', :locals => { :crop => @crop } + + = render :partial => 'varieties', :locals => { :crop => @crop } + + = render :partial => 'planting_advice', :locals => { :crop => @crop } + + + %h2 Who's planted this crop? + + %p + - if @crop.plantings.size > 0 + = @crop.name.titleize + has been planted + = pluralize(@crop.plantings.size, "time") + by #{Growstuff::Application.config.site_name} members. + - else + Nobody is growing this yet. You could be the first! + + - if @crop.plantings.size > 0 - @crop.plantings.each do |p| = render :partial => "plantings/thumbnail", :locals => { :planting => p, :title => 'owner' } @@ -62,4 +67,5 @@ %ul %li= link_to 'Wikipedia (English)', @crop.en_wikipedia_url + = render :partial => 'harvests', :locals => { :crop => @crop } = render :partial => 'find_seeds', :locals => { :crop => @crop } diff --git a/spec/views/crops/show.html.haml_spec.rb b/spec/views/crops/show.html.haml_spec.rb index 34462bbda..3b3341a03 100644 --- a/spec/views/crops/show.html.haml_spec.rb +++ b/spec/views/crops/show.html.haml_spec.rb @@ -62,13 +62,24 @@ describe "crops/show" do assert_select "a[href=#{seed_path(seed)}]" end end + end - it "shows location if available" do - rendered.should contain "#{@owner1} in #{@owner1.location} will trade #{@seed1.tradable_to}" + context "harvests" do + before(:each) do + @owner1 = FactoryGirl.create(:london_member) + @h1 = FactoryGirl.create(:harvest, :owner => @owner1, :crop => @crop) + @h2 = FactoryGirl.create(:harvest, :owner => @owner1, :crop => @crop) + render end - it "shows grammatical text if seed trader has no location" do - rendered.should contain "#{@owner2} (location unknown) will trade #{@seed2.tradable_to}" + it "shows a heading" do + rendered.should contain "Harvests" + end + + it "shows a list of people who have harvested this crop" do + @crop.harvests.each do |harvest| + assert_select "a[href=#{harvest_path(harvest)}]" + end end end