Skip to content

Instantly share code, notes, and snippets.

@banker
Created August 5, 2011 15:02
Show Gist options
  • Save banker/1127719 to your computer and use it in GitHub Desktop.
Save banker/1127719 to your computer and use it in GitHub Desktop.
Test Ruby / Mongoid
require 'rubygems'
require 'mongoid'
require 'test/unit'
if BSON::BSON_CODER != BSON::BSON_C
raise "Please ensure that bson_ext is installed and loaded."
end
class LionTest < Test::Unit::TestCase
DB = "test-mongoid-lion"
class Foo
include Mongoid::Document
field :name, :type => String
end
def setup
@conn = Mongo::Connection.new("localhost", 33331)
@conn.drop_database(DB)
Mongoid.configure do |config|
config.master = @conn[DB]
end
end
def test_connected
assert( Mongoid.config.master.connection.connected? )
end
def test_mongoid
f = Foo.new
f.name = "Bob"
assert f.save
assert Foo.all[0].name == "Bob"
end
def test_serialize
# Test serialization
100.times do |n|
doc = {"a" => n}
b = BSON::BSON_CODER.serialize( doc )
assert( BSON::BSON_CODER.deserialize( b ) == doc )
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment