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.
cucumber feature and example app done. Got the AR transaction strateg…
…y done as well.
- Loading branch information
Showing
6 changed files
with
81 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default: features |
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,19 +1,16 @@ | ||
require 'rubygems' | ||
require 'spec/expectations' | ||
|
||
require 'activerecord' | ||
require '../../lib/database_cleaner' | ||
begin | ||
require "#{File.dirname(__FILE__)}/../../lib/#{ENV['ORM']}" | ||
rescue LoadError | ||
raise "I don't have the setup for the '#{ENV['ORM']}' ORM!" | ||
end | ||
|
||
$:.unshift(File.dirname(__FILE__) + '/../../../lib') | ||
require 'database_cleaner' | ||
require 'database_cleaner/cucumber' | ||
|
||
DatabaseCleaner.strategy = :transaction #DatabaseCleaner::ActiveRecord::Transaction.new | ||
DatabaseCleaner.strategy = ENV['STRATEGY'].to_sym | ||
|
||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:") | ||
|
||
ActiveRecord::Schema.define(:version => 1) do | ||
create_table :widgets do |t| | ||
t.string :name | ||
end | ||
end | ||
|
||
class Widget < ActiveRecord::Base | ||
end |
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,12 @@ | ||
require 'activerecord' | ||
|
||
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :dbfile => ":memory:") | ||
|
||
ActiveRecord::Schema.define(:version => 1) do | ||
create_table :widgets do |t| | ||
t.string :name | ||
end | ||
end | ||
|
||
class Widget < ActiveRecord::Base | ||
end |
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,9 +1,15 @@ | ||
Feature: something something | ||
In order to something something | ||
A user something something | ||
something something something | ||
Feature: database cleaning | ||
In order to ease example and feature writing | ||
As a developer | ||
I want to have my database in a clean state | ||
|
||
Scenario: something something | ||
Given inspiration | ||
When I create a sweet new gem | ||
Then everyone should see how awesome I am | ||
Scenario Outline: ruby app | ||
Given I am using <ORM> | ||
And the <Strategy> cleaning strategy | ||
|
||
When I run my scenarios that rely on a clean database | ||
Then I should see all green | ||
|
||
Examples: | ||
| ORM | Strategy | | ||
| ActiveRecord | transaction | |
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,25 @@ | ||
Given /^I am using (ActiveRecord|DataMapper)$/ do |orm| | ||
@orm = orm | ||
end | ||
|
||
Given /^the (.+) cleaning strategy$/ do |strategy| | ||
@strategy = strategy | ||
end | ||
|
||
When "I run my scenarios that rely on a clean database" do | ||
full_dir ||= File.expand_path(File.dirname(__FILE__) + "/../../examples/") | ||
Dir.chdir(full_dir) do | ||
ENV['ORM'] = @orm.downcase | ||
ENV['STRATEGY'] = @strategy | ||
@out = `cucumber features` | ||
@status = $?.exitstatus | ||
end | ||
end | ||
|
||
Then "I should see all green" do | ||
unless @status == 0 | ||
raise "Expected to see all green but we saw FAIL! Output:\n#{@out}" | ||
end | ||
end | ||
|
||
|
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,6 +1,26 @@ | ||
module DatabaseCleaner::ActiveRecord | ||
class Transaction | ||
|
||
def start | ||
if ActiveRecord::Base.connection.respond_to?(:increment_open_transactions) | ||
ActiveRecord::Base.connection.increment_open_transactions | ||
else | ||
ActiveRecord::Base.__send__(:increment_open_transactions) | ||
end | ||
|
||
ActiveRecord::Base.connection.begin_db_transaction | ||
end | ||
|
||
|
||
def clean | ||
ActiveRecord::Base.connection.rollback_db_transaction | ||
|
||
if ActiveRecord::Base.connection.respond_to?(:decrement_open_transactions) | ||
ActiveRecord::Base.connection.decrement_open_transactions | ||
else | ||
ActiveRecord::Base.__send__(:decrement_open_transactions) | ||
end | ||
end | ||
end | ||
|
||
end |