forked from DatabaseCleaner/database_cleaner
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request DatabaseCleaner#56 from gucki/master
sequel adapter
- Loading branch information
Showing
10 changed files
with
147 additions
and
2 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
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
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,22 @@ | ||
require 'database_cleaner/generic/base' | ||
module DatabaseCleaner | ||
module Sequel | ||
def self.available_strategies | ||
%w[truncation transaction] | ||
end | ||
|
||
module Base | ||
include ::DatabaseCleaner::Generic::Base | ||
|
||
def db=(desired_db) | ||
@db = desired_db | ||
end | ||
|
||
def db | ||
return @db if @db && @db != :default | ||
raise "As you have more than one active sequel database you have to specify the one to use manually!" if ::Sequel::DATABASES.count > 1 | ||
::Sequel::DATABASES.first | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'database_cleaner/sequel/base' | ||
module DatabaseCleaner | ||
module Sequel | ||
class Transaction | ||
include ::DatabaseCleaner::Sequel::Base | ||
|
||
def start | ||
@transactions ||= [] | ||
db.send(:add_transaction) | ||
@transactions << db.send(:begin_transaction, db) | ||
end | ||
|
||
def clean | ||
transaction = @transactions.pop | ||
db.send(:rollback_transaction, transaction) | ||
db.send(:remove_transaction, transaction) | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require "database_cleaner/generic/truncation" | ||
require 'database_cleaner/sequel/base' | ||
|
||
module DatabaseCleaner | ||
module Sequel | ||
class Truncation | ||
include ::DatabaseCleaner::Sequel::Base | ||
include ::DatabaseCleaner::Generic::Truncation | ||
|
||
def clean | ||
each_table do |db, table| | ||
db[table].truncate | ||
end | ||
end | ||
|
||
def each_table | ||
tables_to_truncate(db).each do |table| | ||
yield db, table | ||
end | ||
end | ||
|
||
private | ||
|
||
def tables_to_truncate(db) | ||
(@only || db.tables) - @tables_to_exclude | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
require 'database_cleaner/sequel/base' | ||
require 'database_cleaner/shared_strategy_spec' | ||
require 'sequel' | ||
|
||
module DatabaseCleaner | ||
describe Sequel do | ||
it { should respond_to(:available_strategies) } | ||
end | ||
|
||
module Sequel | ||
class ExampleStrategy | ||
include ::DatabaseCleaner::Sequel::Base | ||
end | ||
|
||
describe ExampleStrategy do | ||
it_should_behave_like "a generic strategy" | ||
it { should respond_to(:db) } | ||
it { should respond_to(:db=) } | ||
|
||
it "should store my desired db" do | ||
subject.db = :my_db | ||
subject.db.should == :my_db | ||
end | ||
|
||
it "should default to :default" do | ||
subject.db.should == :default | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require 'spec_helper' | ||
require 'database_cleaner/sequel/transaction' | ||
require 'database_cleaner/shared_strategy_spec' | ||
require 'sequel' | ||
|
||
module DatabaseCleaner | ||
module Sequel | ||
describe Transaction do | ||
it_should_behave_like "a generic strategy" | ||
it_should_behave_like "a generic transaction strategy" | ||
|
||
describe "start" do | ||
it "should start a transaction" | ||
end | ||
|
||
describe "clean" do | ||
it "should finish a transaction" | ||
end | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
require 'database_cleaner/sequel/truncation' | ||
require 'database_cleaner/shared_strategy_spec' | ||
require 'sequel' | ||
|
||
module DatabaseCleaner | ||
module Sequel | ||
describe Truncation do | ||
it_should_behave_like "a generic strategy" | ||
it_should_behave_like "a generic truncation strategy" | ||
end | ||
end | ||
end |