mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge branch 'mongo_multiple' of github.com:nyarly/database_cleaner into nyarly-mongo_multiple
Conflicts: Gemfile Gemfile.lock lib/database_cleaner/mongo/truncation.rb lib/database_cleaner/mongoid/truncation.rb spec/database_cleaner/base_spec.rb
This commit is contained in:
commit
69cc5fc897
5 changed files with 297 additions and 116 deletions
8
Gemfile
8
Gemfile
|
@ -3,8 +3,8 @@ source "http://rubygems.org"
|
|||
|
||||
group :development do
|
||||
gem "rake"
|
||||
#gem "ruby-debug"
|
||||
|
||||
gem "ruby-debug", :platform => :ruby_18
|
||||
gem "ruby-debug19", :platform => :ruby_19
|
||||
gem "bundler"
|
||||
gem "jeweler"
|
||||
|
||||
|
@ -26,7 +26,6 @@ group :development do
|
|||
gem 'mysql', '~> 2.8.1'
|
||||
gem 'mysql2'
|
||||
gem 'pg'
|
||||
gem 'sqlite3'
|
||||
gem 'ohm', '~> 0.1.3'
|
||||
|
||||
gem 'guard-rspec'
|
||||
|
@ -34,9 +33,6 @@ end
|
|||
|
||||
group :test do
|
||||
gem "rspec-rails"
|
||||
#gem "rspactor"
|
||||
#gem "rcov"
|
||||
#gem "ZenTest"
|
||||
end
|
||||
|
||||
group :cucumber do
|
||||
|
|
330
Gemfile.lock
330
Gemfile.lock
|
@ -1,49 +1,143 @@
|
|||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
actionpack (3.2.11)
|
||||
activemodel (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
builder (~> 3.0.0)
|
||||
erubis (~> 2.7.0)
|
||||
journey (~> 1.0.4)
|
||||
rack (~> 1.4.0)
|
||||
rack-cache (~> 1.2)
|
||||
rack-test (~> 0.6.1)
|
||||
sprockets (~> 2.2.1)
|
||||
activemodel (3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
builder (~> 3.0.0)
|
||||
activerecord (3.2.11)
|
||||
activemodel (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
arel (~> 3.0.2)
|
||||
tzinfo (~> 0.3.29)
|
||||
activesupport (3.2.11)
|
||||
i18n (~> 0.6)
|
||||
multi_json (~> 1.0)
|
||||
addressable (2.2.8)
|
||||
arel (3.0.2)
|
||||
bcrypt-ruby (3.0.1)
|
||||
bson (1.8.2)
|
||||
bson_ext (1.8.2)
|
||||
bson (~> 1.8.2)
|
||||
builder (3.0.4)
|
||||
coderay (1.0.8)
|
||||
couch_potato (0.7.1)
|
||||
abstract (1.0.0)
|
||||
actionpack (3.0.0)
|
||||
activemodel (= 3.0.0)
|
||||
activesupport (= 3.0.0)
|
||||
builder (~> 2.1.2)
|
||||
erubis (~> 2.6.6)
|
||||
i18n (~> 0.4.1)
|
||||
rack (~> 1.2.1)
|
||||
rack-mount (~> 0.6.12)
|
||||
rack-test (~> 0.5.4)
|
||||
tzinfo (~> 0.3.23)
|
||||
activemodel (3.0.0)
|
||||
activesupport (= 3.0.0)
|
||||
builder (~> 2.1.2)
|
||||
i18n (~> 0.4.1)
|
||||
activerecord (3.0.0)
|
||||
activemodel (= 3.0.0)
|
||||
activesupport (= 3.0.0)
|
||||
arel (~> 1.0.0)
|
||||
tzinfo (~> 0.3.23)
|
||||
activesupport (3.0.0)
|
||||
addressable (2.3.6)
|
||||
archive-tar-minitar (0.5.2)
|
||||
arel (1.0.1)
|
||||
activesupport (~> 3.0.0)
|
||||
bcrypt (3.1.7)
|
||||
bcrypt-ruby (3.1.5)
|
||||
bcrypt (>= 3.1.3)
|
||||
bson (1.11.1)
|
||||
bson_ext (1.11.1)
|
||||
bson (~> 1.11.1)
|
||||
builder (2.1.2)
|
||||
coderay (1.1.0)
|
||||
columnize (0.8.9)
|
||||
couch_potato (1.3.0)
|
||||
activemodel
|
||||
couchrest (>= 1.0.1)
|
||||
couchrest (~> 1.2.0)
|
||||
json (~> 1.6)
|
||||
couchrest (1.1.3)
|
||||
couchrest (1.2.0)
|
||||
mime-types (~> 1.15)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
rest-client (~> 1.6.1)
|
||||
cucumber (1.2.1)
|
||||
builder (>= 2.1.2)
|
||||
diff-lcs (>= 1.1.3)
|
||||
gherkin (~> 2.11.0)
|
||||
json (>= 1.4.6)
|
||||
data_objects (0.10.11)
|
||||
data_objects (0.10.14)
|
||||
addressable (~> 2.1)
|
||||
datamapper (1.2.0)
|
||||
dm-aggregates (~> 1.2.0)
|
||||
|
@ -60,8 +154,8 @@ GEM
|
|||
dm-core (~> 1.2.0)
|
||||
dm-constraints (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
dm-core (1.2.0)
|
||||
addressable (~> 2.2.6)
|
||||
dm-core (1.2.1)
|
||||
addressable (~> 2.3)
|
||||
dm-do-adapter (1.2.0)
|
||||
data_objects (~> 0.10.6)
|
||||
dm-core (~> 1.2.0)
|
||||
|
@ -90,113 +184,129 @@ GEM
|
|||
uuidtools (~> 2.1)
|
||||
dm-validations (1.2.0)
|
||||
dm-core (~> 1.2.0)
|
||||
do_sqlite3 (0.10.11)
|
||||
data_objects (= 0.10.11)
|
||||
erubis (2.7.0)
|
||||
do_sqlite3 (0.10.14)
|
||||
data_objects (= 0.10.14)
|
||||
erubis (2.6.6)
|
||||
abstract (>= 1.0.0)
|
||||
fastercsv (1.5.5)
|
||||
gherkin (2.11.5)
|
||||
json (>= 1.4.6)
|
||||
git (1.2.5)
|
||||
guard (1.6.1)
|
||||
listen (>= 0.6.0)
|
||||
ffi (1.9.6)
|
||||
formatador (0.2.5)
|
||||
gherkin (2.11.6)
|
||||
json (>= 1.7.6)
|
||||
git (1.2.8)
|
||||
guard (1.8.3)
|
||||
formatador (>= 0.2.4)
|
||||
listen (~> 1.3)
|
||||
lumberjack (>= 1.0.2)
|
||||
pry (>= 0.9.10)
|
||||
thor (>= 0.14.6)
|
||||
guard-rspec (2.3.3)
|
||||
guard-rspec (2.5.4)
|
||||
guard (>= 1.1)
|
||||
rspec (~> 2.11)
|
||||
hike (1.2.1)
|
||||
i18n (0.6.1)
|
||||
i18n (0.4.2)
|
||||
jeweler (1.8.4)
|
||||
bundler (~> 1.0)
|
||||
git (>= 1.2.5)
|
||||
rake
|
||||
rdoc
|
||||
journey (1.0.4)
|
||||
json (1.7.6)
|
||||
json_pure (1.7.6)
|
||||
listen (0.7.1)
|
||||
lumberjack (1.0.2)
|
||||
method_source (0.8.1)
|
||||
mime-types (1.19)
|
||||
mongo (1.8.2)
|
||||
bson (~> 1.8.2)
|
||||
json (1.8.1)
|
||||
json_pure (1.8.1)
|
||||
linecache (0.46)
|
||||
rbx-require-relative (> 0.0.4)
|
||||
linecache19 (0.5.12)
|
||||
ruby_core_source (>= 0.1.4)
|
||||
listen (1.3.1)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
rb-kqueue (>= 0.2)
|
||||
lumberjack (1.0.9)
|
||||
method_source (0.8.2)
|
||||
mime-types (1.25.1)
|
||||
mongo (1.11.1)
|
||||
bson (= 1.11.1)
|
||||
mongo_ext (0.19.3)
|
||||
mongo_mapper (0.12.0)
|
||||
activemodel (~> 3.0)
|
||||
activesupport (~> 3.0)
|
||||
plucky (~> 0.5.2)
|
||||
mongoid (3.0.16)
|
||||
activemodel (~> 3.1)
|
||||
moped (~> 1.1)
|
||||
origin (~> 1.0)
|
||||
mongoid (2.2.6)
|
||||
activemodel (~> 3.0.0)
|
||||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
moped (1.3.2)
|
||||
multi_json (1.5.0)
|
||||
multi_json (1.2.0)
|
||||
mysql (2.8.1)
|
||||
mysql2 (0.3.11)
|
||||
mysql2 (0.3.16)
|
||||
nest (1.1.2)
|
||||
redis
|
||||
ohm (0.1.5)
|
||||
nest (~> 1.0)
|
||||
origin (1.0.11)
|
||||
pg (0.14.1)
|
||||
pg (0.17.1)
|
||||
plucky (0.5.2)
|
||||
mongo (~> 1.5)
|
||||
pry (0.9.10)
|
||||
coderay (~> 1.0.5)
|
||||
method_source (~> 0.8)
|
||||
slop (~> 3.3.1)
|
||||
rack (1.4.3)
|
||||
rack-cache (1.2)
|
||||
rack (>= 0.4)
|
||||
rack-ssl (1.3.2)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
pry (0.10.1)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
rack (1.2.8)
|
||||
rack-mount (0.6.14)
|
||||
rack (>= 1.0.0)
|
||||
rack-test (0.5.7)
|
||||
rack (>= 1.0)
|
||||
railties (3.2.11)
|
||||
actionpack (= 3.2.11)
|
||||
activesupport (= 3.2.11)
|
||||
rack-ssl (~> 1.3.2)
|
||||
rake (>= 0.8.7)
|
||||
rdoc (~> 3.4)
|
||||
thor (>= 0.14.6, < 2.0)
|
||||
rake (10.0.3)
|
||||
rdoc (3.12)
|
||||
railties (3.0.0)
|
||||
actionpack (= 3.0.0)
|
||||
activesupport (= 3.0.0)
|
||||
rake (>= 0.8.4)
|
||||
thor (~> 0.14.0)
|
||||
rake (10.3.2)
|
||||
rb-fsevent (0.9.4)
|
||||
rb-inotify (0.9.5)
|
||||
ffi (>= 0.5.0)
|
||||
rb-kqueue (0.2.3)
|
||||
ffi (>= 0.5.0)
|
||||
rbx-require-relative (0.0.9)
|
||||
rdoc (4.1.2)
|
||||
json (~> 1.4)
|
||||
redis (3.0.4)
|
||||
rest-client (1.6.7)
|
||||
mime-types (>= 1.16)
|
||||
rspec (2.14.1)
|
||||
rspec-core (~> 2.14.0)
|
||||
rspec-expectations (~> 2.14.0)
|
||||
rspec-mocks (~> 2.14.0)
|
||||
rspec-core (2.14.5)
|
||||
rspec-expectations (2.14.2)
|
||||
diff-lcs (>= 1.1.3, < 2.0)
|
||||
rspec-mocks (2.14.3)
|
||||
rspec-rails (2.14.0)
|
||||
redis (3.1.0)
|
||||
rest-client (1.6.8)
|
||||
mime-types (~> 1.16)
|
||||
rdoc (>= 2.4.2)
|
||||
rspec (2.11.0)
|
||||
rspec-core (~> 2.11.0)
|
||||
rspec-expectations (~> 2.11.0)
|
||||
rspec-mocks (~> 2.11.0)
|
||||
rspec-core (2.11.1)
|
||||
rspec-expectations (2.11.3)
|
||||
diff-lcs (~> 1.1.3)
|
||||
rspec-mocks (2.11.3)
|
||||
rspec-rails (2.11.4)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec-core (~> 2.14.0)
|
||||
rspec-expectations (~> 2.14.0)
|
||||
rspec-mocks (~> 2.14.0)
|
||||
rspec (~> 2.11.0)
|
||||
ruby-debug (0.10.4)
|
||||
columnize (>= 0.1)
|
||||
ruby-debug-base (~> 0.10.4.0)
|
||||
ruby-debug-base (0.10.4)
|
||||
linecache (>= 0.3)
|
||||
ruby-debug-base19 (0.11.25)
|
||||
columnize (>= 0.3.1)
|
||||
linecache19 (>= 0.5.11)
|
||||
ruby_core_source (>= 0.1.4)
|
||||
ruby-debug19 (0.11.6)
|
||||
columnize (>= 0.3.1)
|
||||
linecache19 (>= 0.5.11)
|
||||
ruby-debug-base19 (>= 0.11.19)
|
||||
ruby_core_source (0.1.5)
|
||||
archive-tar-minitar (>= 0.5.2)
|
||||
sequel (3.21.0)
|
||||
slop (3.3.3)
|
||||
sprockets (2.2.2)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sqlite3 (1.3.6)
|
||||
slop (3.6.0)
|
||||
sqlite3 (1.3.9)
|
||||
sqlite3-ruby (1.3.3)
|
||||
sqlite3 (>= 1.3.3)
|
||||
stringex (1.5.1)
|
||||
thor (0.16.0)
|
||||
tilt (1.3.3)
|
||||
tzinfo (0.3.35)
|
||||
uuidtools (2.1.3)
|
||||
thor (0.14.6)
|
||||
tzinfo (0.3.41)
|
||||
uuidtools (2.1.5)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
@ -222,6 +332,8 @@ DEPENDENCIES
|
|||
pg
|
||||
rake
|
||||
rspec-rails
|
||||
ruby-debug
|
||||
ruby-debug19
|
||||
sequel (~> 3.21.0)
|
||||
sqlite3
|
||||
sqlite3-ruby
|
||||
|
|
|
@ -12,6 +12,46 @@ module DatabaseCleaner
|
|||
def database
|
||||
db
|
||||
end
|
||||
|
||||
def collections_cache
|
||||
@@collections_cache ||= {}
|
||||
end
|
||||
|
||||
def mongoid_collection_names
|
||||
@@mongoid_collection_names ||= Hash.new{|h,k| h[k]=[]}.tap do |names|
|
||||
ObjectSpace.each_object(Class) do |klass|
|
||||
next unless klass.ancestors.include?(::Mongoid::Document)
|
||||
next if klass.embedded
|
||||
next if klass.collection_name.empty?
|
||||
names[klass.db.name] << klass.collection_name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def not_caching(db_name, list)
|
||||
@@not_caching ||= {}
|
||||
|
||||
unless @@not_caching.has_key?(db_name)
|
||||
@@not_caching[db_name] = true
|
||||
|
||||
puts "Not caching collection names for db #{db_name}. Missing these from models: #{list}"
|
||||
end
|
||||
end
|
||||
|
||||
def collections
|
||||
return collections_cache[database.name] if collections_cache.has_key?(database.name)
|
||||
db_collections = database.collections.select { |c| c.name !~ /^system\./ }
|
||||
|
||||
missing_collections = mongoid_collection_names[database.name] - db_collections.map(&:name)
|
||||
|
||||
if missing_collections.empty?
|
||||
collections_cache[database.name] = db_collections
|
||||
else
|
||||
not_caching(database.name, missing_collections)
|
||||
end
|
||||
|
||||
db_collections
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -30,7 +30,13 @@ module DatabaseCleaner
|
|||
::Mongoid.default_session
|
||||
end
|
||||
|
||||
end
|
||||
def database
|
||||
if not(@db.nil? or @db == :default)
|
||||
::Mongoid.databases[@db]
|
||||
else
|
||||
::Mongoid.database
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -181,7 +181,12 @@ module DatabaseCleaner
|
|||
|
||||
describe "comparison" do
|
||||
it "should be equal if orm, connection and strategy are the same" do
|
||||
<<<<<<< HEAD
|
||||
strategy = double("strategy")
|
||||
=======
|
||||
strategy = mock("strategy")
|
||||
strategy.stub!(:to_ary => [strategy])
|
||||
>>>>>>> bb3dce2558d2888ef581affb0de4d5e55118cd3d
|
||||
|
||||
one = DatabaseCleaner::Base.new(:active_record,:connection => :default)
|
||||
one.strategy = strategy
|
||||
|
@ -248,7 +253,15 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
describe "strategy_db=" do
|
||||
<<<<<<< HEAD
|
||||
let(:strategy) { double("strategy") }
|
||||
=======
|
||||
let(:strategy) {
|
||||
mock("strategy").tap{|strategy|
|
||||
strategy.stub!(:to_ary => [strategy])
|
||||
}
|
||||
}
|
||||
>>>>>>> bb3dce2558d2888ef581affb0de4d5e55118cd3d
|
||||
|
||||
before(:each) do
|
||||
subject.strategy = strategy
|
||||
|
@ -348,7 +361,15 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
describe "strategy=" do
|
||||
<<<<<<< HEAD
|
||||
let(:mock_strategy) { double("strategy") }
|
||||
=======
|
||||
let(:mock_strategy) {
|
||||
mock("strategy").tap{|strategy|
|
||||
strategy.stub!(:to_ary => [strategy])
|
||||
}
|
||||
}
|
||||
>>>>>>> bb3dce2558d2888ef581affb0de4d5e55118cd3d
|
||||
|
||||
it "should proxy symbolised strategies to create_strategy" do
|
||||
subject.should_receive(:create_strategy).with(:symbol)
|
||||
|
@ -388,7 +409,13 @@ module DatabaseCleaner
|
|||
end
|
||||
|
||||
it "returns the set strategy" do
|
||||
<<<<<<< HEAD
|
||||
strategum = double("strategy")
|
||||
=======
|
||||
strategum = mock("strategy").tap{|strategy|
|
||||
strategy.stub!(:to_ary => [strategy])
|
||||
}
|
||||
>>>>>>> bb3dce2558d2888ef581affb0de4d5e55118cd3d
|
||||
subject.strategy = strategum
|
||||
subject.strategy.should eq strategum
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue