Permalink
Browse files

first model.

  • Loading branch information...
rgraff committed Apr 19, 2010
1 parent bd1fbf5 commit 10901eb91d7c2958ff97ef05771d01b4d670c8ad
Showing with 35 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +6 −2 config/init.rb
  3. +12 −0 config/migrations.rb
  4. +5 −0 models/person.rb
  5. +11 −0 spec/models/person_spec.rb
View
@@ -0,0 +1 @@
*.sqlite
View
@@ -2,10 +2,14 @@
require 'sqlite3'
configure :development do
set :database, 'sqlite://tmp/development.sqlite'
set :database, 'sqlite://development.sqlite'
end
configure :test do
set :database, 'sqlite3::memory:'
end
require 'config/migrations'
require 'config/migrations'
Dir["models/**/*.rb"].each{|model|
require model
}
View
@@ -0,0 +1,12 @@
# Migrations will run automatically. The DSL like wrapper syntax is courtesy
# of sinatra-sequel
#
# For details on sequel's schema modifications, check out:
# http://sequel.rubyforge.org/rdoc/files/doc/schema_rdoc.html
migration "create the people table" do
database.create_table :people do
primary_key :id
string :name
end
end
View
@@ -0,0 +1,5 @@
class Person < Sequel::Model
def validate
errors.add(:name, "can't be empty") if name.nil? || name.empty?
end
end
View
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Person do
describe "validations" do
it "should require a name" do
Person.new().should_not be_valid
Person.new(:name => '').should_not be_valid
Person.new(:name => "Maggie").should be_valid
end
end
end

0 comments on commit 10901eb

Please sign in to comment.