mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-26 18:56:06 -04:00
generalised sunniness into a variable for later reuse
This commit is contained in:
@@ -2,8 +2,8 @@ class Planting < ActiveRecord::Base
|
||||
extend FriendlyId
|
||||
friendly_id :planting_slug, use: :slugged
|
||||
|
||||
attr_accessible :crop_id, :description, :garden_id, :planted_at, :quantity,
|
||||
:planted_at_string
|
||||
attr_accessible :crop_id, :description, :garden_id, :planted_at,
|
||||
:quantity, :sunniness, :planted_at_string
|
||||
|
||||
belongs_to :garden
|
||||
belongs_to :crop
|
||||
@@ -13,8 +13,10 @@ class Planting < ActiveRecord::Base
|
||||
:to => :crop,
|
||||
:prefix => true
|
||||
|
||||
validates :sunniness, :inclusion => { :in => %w(sun semi-shade shade),
|
||||
:message => "%{value} is not a valid sunniness value" }
|
||||
SUNNINESS_VALUES = %w(sun semi-shade shade)
|
||||
validates :sunniness, :inclusion => { :in => SUNNINESS_VALUES,
|
||||
:message => "%{value} is not a valid sunniness value" },
|
||||
:allow_nil => true
|
||||
|
||||
def planting_slug
|
||||
"#{owner.login_name}-#{garden}-#{crop}".downcase.gsub(' ', '-')
|
||||
|
||||
@@ -43,7 +43,7 @@ describe Planting do
|
||||
end
|
||||
|
||||
it 'all three valid sunniness values should work' do
|
||||
['sun', 'shade', 'semi-shade'].each do |s|
|
||||
['sun', 'shade', 'semi-shade', nil].each do |s|
|
||||
@planting = FactoryGirl.build(:planting, :sunniness => s)
|
||||
@planting.should be_valid
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user