mongo 0.19.3 → 0.20

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 (65) hide show
  1. data/README.rdoc +7 -3
  2. data/Rakefile +16 -6
  3. data/bin/bson_benchmark.rb +2 -2
  4. data/examples/gridfs.rb +3 -2
  5. data/lib/mongo.rb +3 -26
  6. data/lib/mongo/collection.rb +69 -50
  7. data/lib/mongo/connection.rb +16 -41
  8. data/lib/mongo/cursor.rb +22 -32
  9. data/lib/mongo/db.rb +13 -5
  10. data/lib/mongo/exceptions.rb +11 -15
  11. data/lib/mongo/gridfs/grid.rb +14 -3
  12. data/lib/mongo/gridfs/grid_file_system.rb +28 -5
  13. data/lib/mongo/gridfs/grid_io.rb +42 -24
  14. data/lib/mongo/util/support.rb +13 -2
  15. data/mongo-ruby-driver.gemspec +3 -1
  16. data/test/collection_test.rb +62 -9
  17. data/test/connection_test.rb +21 -32
  18. data/test/conversions_test.rb +1 -1
  19. data/test/cursor_test.rb +2 -2
  20. data/test/db_api_test.rb +28 -27
  21. data/test/db_connection_test.rb +1 -1
  22. data/test/db_test.rb +23 -13
  23. data/test/grid_file_system_test.rb +30 -4
  24. data/test/grid_io_test.rb +14 -1
  25. data/test/grid_test.rb +59 -3
  26. data/test/test_helper.rb +4 -1
  27. data/test/threading/test_threading_large_pool.rb +1 -1
  28. data/test/threading_test.rb +1 -1
  29. data/test/unit/collection_test.rb +2 -2
  30. data/test/unit/cursor_test.rb +7 -0
  31. data/test/unit/db_test.rb +8 -8
  32. metadata +6 -46
  33. data/bin/gr.rb +0 -14
  34. data/lib/bson.rb +0 -46
  35. data/lib/bson/bson_c.rb +0 -20
  36. data/lib/bson/bson_ruby.rb +0 -601
  37. data/lib/bson/byte_buffer.rb +0 -224
  38. data/lib/bson/exceptions.rb +0 -39
  39. data/lib/bson/ordered_hash.rb +0 -140
  40. data/lib/bson/types/binary.rb +0 -54
  41. data/lib/bson/types/code.rb +0 -36
  42. data/lib/bson/types/dbref.rb +0 -40
  43. data/lib/bson/types/min_max_keys.rb +0 -58
  44. data/lib/bson/types/objectid.rb +0 -180
  45. data/lib/bson/types/regexp_of_holding.rb +0 -45
  46. data/lib/mongo/gridfs.rb +0 -29
  47. data/lib/mongo/gridfs/chunk.rb +0 -91
  48. data/lib/mongo/gridfs/grid_store.rb +0 -580
  49. data/lib/mongo/types/binary.rb +0 -52
  50. data/lib/mongo/types/code.rb +0 -36
  51. data/lib/mongo/types/dbref.rb +0 -40
  52. data/lib/mongo/types/min_max_keys.rb +0 -58
  53. data/lib/mongo/types/objectid.rb +0 -180
  54. data/lib/mongo/types/regexp_of_holding.rb +0 -45
  55. data/lib/mongo/util/bson_c.rb +0 -18
  56. data/lib/mongo/util/bson_ruby.rb +0 -606
  57. data/lib/mongo/util/byte_buffer.rb +0 -222
  58. data/lib/mongo/util/ordered_hash.rb +0 -140
  59. data/test/binary_test.rb +0 -15
  60. data/test/bson_test.rb +0 -459
  61. data/test/byte_buffer_test.rb +0 -81
  62. data/test/chunk_test.rb +0 -82
  63. data/test/grid_store_test.rb +0 -337
  64. data/test/objectid_test.rb +0 -125
  65. data/test/ordered_hash_test.rb +0 -172
@@ -1,125 +0,0 @@
1
- require 'test/test_helper'
2
-
3
- class ObjectIDTest < Test::Unit::TestCase
4
-
5
- include Mongo
6
-
7
- def setup
8
- @o = ObjectID.new
9
- end
10
-
11
- def test_hashcode
12
- assert_equal @o.instance_variable_get(:@data).hash, @o.hash
13
- end
14
-
15
- def test_array_uniq_for_equilavent_ids
16
- a = ObjectID.new('123')
17
- b = ObjectID.new('123')
18
- assert_equal a, b
19
- assert_equal 1, [a, b].uniq.size
20
- end
21
-
22
- def test_create_pk_method
23
- doc = {:name => 'Mongo'}
24
- doc = ObjectID.create_pk(doc)
25
- assert doc[:_id]
26
-
27
- doc = {:name => 'Mongo', :_id => '12345'}
28
- doc = ObjectID.create_pk(doc)
29
- assert_equal '12345', doc[:_id]
30
- end
31
-
32
- def test_different
33
- a = ObjectID.new
34
- b = ObjectID.new
35
- assert_not_equal a.to_a, b.to_a
36
- assert_not_equal a, b
37
- end
38
-
39
- def test_eql?
40
- o2 = ObjectID.new(@o.to_a)
41
- assert_equal @o, o2
42
- end
43
-
44
- def test_to_s
45
- s = @o.to_s
46
- assert_equal 24, s.length
47
- s =~ /^([0-9a-f]+)$/
48
- assert_equal 24, $1.length
49
- end
50
-
51
- def test_inspect
52
- assert_equal "ObjectID('#{@o.to_s}')", @o.inspect
53
- end
54
-
55
- def test_save_and_restore
56
- host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
57
- port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
58
- db = Connection.new(host, port).db('ruby-mongo-test')
59
- coll = db.collection('test')
60
-
61
- coll.remove
62
- coll << {'a' => 1, '_id' => @o}
63
-
64
- row = coll.find().collect.first
65
- assert_equal 1, row['a']
66
- assert_equal @o, row['_id']
67
- end
68
-
69
- def test_from_string
70
- hex_str = @o.to_s
71
- o2 = ObjectID.from_string(hex_str)
72
- assert_equal hex_str, o2.to_s
73
- assert_equal @o, o2
74
- assert_equal @o.to_s, o2.to_s
75
- end
76
-
77
- def test_illegal_from_string
78
- assert_raise InvalidObjectID do
79
- ObjectID.from_string("")
80
- end
81
- end
82
-
83
- def test_legal
84
- assert !ObjectID.legal?(nil)
85
- assert !ObjectID.legal?("fred")
86
- assert !ObjectID.legal?("0000")
87
- assert !ObjectID.legal?('000102030405060708090A0')
88
- assert ObjectID.legal?('000102030405060708090A0B')
89
- assert ObjectID.legal?('abcdefABCDEF123456789012')
90
- assert !ObjectID.legal?('abcdefABCDEF12345678901x')
91
- end
92
-
93
- def test_from_string_leading_zeroes
94
- hex_str = '000000000000000000000000'
95
- o = ObjectID.from_string(hex_str)
96
- assert_equal hex_str, o.to_s
97
- end
98
-
99
- def test_byte_order
100
- hex_str = '000102030405060708090A0B'
101
- o = ObjectID.from_string(hex_str)
102
- assert_equal [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b], o.to_a
103
- end
104
-
105
- def test_generation_time
106
- time = Time.now
107
- id = ObjectID.new
108
- generated_time = id.generation_time
109
-
110
- assert_in_delta time.to_i, generated_time.to_i, 2
111
- assert_equal "UTC", generated_time.zone
112
- end
113
-
114
- def test_from_time
115
- time = Time.now.utc
116
- id = ObjectID.from_time(time)
117
-
118
- assert_equal time.to_i, id.generation_time.to_i
119
- end
120
-
121
- def test_json
122
- id = ObjectID.new
123
- assert_equal "{\"$oid\": \"#{id}\"}", id.to_json
124
- end
125
- end
@@ -1,172 +0,0 @@
1
- require 'test/test_helper'
2
-
3
- class OrderedHashTest < Test::Unit::TestCase
4
-
5
- def setup
6
- @oh = 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 = OrderedHash.new
15
- a['x'] = 1
16
- a['y'] = 2
17
-
18
- b = OrderedHash['x' => 1, 'y' => 2]
19
- assert_equal a, b
20
- end
21
-
22
- def test_hash_code
23
- o = OrderedHash.new
24
- o['number'] = 50
25
- assert o.hash
26
- end
27
-
28
- def test_empty
29
- assert_equal [], OrderedHash.new.keys
30
- end
31
-
32
- def test_uniq
33
- list = []
34
- doc = OrderedHash.new
35
- doc['_id'] = 'ab12'
36
- doc['name'] = 'test'
37
-
38
- same_doc = 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 = OrderedHash.new
50
- a['x'] = 1
51
- a['y'] = 2
52
-
53
- b = OrderedHash.new
54
- b['y'] = 2
55
- b['x'] = 1
56
-
57
- c = OrderedHash.new
58
- c['x'] = 1
59
- c['y'] = 2
60
-
61
- d = OrderedHash.new
62
- d['x'] = 2
63
- d['y'] = 3
64
-
65
- e = 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 = 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 = 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 = 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_update
144
- other = OrderedHash.new
145
- other['f'] = 'foo'
146
- noob = @oh.update(other)
147
- assert_equal @ordered_keys + ['f'], noob.keys
148
- assert_equal [1, 2, 3, 'foo'], noob.values
149
- end
150
-
151
- def test_inspect_retains_order
152
- assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect
153
- end
154
-
155
- def test_clear
156
- @oh.clear
157
- assert @oh.keys.empty?
158
- end
159
-
160
- def test_delete
161
- assert @oh.keys.include?('z')
162
- @oh.delete('z')
163
- assert !@oh.keys.include?('z')
164
- end
165
-
166
- def test_delete_if
167
- assert @oh.keys.include?('z')
168
- @oh.delete_if { |k,v| k == 'z' }
169
- assert !@oh.keys.include?('z')
170
- end
171
-
172
- end