mongo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ # NOTE: assumes Mongo is running
6
+ class DBConnectionTest < Test::Unit::TestCase
7
+
8
+ include XGen::Mongo::Driver
9
+
10
+ def test_no_exceptions
11
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
12
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
13
+ db = Mongo.new(host, port).db('ruby-mongo-demo')
14
+ coll = db.collection('test')
15
+ coll.clear
16
+ end
17
+ end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ class MessageTest < Test::Unit::TestCase
6
+
7
+ include XGen::Mongo::Driver
8
+
9
+ def setup
10
+ @msg = Message.new(42)
11
+ end
12
+
13
+ def test_initial_info
14
+ assert_equal Message::HEADER_SIZE, @msg.buf.length
15
+ @msg.write_long(1029)
16
+ @msg.buf.rewind
17
+ assert_equal Message::HEADER_SIZE + 8, @msg.buf.get_int
18
+ @msg.buf.get_int # skip message id
19
+ assert_equal 0, @msg.buf.get_int
20
+ assert_equal 42, @msg.buf.get_int
21
+ assert_equal 1029, @msg.buf.get_long
22
+ end
23
+
24
+ def test_update_length
25
+ @msg.update_message_length
26
+ @msg.buf.rewind
27
+ assert_equal Message::HEADER_SIZE, @msg.buf.get_int
28
+ end
29
+
30
+ def test_long_length
31
+ @msg.write_long(1027)
32
+ assert_equal Message::HEADER_SIZE + 8, @msg.buf.length
33
+ end
34
+
35
+ end
@@ -0,0 +1,68 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'test/unit'
4
+
5
+ class ObjectIDTest < Test::Unit::TestCase
6
+
7
+ include XGen::Mongo::Driver
8
+
9
+ def setup
10
+ @t = 42
11
+ @o = ObjectID.new(nil, @t)
12
+ end
13
+
14
+ def test_index_for_time
15
+ t = 99
16
+ assert_equal 0, @o.index_for_time(t)
17
+ assert_equal 1, @o.index_for_time(t)
18
+ assert_equal 2, @o.index_for_time(t)
19
+ t = 100
20
+ assert_equal 0, @o.index_for_time(t)
21
+ end
22
+
23
+ def test_time_bytes
24
+ a = @o.to_a
25
+ assert_equal @t, a[0]
26
+ 3.times { |i| assert_equal 0, a[i+1] }
27
+
28
+ t = 43
29
+ o = ObjectID.new(nil, t)
30
+ a = o.to_a
31
+ assert_equal t, a[0]
32
+ 3.times { |i| assert_equal 0, a[i+1] }
33
+ assert_equal 1, o.index_for_time(t) # 0 was used for o
34
+ end
35
+
36
+ def test_different
37
+ o2 = ObjectID.new(nil, @t)
38
+ assert @o.to_a != o2.to_a
39
+ end
40
+
41
+ def test_eql?
42
+ o2 = ObjectID.new(@o.to_a)
43
+ assert @o.eql?(o2)
44
+ assert @o == o2
45
+ end
46
+
47
+ def test_to_s
48
+ s = @o.to_s
49
+ assert_equal 24, s.length
50
+ s =~ /^([0-9a-f]+)$/
51
+ assert_equal 24, $1.length
52
+ end
53
+
54
+ def test_save_and_restore
55
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
56
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
57
+ db = Mongo.new(host, port).db('ruby-mongo-test')
58
+ coll = db.collection('test')
59
+
60
+ coll.clear
61
+ coll << {'a' => 1, '_id' => @o}
62
+
63
+ row = coll.find().collect.first
64
+ assert_equal 1, row['a']
65
+ assert_equal @o, row['_id']
66
+ end
67
+
68
+ end
@@ -0,0 +1,82 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo/util/ordered_hash'
3
+ require 'test/unit'
4
+
5
+ # NOTE: assumes Mongo is running
6
+ class OrderedHashTest < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @oh = OrderedHash.new
10
+ @oh['c'] = 1
11
+ @oh['a'] = 2
12
+ @oh['z'] = 3
13
+ @ordered_keys = %w(c a z)
14
+ end
15
+
16
+ def test_empty
17
+ assert_equal [], OrderedHash.new.keys
18
+ end
19
+
20
+ def test_order_preserved
21
+ assert_equal @ordered_keys, @oh.keys
22
+ end
23
+
24
+ def test_order_preserved_after_replace
25
+ @oh['a'] = 42
26
+ assert_equal @ordered_keys, @oh.keys
27
+ @oh['c'] = 'foobar'
28
+ assert_equal @ordered_keys, @oh.keys
29
+ @oh['z'] = /huh?/
30
+ assert_equal @ordered_keys, @oh.keys
31
+ end
32
+
33
+ def test_each
34
+ keys = []
35
+ @oh.each { |k, v| keys << k }
36
+ assert_equal keys, @oh.keys
37
+
38
+ @oh['z'] = 42
39
+ assert_equal keys, @oh.keys
40
+ end
41
+
42
+ def test_values
43
+ assert_equal [1, 2, 3], @oh.values
44
+ end
45
+
46
+ def test_merge
47
+ other = OrderedHash.new
48
+ other['f'] = 'foo'
49
+ noob = @oh.merge(other)
50
+ assert_equal @ordered_keys + ['f'], noob.keys
51
+ assert_equal [1, 2, 3, 'foo'], noob.values
52
+ end
53
+
54
+ def test_merge_bang
55
+ other = OrderedHash.new
56
+ other['f'] = 'foo'
57
+ @oh.merge!(other)
58
+ assert_equal @ordered_keys + ['f'], @oh.keys
59
+ assert_equal [1, 2, 3, 'foo'], @oh.values
60
+ end
61
+
62
+ def test_merge_bang_with_overlap
63
+ other = OrderedHash.new
64
+ other['a'] = 'apple'
65
+ other['c'] = 'crab'
66
+ other['f'] = 'foo'
67
+ @oh.merge!(other)
68
+ assert_equal @ordered_keys + ['f'], @oh.keys
69
+ assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
70
+ end
71
+
72
+ def test_merge_bang_with_hash_with_overlap
73
+ other = Hash.new
74
+ other['a'] = 'apple'
75
+ other['c'] = 'crab'
76
+ other['f'] = 'foo'
77
+ @oh.merge!(other)
78
+ assert_equal @ordered_keys + ['f'], @oh.keys
79
+ assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
80
+ end
81
+
82
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jim Menard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-08 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This is a simple pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.
17
+ email: jimm@io.com
18
+ executables:
19
+ - mongo_console
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - bin/mongo_console
26
+ - lib/mongo/admin.rb
27
+ - lib/mongo/collection.rb
28
+ - lib/mongo/cursor.rb
29
+ - lib/mongo/db.rb
30
+ - lib/mongo/message/get_more_message.rb
31
+ - lib/mongo/message/insert_message.rb
32
+ - lib/mongo/message/kill_cursors_message.rb
33
+ - lib/mongo/message/message.rb
34
+ - lib/mongo/message/message_header.rb
35
+ - lib/mongo/message/msg_message.rb
36
+ - lib/mongo/message/opcodes.rb
37
+ - lib/mongo/message/query_message.rb
38
+ - lib/mongo/message/remove_message.rb
39
+ - lib/mongo/message/update_message.rb
40
+ - lib/mongo/message.rb
41
+ - lib/mongo/mongo.rb
42
+ - lib/mongo/objectid.rb
43
+ - lib/mongo/query.rb
44
+ - lib/mongo/util/bson.rb
45
+ - lib/mongo/util/byte_buffer.rb
46
+ - lib/mongo/util/ordered_hash.rb
47
+ - lib/mongo.rb
48
+ - tests/test_admin.rb
49
+ - tests/test_bson.rb
50
+ - tests/test_byte_buffer.rb
51
+ - tests/test_db_api.rb
52
+ - tests/test_db_connection.rb
53
+ - tests/test_message.rb
54
+ - tests/test_objectid.rb
55
+ - tests/test_ordered_hash.rb
56
+ - Rakefile
57
+ - README.rdoc
58
+ has_rdoc: true
59
+ homepage: http://www.mongodb.org
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: mongo
80
+ rubygems_version: 1.3.1
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: Simple pure-Ruby driver for the 10gen Mongo DB
84
+ test_files: []
85
+