allow nil/blank qtys for plantings/seeds

This commit is contained in:
Skud
2013-07-23 21:19:21 +10:00
parent bdc267b044
commit 470f8f2f22
4 changed files with 10 additions and 6 deletions

View File

@@ -23,7 +23,9 @@ class Planting < ActiveRecord::Base
default_scope order("created_at desc")
validates :quantity, :numericality => { :only_integer => true }
validates :quantity,
:numericality => { :only_integer => true },
:allow_nil => true
SUNNINESS_VALUES = %w(sun semi-shade shade)
validates :sunniness, :inclusion => { :in => SUNNINESS_VALUES,

View File

@@ -8,7 +8,9 @@ class Seed < ActiveRecord::Base
belongs_to :crop
belongs_to :owner, :class_name => 'Member', :foreign_key => 'owner_id'
validates :quantity, :numericality => { :only_integer => true }
validates :quantity,
:numericality => { :only_integer => true },
:allow_nil => true
TRADABLE_TO_VALUES = %w(nowhere locally nationally internationally)
validates :tradable_to, :inclusion => { :in => TRADABLE_TO_VALUES,

View File

@@ -67,9 +67,9 @@ describe Planting do
it "allows blank quantities" do
@planting = FactoryGirl.build(:planting, :quantity => nil)
@planting.should_not be_valid
@planting.should be_valid
@planting = FactoryGirl.build(:planting, :quantity => '')
@planting.should_not be_valid
@planting.should be_valid
end
end

View File

@@ -33,9 +33,9 @@ describe Seed do
it "allows blank quantities" do
@seed = FactoryGirl.build(:seed, :quantity => nil)
@seed.should_not be_valid
@seed.should be_valid
@seed = FactoryGirl.build(:seed, :quantity => '')
@seed.should_not be_valid
@seed.should be_valid
end
end