Merge branch 'finished' of github.com:Skud/growstuff into Skud-finished2

This commit is contained in:
Skud
2014-09-12 08:40:57 +10:00
5 changed files with 30 additions and 1 deletions

View File

@@ -56,6 +56,14 @@ class Planting < ActiveRecord::Base
:allow_nil => true,
:allow_blank => true
validate :finished_must_be_after_planted
# check that any finished_at date occurs after planted_at
def finished_must_be_after_planted
return unless planted_at and finished_at # only check if we have both
errors.add(:finished_at, "must be after the planting date") unless planted_at < finished_at
end
def planting_slug
"#{owner.login_name}-#{garden}-#{crop}".downcase.gsub(' ', '-')
end

View File

@@ -39,7 +39,8 @@
= f.label :active, 'Active? ', :class => 'control-label col-md-2'
.col-md-8
= f.check_box :active
You can mark a garden as inactive if you no longer use it.
You can mark a garden as inactive if you no longer use it. Note:
this will mark all plantings in the garden as "finished".
.form-group
.form-actions.col-md-offset-2.col-md-8

View File

@@ -33,6 +33,7 @@ FactoryGirl.define do
factory :finished_planting do
finished true
planted_at '2014-07-30'
finished_at '2014-08-30'
end
end

View File

@@ -42,6 +42,7 @@ feature "Planting a crop", :js => true do
fill_autocomplete "crop", :with => "m"
select_from_autocomplete "maize"
within "form#new_planting" do
fill_in "When?", :with => '2014-07-01'
check 'Mark as finished'
fill_in "Finished date", :with => '2014-08-30'
click_button "Save"

View File

@@ -229,6 +229,24 @@ describe Planting do
Planting.current.should_not include @f
end
context "finished date validation" do
it 'requires finished date after planting date' do
@f = FactoryGirl.build(:finished_planting, :planted_at =>
'2014-01-01', :finished_at => '2013-01-01')
@f.should_not be_valid
end
it 'allows just the planted date' do
@f = FactoryGirl.build(:planting, :planted_at => '2013-01-01', :finished_at => nil)
@f.should be_valid
end
it 'allows just the finished date' do
@f = FactoryGirl.build(:planting, :finished_at => '2013-01-01', :planted_at => nil)
@f.should be_valid
end
end
end
end