mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-24 16:58:35 -04:00
Require a system name for crops.
This commit is contained in:
15
db/migrate/20121003190731_require_system_name_for_crops.rb
Normal file
15
db/migrate/20121003190731_require_system_name_for_crops.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class RequireSystemNameForCrops < ActiveRecord::Migration
|
||||
def up
|
||||
change_table :crops do |t|
|
||||
t.index :system_name
|
||||
t.change :system_name, :string, :null => false
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
change_table :crops do |t|
|
||||
t.change :system_name, :string, :null => true
|
||||
t.remove_index :system_name
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -11,15 +11,17 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121001212604) do
|
||||
ActiveRecord::Schema.define(:version => 20121003190731) do
|
||||
|
||||
create_table "crops", :force => true do |t|
|
||||
t.string "system_name"
|
||||
t.string "system_name", :null => false
|
||||
t.string "en_wikipedia_url"
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
end
|
||||
|
||||
add_index "crops", ["system_name"], :name => "index_crops_on_system_name"
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.string "email", :default => "", :null => false
|
||||
t.string "encrypted_password", :default => "", :null => false
|
||||
|
||||
@@ -24,7 +24,7 @@ describe CropsController do
|
||||
# Crop. As you add validations to Crop, be sure to
|
||||
# update the return value of this method accordingly.
|
||||
def valid_attributes
|
||||
{}
|
||||
{ :system_name => "Tomato" }
|
||||
end
|
||||
|
||||
# This should return the minimal set of values that should be in the session
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Crop do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
context 'all fields present' do
|
||||
|
||||
before(:each) do
|
||||
@crop = Crop.new
|
||||
@crop.system_name = "Tomato"
|
||||
@crop.en_wikipedia_url = "http://en.wikipedia.org/wiki/Tomato"
|
||||
end
|
||||
|
||||
it 'should save a basic crop' do
|
||||
@crop.save.should be_true
|
||||
end
|
||||
|
||||
it 'should be fetchable from the database' do
|
||||
@crop.save
|
||||
@crop2 = Crop.find_by_system_name('Tomato')
|
||||
@crop2.en_wikipedia_url.should == "http://en.wikipedia.org/wiki/Tomato"
|
||||
end
|
||||
end
|
||||
|
||||
context 'invalid data' do
|
||||
it 'should not save a crop without a system name' do
|
||||
@crop = Crop.new
|
||||
expect { @crop.save }.to raise_error ActiveRecord::StatementInvalid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user