Skip to content

Commit

Permalink
first model.
Browse files Browse the repository at this point in the history
  • Loading branch information
rgraff committed Apr 19, 2010
1 parent bd1fbf5 commit 10901eb
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.sqlite
8 changes: 6 additions & 2 deletions config/init.rb
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions config/migrations.rb
@@ -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
5 changes: 5 additions & 0 deletions models/person.rb
@@ -0,0 +1,5 @@
class Person < Sequel::Model
def validate
errors.add(:name, "can't be empty") if name.nil? || name.empty?
end
end
11 changes: 11 additions & 0 deletions spec/models/person_spec.rb
@@ -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.