Commit 79bd39cf authored by Lucas Kanashiro's avatar Lucas Kanashiro

New upstream version 1.7.0

parent 2cbe0207
*.sw?
.DS_Store
coverage
pkg
.bundle
bundled_gems/
vendor/
examples/db/*.db
examples/config/database.yml
db/config.yml
db/test.sqlite3
.rbenv-version
.rvmrc
.ruby-version
.vagrant
--color
--format documentation
mtime
--backtrace
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
script:
- bundle exec rspec
# - bundle exec cucumber
gemfile:
- Gemfile
before_install:
- gem install bundler -v 1.14.6
# install Neo4j locally:
- wget dist.neo4j.org/neo4j-community-2.3.3-unix.tar.gz
- tar -xzf neo4j-community-2.3.3-unix.tar.gz
- sed -i.bak s/dbms.security.auth_enabled=true/dbms.security.auth_enabled=false/g neo4j-community-2.3.3/conf/neo4j-server.properties
- neo4j-community-2.3.3/bin/neo4j start
before_script:
- mysql -e 'create database database_cleaner_test;'
- psql -c 'create database database_cleaner_test;' -U postgres
- cp db/sample.config.yml db/config.yml
services:
- redis-server
- mongodb
gemspec
PATH
remote: .
specs:
database_cleaner (1.5.1)
database_cleaner (1.6.3)
GEM
remote: https://rubygems.org/
......@@ -69,7 +69,7 @@ GEM
dm-transactions (~> 1.2.0)
dm-types (~> 1.2.0)
dm-validations (~> 1.2.0)
diff-lcs (1.1.3)
diff-lcs (1.2.5)
dm-aggregates (1.2.0)
dm-core (~> 1.2.0)
dm-constraints (1.2.0)
......@@ -141,8 +141,8 @@ GEM
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 (1.8.6)
json (1.8.6-java)
json_pure (1.8.1)
listen (1.3.1)
rb-fsevent (>= 0.9.3)
......@@ -210,7 +210,7 @@ GEM
activesupport (= 3.0.0)
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (10.3.2)
rake (11.1.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
......@@ -222,19 +222,22 @@ GEM
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)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.8)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.2)
actionpack (>= 3.0)
activemodel (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec (~> 2.11.0)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
sequel (3.21.0)
slop (3.6.0)
spoon (0.0.4)
......@@ -242,7 +245,7 @@ GEM
sqlite3 (1.3.10)
stringex (1.5.1)
thor (0.14.6)
tzinfo (0.3.41)
tzinfo (0.3.48)
uuidtools (2.1.5)
zip (2.0.2)
......@@ -274,10 +277,10 @@ DEPENDENCIES
ohm (~> 0.1.3)
pg
rake
rspec-rails (~> 2.11.0)
rspec-rails (~> 2.14.2)
sequel (~> 3.21.0)
sqlite3
tzinfo
BUNDLED WITH
1.10.5
1.15.0
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
== Development (master)
=== Bug Fixes
=== Changes
== 1.7.0 2017-04-19
=== Bug Fixes
* Remove unnecessary folders from gem: https://github.com/DatabaseCleaner/database_cleaner/pull/508
* Properly quote table names: https://github.com/DatabaseCleaner/database_cleaner/pull/501
* Use more idiomatic Ruby in README: https://github.com/DatabaseCleaner/database_cleaner/pull/510
* Return ::ActiveRecord::Base from `establish_connection`: https://github.com/DatabaseCleaner/database_cleaner/pull/399
=== Changes
* Safeguard against running in production or running against a remote database: https://github.com/DatabaseCleaner/database_cleaner/pull/521
== 1.6.2 2017-10-29
=== Bug Fixes
* ActiveRecord::Base namespace patch: https://github.com/DatabaseCleaner/database_cleaner/pull/490
* Better exclusion condition based on Rails version: https://github.com/DatabaseCleaner/database_cleaner/pull/487
=== Changes
* Better documentation. Typos were fixed. Sequel deletion is supported: https://github.com/DatabaseCleaner/database_cleaner/pull/500
== 1.6.1 2017-05-09
=== Bug Fixes
* Deletion strategy fix for ActiveRecord (@kawamoto)
== 1.6.0 2017-05-04
=== New Features/Changes
* Rails 5.1 support: Remove deprecation warning (@activefx)
* MySQL 5.6+ InnoDB support (@ahorek)
* Better documentation (fixed typo) (@hoshinotsuyoshi)
=== Bug Fixes
* Fix Redis db option (@soylent)
* Make NullStrategy API-complete (@anicholson)
== 1.5.3 2016-04-22
=== Bug Fixes
* @P9GIT fixed issue #436
== 1.5.2 2016-04-17
=== New Features/Changes
* Use default_client with mongoid 5.0 (@stjhimy)
* Added comparable support for strategies (@st0012)
* Better README instructions that suggest `append_after` (@jrochkind)
* Removed deprecation warnings for Rails 5.0+ (@pschambacher)
* Upgrade to RSpec 2.14 (@skalee)
=== Bug Fixes
* @dmitrypol fixed issue #409
* @schmierkov fixed the Travis builds with PR #416
* @shosti fixed issue #345
* @kylev fixed issue #379
* @skalee fixed the Travis builds for Neo4j with PR #433
== 1.5.1 2015-09-05
== Bug Fix
* Added mongo2 missing files to the gemspec. (@geerzo)
== 1.5.0 2015-09-02
=== New Features/Changes
* Use ensure within the cleaning method. (@cema-sp)
* Restored mysql2 + jruby support. (@ahorek)
* Added required ruby version to gemspec. (@garethrees)
* Added support for Mongoid 5.0 and Mongo Ruby Driver 2.0. (@jprincipe)
* Added support for additional Neo4j::Session.open options. (@brienw)
* And a bunch of code style and README improvements
=== Bug Fixes
* Fixed truncation for MongoDB 3. (@andreale)
* Fixed YAML error when building gem. (@joshnesbitt)
* Fixed deletion strategy for JDBC MySQL. (@DanElbert)
* Fixed open transactions for multiple connections. (@claptimes5)
== 1.4.1 2015-03-09
* Support for deletion with Sequel. (@cyberdelia)
* Use ActiveRecord::Base configuration when different from config file. (@wendy0402)
......
# 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)
Database Cleaner is a set of strategies for cleaning your database in Ruby.
The original use case was to ensure a clean state during tests.
Each strategy is a small amount of code but is code that is usually needed in any ruby app that is testing with a database.
ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
## Gem Setup
```ruby
# Gemfile
group :test do
gem 'database_cleaner'
end
```
## Supported Databases, Libraries and Strategies
[![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)
ActiveRecord, DataMapper, Sequel, MongoMapper, Mongoid, CouchPotato, Ohm and Redis are supported.
Here is an overview of the strategies supported for each library:
......@@ -53,7 +65,7 @@ Here is an overview of the strategies supported for each library:
<td> Sequel</td>
<td> <b>Yes</b></td>
<td> Yes</td>
<td> No</td>
<td> Yes</td>
</tr>
<tr>
<td>Redis</td>
......@@ -76,7 +88,7 @@ Here is an overview of the strategies supported for each library:
</tbody>
</table>
* Truncation and Deletion strategies for Neo4j will just delete all nodes and relationships from the database.
\* Truncation and Deletion strategies for Neo4j will just delete all nodes and relationships from the database.
<table>
<tbody>
......@@ -154,7 +166,7 @@ passed to [`keys`](http://redis.io/commands/keys)).
(I should point out the truncation strategy will never truncate your schema_migrations table.)
Some strategies need to be started before tests are run (for example the `:transaction` strategy needs to know to open up a transaction). This can be accomplished by calling `DatabaseCleaner.start` at the beginning of the run, or by running the tests inside a block to `Database.cleaning`. So you would have:
Some strategies need to be started before tests are run (for example the `:transaction` strategy needs to know to open up a transaction). This can be accomplished by calling `DatabaseCleaner.start` at the beginning of the run, or by running the tests inside a block to `DatabaseCleaner.cleaning`. So you would have:
```ruby
require 'database_cleaner'
......@@ -221,23 +233,81 @@ 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`.
You'll typically discover a feature spec is incorrectly using transaction
instead of truncation strategy when the data created in the spec is not
visible in the app-under-test.
A frequently occurring example of this is when, after creating a user in a
spec, the spec mysteriously fails to login with the user. This happens because
the user is created inside of an uncommitted transaction on one database
connection, while the login attempt is made using a separate database
connection. This separate database connection cannot access the
uncommitted user data created over the first database connection due to
transaction isolation.
For feature specs using a Capybara driver for an external
JavaScript-capable browser (in practice this is all drivers except
`:rack_test`), the Rack app under test and the specs do not share a
database connection.
When a spec and app-under-test do not share a database connection,
you'll likely need to use the truncation strategy instead of the
transaction strategy.
See the suggested config below to temporarily enable truncation strategy
for affected feature specs only. This config continues to use transaction
strategy for all other specs.
It's also recommended to use `append_after` to ensure `DatabaseCleaner.clean`
runs *after* the after-test cleanup `capybara/rspec` installs.
```ruby
require 'capybara/rspec'
#...
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before(:suite) do
if config.use_transactional_fixtures?
raise(<<-MSG)
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
(or set it to false) to prevent uncommitted transactions being used in
JavaScript-dependent specs.
During testing, the app-under-test that the browser driver connects to
uses a different database connection to the database connection used by
the spec. The app's database connection would not be able to access
uncommitted transaction data setup over the spec's database connection.
MSG
end
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do |example|
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, type: :feature) do
# :rack_test driver's Rack app under test shares database connection
# with the specs, so continue to use transaction strategy for speed.
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
unless driver_shares_db_connection_with_specs
# Driver is probably for an external browser with an app
# under test that does *not* share a database connection with the
# specs, so use truncation strategy.
DatabaseCleaner.strategy = :truncation
end
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
config.append_after(:each) do
DatabaseCleaner.clean
end
......@@ -293,7 +363,7 @@ This should cover the basics of tear down between scenarios and keeping your dat
For more examples see the section ["Why?"](#why).
## How to use with multiple ORM's
## How to use with multiple ORMs
Sometimes you need to use multiple ORMs in your application.
......@@ -412,7 +482,7 @@ For ActiveRecord, you add the following parameter in your database.yml file:
test:
adapter: postgresql
# ...
min_messages: WARNING
min_messages: WARNING
</pre>
### Nothing happens in JRuby with Sequel using transactions
......@@ -432,6 +502,29 @@ Dir["#{Rails.root}/app/models/**/*.rb"].each do |model|
end
```
## Safeguards
DatabaseCleaner comes with safeguards against:
* Running in production (checking for `ENV`, `RACK_ENV`, and `RAILS_ENV`)
* Running against a remote database (checking for a `DATABASE_URL` that does not include `localhost`)
Both safeguards can be disabled separately as follows.
Using environment variables:
```
export DATABASE_CLEANER_ALLOW_PRODUCTION=true
export DATABASE_CLEANER_ALLOW_REMOTE_DATABASE_URL=true
```
In Ruby:
```ruby
DatabaseCleaner.allow_production = true
DatabaseCleaner.allow_remote_database_url = true
```
## Debugging
In rare cases DatabaseCleaner will encounter errors that it will log. By default it uses STDOUT set to the ERROR level but you can configure this to use whatever Logger you desire.
......
---
:major: 1
:minor: 5
:patch: 1
:minor: 7
:patch: 0
require 'yaml'
version = YAML.load_file 'VERSION.yml'
Gem::Specification.new do |s|
s.name = "database_cleaner"
s.version = "#{version[:major]}.#{version[:minor]}.#{version[:patch]}"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.required_ruby_version = ">= 1.9.3"
s.require_paths = ["lib"]
s.authors = ["Ben Mabey", "Ernesto Tagwerker"]
s.description = "Strategies for cleaning databases. Can be used to ensure a clean state for testing."
s.email = "ernesto@ombulabs.com"
s.extra_rdoc_files = [
"LICENSE",
"README.markdown",
"TODO"
]
s.files = [
"CONTRIBUTE.markdown",
"Gemfile.lock",
"History.rdoc",
"README.markdown",
"Rakefile",
"VERSION.yml",
"cucumber.yml"]
s.files += Dir['lib/**/*.rb']
s.homepage = "http://github.com/DatabaseCleaner/database_cleaner"
s.license = 'MIT'
s.rubygems_version = "2.4.5"
s.summary = "Strategies for cleaning databases. Can be used to ensure a clean state for testing."
s.add_development_dependency "rake"
s.add_development_dependency "bundler"
s.add_development_dependency "json_pure"
s.add_development_dependency "activerecord-mysql2-adapter" unless RUBY_PLATFORM =~ /java/
s.add_development_dependency "activerecord"
s.add_development_dependency "datamapper"
s.add_development_dependency "dm-migrations"
s.add_development_dependency "dm-sqlite-adapter"
s.add_development_dependency "mongoid"
s.add_development_dependency "tzinfo"
s.add_development_dependency "mongoid-tree"
s.add_development_dependency "mongo_mapper"
s.add_development_dependency "moped"
s.add_development_dependency "neo4j-core"
s.add_development_dependency "couch_potato"
s.add_development_dependency "sequel", "~> 3.21.0"
s.add_development_dependency 'ohm', '~> 0.1.3'
s.add_development_dependency 'guard-rspec'
s.add_development_dependency "rspec-rails", "~> 2.14.2"
s.add_development_dependency "cucumber"
unless RUBY_PLATFORM =~ /java/
s.add_development_dependency "mongo_ext"
s.add_development_dependency "bson_ext"
s.add_development_dependency 'mysql', '~> 2.9.1'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'pg'
s.add_development_dependency "sqlite3-ruby" if RUBY_VERSION < "1.9"
s.add_development_dependency "sqlite3" if RUBY_VERSION >= "1.9"
else
s.add_development_dependency "activerecord-jdbc-adapter"
end
end
mysql:
adapter: mysql
database: database_cleaner_test
username: root
password:
host: 127.0.0.1
port: 3306
encoding: utf8
mysql2:
adapter: mysql2
database: database_cleaner_test
username: root
password:
host: 127.0.0.1
port: 3306
encoding: utf8
postgres:
adapter: postgresql
database: database_cleaner_test
username: postgres
password:
host: 127.0.0.1
encoding: unicode
template: template0
sqlite3:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
../Gemfile
\ No newline at end of file
PATH
remote: .
specs:
database_cleaner (1.5.1)
GEM
remote: https://rubygems.org/
specs:
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.2.0)
json (~> 1.6)
couchrest (1.2.0)
mime-types (~> 1.15)
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.14)
addressable (~> 2.1)
datamapper (1.2.0)
dm-aggregates (~> 1.2.0)
dm-constraints (~> 1.2.0)
dm-core (~> 1.2.0)
dm-migrations (~> 1.2.0)
dm-serializer (~> 1.2.0)
dm-timestamps (~> 1.2.0)
dm-transactions (~> 1.2.0)
dm-types (~> 1.2.0)
dm-validations (~> 1.2.0)
diff-lcs (1.1.3)
dm-aggregates (1.2.0)
dm-core (~> 1.2.0)
dm-constraints (1.2.0)
dm-core (~> 1.2.0)
dm-core (1.2.1)
addressable (~> 2.3)
dm-do-adapter (1.2.0)
data_objects (~> 0.10.6)
dm-core (~> 1.2.0)
dm-migrations (1.2.0)
dm-core (~> 1.2.0)
dm-serializer (1.2.2)
dm-core (~> 1.2.0)
fastercsv (~> 1.5)
json (~> 1.6)
json_pure (~> 1.6)
multi_json (~> 1.0)
dm-sqlite-adapter (1.2.0)
dm-do-adapter (~> 1.2.0)
do_sqlite3 (~> 0.10.6)
dm-timestamps (1.2.0)
dm-core (~> 1.2.0)
dm-transactions (1.2.0)
dm-core (~> 1.2.0)
dm-types (1.2.2)
bcrypt-ruby (~> 3.0)
dm-core (~> 1.2.0)
fastercsv (~> 1.5)
json (~> 1.6)
multi_json (~> 1.0)
stringex (~> 1.4)
uuidtools (~> 2.1)
dm-validations (1.2.0)
dm-core (~> 1.2.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)
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.5.4)
guard (>= 1.1)
rspec (~> 2.11)
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 (2.2.6)
activemodel (~> 3.0.0)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
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)
os (0.9.6)
pg (0.18.2)
plucky (0.5.2)
mongo (~> 1.5)
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.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.1.0)
rest-client (1.6.8)
mime-types (~> 1.16)