Merge branch 'dev' into seed_trade

This commit is contained in:
Skud
2013-07-23 20:21:58 +10:00
8 changed files with 206 additions and 25 deletions

View File

@@ -2,7 +2,7 @@ Thanks for contributing to Growstuff! We have different contribution
guidelines depending on whether your change is a small one (a one-line
bugfix or similar) or a larger one.
## Small changes (no more than a couple of lines)
## Small changes
Send us a pull request! We will get one of our pairs of coders to
review it.
@@ -14,8 +14,9 @@ wiki](http://wiki.growstuff.org/) for more information.
## Larger changes
Growstuff does pair programming (two coders working together) for all
significant changes. This means that if you submit a pull request and
weren't working in a pair, we can't merge it into the project as-is.
new features and other significant changes. This means that if you
submit a pull request and weren't working in a pair, we're unlikely to
merge it into the project as-is.
If you would like to work on any larger change, we would appreciate it
if you would get in touch with us, preferably via our [mailing
@@ -26,9 +27,9 @@ The [Growstuff wiki](http://wiki.growstuff.org/) has lots more
information on our dev process, to get you started if you would like to
join us.
If you submit a significant change without working in a pair, we will
treat your work as an experimental "spike" and get one of our pairs of
If you submit a larger change without working in a pair, we will treat
your work as an experimental "spike" and get one of our pairs of
programmers to look over it and maybe use what you've done as the basis
for re-implementing it using our processes. **We'd much rather work with
you, so please talk to us first!**
for re-implementing it using our processes. **We'd much rather work
with you, so please talk to us first!**

View File

@@ -43,4 +43,24 @@ class Crop < ActiveRecord::Base
return photos.first
end
def sunniness
sunniness = Hash.new(0)
plantings.each do |p|
if !p.sunniness.blank?
sunniness[p.sunniness] += 1
end
end
return sunniness
end
def planted_from
planted_from = Hash.new(0)
plantings.each do |p|
if !p.planted_from.blank?
planted_from[p.planted_from] += 1
end
end
return planted_from
end
end

View File

@@ -14,6 +14,16 @@
= succeed ":" do
= @crop.system_name
!= @crop.varieties.map{ |c| link_to c, c }.join(", ")
- if @crop.planted_from.length > 0
%p
Plant from:
- planted_from = @crop.planted_from.sort_by {|s, freq| freq }.reverse
= planted_from.map {|s, freq| "#{s} (#{freq})" }.join(", ")
- if @crop.sunniness.length > 0
%p
Plant in:
- sunniness = @crop.sunniness.sort_by {|s, freq| freq }.reverse
= sunniness.map {|s, freq| "#{s} (#{freq})" }.join(", ")
%p
- if @crop.plantings_count > 0

View File

@@ -5,7 +5,29 @@ FactoryGirl.define do
planted_at Date.today
quantity 33
description "This is a *really* good plant."
sunniness 'sun'
planted_from 'seed'
factory :seed_planting do
planted_from 'seed'
end
factory :seedling_planting do
planted_from 'seedling'
end
factory :cutting_planting do
planted_from 'cutting'
end
factory :sunny_planting do
sunniness 'sun'
end
factory :semi_shady_planting do
sunniness 'semi-shade'
end
factory :shady_planting do
sunniness 'shade'
end
end
end

View File

@@ -79,4 +79,64 @@ describe Crop do
@crop.default_photo.should be_an_instance_of Photo
end
end
context 'sunniness' do
before(:each) do
@crop = FactoryGirl.create(:tomato)
end
it 'returns a hash of sunniness values' do
planting1 = FactoryGirl.create(:sunny_planting, :crop => @crop)
planting2 = FactoryGirl.create(:sunny_planting, :crop => @crop)
planting3 = FactoryGirl.create(:semi_shady_planting, :crop => @crop)
planting4 = FactoryGirl.create(:shady_planting, :crop => @crop)
@crop.sunniness.should be_an_instance_of Hash
end
it 'counts each sunniness value' do
planting1 = FactoryGirl.create(:sunny_planting, :crop => @crop)
planting2 = FactoryGirl.create(:sunny_planting, :crop => @crop)
planting3 = FactoryGirl.create(:semi_shady_planting, :crop => @crop)
planting4 = FactoryGirl.create(:shady_planting, :crop => @crop)
@crop.sunniness.should == { 'sun' => 2, 'shade' => 1, 'semi-shade' => 1 }
end
it 'ignores unused sunniness values' do
planting1 = FactoryGirl.create(:sunny_planting, :crop => @crop)
planting2 = FactoryGirl.create(:sunny_planting, :crop => @crop)
planting3 = FactoryGirl.create(:semi_shady_planting, :crop => @crop)
@crop.sunniness.should == { 'sun' => 2, 'semi-shade' => 1 }
end
end
context 'planted_from' do
before(:each) do
@crop = FactoryGirl.create(:tomato)
end
it 'returns a hash of sunniness values' do
planting1 = FactoryGirl.create(:seed_planting, :crop => @crop)
planting2 = FactoryGirl.create(:seed_planting, :crop => @crop)
planting3 = FactoryGirl.create(:seedling_planting, :crop => @crop)
planting4 = FactoryGirl.create(:cutting_planting, :crop => @crop)
@crop.planted_from.should be_an_instance_of Hash
end
it 'counts each planted_from value' do
planting1 = FactoryGirl.create(:seed_planting, :crop => @crop)
planting2 = FactoryGirl.create(:seed_planting, :crop => @crop)
planting3 = FactoryGirl.create(:seedling_planting, :crop => @crop)
planting4 = FactoryGirl.create(:cutting_planting, :crop => @crop)
@crop.planted_from.should == { 'seed' => 2, 'seedling' => 1, 'cutting' => 1 }
end
it 'ignores unused planted_from values' do
planting1 = FactoryGirl.create(:seed_planting, :crop => @crop)
planting2 = FactoryGirl.create(:seed_planting, :crop => @crop)
planting3 = FactoryGirl.create(:seedling_planting, :crop => @crop)
@crop.planted_from.should == { 'seed' => 2, 'seedling' => 1 }
end
end
end

View File

@@ -74,6 +74,10 @@ describe Planting do
end
context 'sunniness' do
before(:each) do
@planting = FactoryGirl.create(:sunny_planting)
end
it 'should have a sunniness value' do
@planting.sunniness.should eq 'sun'
end
@@ -94,6 +98,7 @@ describe Planting do
context 'planted from' do
it 'should have a planted_from value' do
@planting = FactoryGirl.create(:seed_planting)
@planting.planted_from.should eq 'seed'
end

View File

@@ -6,15 +6,7 @@ describe "crops/show" do
@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
)
assign(:crop, @crop)
end
it "shows the wikipedia URL" do
@@ -28,18 +20,80 @@ describe "crops/show" do
rendered.should contain "Zea mays"
end
it "links to people who are growing this crop" do
it "shows a plant this button" do
render
rendered.should contain /member\d+/
rendered.should contain "Springfield Community Garden"
rendered.should contain "Plant this"
end
it "shows photos where available" do
@planting = FactoryGirl.create(:planting, :crop => @crop)
@photo = FactoryGirl.create(:photo)
@planting.photos << @photo
it "links to the right crop in the planting link" do
render
assert_select "img", :src => @photo.thumbnail_url
assert_select("a[href=#{new_planting_path}?crop_id=#{@crop.id}]")
context "has plantings" do
before(:each) do
@owner = FactoryGirl.create(:member)
@garden = FactoryGirl.create(:garden, :owner => @owner)
@planting = FactoryGirl.create(:planting,
:garden => @garden,
:crop => @crop
)
end
it "doesn't show sunniness if none are set" do
render
rendered.should_not contain "Plant in:"
end
it "shows sunniness frequencies" do
FactoryGirl.create(:sunny_planting, :crop => @crop)
render
rendered.should contain "Plant in:"
rendered.should contain "sun (1)"
end
it "shows multiple sunniness frequencies" do
FactoryGirl.create(:sunny_planting, :crop => @crop)
FactoryGirl.create(:sunny_planting, :crop => @crop)
FactoryGirl.create(:shady_planting, :crop => @crop)
render
rendered.should contain "Plant in:"
rendered.should contain "sun (2), shade (1)"
end
it "doesn't show planted_from if none are set" do
render
rendered.should_not contain "Plant from:"
end
it "shows planted_from frequencies" do
FactoryGirl.create(:seed_planting, :crop => @crop)
render
rendered.should contain "Plant from:"
rendered.should contain "seed (1)"
end
it "shows multiple planted_from frequencies" do
FactoryGirl.create(:seed_planting, :crop => @crop)
FactoryGirl.create(:seed_planting, :crop => @crop)
FactoryGirl.create(:cutting_planting, :crop => @crop)
render
rendered.should contain "Plant from:"
rendered.should contain "seed (2), cutting (1)"
end
it "links to people who are growing this crop" do
render
rendered.should contain /member\d+/
rendered.should contain "Springfield Community Garden"
end
it "shows photos where available" do
@photo = FactoryGirl.create(:photo)
@planting.photos << @photo
render
assert_select "img", :src => @photo.thumbnail_url
end
end
context 'varieties' do

View File

@@ -17,6 +17,11 @@ describe "plantings/show" do
end
context 'sunniness' do
before(:each) do
@p = assign(:planting,
FactoryGirl.create(:sunny_planting)
)
end
it "shows the sunniness" do
render
@@ -34,6 +39,10 @@ describe "plantings/show" do
end
context 'planted from' do
before(:each) do
@p = assign(:planting, FactoryGirl.create(:seed_planting))
end
it "shows planted_from" do
render
rendered.should contain 'Planted from:'