Created
August 23, 2009 14:33
-
-
Save snusnu/173315 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# | |
# A one file test to show ... | |
require 'rubygems' | |
require 'dm-core' | |
require 'dm-validations' | |
# setup the logger | |
DataMapper::Logger.new(STDOUT, :debug) | |
# connect to the DB | |
DataMapper.setup(:default, 'sqlite3::memory:') | |
class User | |
include DataMapper::Resource | |
# properties | |
property :id, Serial | |
property :username, String | |
property :password, String, :length => 10..50 | |
has 1..n, :pages | |
end | |
class Page | |
include DataMapper::Resource | |
# properties | |
property :id, Serial | |
property :name, String | |
belongs_to :user | |
end | |
DataMapper.auto_migrate! | |
def save_without_transaction(username, password) | |
@user = User.new(:username => username, :password => password, :pages => [ Page.new(:name => 'a'*51) ]) | |
if @user.save | |
puts "YAY!" | |
true | |
else | |
puts "BOO!" | |
puts @user.errors.full_messages.join("\n") | |
@user.pages.map { |p| puts(p.errors.full_messages.join("\n")) } | |
end | |
end | |
puts "All users:" | |
p User.all | |
puts "All pages:" | |
p Page.all | |
save_without_transaction('namelessjon', 'rlyrlysecret!') | |
puts "All users:" | |
p User.all | |
puts "All pages:" | |
p Page.all | |
save_without_transaction('namedjon', 'notsogood') | |
puts "All users:" | |
p User.all | |
puts "All pages:" | |
p Page.all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment