Commit 2cbe0207 authored by Antonio Terceiro's avatar Antonio Terceiro

Imported Upstream version 1.5.1

parent 9c5ad27e
# Guidelines for contributing
## 1. Fork & Clone
Since you probably don't have rights to the main repo, you should Fork it (big
button up top). After that, clone your fork locally and optionally add an
upstream:
git remote add upstream git@github.com:DatabaseCleaner/database_cleaner.git
## 2. Make sure the tests run fine
- `bundle install`
- Copy `db/sample.config.yml` to `db/config.yml` and edit it
- Make sure to create the databases specified in `db/config.yml`
- Run the tests with `bundle exec rspec`
Note that if you don't have all the supported databases installed and running,
some tests will fail.
## 3. Prepare your contribution
This is all up to you but a few points should be kept in mind:
- Please write tests for your contribution
- Make sure that previous tests still pass
- Push it to a branch of your fork
- Submit a pull request
PATH
remote: .
specs:
database_cleaner (1.5.1)
GEM
remote: http://rubygems.org/
remote: https://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)
activerecord-mysql2-adapter (0.0.3)
mysql2
activesupport (3.0.0)
addressable (2.3.6)
arel (1.0.1)
activesupport (~> 3.0.0)
bcrypt (3.1.7)
bcrypt (3.1.7-java)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
bcrypt-ruby (3.1.5-java)
bcrypt (>= 3.1.3)
bson (1.11.1)
bson (1.11.1-java)
bson_ext (1.11.1)
bson (~> 1.11.1)
builder (2.1.2)
coderay (1.1.0)
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)
rest-client (~> 1.6.1)
......@@ -43,7 +57,7 @@ GEM
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 +74,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,139 +104,180 @@ 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_jdbc (0.10.14-java)
data_objects (= 0.10.14)
do_sqlite3 (0.10.14)
data_objects (= 0.10.14)
do_sqlite3 (0.10.14-java)
data_objects (= 0.10.14)
do_jdbc (= 0.10.14)
jdbc-sqlite3 (>= 3.5.8)
erubis (2.6.6)
abstract (>= 1.0.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.1)
faraday (>= 0.7.4, < 0.10)
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)
ffi (1.9.6-java)
formatador (0.2.5)
gherkin (2.11.6)
json (>= 1.7.6)
gherkin (2.11.6-java)
json (>= 1.7.6)
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)
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)
httparty (0.13.3)
json (~> 1.8)
multi_xml (>= 0.5.2)
httpclient (2.5.3.3)
i18n (0.4.2)
jdbc-sqlite3 (3.8.10.1)
json (1.8.1)
json (1.8.1-java)
json_pure (1.8.1)
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)
mysql (2.8.1)
mysql2 (0.3.11)
mongoid-tree (0.7.0)
mongoid (~> 2.0)
moped (1.5.2)
multi_json (1.2.0)
multi_xml (0.5.5)
multipart-post (2.0.0)
mysql (2.9.1)
mysql2 (0.3.18)
neo4j-community (2.1.5)
neo4j-core (3.0.8)
activesupport
faraday (~> 0.9.0)
faraday_middleware (~> 0.9.1)
httparty
httpclient
json
neo4j-community (~> 2.1.1)
net-http-persistent
os
zip
nest (1.1.2)
redis
net-http-persistent (2.9.4)
ohm (0.1.5)
nest (~> 1.0)
origin (1.0.11)
pg (0.14.1)
os (0.9.6)
pg (0.18.2)
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)
pry (0.10.1-java)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
spoon (~> 0.0)
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)
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)
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)
sqlite3-ruby (1.3.3)
sqlite3 (>= 1.3.3)
slop (3.6.0)
spoon (0.0.4)
ffi
sqlite3 (1.3.10)
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)
zip (2.0.2)
PLATFORMS
java
ruby
DEPENDENCIES
activerecord
activerecord-mysql2-adapter
bson_ext
bundler
couch_potato
cucumber
database_cleaner!
datamapper
dm-migrations
dm-sqlite-adapter
guard-rspec
jeweler
json_pure
mongo_ext
mongo_mapper
mongoid
mysql (~> 2.8.1)
mongoid-tree
moped
mysql (~> 2.9.1)
mysql2
neo4j-core
ohm (~> 0.1.3)
pg
rake
rspec-rails
rspec-rails (~> 2.11.0)
sequel (~> 3.21.0)
sqlite3
sqlite3-ruby
tzinfo
BUNDLED WITH
1.10.5
== Development (master)
== 1.4.1 2015-03-09
* Support for deletion with Sequel. (@cyberdelia)
* Use ActiveRecord::Base configuration when different from config file. (@wendy0402)
* Removed dependency of Mongo. (@codegourmet)
* Fixed issue with tables schema prefix in Postgres. (@phoenixek12)
* Use ruby 1.8 syntax. (@daniel-g)
* Added license to gemspec. (@chrismar035)
* Improved coverage for migrations table. (@jonallured)
== 1.4.0 2014-12-17
=== New Features/Changes
* Support for Neo4j. (@dpisarewski)
* Support for multiple connections on Mongoid. (@nyarly)
=== Better Performance
* Using the deletion strategy with Mysql now only deletes those tables which have had records added to them. (@MadRabbit)
* Add support for pre_count on Sequel with Mysql. (@vrinek)
* Cache collection names in mongo's truncation strategy. (@nyarly)
=== Bug Fixes
* Fix undefined method error with DataMapper SQLite adaptor. (@lanej)
* Fully define Mysql2 adaptor constant. (@jgonera)
* Don't truncate schema tables in Postgres. (@billywatson)
* Fix issue where Moped cleaner was missing collections with 'system' in their name. (@MartinNowak)
== 1.3.0 2014-05-23
=== New Features/Changes
* Introduced `DatabaseCleaener::cleaninng` method that takes a block. (@ethco)
* Introduced `DatabaseCleaner::cleaning` method that takes a block. (@ethco)
* Improved Sequel support and added more tests (@ethco, @rhunter)
=== Bug Fixes
......
......@@ -7,7 +7,7 @@ Each strategy is a small amount of code but is code that is usually needed in an
ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
[![Build Status](https://secure.travis-ci.org/bmabey/database_cleaner.png)](http://travis-ci.org/bmabey/database_cleaner)
[![Build Status](https://travis-ci.org/DatabaseCleaner/database_cleaner.svg?branch=master)](https://travis-ci.org/DatabaseCleaner/database_cleaner) [![Code Climate](https://codeclimate.com/github/DatabaseCleaner/database_cleaner/badges/gpa.svg)](https://codeclimate.com/github/DatabaseCleaner/database_cleaner)
Here is an overview of the strategies supported for each library:
......@@ -67,9 +67,17 @@ Here is an overview of the strategies supported for each library:
<td>No</td>
<td>No</td>
</tr>
<tr>
<td>Neo4j</td>
<td>Yes</td>
<td>Yes*</td>
<td>Yes*</td>
</tr>
</tbody>
</table>
* Truncation and Deletion strategies for Neo4j will just delete all nodes and relationships from the database.
<table>
<tbody>
<tr>
......@@ -189,7 +197,7 @@ The following options are available for ActiveRecord's `:truncation` strategy _o
The following option is available for ActiveRecord's `:truncation` and `:deletion` strategy for any DB.
* `:cache_tables` - When set to `true` the list of tables to truncate or delete from will only be read from the DB once, otherwise it will be read before each cleanup run. Set this to `false` if you create and drop tables in your tests. Defaults to `true`.
* `:cache_tables` - When set to `true` the list of tables to truncate or delete from will only be read from the DB once, otherwise it will be read before each cleanup run. Set this to `false` if (1) you create and drop tables in your tests, or (2) you change Postgres schemas (`ActiveRecord::Base.connection.schema_search_path`) in your tests (for example, in a multitenancy setup with each tenant in a different Postgres schema). Defaults to `true`.
### RSpec Example
......@@ -211,12 +219,38 @@ RSpec.configure do |config|
end
```
### RSpec with Capybara Example
If you're using Capybara with RSpec and using an external browser (not using RackTest) you'll almost certainly need to use truncation rather than transactions for tests tagged `:js`.
```ruby
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
```
### Minitest Example
```ruby
DatabaseCleaner.strategy = :transaction
class MiniTest::Spec
class Minitest::Spec
before :each do
DatabaseCleaner.start
end
......@@ -271,10 +305,10 @@ DatabaseCleaner[:active_record].strategy = :transaction
DatabaseCleaner[:mongo_mapper].strategy = :truncation
#How to specify particular connections
DatabaseCleaner[:active_record,{:connection => :two}]
DatabaseCleaner[:active_record, { :connection => :two }]
# You may also pass in the model directly:
DatabaseCleaner[:active_record,{:model => ModelWithDifferentConnection}]
DatabaseCleaner[:active_record, { :model => ModelWithDifferentConnection }]
```
Usage beyond that remains the same with `DatabaseCleaner.start` calling any setup on the different configured connections, and `DatabaseCleaner.clean` executing afterwards.
......@@ -333,6 +367,11 @@ Usage beyond that remains the same with `DatabaseCleaner.start` calling any setu
<td><code>DatabaseCleaner[:ohm]</code></td>
<td>Connection specified as Redis URI</td>
</tr>
<tr>
<td>Neo4j</td>
<td><code>DatabaseCleaner[:neo4j]</code></td>
<td>Database type and path(URI) <code>DatabaseCleaner[:neo4j, connection: {type: :server_db, path: 'http://localhost:7475'}].</code></td>
</tr>
</tbody>
</table>
......@@ -359,15 +398,39 @@ DatabaseCleaner[:mongoid].strategy = :truncation
### STDERR is being flooded when using Postgres
If you are using Postgres and have foreign key constraints, the truncation strategy will cause a lot of extra noise to appear on STDERR (in the form of "NOTICE truncate cascades" messages). To silence these warnings set the following log level in your `postgresql.conf` file:
If you are using Postgres and have foreign key constraints, the truncation strategy will cause a lot of extra noise to appear on STDERR (in the form of "NOTICE truncate cascades" messages).
To silence these warnings set the following log level in your `postgresql.conf` file:
```ruby
client_min_messages = warning
```
For ActiveRecord, you add the following parameter in your database.yml file:
<pre>
test:
adapter: postgresql
# ...
min_messages: WARNING
</pre>
### Nothing happens in JRuby with Sequel using transactions
Due to an inconsistency in JRuby's implementation of Fibers, Sequel gives a different connection to `DatabaseCleaner.start` than is used for tests run between `.start` and `.clean`. This can be worked around by running your tests in a block like `DatabaseCleaner.cleaning { run_my_tests }` instead, which does not use Fibers.
Due to an inconsistency in JRuby's implementation of Fibers, Sequel gives a different connection to `DatabaseCleaner.start` than is used for tests run between `.start` and `.clean`. This can be worked around by running your tests in a block like `DatabaseCleaner.cleaning { run_my_tests }` instead, which does not use Fibers.
### Model fails to load with Neo4j using transactions
When you are using [neo4j](https://github.com/neo4jrb/neo4j) gem it creates schema and reads indexes upon loading models. These operations can't be done during a transaction. You have to preload your models before DatabaseCleaner starts a transaction.
Add to your rails_helper or spec_helper after requiring database_cleaner:
```ruby
require 'database_cleaner'
Dir["#{Rails.root}/app/models/**/*.rb"].each do |model|
load model
end
```
## Debugging
......@@ -382,4 +445,4 @@ DatabaseCleaner.logger = Rails.logger
## COPYRIGHT
Copyright (c) 2009 Ben Mabey. See LICENSE for details.
Copyright (c) 2014 Ben Mabey. See LICENSE for details.
......@@ -3,26 +3,10 @@ require "bundler"
Bundler.setup
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "database_cleaner"
s.summary = %Q{Strategies for cleaning databases. Can be used to ensure a clean state for testing.}
s.email = "ben@benmabey.com"
s.homepage = "http://github.com/bmabey/database_cleaner"
s.description = "Strategies for cleaning databases. Can be used to ensure a clean state for testing."
s.files = FileList["[A-Z]*.*", "{examples,lib,features,spec}/**/*", "Rakefile", "cucumber.yml"]
s.authors = ["Ben Mabey"]
# s.licence = 'MIT'
end
rescue LoadError
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
......
---
:minor: 3
:build:
:patch: 0
:major: 1
:minor: 5
:patch: 1
source "http://rubygems.org"
# TODO: move these to the gemspec...
group :development do
gem "rake"
#gem "ruby-debug"
gem "bundler"
gem "jeweler"
gem "json_pure"
#ORM's
gem "activerecord"
gem "datamapper"
gem "dm-migrations"
gem "dm-sqlite-adapter"
gem "mongoid"
gem "tzinfo"
gem "mongo_ext"
gem "bson_ext"
gem "mongo_mapper"
gem "couch_potato"
gem "sequel", "~>3.21.0"
#gem "ibm_db" # I don't want to add this dependency, even as a dev one since it requires DB2 to be installed
gem 'mysql', '~> 2.8.1'
gem 'mysql2'
gem 'pg'
gem 'sqlite3'
gem 'ohm', '~> 0.1.3'
gem 'guard-rspec'
end
group :test do
gem "rspec-rails"
#gem "rspactor"
#gem "rcov"
#gem "ZenTest"
end
group :cucumber do
gem "cucumber"
end
platforms :mri_18 do
gem 'sqlite3-ruby', :group => :cucumber
#gem 'mysql', :group => :development
end
platforms :mri_19 do
gem 'sqlite3', :group => :cucumber
#gem 'mysql2', :group => :development
end
gemspec
PATH
remote: .
specs:
database_cleaner (1.5.1)
GEM
remote: http://rubygems.org/
remote: https://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)
activerecord-mysql2-adapter (0.0.3)
mysql2
activesupport (3.0.0)
addressable (2.3.6)
arel (1.0.1)
activesupport (~> 3.0.0)
bcrypt (3.1.7)
bcrypt (3.1.7-java)
bcrypt-ruby (3.1.5)
bcrypt (>= 3.1.3)
bcrypt-ruby (3.1.5-java)
bcrypt (>= 3.1.3)
bson (1.11.1)
bson (1.11.1-java)
bson_ext (1.11.1)
bson (~> 1.11.1)
builder (2.1.2)
coderay (1.1.0)
couch_potato (1.3.0)
activemodel
couchrest (>= 1.0.1)
couchrest (~> 1.2.0)