Created
August 5, 2011 15:02
-
-
Save banker/1127719 to your computer and use it in GitHub Desktop.
Test Ruby / Mongoid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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