Skip to content

Instantly share code, notes, and snippets.

@jacquescrocker
Created April 30, 2010 17:44
Show Gist options
  • Select an option

  • Save jacquescrocker/385535 to your computer and use it in GitHub Desktop.

Select an option

Save jacquescrocker/385535 to your computer and use it in GitHub Desktop.

Revisions

  1. railsjedi created this gist Apr 30, 2010.
    28 changes: 28 additions & 0 deletions gistfile1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    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