Skip to content

Instantly share code, notes, and snippets.

@tpitale
Created June 25, 2009 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tpitale/136078 to your computer and use it in GitHub Desktop.
Save tpitale/136078 to your computer and use it in GitHub Desktop.
Failed create!
require 'rubygems'
gem 'dm-core', '0.10.0'
gem 'dm-validations', '0.10.0'
require 'dm-core'
require 'dm-validations'
DataMapper.setup(:default, 'postgres://tpitale@localhost/test_create_fail')
class User1
include DataMapper::Resource
property :id, Serial
property :name, String, :nullable => false
end
class User2
include DataMapper::Resource
property :id, Serial
validates_with_block(:test) {always_fails}
def always_fails
[false, "You are bound to fail!"]
end
end
DataObjects::Postgres.logger = DataObjects::Logger.new(STDOUT, 0)
DataMapper.auto_migrate!
# correctly returns false
user = User2.new
puts user.valid?
# does not fail
puts User2.create!.id
# correctly returns false
user = User1.new
puts user.valid?
# only fails because of database constraints
# also, blows up
puts User1.create!.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment