Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Forked from jacquescrocker/gist:385535
Created April 30, 2010 17:51
Show Gist options
  • Save henrypoydar/385543 to your computer and use it in GitHub Desktop.
Save henrypoydar/385543 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