diff --git a/app/models/planting.rb b/app/models/planting.rb index 3f88a666c..05c2a7024 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -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, diff --git a/app/models/seed.rb b/app/models/seed.rb index bb39bf15b..1f6eef887 100644 --- a/app/models/seed.rb +++ b/app/models/seed.rb @@ -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, diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 607a2b920..bb5d87e0a 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -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 diff --git a/spec/models/seed_spec.rb b/spec/models/seed_spec.rb index ce3088aa2..896416441 100644 --- a/spec/models/seed_spec.rb +++ b/spec/models/seed_spec.rb @@ -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