Skip to content
Browse files

ruby 1.9.2 ready, Gemfile for bundler and tests run with rspec

  • Loading branch information...
1 parent 6abbcd1 commit adfe68b2cdd1ebea6915b620da29c6e48cac344e @oma oma committed Sep 3, 2010
Showing with 71 additions and 11 deletions.
  1. +1 −0 .gitignore
  2. +9 −0 Gemfile
  3. +36 −0 Gemfile.lock
  4. +1 −1 lib/heroku/command/mongo.rb
  5. +24 −10 spec/mongo_spec.rb
View
1 .gitignore
@@ -0,0 +1 @@
+.bundle
View
9 Gemfile
@@ -0,0 +1,9 @@
+# run 'gem install bundler'
+# then 'bundle install' to get ready and set for coding
+source :gemcutter
+
+gem 'heroku'
+gem 'mongo'
+gem 'rspec'
+gem 'mocha'
+
View
36 Gemfile.lock
@@ -0,0 +1,36 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ bacon (1.1.0)
+ baconmocha (0.0.2)
+ bacon
+ mocha (>= 0.9.6)
+ bson (1.0.4)
+ configuration (1.1.0)
+ heroku (1.9.14)
+ json_pure (>= 1.2.0, < 1.5.0)
+ launchy (~> 0.3.2)
+ rest-client (~> 1.4.0)
+ json_pure (1.4.6)
+ launchy (0.3.7)
+ configuration (>= 0.0.5)
+ rake (>= 0.8.1)
+ mime-types (1.16)
+ mocha (0.9.8)
+ rake
+ mongo (1.0.7)
+ bson (>= 1.0.4)
+ rake (0.8.7)
+ rest-client (1.4.2)
+ mime-types (>= 1.16)
+ rspec (1.3.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ baconmocha
+ heroku
+ mocha
+ mongo
+ rspec
View
2 lib/heroku/command/mongo.rb
@@ -62,7 +62,7 @@ def local_mongo_uri
end
def make_uri(url)
- url.gsub!('local.mongohq.com', 'mongohq.com')
+ url = url.gsub('local.mongohq.com', 'mongohq.com')
uri = URI.parse(url)
raise URI::InvalidURIError unless uri.host
uri
View
34 spec/mongo_spec.rb
@@ -1,15 +1,19 @@
+#run as 'spec spec'
require 'rubygems'
require 'mongo'
-require 'baconmocha'
+require 'mocha'
$: << File.dirname(__FILE__) + '/../lib'
require 'heroku'
require 'heroku/command'
require 'heroku/command/mongo'
+include Mocha::API
describe Heroku::Command::Mongo do
+
before do
@mongo = Heroku::Command::Mongo.new ['--app', 'myapp']
+ #@mongo.context()
@mongo.stubs(:app).returns('myapp')
@mongo.stubs(:display)
end
@@ -34,33 +38,34 @@
uri = @mongo.send(:make_uri, 'mongodb://root:secret@hatch.local.mongohq.com/mydb')
uri.host.should == 'hatch.mongohq.com'
end
-
+
+ #cleanup mocks after use. The integration tests that follow require the real thing
+ after do
+ mocha_verify
+ mocha_teardown
+ end
+
describe "Integration test" do
before do
conn = Mongo::Connection.new
@from = conn.db('heroku-mongo-sync-origin')
- @from_uri = URI.parse('mongodb://localhost/heroku-mongo-sync-origin')
+ @from_uri = URI.parse('mongodb://localhost:27017/heroku-mongo-sync-origin')
@to = conn.db('heroku-mongo-sync-dest')
- @to_uri = URI.parse('mongodb://localhost/heroku-mongo-sync-dest')
+ @to_uri = URI.parse('mongodb://localhost:27017/heroku-mongo-sync-dest')
clear_collections
end
after do
clear_collections
end
- def clear_collections
- @from.collections.each { |c| c.drop }
- @to.collections.each { |c| c.drop }
- end
-
it "transfers records" do
col = @from.create_collection('a')
col.insert(:id => 1, :name => 'first')
col.insert(:id => 2, :name => 'second')
@mongo.send(:transfer, @from_uri, @to_uri)
- @to.collection_names.should.include('a')
+ @to.collection_names.should include('a')
@to.collection('a').find_one(:id => 1)['name'].should == 'first'
end
@@ -74,4 +79,13 @@ def clear_collections
@to.collection('a').size.should == 1
end
end
+
+ def clear_collections
+ @from.collections.each { |c| c.drop unless sys_indexes?(c)}
+ @to.collections.each { |c| c.drop unless sys_indexes?(c)}
+ end
+
+ def sys_indexes?(c)
+ c.name == 'system.indexes'
+ end
end

0 comments on commit adfe68b

Please sign in to comment.
Something went wrong with that request. Please try again.