mongodb-mongo 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -133,17 +133,16 @@ The tests assume that the Mongo database is running on the default port.
133
133
 
134
134
  The project mongo-qa (http://github.com/mongodb/mongo-qa) contains many more
135
135
  Mongo driver tests that are language independent. To run thoses tests as part
136
- of the "rake test" task, run
136
+ of the "rake test" task, download the code "next to" this directory. So, after
137
+ installing the mongo-qa code you would have these two directories next to each
138
+ other:
137
139
 
138
- $ rake mongo_qa
140
+ $ ls
141
+ mongo-qa
142
+ mongo-ruby-driver
139
143
  $ rake test
140
144
 
141
- The mongo_qa task uses the "git clone" command to make a copy of that project
142
- in a directory named mongo-qa. If the directory already exists, then the
143
- mongo_qa task uses "git pull" to updated the code that's there. The Ruby
144
- driver tests will then use some of the data files from that project when it
145
- runs BSON tests. You can delete this directory at any time if you don't want
146
- to run those tests any more.
145
+ The tests run just fine if the mongo-qa directory is not there.
147
146
 
148
147
  Additionally, the script bin/validate is used by the mongo-qa project's
149
148
  validator script.
data/Rakefile CHANGED
@@ -11,17 +11,6 @@ Rake::TestTask.new do |t|
11
11
  t.test_files = FileList['tests/test*.rb']
12
12
  end
13
13
 
14
- desc "Clone or pull (update) the mongo-qa project used for testing"
15
- task :mongo_qa do
16
- if File.exist?('mongo-qa')
17
- Dir.chdir('mongo-qa') do
18
- system('git pull')
19
- end
20
- else
21
- system('git clone git://github.com/mongodb/mongo-qa.git')
22
- end
23
- end
24
-
25
14
  desc "Generate documentation"
26
15
  task :rdoc do
27
16
  FileUtils.rm_rf('html')
@@ -80,9 +80,9 @@ class BSON
80
80
  @buf.put_int(0)
81
81
 
82
82
  # Write key/value pairs. Always write _id first if it exists.
83
- oid = obj.delete('_id') || obj.delete(:_id)
83
+ oid = obj['_id'] || obj[:_id]
84
84
  serialize_key_value('_id', oid) if oid
85
- obj.each {|k, v| serialize_key_value(k, v) }
85
+ obj.each {|k, v| serialize_key_value(k, v) unless k == '_id' || k == :_id }
86
86
 
87
87
  serialize_eoo_element(@buf)
88
88
  @buf.put_int(@buf.size, 0)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongo'
3
- s.version = '0.3.0'
3
+ s.version = '0.3.1'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
6
6
  s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
data/tests/test_bson.rb CHANGED
@@ -155,4 +155,18 @@ class BSONTest < Test::Unit::TestCase
155
155
  assert_equal '_id', roundtrip.keys.first
156
156
  end
157
157
 
158
+ def test_do_not_change_original_object
159
+ val = OrderedHash.new
160
+ val['not_id'] = 1
161
+ val['_id'] = 2
162
+ assert val.keys.include?('_id')
163
+ @b.serialize(val)
164
+ assert val.keys.include?('_id')
165
+
166
+ val = {'a' => 'foo', 'b' => 'bar', :_id => 42, 'z' => 'hello'}
167
+ assert val.keys.include?(:_id)
168
+ @b.serialize(val)
169
+ assert val.keys.include?(:_id)
170
+ end
171
+
158
172
  end
data/tests/test_mongo.rb CHANGED
@@ -14,31 +14,41 @@ class MongoTest < Test::Unit::TestCase
14
14
  end
15
15
 
16
16
  def test_database_info
17
+ @mongo.drop_database('ruby-mongo-info-test')
18
+ @mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
19
+
17
20
  info = @mongo.database_info
18
21
  assert_not_nil info
19
22
  assert_kind_of Hash, info
20
- assert_not_nil info['admin']
21
- assert info['admin'] > 0
23
+ assert_not_nil info['ruby-mongo-info-test']
24
+ assert info['ruby-mongo-info-test'] > 0
25
+
26
+ @mongo.drop_database('ruby-mongo-info-test')
22
27
  end
23
28
 
24
29
  def test_database_names
30
+ @mongo.drop_database('ruby-mongo-info-test')
31
+ @mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
32
+
25
33
  names = @mongo.database_names
26
34
  assert_not_nil names
27
35
  assert_kind_of Array, names
28
36
  assert names.length >= 1
29
- assert names.include?('admin')
37
+ assert names.include?('ruby-mongo-info-test')
38
+
39
+ @mongo.drop_database('ruby-mongo-info-test')
30
40
  end
31
41
 
32
42
  def test_drop_database
33
- db = @mongo.db('will-be-deleted')
43
+ db = @mongo.db('ruby-mongo-will-be-deleted')
34
44
  coll = db.collection('temp')
35
45
  coll.clear
36
46
  coll.insert(:name => 'temp')
37
47
  assert_equal 1, coll.count()
38
- assert @mongo.database_names.include?('will-be-deleted')
48
+ assert @mongo.database_names.include?('ruby-mongo-will-be-deleted')
39
49
 
40
- @mongo.drop_database('will-be-deleted')
41
- assert !@mongo.database_names.include?('will-be-deleted')
50
+ @mongo.drop_database('ruby-mongo-will-be-deleted')
51
+ assert !@mongo.database_names.include?('ruby-mongo-will-be-deleted')
42
52
  end
43
53
 
44
54
  def test_pair
@@ -8,9 +8,9 @@ require 'test/unit'
8
8
  # OrderedHash and then test both Ruby-to-BSON and BSON-to-Ruby translations.
9
9
  #
10
10
  # There is a whole other project that includes similar tests
11
- # (http://github.com/mongodb/mongo-qa). If the directory ../mongo-qa exists,
12
- # then we find the BSON test files there and use those, too. Use the Rake task
13
- # "mongo_qa" to obtain those tests.
11
+ # (http://github.com/mongodb/mongo-qa). If the directory ../../mongo-qa
12
+ # exists, (that is, the top-level dir of mongo-qa is next to the top-level dir
13
+ # of this project), then we find the BSON test files there and use those, too.
14
14
  class RoundTripTest < Test::Unit::TestCase
15
15
 
16
16
  include XGen::Mongo::Driver
@@ -47,7 +47,7 @@ EOS
47
47
  # Dynamically generate one test for each test file. This way, if one test
48
48
  # fails the others will still run.
49
49
  create_test_for_round_trip_files_in_dir(File.join(HERE, 'data'))
50
- mongo_qa_dir = File.join(HERE, '..', 'mongo-qa/modules/bson_tests/tests')
50
+ mongo_qa_dir = File.join(HERE, '../..', 'mongo-qa/modules/bson_tests/tests')
51
51
  if File.exist?(mongo_qa_dir)
52
52
  %w(basic_types complex single_types).each { |subdir_name|
53
53
  create_test_for_round_trip_files_in_dir(File.join(mongo_qa_dir, subdir_name))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard