Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Forked from fredrikhenne/gist:382193
Created April 28, 2010 17:44
Show Gist options
  • Save jacquescrocker/382436 to your computer and use it in GitHub Desktop.
Save jacquescrocker/382436 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mongoid'
Mongoid.configure do |config|
config.master = Mongo::Connection.new.db("mongoid_key_test")
end
Mongoid.master.collection("users").drop
class User
include Mongoid::Document
field :username
key :username
validates_uniqueness_of :username
end
2.times do
begin
@user = User.create(:username => "Charles")
rescue => e
puts "ERROR!: #{e}"
end
if @user and !@user.valid?
puts "FAILED VALIDATION"
puts @user.errors.inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment