mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 08:52:14 -04:00
Add new properties to seeds
Added days_until_maturity, gmo, organic and heirloom properties; added validation and tests for the last three.
This commit is contained in:
@@ -20,6 +20,32 @@ class Seed < ActiveRecord::Base
|
||||
:allow_nil => false,
|
||||
:allow_blank => false
|
||||
|
||||
ORGANIC_VALUES = [
|
||||
'certified organic',
|
||||
'non-certified organic',
|
||||
'conventional/non-organic',
|
||||
'unknown']
|
||||
validates :organic, :inclusion => { :in => ORGANIC_VALUES,
|
||||
:message => "You must say whether the seeds are organic or not, or that you don't know" },
|
||||
:allow_nil => false,
|
||||
:allow_blank => false
|
||||
|
||||
GMO_VALUES = [
|
||||
'certified GMO-free',
|
||||
'non-certified GMO-free',
|
||||
'GMO',
|
||||
'unknown']
|
||||
validates :gmo, :inclusion => { :in => GMO_VALUES,
|
||||
:message => "You must say whether the seeds are genetically modified or not, or that you don't know" },
|
||||
:allow_nil => false,
|
||||
:allow_blank => false
|
||||
|
||||
HEIRLOOM_VALUES = %w(heirloom hybrid unknown)
|
||||
validates :heirloom, :inclusion => { :in => HEIRLOOM_VALUES,
|
||||
:message => "You must say whether the seeds are heirloom, hybrid, or unknown" },
|
||||
:allow_nil => false,
|
||||
:allow_blank => false
|
||||
|
||||
def tradable?
|
||||
if self.tradable_to == 'nowhere'
|
||||
return false
|
||||
|
||||
8
db/migrate/20150124110540_add_properties_to_seeds.rb
Normal file
8
db/migrate/20150124110540_add_properties_to_seeds.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class AddPropertiesToSeeds < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :seeds, :days_until_maturity, :integer
|
||||
add_column :seeds, :organic, :text, :default => 'unknown'
|
||||
add_column :seeds, :gmo, :text, :default => 'unknown'
|
||||
add_column :seeds, :heirloom, :text, :default => 'unknown'
|
||||
end
|
||||
end
|
||||
117
db/schema.rb
117
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
ActiveRecord::Schema.define(version: 20150124110540) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
@@ -20,24 +20,24 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.string "name", null: false
|
||||
t.boolean "is_paid"
|
||||
t.boolean "is_permanent_paid"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "accounts", force: true do |t|
|
||||
t.integer "member_id", null: false
|
||||
t.integer "account_type_id"
|
||||
t.datetime "paid_until"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "alternate_names", force: true do |t|
|
||||
t.string "name", null: false
|
||||
t.integer "crop_id", null: false
|
||||
t.integer "creator_id", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "authentications", force: true do |t|
|
||||
@@ -46,8 +46,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.string "uid"
|
||||
t.string "token"
|
||||
t.string "secret"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "name"
|
||||
end
|
||||
|
||||
@@ -57,15 +57,15 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.integer "post_id", null: false
|
||||
t.integer "author_id", null: false
|
||||
t.text "body", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "crops", force: true do |t|
|
||||
t.string "name", null: false
|
||||
t.string "en_wikipedia_url"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
t.integer "parent_id"
|
||||
t.integer "plantings_count", default: 0
|
||||
@@ -86,16 +86,16 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
create_table "follows", force: true do |t|
|
||||
t.integer "follower_id"
|
||||
t.integer "followed_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "forums", force: true do |t|
|
||||
t.string "name", null: false
|
||||
t.text "description", null: false
|
||||
t.integer "owner_id", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
@@ -105,8 +105,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.string "name", null: false
|
||||
t.integer "owner_id"
|
||||
t.string "slug", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "description"
|
||||
t.boolean "active", default: true
|
||||
t.string "location"
|
||||
@@ -116,7 +116,7 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.string "area_unit"
|
||||
end
|
||||
|
||||
add_index "gardens", ["owner_id"], name: "index_gardens_on_owner_id", using: :btree
|
||||
add_index "gardens", ["owner_id"], name: "index_gardens_on_user_id", using: :btree
|
||||
add_index "gardens", ["slug"], name: "index_gardens_on_slug", unique: true, using: :btree
|
||||
|
||||
create_table "harvests", force: true do |t|
|
||||
@@ -126,8 +126,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.decimal "quantity"
|
||||
t.string "unit"
|
||||
t.text "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
t.decimal "weight_quantity"
|
||||
t.string "weight_unit"
|
||||
@@ -159,8 +159,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.integer "failed_attempts", default: 0
|
||||
t.string "unlock_token"
|
||||
t.datetime "locked_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "login_name"
|
||||
t.string "slug"
|
||||
t.boolean "tos_agreement"
|
||||
@@ -175,11 +175,11 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.boolean "send_planting_reminder", default: true
|
||||
end
|
||||
|
||||
add_index "members", ["confirmation_token"], name: "index_members_on_confirmation_token", unique: true, using: :btree
|
||||
add_index "members", ["email"], name: "index_members_on_email", unique: true, using: :btree
|
||||
add_index "members", ["reset_password_token"], name: "index_members_on_reset_password_token", unique: true, using: :btree
|
||||
add_index "members", ["slug"], name: "index_members_on_slug", unique: true, using: :btree
|
||||
add_index "members", ["unlock_token"], name: "index_members_on_unlock_token", unique: true, using: :btree
|
||||
add_index "members", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true, using: :btree
|
||||
add_index "members", ["email"], name: "index_users_on_email", unique: true, using: :btree
|
||||
add_index "members", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
|
||||
add_index "members", ["slug"], name: "index_users_on_slug", unique: true, using: :btree
|
||||
add_index "members", ["unlock_token"], name: "index_users_on_unlock_token", unique: true, using: :btree
|
||||
|
||||
create_table "members_roles", id: false, force: true do |t|
|
||||
t.integer "member_id"
|
||||
@@ -193,8 +193,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.text "body"
|
||||
t.boolean "read", default: false
|
||||
t.integer "post_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "order_items", force: true do |t|
|
||||
@@ -202,13 +202,13 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.integer "product_id"
|
||||
t.integer "price"
|
||||
t.integer "quantity"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "orders", force: true do |t|
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "completed_at"
|
||||
t.integer "member_id"
|
||||
t.string "paypal_express_token"
|
||||
@@ -225,8 +225,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.integer "owner_id", null: false
|
||||
t.string "thumbnail_url", null: false
|
||||
t.string "fullsize_url", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "title", null: false
|
||||
t.string "license_name", null: false
|
||||
t.string "license_url"
|
||||
@@ -241,8 +241,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
|
||||
create_table "plant_parts", force: true do |t|
|
||||
t.string "name"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
@@ -252,8 +252,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.date "planted_at"
|
||||
t.integer "quantity"
|
||||
t.text "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
t.string "sunniness"
|
||||
t.string "planted_from"
|
||||
@@ -268,21 +268,22 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
t.integer "author_id", null: false
|
||||
t.string "subject", null: false
|
||||
t.text "body", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
t.integer "forum_id"
|
||||
t.integer "parent_id"
|
||||
end
|
||||
|
||||
add_index "posts", ["created_at", "author_id"], name: "index_posts_on_created_at_and_author_id", using: :btree
|
||||
add_index "posts", ["slug"], name: "index_posts_on_slug", unique: true, using: :btree
|
||||
add_index "posts", ["created_at", "author_id"], name: "index_updates_on_created_at_and_user_id", using: :btree
|
||||
add_index "posts", ["slug"], name: "index_updates_on_slug", unique: true, using: :btree
|
||||
|
||||
create_table "products", force: true do |t|
|
||||
t.string "name", null: false
|
||||
t.text "description", null: false
|
||||
t.integer "min_price", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "account_type_id"
|
||||
t.integer "paid_months"
|
||||
t.integer "recommended_price"
|
||||
@@ -291,8 +292,8 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
create_table "roles", force: true do |t|
|
||||
t.string "name", null: false
|
||||
t.text "description"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "slug"
|
||||
end
|
||||
|
||||
@@ -301,21 +302,25 @@ ActiveRecord::Schema.define(version: 20141119130555) do
|
||||
create_table "scientific_names", force: true do |t|
|
||||
t.string "scientific_name", null: false
|
||||
t.integer "crop_id", null: false
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "creator_id"
|
||||
end
|
||||
|
||||
create_table "seeds", force: true do |t|
|
||||
t.integer "owner_id", null: false
|
||||
t.integer "crop_id", null: false
|
||||
t.integer "owner_id", null: false
|
||||
t.integer "crop_id", null: false
|
||||
t.text "description"
|
||||
t.integer "quantity"
|
||||
t.date "plant_before"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "tradable_to", default: "nowhere"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "tradable_to", default: "nowhere"
|
||||
t.string "slug"
|
||||
t.integer "days_until_maturity"
|
||||
t.text "organic", default: "unknown"
|
||||
t.text "gmo", default: "unknown"
|
||||
t.text "heirloom", default: "unknown"
|
||||
end
|
||||
|
||||
add_index "seeds", ["slug"], name: "index_seeds_on_slug", unique: true, using: :btree
|
||||
|
||||
@@ -8,6 +8,9 @@ FactoryGirl.define do
|
||||
quantity 1
|
||||
plant_before "2013-07-15"
|
||||
tradable_to 'nowhere'
|
||||
organic 'unknown'
|
||||
gmo 'unknown'
|
||||
heirloom 'unknown'
|
||||
|
||||
factory :tradable_seed do
|
||||
tradable_to "locally"
|
||||
|
||||
@@ -88,6 +88,49 @@ describe Seed do
|
||||
end
|
||||
end
|
||||
|
||||
context 'organic, gmo, heirloom' do
|
||||
it 'all valid organic values should work' do
|
||||
['certified organic', 'non-certified organic',
|
||||
'conventional/non-organic', 'unknown'].each do |t|
|
||||
@seed = FactoryGirl.build(:seed, :organic => t)
|
||||
@seed.should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it 'all valid GMO values should work' do
|
||||
['certified GMO-free', 'non-certified GMO-free',
|
||||
'GMO', 'unknown'].each do |t|
|
||||
@seed = FactoryGirl.build(:seed, :gmo => t)
|
||||
@seed.should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it 'all valid heirloom values should work' do
|
||||
%w(heirloom hybrid unknown).each do |t|
|
||||
@seed = FactoryGirl.build(:seed, :heirloom => t)
|
||||
@seed.should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it 'should refuse invalid organic/GMO/heirloom values' do
|
||||
[:organic, :gmo, :heirloom].each do |field|
|
||||
@seed = FactoryGirl.build(:seed, field => 'not valid')
|
||||
@seed.should_not be_valid
|
||||
@seed.errors[field].should_not be_empty
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not allow nil or blank values' do
|
||||
[:organic, :gmo, :heirloom].each do |field|
|
||||
@seed = FactoryGirl.build(:seed, field => nil)
|
||||
@seed.should_not be_valid
|
||||
@seed = FactoryGirl.build(:seed, field => '')
|
||||
@seed.should_not be_valid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'interesting' do
|
||||
it 'lists interesting seeds' do
|
||||
|
||||
|
||||
Reference in New Issue
Block a user