From b5d71d97024dc0e2a618b57cd1eb22ac0c054382 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Thu, 20 Aug 2009 14:03:25 -0400 Subject: [PATCH] add back in XGen::Mongo paths with deprecation warning on include - THIS WILL BE REMOVED --- lib/mongo.rb | 34 ++++++++++++++++++ mongo-ruby-driver.gemspec | 3 +- test/test_xgen.rb | 73 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 test/test_xgen.rb diff --git a/lib/mongo.rb b/lib/mongo.rb index d86bb50..0df79bb 100644 --- a/lib/mongo.rb +++ b/lib/mongo.rb @@ -16,3 +16,37 @@ module Mongo ASCENDING = 1 DESCENDING = -1 end + +# DEPRECATED - the XGen namespace is deprecated and will be removed - use Mongo or GridFS instead +MongoCopy = Mongo +module XGen + require 'mongo/gridfs' + GridFSCopy = GridFS + + def self.included(other_module) + warn "the XGen module is deprecated and will be removed - use Mongo or GridFS instead (included from: #{other_module})" + end + + module Mongo + include MongoCopy + + def self.included(other_module) + warn "the XGen::Mongo module is deprecated and will be removed - use Mongo instead (included from: #{other_module})" + end + + module Driver + include MongoCopy + + def self.included(other_module) + warn "the XGen::Mongo::Driver module is deprecated and will be removed - use Mongo instead (included from: #{other_module})" + end + end + module GridFS + include GridFSCopy + + def self.included(other_module) + warn "the XGen::Mongo::GridFS module is deprecated and will be removed - use GridFS instead (included from: #{other_module})" + end + end + end +end diff --git a/mongo-ruby-driver.gemspec b/mongo-ruby-driver.gemspec index 8f1d037..a2141f3 100644 --- a/mongo-ruby-driver.gemspec +++ b/mongo-ruby-driver.gemspec @@ -78,7 +78,8 @@ TEST_FILES = ['test/mongo-qa/_common.rb', 'test/test_objectid.rb', 'test/test_ordered_hash.rb', 'test/test_threading.rb', - 'test/test_round_trip.rb'] + 'test/test_round_trip.rb', + 'test/test_xgen.rb'] Gem::Specification.new do |s| s.name = 'mongo' diff --git a/test/test_xgen.rb b/test/test_xgen.rb new file mode 100644 index 0000000..0696877 --- /dev/null +++ b/test/test_xgen.rb @@ -0,0 +1,73 @@ +# Copyright (C) 2009 10gen Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') +require 'mongo' +require 'test/unit' + +# TODO these tests should be removed - just testing for the deprecated +# XGen::Mongo::Driver include path +class TestXGen < Test::Unit::TestCase + @@db = XGen::Mongo::Driver::Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@test = @@db.collection('test') + + def setup + @@test.clear + end + + def test_sort + @@test.save('x' => 2) + @@test.save('x' => 1) + @@test.save('x' => 3) + + assert_equal 1, @@test.find({}, :sort => {'x' => XGen::Mongo::ASCENDING}).to_a()[0]['x'] + assert_equal 3, @@test.find({}, :sort => {'x' => XGen::Mongo::DESCENDING}).to_a()[0]['x'] + end + + def test_gridfs + XGen::Mongo::GridFS::GridStore.open(@@db, 'foobar', 'w') { |f| f.write('hello world!') } + assert XGen::Mongo::GridFS::GridStore.exist?(@@db, 'foobar') + assert !XGen::Mongo::GridFS::GridStore.exist?(@@db, 'mike') + end +end + +class TestXGenInclude < Test::Unit::TestCase + include XGen::Mongo::GridFS + include XGen::Mongo::Driver + include XGen::Mongo + + @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test') + @@test = @@db.collection('test') + + def setup + @@test.clear + end + + def test_sort + @@test.save('x' => 2) + @@test.save('x' => 1) + @@test.save('x' => 3) + + assert_equal 1, @@test.find({}, :sort => {'x' => ASCENDING}).to_a()[0]['x'] + assert_equal 3, @@test.find({}, :sort => {'x' => DESCENDING}).to_a()[0]['x'] + end + + def test_gridfs + GridStore.open(@@db, 'foobar', 'w') { |f| f.write('hello world!') } + assert GridStore.exist?(@@db, 'foobar') + assert !GridStore.exist?(@@db, 'mike') + end +end