added sunniness field to plantings

This commit is contained in:
Skud
2013-03-29 16:33:37 +11:00
parent b5fee57606
commit 0e9b4caf58
5 changed files with 28 additions and 1 deletions

View File

@@ -13,6 +13,9 @@ 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" }
def planting_slug
"#{owner.login_name}-#{garden}-#{crop}".downcase.gsub(' ', '-')
end

View File

@@ -0,0 +1,5 @@
class AddSunninessToPlanting < ActiveRecord::Migration
def change
add_column :plantings, :sunniness, :string
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130327120024) do
ActiveRecord::Schema.define(:version => 20130329045744) do
create_table "comments", :force => true do |t|
t.integer "post_id", :null => false
@@ -130,6 +130,7 @@ ActiveRecord::Schema.define(:version => 20130327120024) do
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "slug"
t.string "sunniness"
end
add_index "plantings", ["slug"], :name => "index_plantings_on_slug", :unique => true

View File

@@ -5,5 +5,6 @@ FactoryGirl.define do
planted_at Time.now
quantity 33
description "This is a *really* good plant."
sunniness 'sun'
end
end

View File

@@ -38,4 +38,21 @@ describe Planting do
@planting.planted_at_string.should == "2013-03-01"
end
it 'should have a sunniness value' do
@planting.sunniness.should eq 'sun'
end
it 'all three valid sunniness values should work' do
['sun', 'shade', 'semi-shade'].each do |s|
@planting = FactoryGirl.build(:planting, :sunniness => s)
@planting.should be_valid
end
end
it 'should refuse invalid sunniness values' do
@planting = FactoryGirl.build(:planting, :sunniness => 'not valid')
@planting.should_not be_valid
@planting.errors[:sunniness].should include("not valid is not a valid sunniness value")
end
end