Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created April 30, 2010 17:44
Show Gist options
  • Save jacquescrocker/385535 to your computer and use it in GitHub Desktop.
Save jacquescrocker/385535 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 [email protected]?
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