mongo 1.3.0 → 1.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/{LICENSE.txt → LICENSE} +1 -1
  4. data/README.md +122 -271
  5. data/Rakefile +25 -209
  6. data/VERSION +1 -0
  7. data/bin/mongo_console +31 -9
  8. data/lib/mongo/bulk_write_collection_view.rb +387 -0
  9. data/lib/mongo/collection.rb +576 -269
  10. data/lib/mongo/collection_writer.rb +364 -0
  11. data/lib/mongo/connection/node.rb +249 -0
  12. data/lib/mongo/connection/pool.rb +340 -0
  13. data/lib/mongo/connection/pool_manager.rb +320 -0
  14. data/lib/mongo/connection/sharding_pool_manager.rb +67 -0
  15. data/lib/mongo/connection/socket/socket_util.rb +37 -0
  16. data/lib/mongo/connection/socket/ssl_socket.rb +95 -0
  17. data/lib/mongo/connection/socket/tcp_socket.rb +87 -0
  18. data/lib/mongo/connection/socket/unix_socket.rb +39 -0
  19. data/lib/mongo/connection/socket.rb +18 -0
  20. data/lib/mongo/connection.rb +7 -875
  21. data/lib/mongo/cursor.rb +403 -117
  22. data/lib/mongo/db.rb +444 -243
  23. data/lib/mongo/exception.rb +145 -0
  24. data/lib/mongo/functional/authentication.rb +455 -0
  25. data/lib/mongo/functional/logging.rb +85 -0
  26. data/lib/mongo/functional/read_preference.rb +183 -0
  27. data/lib/mongo/functional/scram.rb +556 -0
  28. data/lib/mongo/functional/uri_parser.rb +409 -0
  29. data/lib/mongo/functional/write_concern.rb +66 -0
  30. data/lib/mongo/functional.rb +20 -0
  31. data/lib/mongo/gridfs/grid.rb +30 -24
  32. data/lib/mongo/gridfs/grid_ext.rb +6 -10
  33. data/lib/mongo/gridfs/grid_file_system.rb +38 -20
  34. data/lib/mongo/gridfs/grid_io.rb +84 -75
  35. data/lib/mongo/gridfs.rb +18 -0
  36. data/lib/mongo/legacy.rb +140 -0
  37. data/lib/mongo/mongo_client.rb +697 -0
  38. data/lib/mongo/mongo_replica_set_client.rb +535 -0
  39. data/lib/mongo/mongo_sharded_client.rb +159 -0
  40. data/lib/mongo/networking.rb +372 -0
  41. data/lib/mongo/{util → utils}/conversions.rb +29 -8
  42. data/lib/mongo/{util → utils}/core_ext.rb +28 -18
  43. data/lib/mongo/{util → utils}/server_version.rb +4 -6
  44. data/lib/mongo/{util → utils}/support.rb +29 -31
  45. data/lib/mongo/utils/thread_local_variable_manager.rb +25 -0
  46. data/lib/mongo/utils.rb +19 -0
  47. data/lib/mongo.rb +51 -50
  48. data/mongo.gemspec +29 -32
  49. data/test/functional/authentication_test.rb +39 -0
  50. data/test/functional/bulk_api_stress_test.rb +133 -0
  51. data/test/functional/bulk_write_collection_view_test.rb +1198 -0
  52. data/test/functional/client_test.rb +627 -0
  53. data/test/functional/collection_test.rb +2175 -0
  54. data/test/functional/collection_writer_test.rb +83 -0
  55. data/test/{conversions_test.rb → functional/conversions_test.rb} +47 -3
  56. data/test/functional/cursor_fail_test.rb +57 -0
  57. data/test/functional/cursor_message_test.rb +56 -0
  58. data/test/functional/cursor_test.rb +683 -0
  59. data/test/functional/db_api_test.rb +835 -0
  60. data/test/functional/db_connection_test.rb +25 -0
  61. data/test/functional/db_test.rb +348 -0
  62. data/test/functional/grid_file_system_test.rb +285 -0
  63. data/test/{grid_io_test.rb → functional/grid_io_test.rb} +72 -11
  64. data/test/{grid_test.rb → functional/grid_test.rb} +88 -15
  65. data/test/functional/pool_test.rb +136 -0
  66. data/test/functional/safe_test.rb +98 -0
  67. data/test/functional/ssl_test.rb +29 -0
  68. data/test/functional/support_test.rb +62 -0
  69. data/test/functional/timeout_test.rb +60 -0
  70. data/test/functional/uri_test.rb +446 -0
  71. data/test/functional/write_concern_test.rb +118 -0
  72. data/test/helpers/general.rb +50 -0
  73. data/test/helpers/test_unit.rb +476 -0
  74. data/test/replica_set/authentication_test.rb +37 -0
  75. data/test/replica_set/basic_test.rb +189 -0
  76. data/test/replica_set/client_test.rb +393 -0
  77. data/test/replica_set/connection_test.rb +138 -0
  78. data/test/replica_set/count_test.rb +66 -0
  79. data/test/replica_set/cursor_test.rb +220 -0
  80. data/test/replica_set/insert_test.rb +157 -0
  81. data/test/replica_set/max_values_test.rb +151 -0
  82. data/test/replica_set/pinning_test.rb +105 -0
  83. data/test/replica_set/query_test.rb +73 -0
  84. data/test/replica_set/read_preference_test.rb +219 -0
  85. data/test/replica_set/refresh_test.rb +211 -0
  86. data/test/replica_set/replication_ack_test.rb +95 -0
  87. data/test/replica_set/ssl_test.rb +32 -0
  88. data/test/sharded_cluster/basic_test.rb +203 -0
  89. data/test/shared/authentication/basic_auth_shared.rb +260 -0
  90. data/test/shared/authentication/bulk_api_auth_shared.rb +249 -0
  91. data/test/shared/authentication/gssapi_shared.rb +176 -0
  92. data/test/shared/authentication/sasl_plain_shared.rb +96 -0
  93. data/test/shared/authentication/scram_shared.rb +92 -0
  94. data/test/shared/ssl_shared.rb +235 -0
  95. data/test/test_helper.rb +53 -94
  96. data/test/threading/basic_test.rb +120 -0
  97. data/test/tools/mongo_config.rb +708 -0
  98. data/test/tools/mongo_config_test.rb +160 -0
  99. data/test/unit/client_test.rb +381 -0
  100. data/test/unit/collection_test.rb +89 -53
  101. data/test/unit/connection_test.rb +282 -32
  102. data/test/unit/cursor_test.rb +206 -8
  103. data/test/unit/db_test.rb +55 -13
  104. data/test/unit/grid_test.rb +43 -16
  105. data/test/unit/mongo_sharded_client_test.rb +48 -0
  106. data/test/unit/node_test.rb +93 -0
  107. data/test/unit/pool_manager_test.rb +111 -0
  108. data/test/unit/read_pref_test.rb +406 -0
  109. data/test/unit/read_test.rb +159 -0
  110. data/test/unit/safe_test.rb +69 -36
  111. data/test/unit/sharding_pool_manager_test.rb +84 -0
  112. data/test/unit/write_concern_test.rb +175 -0
  113. data.tar.gz.sig +3 -0
  114. metadata +227 -216
  115. metadata.gz.sig +0 -0
  116. data/docs/CREDITS.md +0 -123
  117. data/docs/FAQ.md +0 -116
  118. data/docs/GridFS.md +0 -158
  119. data/docs/HISTORY.md +0 -244
  120. data/docs/RELEASES.md +0 -33
  121. data/docs/REPLICA_SETS.md +0 -72
  122. data/docs/TUTORIAL.md +0 -247
  123. data/docs/WRITE_CONCERN.md +0 -28
  124. data/lib/mongo/exceptions.rb +0 -71
  125. data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
  126. data/lib/mongo/repl_set_connection.rb +0 -342
  127. data/lib/mongo/test.rb +0 -20
  128. data/lib/mongo/util/pool.rb +0 -177
  129. data/lib/mongo/util/uri_parser.rb +0 -185
  130. data/test/async/collection_test.rb +0 -224
  131. data/test/async/connection_test.rb +0 -24
  132. data/test/async/cursor_test.rb +0 -162
  133. data/test/async/worker_pool_test.rb +0 -99
  134. data/test/auxillary/1.4_features.rb +0 -166
  135. data/test/auxillary/authentication_test.rb +0 -68
  136. data/test/auxillary/autoreconnect_test.rb +0 -41
  137. data/test/auxillary/fork_test.rb +0 -30
  138. data/test/auxillary/repl_set_auth_test.rb +0 -58
  139. data/test/auxillary/slave_connection_test.rb +0 -36
  140. data/test/auxillary/threaded_authentication_test.rb +0 -101
  141. data/test/bson/binary_test.rb +0 -15
  142. data/test/bson/bson_test.rb +0 -649
  143. data/test/bson/byte_buffer_test.rb +0 -208
  144. data/test/bson/hash_with_indifferent_access_test.rb +0 -38
  145. data/test/bson/json_test.rb +0 -17
  146. data/test/bson/object_id_test.rb +0 -154
  147. data/test/bson/ordered_hash_test.rb +0 -204
  148. data/test/bson/timestamp_test.rb +0 -24
  149. data/test/collection_test.rb +0 -910
  150. data/test/connection_test.rb +0 -309
  151. data/test/cursor_fail_test.rb +0 -75
  152. data/test/cursor_message_test.rb +0 -43
  153. data/test/cursor_test.rb +0 -483
  154. data/test/db_api_test.rb +0 -726
  155. data/test/db_connection_test.rb +0 -15
  156. data/test/db_test.rb +0 -287
  157. data/test/grid_file_system_test.rb +0 -243
  158. data/test/load/resque/load.rb +0 -21
  159. data/test/load/resque/processor.rb +0 -26
  160. data/test/load/thin/load.rb +0 -24
  161. data/test/load/unicorn/load.rb +0 -23
  162. data/test/load/unicorn/unicorn.rb +0 -29
  163. data/test/replica_sets/connect_test.rb +0 -94
  164. data/test/replica_sets/connection_string_test.rb +0 -32
  165. data/test/replica_sets/count_test.rb +0 -35
  166. data/test/replica_sets/insert_test.rb +0 -53
  167. data/test/replica_sets/pooled_insert_test.rb +0 -55
  168. data/test/replica_sets/query_secondaries.rb +0 -96
  169. data/test/replica_sets/query_test.rb +0 -51
  170. data/test/replica_sets/replication_ack_test.rb +0 -66
  171. data/test/replica_sets/rs_test_helper.rb +0 -27
  172. data/test/safe_test.rb +0 -68
  173. data/test/support/hash_with_indifferent_access.rb +0 -186
  174. data/test/support/keys.rb +0 -45
  175. data/test/support_test.rb +0 -18
  176. data/test/threading/threading_with_large_pool_test.rb +0 -90
  177. data/test/threading_test.rb +0 -87
  178. data/test/tools/auth_repl_set_manager.rb +0 -14
  179. data/test/tools/load.rb +0 -58
  180. data/test/tools/repl_set_manager.rb +0 -266
  181. data/test/tools/sharding_manager.rb +0 -202
  182. data/test/tools/test.rb +0 -4
  183. data/test/unit/pool_test.rb +0 -9
  184. data/test/unit/repl_set_connection_test.rb +0 -59
  185. data/test/uri_test.rb +0 -91
@@ -1,208 +0,0 @@
1
- # encoding: binary
2
- require './test/test_helper'
3
-
4
- class ByteBufferTest < Test::Unit::TestCase
5
- include BSON
6
-
7
- def setup
8
- @buf = ByteBuffer.new
9
- end
10
-
11
- def test_initial_state
12
- assert_equal 0, @buf.position
13
- assert_equal [], @buf.to_a
14
- assert_equal "", @buf.to_s
15
- assert_equal 0, @buf.length
16
- end
17
-
18
- def test_nil_get_returns_one_byte
19
- @buf.put_array([1, 2, 3, 4])
20
- @buf.rewind
21
- assert_equal 1, @buf.get
22
- end
23
-
24
- def test_unpack
25
- @buf.put_array([17, 2, 3, 4])
26
- assert_equal [17, 2, 3, 4], @buf.to_a
27
- assert_equal ["11020304"], @buf.unpack("H*")
28
- assert_equal ["11020304"], @buf.to_a("H*")
29
- end
30
-
31
- def test_one_get_returns_array_length_one
32
- @buf.put_array([1, 2, 3, 4])
33
- @buf.rewind
34
- assert_equal [1], @buf.get(1)
35
- end
36
-
37
- def test_zero_get_returns_empty_array
38
- @buf.put_array([1, 2, 3, 4])
39
- @buf.rewind
40
- assert_equal [], @buf.get(0)
41
- end
42
-
43
- def test_length
44
- @buf.put_int 3
45
- assert_equal 4, @buf.length
46
- end
47
-
48
- def test_default_order
49
- assert_equal :little_endian, @buf.order
50
- end
51
-
52
- def test_long_length
53
- @buf.put_long 1027
54
- assert_equal 8, @buf.length
55
- end
56
-
57
- def test_get_long
58
- @buf.put_long 1027
59
- @buf.rewind
60
- assert_equal 1027, @buf.get_long
61
- end
62
-
63
- def test_get_double
64
- @buf.put_double 41.2
65
- @buf.rewind
66
- assert_equal 41.2, @buf.get_double
67
- end
68
-
69
- if defined?(Encoding)
70
- def test_serialize_cstr_converts_encoding_to_utf8
71
- theta = "hello \xC8".force_encoding("ISO-8859-7")
72
- ByteBuffer.serialize_cstr(@buf, theta)
73
- assert_equal "hello \xCE\x98\0", @buf.to_s
74
- assert_equal Encoding.find('binary'), @buf.to_s.encoding
75
- end
76
-
77
- def test_serialize_cstr_validates_data_as_utf8
78
- assert_raises(Encoding::UndefinedConversionError) do
79
- ByteBuffer.serialize_cstr(@buf, "hello \xFF")
80
- end
81
- end
82
- else
83
- def test_serialize_cstr_forces_encoding_to_utf8
84
- # Unicode snowman (\u2603)
85
- ByteBuffer.serialize_cstr(@buf, "hello \342\230\203")
86
- assert_equal "hello \342\230\203\0", @buf.to_s
87
- end
88
-
89
- def test_serialize_cstr_validates_data_as_utf8
90
- assert_raises(BSON::InvalidStringEncoding) do
91
- ByteBuffer.serialize_cstr(@buf, "hello \xFF")
92
- end
93
- end
94
- end
95
-
96
- def test_put_negative_byte
97
- @buf.put(-1)
98
- @buf.rewind
99
- assert_equal 255, @buf.get
100
- assert_equal "\xFF", @buf.to_s
101
- end
102
-
103
- def test_put_with_offset
104
- @buf.put(1)
105
- @buf.put(2, 0)
106
- @buf.put(3, 3)
107
- assert_equal "\x02\x00\x00\x03", @buf.to_s
108
- end
109
-
110
- def test_put_array_with_offset
111
- @buf.put(1)
112
- @buf.put_array([2, 3], 0)
113
- @buf.put_array([4, 5], 4)
114
- assert_equal "\x02\x03\x00\x00\x04\x05", @buf.to_s
115
- end
116
-
117
- def test_put_int_with_offset
118
- @buf.put(1)
119
- @buf.put_int(2, 0)
120
- @buf.put_int(3, 5)
121
- assert_equal "\x02\x00\x00\x00\x00\x03\x00\x00\x00", @buf.to_s
122
- end
123
-
124
- def test_put_long_with_offset
125
- @buf.put(1)
126
- @buf.put_long(2, 0)
127
- @buf.put_long(3, 9)
128
- assert_equal(
129
- "\x02\x00\x00\x00\x00\x00\x00\x00" +
130
- "\x00" +
131
- "\x03\x00\x00\x00\x00\x00\x00\x00",
132
- @buf.to_s)
133
- end
134
-
135
- def test_put_binary
136
- @buf.put(1)
137
- @buf.put_binary("\x02\x03", 0)
138
- @buf.put_binary("\x04\x05", 4)
139
- assert_equal "\x02\x03\x00\x00\x04\x05", @buf.to_s
140
- end
141
-
142
- def test_rewrite
143
- @buf.put_int(0)
144
- @buf.rewind
145
- @buf.put_int(1027)
146
- assert_equal 4, @buf.length
147
- @buf.rewind
148
- assert_equal 1027, @buf.get_int
149
- assert_equal 4, @buf.position
150
- end
151
-
152
- def test_prepend_byte_buffer
153
- @buf.put_int(4)
154
- new_buf = ByteBuffer.new([5, 0, 0, 0])
155
- @buf.prepend!(new_buf)
156
- assert_equal [5, 0, 0, 0, 4, 0, 0, 0], @buf.to_a
157
- end
158
-
159
- def test_append_byte_buffer
160
- @buf.put_int(4)
161
- new_buf = ByteBuffer.new([5, 0, 0, 0])
162
- @buf.append!(new_buf)
163
- assert_equal [4, 0, 0, 0, 5, 0, 0, 0], @buf.to_a
164
- end
165
-
166
- def test_array_as_initial_input
167
- @buf = ByteBuffer.new([5, 0, 0, 0])
168
- assert_equal 4, @buf.size
169
- assert_equal "\x05\x00\x00\x00", @buf.to_s
170
- assert_equal [5, 0, 0, 0], @buf.to_a
171
- @buf.put_int(32)
172
- @buf.rewind
173
- assert_equal 5, @buf.get_int
174
- assert_equal 32, @buf.get_int
175
- end
176
-
177
- def test_binary_string_as_initial_input
178
- str = "abcd"
179
- str.force_encoding('binary') if str.respond_to?(:force_encoding)
180
- @buf = ByteBuffer.new(str)
181
- assert_equal "abcd", @buf.to_s
182
- assert_equal [97, 98, 99, 100], @buf.to_a
183
- @buf.put_int(0)
184
- assert_equal [97, 98, 99, 100, 0, 0, 0, 0], @buf.to_a
185
- end
186
-
187
- def test_more
188
- assert !@buf.more?
189
- @buf.put_int(5)
190
- assert !@buf.more?
191
- @buf.rewind
192
- assert @buf.more?
193
- @buf.get_int
194
- assert !@buf.more?
195
- end
196
-
197
- def test_equality
198
- @buf = ByteBuffer.new("foo")
199
- assert_equal @buf, @buf
200
- assert_equal ByteBuffer.new(""), ByteBuffer.new("")
201
- assert_equal ByteBuffer.new("123"), ByteBuffer.new("123")
202
- assert_not_equal ByteBuffer.new("123"), ByteBuffer.new("1234")
203
- assert_equal @buf, "foo"
204
- assert_not_equal @buf, 123
205
- assert_not_equal @buf, nil
206
- end
207
-
208
- end
@@ -1,38 +0,0 @@
1
- # encoding:utf-8
2
- require './test/test_helper'
3
- require './test/support/hash_with_indifferent_access'
4
-
5
- class HashWithIndifferentAccessTest < Test::Unit::TestCase
6
- include BSON
7
-
8
- def setup
9
- @encoder = BSON::BSON_CODER
10
- end
11
-
12
- def test_document
13
- doc = HashWithIndifferentAccess.new
14
- doc['foo'] = 1
15
- doc['bar'] = 'baz'
16
-
17
- bson = @encoder.serialize(doc)
18
- assert_equal doc, @encoder.deserialize(bson.to_s)
19
- end
20
-
21
- def test_embedded_document
22
- jimmy = HashWithIndifferentAccess.new
23
- jimmy['name'] = 'Jimmy'
24
- jimmy['species'] = 'Siberian Husky'
25
-
26
- stats = HashWithIndifferentAccess.new
27
- stats['eyes'] = 'blue'
28
-
29
- person = HashWithIndifferentAccess.new
30
- person['_id'] = BSON::ObjectId.new
31
- person['name'] = 'Mr. Pet Lover'
32
- person['pets'] = [jimmy, {'name' => 'Sasha'}]
33
- person['stats'] = stats
34
-
35
- bson = @encoder.serialize(person)
36
- assert_equal person, @encoder.deserialize(bson.to_s)
37
- end
38
- end
@@ -1,17 +0,0 @@
1
- require './test/test_helper'
2
- require 'rubygems'
3
- require 'json'
4
-
5
- class JSONTest < Test::Unit::TestCase
6
-
7
- # This test passes when run by itself but fails
8
- # when run as part of the whole test suite.
9
- def test_object_id_as_json
10
- warn "Pending test object id as json"
11
- #id = BSON::ObjectId.new
12
-
13
- #obj = {'_id' => id}
14
- #assert_equal "{\"_id\":#{id.to_json}}", obj.to_json
15
- end
16
-
17
- end
@@ -1,154 +0,0 @@
1
- require './test/test_helper'
2
- require 'rubygems'
3
- require 'json'
4
-
5
- class ObjectIdTest < Test::Unit::TestCase
6
-
7
- include Mongo
8
- include BSON
9
-
10
- def setup
11
- @o = ObjectId.new
12
- end
13
-
14
- def test_hashcode
15
- assert_equal @o.instance_variable_get(:@data).hash, @o.hash
16
- end
17
-
18
- def test_array_uniq_for_equilavent_ids
19
- a = ObjectId.new('123')
20
- b = ObjectId.new('123')
21
- assert_equal a, b
22
- assert_equal 1, [a, b].uniq.size
23
- end
24
-
25
- def test_create_pk_method
26
- doc = {:name => 'Mongo'}
27
- doc = ObjectId.create_pk(doc)
28
- assert doc[:_id]
29
-
30
- doc = {:name => 'Mongo', :_id => '12345'}
31
- doc = ObjectId.create_pk(doc)
32
- assert_equal '12345', doc[:_id]
33
- end
34
-
35
- def test_different
36
- a = ObjectId.new
37
- b = ObjectId.new
38
- assert_not_equal a.to_a, b.to_a
39
- assert_not_equal a, b
40
- end
41
-
42
- def test_eql?
43
- o2 = ObjectId.new(@o.to_a)
44
- assert_equal @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_to_s2
55
- @o = ObjectId.new([76, 244, 52, 174, 44, 84, 121, 76, 88, 0, 0, 3])
56
- s = '4cf434ae2c54794c58000003'
57
- assert_equal @o.to_s, s
58
- end
59
-
60
- def test_method
61
- assert_equal ObjectId.from_string(@o.to_s), BSON::ObjectId(@o.to_s)
62
- end
63
-
64
- def test_inspect
65
- assert_equal "BSON::ObjectId('#{@o.to_s}')", @o.inspect
66
- end
67
-
68
- def test_save_and_restore
69
- db = standard_connection.db(MONGO_TEST_DB)
70
- coll = db.collection('test')
71
-
72
- coll.remove
73
- coll << {'a' => 1, '_id' => @o}
74
-
75
- row = coll.find().collect.first
76
- assert_equal 1, row['a']
77
- assert_equal @o, row['_id']
78
- end
79
-
80
- def test_from_string
81
- hex_str = @o.to_s
82
- o2 = ObjectId.from_string(hex_str)
83
- assert_equal hex_str, o2.to_s
84
- assert_equal @o, o2
85
- assert_equal @o.to_s, o2.to_s
86
- end
87
-
88
- def test_illegal_from_string
89
- assert_raise InvalidObjectId do
90
- ObjectId.from_string("")
91
- end
92
- end
93
-
94
- def test_legal
95
- assert !ObjectId.legal?(nil)
96
- assert !ObjectId.legal?("fred")
97
- assert !ObjectId.legal?("0000")
98
- assert !ObjectId.legal?('000102030405060708090A0')
99
- assert ObjectId.legal?('000102030405060708090A0B')
100
- assert ObjectId.legal?('abcdefABCDEF123456789012')
101
- assert !ObjectId.legal?('abcdefABCDEF12345678901x')
102
- end
103
-
104
- def test_from_string_leading_zeroes
105
- hex_str = '000000000000000000000000'
106
- o = ObjectId.from_string(hex_str)
107
- assert_equal hex_str, o.to_s
108
- end
109
-
110
- def test_byte_order
111
- hex_str = '000102030405060708090A0B'
112
- o = ObjectId.from_string(hex_str)
113
- assert_equal [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b], o.to_a
114
- end
115
-
116
- def test_generation_time
117
- time = Time.now
118
- id = ObjectId.new
119
- generated_time = id.generation_time
120
-
121
- assert_in_delta time.to_i, generated_time.to_i, 2
122
- assert_equal "UTC", generated_time.zone
123
- end
124
-
125
- def test_from_time
126
- time = Time.now.utc
127
- id = ObjectId.from_time(time)
128
-
129
- assert id.to_a[4, 8].all? {|byte| byte == 0 }
130
- assert_equal time.to_i, id.generation_time.to_i
131
- end
132
-
133
- def test_from_time_unique
134
- time = Time.now.utc
135
- id = ObjectId.from_time(time, :unique => true)
136
-
137
- mac_id = Digest::MD5.digest(Socket.gethostname)[0, 3].unpack("C3")
138
- assert_equal id.to_a[4, 3], mac_id
139
- assert_equal time.to_i, id.generation_time.to_i
140
-
141
- id2 = ObjectId.new(nil, time)
142
- assert_equal time.to_i, id2.generation_time.to_i
143
- end
144
-
145
- def test_json
146
- id = ObjectId.new
147
- assert_equal "{\"$oid\": \"#{id}\"}", id.to_json
148
- end
149
-
150
- def test_as_json
151
- id = ObjectId.new
152
- assert_equal({"$oid" => id.to_s}, id.as_json)
153
- end
154
- end
@@ -1,204 +0,0 @@
1
- require './test/test_helper'
2
-
3
- class OrderedHashTest < Test::Unit::TestCase
4
-
5
- def setup
6
- @oh = BSON::OrderedHash.new
7
- @oh['c'] = 1
8
- @oh['a'] = 2
9
- @oh['z'] = 3
10
- @ordered_keys = %w(c a z)
11
- end
12
-
13
- def test_initialize
14
- a = BSON::OrderedHash.new
15
- a['x'] = 1
16
- a['y'] = 2
17
-
18
- b = BSON::OrderedHash['x' => 1, 'y' => 2]
19
- assert_equal a, b
20
- end
21
-
22
- def test_hash_code
23
- o = BSON::OrderedHash.new
24
- o['number'] = 50
25
- assert o.hash
26
- end
27
-
28
- def test_empty
29
- assert_equal [], BSON::OrderedHash.new.keys
30
- end
31
-
32
- def test_uniq
33
- list = []
34
- doc = BSON::OrderedHash.new
35
- doc['_id'] = 'ab12'
36
- doc['name'] = 'test'
37
-
38
- same_doc = BSON::OrderedHash.new
39
- same_doc['_id'] = 'ab12'
40
- same_doc['name'] = 'test'
41
- list << doc
42
- list << same_doc
43
-
44
- assert_equal 2, list.size
45
- assert_equal 1, list.uniq.size
46
- end
47
-
48
- def test_equality
49
- a = BSON::OrderedHash.new
50
- a['x'] = 1
51
- a['y'] = 2
52
-
53
- b = BSON::OrderedHash.new
54
- b['y'] = 2
55
- b['x'] = 1
56
-
57
- c = BSON::OrderedHash.new
58
- c['x'] = 1
59
- c['y'] = 2
60
-
61
- d = BSON::OrderedHash.new
62
- d['x'] = 2
63
- d['y'] = 3
64
-
65
- e = BSON::OrderedHash.new
66
- e['z'] = 1
67
- e['y'] = 2
68
-
69
- assert_equal a, c
70
- assert_not_equal a, b
71
- assert_not_equal a, d
72
- assert_not_equal a, e
73
- end
74
-
75
- def test_order_preserved
76
- assert_equal @ordered_keys, @oh.keys
77
- end
78
-
79
- def test_to_a_order_preserved
80
- assert_equal @ordered_keys, @oh.to_a.map {|m| m.first}
81
- end
82
-
83
- def test_order_preserved_after_replace
84
- @oh['a'] = 42
85
- assert_equal @ordered_keys, @oh.keys
86
- @oh['c'] = 'foobar'
87
- assert_equal @ordered_keys, @oh.keys
88
- @oh['z'] = /huh?/
89
- assert_equal @ordered_keys, @oh.keys
90
- end
91
-
92
- def test_each
93
- keys = []
94
- @oh.each { |k, v| keys << k }
95
- assert_equal keys, @oh.keys
96
-
97
- @oh['z'] = 42
98
- assert_equal keys, @oh.keys
99
-
100
- assert_equal @oh, @oh.each {|k,v|}
101
- end
102
-
103
- def test_values
104
- assert_equal [1, 2, 3], @oh.values
105
- end
106
-
107
- def test_merge
108
- other = BSON::OrderedHash.new
109
- other['f'] = 'foo'
110
- noob = @oh.merge(other)
111
- assert_equal @ordered_keys + ['f'], noob.keys
112
- assert_equal [1, 2, 3, 'foo'], noob.values
113
- end
114
-
115
- def test_merge_bang
116
- other = BSON::OrderedHash.new
117
- other['f'] = 'foo'
118
- @oh.merge!(other)
119
- assert_equal @ordered_keys + ['f'], @oh.keys
120
- assert_equal [1, 2, 3, 'foo'], @oh.values
121
- end
122
-
123
- def test_merge_bang_with_overlap
124
- other = BSON::OrderedHash.new
125
- other['a'] = 'apple'
126
- other['c'] = 'crab'
127
- other['f'] = 'foo'
128
- @oh.merge!(other)
129
- assert_equal @ordered_keys + ['f'], @oh.keys
130
- assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
131
- end
132
-
133
- def test_merge_bang_with_hash_with_overlap
134
- other = Hash.new
135
- other['a'] = 'apple'
136
- other['c'] = 'crab'
137
- other['f'] = 'foo'
138
- @oh.merge!(other)
139
- assert_equal @ordered_keys + ['f'], @oh.keys
140
- assert_equal ['crab', 'apple', 3, 'foo'], @oh.values
141
- end
142
-
143
- def test_equality_with_hash
144
- o = BSON::OrderedHash.new
145
- o[:a] = 1
146
- o[:b] = 2
147
- o[:c] = 3
148
- r = {:a => 1, :b => 2, :c => 3}
149
- assert r == o
150
- assert o == r
151
- end
152
-
153
- def test_update
154
- other = BSON::OrderedHash.new
155
- other['f'] = 'foo'
156
- noob = @oh.update(other)
157
- assert_equal @ordered_keys + ['f'], noob.keys
158
- assert_equal [1, 2, 3, 'foo'], noob.values
159
- end
160
-
161
- def test_inspect_retains_order
162
- assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
163
- end
164
-
165
- def test_clear
166
- @oh.clear
167
- assert @oh.keys.empty?
168
- end
169
-
170
- def test_delete
171
- assert @oh.keys.include?('z')
172
- @oh.delete('z')
173
- assert !@oh.keys.include?('z')
174
- end
175
-
176
- def test_delete_if
177
- assert @oh.keys.include?('z')
178
- @oh.delete_if { |k,v| k == 'z' }
179
- assert !@oh.keys.include?('z')
180
- end
181
-
182
- def test_reject
183
- new = @oh.reject { |k, v| k == 'foo' }
184
- assert new.keys == @oh.keys
185
-
186
- new = @oh.reject { |k, v| k == 'z' }
187
- assert !new.keys.include?('z')
188
- end
189
-
190
- def test_clone
191
- copy = @oh.clone
192
- assert copy.keys == @oh.keys
193
-
194
- copy[:foo] = 1
195
- assert copy.keys != @oh.keys
196
- end
197
-
198
- def test_dup
199
- oh2 = @oh.dup
200
- oh2['f'] = 9
201
- assert_nil @oh['f']
202
- assert_equal ['c', 'a', 'z'], @oh.keys
203
- end
204
- end
@@ -1,24 +0,0 @@
1
- require './test/test_helper'
2
-
3
- class TiumestampTest < Test::Unit::TestCase
4
- include Mongo
5
-
6
- def test_timestamp_equality
7
- t1 = Timestamp.new(5000, 200)
8
- t2 = Timestamp.new(5000, 200)
9
- assert_equal t2, t1
10
- end
11
-
12
- def test_implements_array_for_backward_compatibility
13
- ts = Timestamp.new(5000, 200)
14
- assert_equal 200, ts[0]
15
- assert_equal 5000, ts[1]
16
-
17
- array = ts.map {|t| t }
18
- assert_equal 2, array.length
19
-
20
- assert_equal 200, array[0]
21
- assert_equal 5000, array[1]
22
- end
23
-
24
- end