forked from DatabaseCleaner/database_cleaner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a readme and bumped the version
- Loading branch information
Showing
5 changed files
with
105 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
h1. 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. | ||
|
||
Right now the only ORM supported is ActiveRecord and it currently has two strategies: | ||
truncation and transaction. | ||
|
||
Support for DataMapper is built-in. All that needs to be written are the strategies. :) | ||
|
||
h2. How to use | ||
|
||
<pre> | ||
require 'database_cleaner' | ||
DatabaseCleaner.strategy = :truncation | ||
|
||
# then, whenever you need to clean the DB | ||
DatabaseCleaner.clean | ||
</pre> | ||
|
||
With the :truncation strategy you can also pass in options, for example: | ||
<pre> | ||
DatabaseCleaner.strategy = :truncation, {:only => %[widigets dogs some_other_table]} | ||
</pre> | ||
|
||
<pre> | ||
DatabaseCleaner.strategy = :truncation, {:except => %[widigets]} | ||
</pre> | ||
|
||
(I should point out the truncation strategy will never truncate your schema_migrations table.) | ||
|
||
|
||
Some strategies require that you call DatabaseCleaner.start before calling clean | ||
(for example the :transaction one needs to know to open up a transaction). So | ||
you would have: | ||
|
||
<pre> | ||
require 'database_cleaner' | ||
DatabaseCleaner.strategy = :transaction | ||
|
||
DatabaseCleaner.start # usually this is called in setup of a test | ||
dirty_the_db | ||
DatabaseCleaner.clean # cleanup of the test | ||
</pre> | ||
|
||
At times you may want to do a single clean with one strategy. For example, you may want | ||
to start the process by truncating all the tables, but then use the faster transaction | ||
strategy the remaining time. To accomplish this you can say: | ||
|
||
<pre> | ||
require 'database_cleaner' | ||
DatabaseCleaner.clean_with :truncation | ||
DatabaseCleaner.strategy = :transaction | ||
# then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately | ||
</pre> | ||
|
||
For use in Cucumber please see the section below. | ||
|
||
|
||
|
||
h2. Why? | ||
|
||
One of my motivations for writing this library was to have an easy way to | ||
turn on what Rails calls "transactional_fixtures" in my non-rails | ||
ActiveRecord projects. For example, Cucumber ships with a Rails world that | ||
will wrap each scenario in a transaction. This is great, but what if you are | ||
using ActiveRecord in a non-rails project? You used to have to copy-and-paste | ||
the needed code, but with DatabaseCleaner you can now say: | ||
|
||
<pre> | ||
#env.rb | ||
require 'database_cleaner' | ||
require 'database_cleaner/cucumber' | ||
DatabaseCleaner.strategy = :transaction | ||
</pre> | ||
|
||
Now lets say you are running your features and it requires that another process be | ||
involved (i.e. Selenium running against your app's server.) You can simply change | ||
your strategy type: | ||
|
||
<pre> | ||
#env.rb | ||
require 'database_cleaner' | ||
require 'database_cleaner/cucumber' | ||
DatabaseCleaner.strategy = :truncation | ||
</pre> | ||
|
||
You can have the best of both worlds and use the best one for the job: | ||
<pre> | ||
#env.rb | ||
require 'database_cleaner' | ||
require 'database_cleaner/cucumber' | ||
DatabaseCleaner.strategy = (ENV['SELENIUM'] == 'true') ? :truncation : :transaction | ||
</pre> | ||
|
||
h2. COPYRIGHT | ||
|
||
Copyright (c) 2009 Ben Mabey. See LICENSE for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
:major: 0 | ||
:minor: 0 | ||
:patch: 1 | ||
:minor: 1 | ||
:patch: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,14 @@ | |
|
||
Gem::Specification.new do |s| | ||
s.name = %q{database_cleaner} | ||
s.version = "0.0.1" | ||
s.version = "0.1.0" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Ben Mabey"] | ||
s.date = %q{2009-03-04} | ||
s.description = %q{TODO} | ||
s.email = %q{[email protected]} | ||
s.files = ["VERSION.yml", "examples/features", "examples/features/example.feature", "examples/features/step_definitions", "examples/features/step_definitions/example_steps.rb", "examples/features/support", "examples/features/support/env.rb", "examples/lib", "examples/lib/activerecord.rb", "lib/database_cleaner", "lib/database_cleaner/active_record", "lib/database_cleaner/active_record/transaction.rb", "lib/database_cleaner/active_record/truncation.rb", "lib/database_cleaner/configuration.rb", "lib/database_cleaner/cucumber.rb", "lib/database_cleaner/data_mapper", "lib/database_cleaner/data_mapper/transaction.rb", "lib/database_cleaner.rb", "features/cleaning.feature", "features/step_definitions", "features/step_definitions/database_cleaner_steps.rb", "features/support", "features/support/env.rb", "spec/database_cleaner", "spec/database_cleaner/active_record", "spec/database_cleaner/active_record/truncation_spec.rb", "spec/database_cleaner/configuration_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Rakefile", "cucumber.yml"] | ||
s.files = ["README.textile", "VERSION.yml", "examples/features", "examples/features/example.feature", "examples/features/step_definitions", "examples/features/step_definitions/example_steps.rb", "examples/features/support", "examples/features/support/env.rb", "examples/lib", "examples/lib/activerecord.rb", "lib/database_cleaner", "lib/database_cleaner/active_record", "lib/database_cleaner/active_record/transaction.rb", "lib/database_cleaner/active_record/truncation.rb", "lib/database_cleaner/configuration.rb", "lib/database_cleaner/cucumber.rb", "lib/database_cleaner/data_mapper", "lib/database_cleaner/data_mapper/transaction.rb", "lib/database_cleaner.rb", "features/cleaning.feature", "features/step_definitions", "features/step_definitions/database_cleaner_steps.rb", "features/support", "features/support/env.rb", "spec/database_cleaner", "spec/database_cleaner/active_record", "spec/database_cleaner/active_record/truncation_spec.rb", "spec/database_cleaner/configuration_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "Rakefile", "cucumber.yml"] | ||
s.has_rdoc = true | ||
s.homepage = %q{http://github.com/bmabey/database_cleaner} | ||
s.rdoc_options = ["--inline-source", "--charset=UTF-8"] | ||
|