Created
June 25, 2009 19:03
-
-
Save tpitale/136078 to your computer and use it in GitHub Desktop.
Failed create!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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