mongo_doc 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/.watchr ADDED
@@ -0,0 +1,32 @@
1
+ # vim:set filetype=ruby:
2
+ def run(cmd)
3
+ puts cmd
4
+ system cmd
5
+ end
6
+
7
+ def spec(file)
8
+ if File.exists?(file)
9
+ run("rspec #{file}")
10
+ else
11
+ puts("Spec: #{file} does not exist.")
12
+ end
13
+ end
14
+
15
+ def feature(file)
16
+ if File.exists?(file)
17
+ run("cucumber #{file}")
18
+ else
19
+ puts("Feature: #{file} does not exist.")
20
+ end
21
+ end
22
+
23
+ watch("spec/.*_spec\.rb") do |match|
24
+ puts(match[0])
25
+ spec(match[0])
26
+ end
27
+
28
+ watch("features/.*\.feature") do |match|
29
+ puts(match[0])
30
+ feature(match[0])
31
+ end
32
+
data/README.textile CHANGED
@@ -156,6 +156,17 @@ Finally, if you do not want to use the database configuration file, you can also
156
156
 
157
157
  bc. MongoDoc::Connection.name = 'stats'
158
158
 
159
+ h2. Cleaning the database during testing
160
+
161
+ When testing you may need to clean up and return the database to an empty state. @MongoDoc::DatabaseCleaner.clean_database@ is a helper that can be used to do this, for example with @RSpec@ (note the @require@):
162
+
163
+ bc. require 'mongo_doc/database_cleaner'
164
+ RSpec.configure do |config|
165
+ config.before(:each) do
166
+ MongoDoc::DatabaseCleaner.clean_database
167
+ end
168
+ end
169
+
159
170
  h2. Credits
160
171
 
161
172
  Les Hill, leshill on github
data/Rakefile CHANGED
@@ -64,21 +64,6 @@ Rake::RDocTask.new do |rdoc|
64
64
  rdoc.rdoc_files.include('lib/**/*.rb')
65
65
  end
66
66
 
67
- namespace :mongo do
68
- desc 'Start mongod'
69
- task :start do
70
- default_config = { "dbpath" => "/data/db" }
71
- config = begin
72
- YAML.load_file(File.join(File.dirname(__FILE__), 'mongod.yml'))
73
- rescue Exception => e
74
- {}
75
- end
76
- config = default_config.merge(config)
77
- sh("nohup #{config['mongod'] || 'mongod'} --dbpath #{config['dbpath']} &")
78
- puts "\n"
79
- end
80
- end
81
-
82
67
  namespace :mongoid do
83
68
  desc 'Sync criteria from Mongoid'
84
69
  task :sync do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
@@ -0,0 +1,9 @@
1
+ module MongoDoc
2
+ module DatabaseCleaner
3
+ extend self
4
+
5
+ def clean_database
6
+ MongoDoc::Connection.database.collections.select {|c| c.name !~ /^system/}.each {|c| MongoDoc::Connection.database.drop_collection(c.name)}
7
+ end
8
+ end
9
+ end
data/mongo_doc.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongo_doc}
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Les Hill"]
12
- s.date = %q{2010-06-25}
12
+ s.date = %q{2010-06-27}
13
13
  s.description = %q{ODM for MongoDB}
14
14
  s.email = %q{leshill@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  ".gitignore",
23
23
  ".rspec",
24
24
  ".rvmrc",
25
+ ".watchr",
25
26
  "Gemfile",
26
27
  "HISTORY.md",
27
28
  "LICENSE",
@@ -29,7 +30,6 @@ Gem::Specification.new do |s|
29
30
  "Rakefile",
30
31
  "TODO",
31
32
  "VERSION",
32
- "data/.gitignore",
33
33
  "examples/simple_document.rb",
34
34
  "examples/simple_object.rb",
35
35
  "features/collections.feature",
@@ -76,6 +76,7 @@ Gem::Specification.new do |s|
76
76
  "lib/mongo_doc/contexts/mongo.rb",
77
77
  "lib/mongo_doc/criteria.rb",
78
78
  "lib/mongo_doc/cursor.rb",
79
+ "lib/mongo_doc/database_cleaner.rb",
79
80
  "lib/mongo_doc/document.rb",
80
81
  "lib/mongo_doc/ext.rb",
81
82
  "lib/mongo_doc/ext/array.rb",
@@ -124,7 +125,6 @@ Gem::Specification.new do |s|
124
125
  "lib/mongoid/matchers/nin.rb",
125
126
  "lib/mongoid/matchers/size.rb",
126
127
  "mongo_doc.gemspec",
127
- "mongod.example.yml",
128
128
  "mongodb.example.yml",
129
129
  "perf/mongo_doc_object.rb",
130
130
  "perf/mongo_document.rb",
@@ -147,6 +147,7 @@ Gem::Specification.new do |s|
147
147
  "spec/contexts_spec.rb",
148
148
  "spec/criteria_spec.rb",
149
149
  "spec/cursor_spec.rb",
150
+ "spec/database_cleaner_spec.rb",
150
151
  "spec/document_ext.rb",
151
152
  "spec/document_spec.rb",
152
153
  "spec/embedded_save_spec.rb",
@@ -186,6 +187,7 @@ Gem::Specification.new do |s|
186
187
  "spec/contexts_spec.rb",
187
188
  "spec/criteria_spec.rb",
188
189
  "spec/cursor_spec.rb",
190
+ "spec/database_cleaner_spec.rb",
189
191
  "spec/document_ext.rb",
190
192
  "spec/document_spec.rb",
191
193
  "spec/embedded_save_spec.rb",
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'mongo_doc/database_cleaner'
3
+
4
+ describe "MongoDoc::DatabaseCleaner" do
5
+
6
+ describe "#clean_database" do
7
+
8
+ let(:collections) { [people_collection, system_collection, remove_system_collection] }
9
+ let(:database) { stub(:collections => collections) }
10
+ let(:people_collection) { stub(:name => 'people_collection') }
11
+ let(:system_collection) { stub(:name => 'system_collection') }
12
+ let(:remove_system_collection) { stub(:name => 'remove_this_non_system_collection') }
13
+
14
+ before do
15
+ MongoDoc::Connection.stub(:database).and_return(database)
16
+ end
17
+
18
+ it "removes all the non-system collections" do
19
+ MongoDoc::Connection.database.should_receive(:drop_collection).with(people_collection.name)
20
+ MongoDoc::Connection.database.should_receive(:drop_collection).with(remove_system_collection.name)
21
+ MongoDoc::DatabaseCleaner.clean_database
22
+ end
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_doc
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 2
10
- version: 0.6.2
9
+ - 3
10
+ version: 0.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Les Hill
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-25 00:00:00 -04:00
18
+ date: 2010-06-27 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -151,6 +151,7 @@ files:
151
151
  - .gitignore
152
152
  - .rspec
153
153
  - .rvmrc
154
+ - .watchr
154
155
  - Gemfile
155
156
  - HISTORY.md
156
157
  - LICENSE
@@ -158,7 +159,6 @@ files:
158
159
  - Rakefile
159
160
  - TODO
160
161
  - VERSION
161
- - data/.gitignore
162
162
  - examples/simple_document.rb
163
163
  - examples/simple_object.rb
164
164
  - features/collections.feature
@@ -205,6 +205,7 @@ files:
205
205
  - lib/mongo_doc/contexts/mongo.rb
206
206
  - lib/mongo_doc/criteria.rb
207
207
  - lib/mongo_doc/cursor.rb
208
+ - lib/mongo_doc/database_cleaner.rb
208
209
  - lib/mongo_doc/document.rb
209
210
  - lib/mongo_doc/ext.rb
210
211
  - lib/mongo_doc/ext/array.rb
@@ -253,7 +254,6 @@ files:
253
254
  - lib/mongoid/matchers/nin.rb
254
255
  - lib/mongoid/matchers/size.rb
255
256
  - mongo_doc.gemspec
256
- - mongod.example.yml
257
257
  - mongodb.example.yml
258
258
  - perf/mongo_doc_object.rb
259
259
  - perf/mongo_document.rb
@@ -276,6 +276,7 @@ files:
276
276
  - spec/contexts_spec.rb
277
277
  - spec/criteria_spec.rb
278
278
  - spec/cursor_spec.rb
279
+ - spec/database_cleaner_spec.rb
279
280
  - spec/document_ext.rb
280
281
  - spec/document_spec.rb
281
282
  - spec/embedded_save_spec.rb
@@ -343,6 +344,7 @@ test_files:
343
344
  - spec/contexts_spec.rb
344
345
  - spec/criteria_spec.rb
345
346
  - spec/cursor_spec.rb
347
+ - spec/database_cleaner_spec.rb
346
348
  - spec/document_ext.rb
347
349
  - spec/document_spec.rb
348
350
  - spec/embedded_save_spec.rb
data/data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- *
2
- !.gitignore
data/mongod.example.yml DELETED
@@ -1,2 +0,0 @@
1
- mongod: /usr/local/bin/mongod
2
- dbpath: /data/db