mongo 0.18 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
  require 'logger'
5
3
  require 'stringio'
6
4
 
@@ -1,8 +1,7 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
1
+ require 'test/test_helper'
2
2
  require 'mongo/errors'
3
3
  require 'mongo/util/conversions'
4
4
  require 'mongo/util/ordered_hash'
5
- require 'test/unit'
6
5
 
7
6
  class ConversionsTest < Test::Unit::TestCase
8
7
  include Mongo::Conversions
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
 
5
3
  # NOTE: assumes Mongo is running
6
4
  class CursorTest < Test::Unit::TestCase
@@ -1,7 +1,5 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
1
+ require 'test/test_helper'
2
2
  require 'digest/md5'
3
- require 'mongo'
4
- require 'test/unit'
5
3
  require 'stringio'
6
4
  require 'logger'
7
5
 
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
 
5
3
  # NOTE: assumes Mongo is running
6
4
  class DBAPITest < Test::Unit::TestCase
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
 
5
3
  # NOTE: assumes Mongo is running
6
4
  class DBConnectionTest < Test::Unit::TestCase
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'test/unit'
3
- require 'mongo'
1
+ require 'test/test_helper'
4
2
  require 'mongo/gridfs'
5
3
 
6
4
  class GridStoreTest < Test::Unit::TestCase
@@ -1,8 +1,10 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'rubygems'
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'rubygems' if ENV['C_EXT']
3
+ require 'mongo'
3
4
  require 'test/unit'
4
5
 
5
6
  begin
7
+ require 'rubygems'
6
8
  require 'shoulda'
7
9
  require 'mocha'
8
10
  rescue LoadError
@@ -17,7 +19,7 @@ MSG
17
19
  exit
18
20
  end
19
21
 
20
- require 'mongo'
22
+ require 'mongo_ext/cbson' if ENV['C_EXT']
21
23
 
22
24
  # NOTE: most tests assume that MongoDB is running.
23
25
  class Test::Unit::TestCase
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
 
5
3
  class ObjectIDTest < Test::Unit::TestCase
6
4
 
@@ -123,4 +121,10 @@ class ObjectIDTest < Test::Unit::TestCase
123
121
  assert_equal s, ObjectID.legacy_string_convert(l)
124
122
  end
125
123
 
124
+ def test_generation_time
125
+ time = Time.now
126
+ id = ObjectID.new
127
+
128
+ assert_in_delta time.to_i, id.generation_time.to_i, 2
129
+ end
126
130
  end
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo/util/ordered_hash'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
 
5
3
  class OrderedHashTest < Test::Unit::TestCase
6
4
 
@@ -1,8 +1,7 @@
1
1
  HERE = File.dirname(__FILE__)
2
2
  $LOAD_PATH[0,0] = File.join(HERE, '..', 'lib')
3
- require 'mongo'
3
+ require 'test/test_helper'
4
4
  require 'mongo/util/xml_to_ruby'
5
- require 'test/unit'
6
5
 
7
6
  # For each xml/bson file in the data subdirectory, we turn the XML into an
8
7
  # OrderedHash and then test both Ruby-to-BSON and BSON-to-Ruby translations.
@@ -74,19 +73,14 @@ EOS
74
73
  File.open(File.join(dir, "#{name}.bson"), 'rb') { |f|
75
74
  # Read the BSON from the file
76
75
  bson = f.read
77
- bson = if RUBY_VERSION >= '1.9'
78
- bson.bytes.to_a
79
- else
80
- bson.split(//).collect { |c| c[0] }
81
- end
82
76
 
83
77
  # Turn the Ruby object into BSON bytes and compare with the BSON bytes
84
78
  # from the file.
85
- bson_from_ruby = BSON.new.serialize(obj).to_a
79
+ bson_from_ruby = BSON.serialize(obj)
86
80
 
87
81
  begin
88
- assert_equal bson.length, bson_from_ruby.length
89
- assert_equal bson, bson_from_ruby
82
+ assert_equal bson.length, bson_from_ruby.to_s.length
83
+ assert_equal bson, bson_from_ruby.to_s
90
84
  rescue => ex
91
85
  # File.open(File.join(dir, "#{name}_out_a.bson"), 'wb') { |f| # DEBUG
92
86
  # bson_from_ruby.each { |b| f.putc(b) }
@@ -99,15 +93,15 @@ EOS
99
93
  # We're passing a nil db to the contructor here, but that's OK because
100
94
  # the BSON DBRef bytes don't contain the db object in any case, and we
101
95
  # don't care what the database is.
102
- obj_from_bson = BSON.new.deserialize(ByteBuffer.new(bson_from_ruby))
96
+ obj_from_bson = BSON.deserialize(bson_from_ruby)
103
97
  assert_kind_of OrderedHash, obj_from_bson
104
98
 
105
99
  # Turn that Ruby object into BSON and compare it to the original BSON
106
100
  # bytes.
107
- bson_from_ruby = BSON.new.serialize(obj_from_bson).to_a
101
+ bson_from_ruby = BSON.serialize(obj_from_bson)
108
102
  begin
109
- assert_equal bson.length, bson_from_ruby.length
110
- assert_equal bson, bson_from_ruby
103
+ assert_equal bson.length, bson_from_ruby.to_s.length
104
+ assert_equal bson, bson_from_ruby.to_s
111
105
  rescue => ex
112
106
  # File.open(File.join(dir, "#{name}_out_b.bson"), 'wb') { |f| # DEBUG
113
107
  # bson_from_ruby.each { |b| f.putc(b) }
@@ -1,6 +1,4 @@
1
- $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
- require 'mongo'
3
- require 'test/unit'
1
+ require 'test/test_helper'
4
2
 
5
3
  # NOTE: these tests are run only if we can connect to a single MongoDB in slave mode.
6
4
  class SlaveConnectionTest < Test::Unit::TestCase
@@ -22,7 +22,7 @@ class ConnectionTest < Test::Unit::TestCase
22
22
  context "given a single node" do
23
23
  setup do
24
24
  TCPSocket.stubs(:new).returns(new_mock_socket)
25
- @conn = Connection.new('localhost', 27107, :connect => false)
25
+ @conn = Connection.new('localhost', 27017, :connect => false)
26
26
 
27
27
  admin_db = new_mock_db
28
28
  admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
@@ -45,6 +45,22 @@ class ConnectionTest < Test::Unit::TestCase
45
45
  end
46
46
  end
47
47
 
48
+ context "with a nonstandard port" do
49
+ setup do
50
+ TCPSocket.stubs(:new).returns(new_mock_socket)
51
+ @conn = Connection.new('255.255.255.255', 2500, :connect => false)
52
+ admin_db = new_mock_db
53
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
54
+ @conn.expects(:[]).with('admin').returns(admin_db)
55
+ @conn.connect_to_master
56
+ end
57
+
58
+ should "set localhost and port correctly" do
59
+ assert_equal '255.255.255.255', @conn.host
60
+ assert_equal 2500, @conn.port
61
+ end
62
+ end
63
+
48
64
  context "Connection pooling: " do
49
65
  setup do
50
66
  TCPSocket.stubs(:new).returns(new_mock_socket)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.18"
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-25 00:00:00 -05:00
13
+ date: 2009-12-05 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -42,7 +42,8 @@ files:
42
42
  - lib/mongo/types/dbref.rb
43
43
  - lib/mongo/types/objectid.rb
44
44
  - lib/mongo/types/regexp_of_holding.rb
45
- - lib/mongo/util/bson.rb
45
+ - lib/mongo/util/bson_c.rb
46
+ - lib/mongo/util/bson_ruby.rb
46
47
  - lib/mongo/util/byte_buffer.rb
47
48
  - lib/mongo/util/conversions.rb
48
49
  - lib/mongo/util/ordered_hash.rb
@@ -67,8 +68,6 @@ files:
67
68
  - bin/fail_if_no_c.rb
68
69
  has_rdoc: true
69
70
  homepage: http://www.mongodb.org
70
- licenses: []
71
-
72
71
  post_install_message:
73
72
  rdoc_options:
74
73
  - --main
@@ -91,9 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
90
  requirements: []
92
91
 
93
92
  rubyforge_project:
94
- rubygems_version: 1.3.5
93
+ rubygems_version: 1.3.1
95
94
  signing_key:
96
- specification_version: 3
95
+ specification_version: 2
97
96
  summary: Ruby driver for the MongoDB
98
97
  test_files:
99
98
  - test/mongo-qa/_common.rb