2
require 'database_cleaner/generic/truncation'
4
module ::DatabaseCleaner
6
class TruncationExample
7
include ::DatabaseCleaner::Generic::Truncation
26
class MigrationExample < TruncationExample
27
def migration_storage_names
28
%w[migration_storage_name]
32
describe TruncationExample do
33
subject(:truncation_example) { TruncationExample.new }
36
expect { truncation_example.start }.to_not raise_error
39
it "expects clean to be implemented later" do
40
expect { truncation_example.clean }.to raise_error(NotImplementedError)
43
context "private methods" do
44
it { should_not respond_to(:tables_to_truncate) }
46
it 'expects #tables_to_truncate to be implemented later' do
47
expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
50
it { should_not respond_to(:migration_storage_names) }
51
its(:migration_storage_names) { should be_empty }
54
describe "initialize" do
55
it { expect{ subject }.to_not raise_error }
57
it "should accept a hash of options" do
58
expect{ TruncationExample.new {} }.to_not raise_error
61
it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError" } ) }.to raise_error(ArgumentError) }
62
it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to raise_error(ArgumentError) }
63
it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error }
64
it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error }
65
it { expect{ TruncationExample.new( { :pre_count => "something" } ) }.to_not raise_error }
66
it { expect{ TruncationExample.new( { :reset_ids => "something" } ) }.to_not raise_error }
69
subject { TruncationExample.new( { :only => ["something"] } ) }
70
its(:only) { should eq ["something"] }
71
its(:except) { should eq [] }
75
subject { TruncationExample.new( { :except => ["something"] } ) }
76
its(:only) { should eq nil }
77
its(:except) { should include("something") }
81
subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
82
its(:reset_ids?) { should eq true }
86
subject { TruncationExample.new( { :reset_ids => nil } ) }
87
its(:reset_ids?) { should eq false }
91
subject { TruncationExample.new( { :pre_count => ["something"] } ) }
92
its(:pre_count?) { should eq true }
96
subject { TruncationExample.new( { :pre_count => nil } ) }
97
its(:pre_count?) { should eq false }
101
subject { MigrationExample.new }
102
its(:only) { should eq nil }
103
its(:except) { should eq %w[migration_storage_name] }
107
EXCEPT_TABLES = ["something"]
108
subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
110
it "should not modify the array of excepted tables" do
111
subject.except.should include("migration_storage_name")
112
EXCEPT_TABLES.should_not include("migration_storage_name")