Merge pull request #335 from Skud/crop-harvests

Show harvests on crop page
This commit is contained in:
pozorvlak
2013-10-29 04:31:27 -07:00
7 changed files with 105 additions and 25 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -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" }

View File

@@ -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 }

View File

@@ -0,0 +1,5 @@
.member-location
- if member.location.blank?
unknown location
- else
= link_to member.location, place_path(:place => member.location)

View File

@@ -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

View File

@@ -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