diff --git a/LICENSE b/LICENSE index b2fa687..96814ef 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2008 Ben Mabey +Copyright (c) 2009 Ben Mabey Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README b/README deleted file mode 100644 index b51d968..0000000 --- a/README +++ /dev/null @@ -1,7 +0,0 @@ -database_cleaner================ -Description goes here. - -COPYRIGHT -========= - -Copyright (c) 2008 Ben Mabey. See LICENSE for details. \ No newline at end of file diff --git a/README.textile b/README.textile new file mode 100644 index 0000000..a0278f4 --- /dev/null +++ b/README.textile @@ -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 + +
+  require 'database_cleaner'
+  DatabaseCleaner.strategy = :truncation
+
+  # then, whenever you need to clean the DB
+  DatabaseCleaner.clean
+
+ +With the :truncation strategy you can also pass in options, for example: +
+  DatabaseCleaner.strategy = :truncation, {:only => %[widigets dogs some_other_table]}
+
+ +
+  DatabaseCleaner.strategy = :truncation, {:except => %[widigets]}
+
+ +(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: + +
+  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
+
+ +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: + +
+  require 'database_cleaner'
+  DatabaseCleaner.clean_with :truncation
+  DatabaseCleaner.strategy = :transaction
+  # then make the DatabaseCleaner.start and DatabaseCleaner.clean calls appropriately
+
+ +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: + +
+  #env.rb
+  require 'database_cleaner'
+  require 'database_cleaner/cucumber'
+  DatabaseCleaner.strategy = :transaction
+
+ +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: + +
+  #env.rb
+  require 'database_cleaner'
+  require 'database_cleaner/cucumber'
+  DatabaseCleaner.strategy = :truncation
+
+ +You can have the best of both worlds and use the best one for the job: +
+  #env.rb
+  require 'database_cleaner'
+  require 'database_cleaner/cucumber'
+  DatabaseCleaner.strategy = (ENV['SELENIUM'] == 'true') ? :truncation : :transaction
+
+ +h2. COPYRIGHT + +Copyright (c) 2009 Ben Mabey. See LICENSE for details. diff --git a/VERSION.yml b/VERSION.yml index e7d0bbc..0066fa4 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,4 +1,4 @@ --- :major: 0 -:minor: 0 -:patch: 1 +:minor: 1 +:patch: 0 diff --git a/database_cleaner.gemspec b/database_cleaner.gemspec index f83d601..50d058f 100644 --- a/database_cleaner.gemspec +++ b/database_cleaner.gemspec @@ -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{ben@benmabey.com} - 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"]