mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 08:52:14 -04:00
added sunniness field to plantings
This commit is contained in:
@@ -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
|
||||
|
||||
5
db/migrate/20130329045744_add_sunniness_to_planting.rb
Normal file
5
db/migrate/20130329045744_add_sunniness_to_planting.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
class AddSunninessToPlanting < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :plantings, :sunniness, :string
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
|
||||
@@ -5,5 +5,6 @@ FactoryGirl.define do
|
||||
planted_at Time.now
|
||||
quantity 33
|
||||
description "This is a *really* good plant."
|
||||
sunniness 'sun'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user