Require a system name for crops.

This commit is contained in:
Miles Gould
2012-10-03 20:38:39 +01:00
parent 79a98d6225
commit 3419a559e1
5 changed files with 45 additions and 4 deletions

View 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

View File

@@ -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

View File

@@ -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

View File

@@ -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