1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
require 'spec_helper'
require 'database_cleaner/generic/truncation'
module ::DatabaseCleaner
module Generic
class TruncationExample
include ::DatabaseCleaner::Generic::Truncation
def only
@only
end
def except
@tables_to_exclude
end
def reset_ids?
!!@reset_ids
end
def pre_count?
!!@pre_count
end
end
class MigrationExample < TruncationExample
def migration_storage_names
%w[migration_storage_name]
end
end
describe TruncationExample do
subject(:truncation_example) { TruncationExample.new }
it "will start" do
expect { truncation_example.start }.to_not raise_error
end
it "expects clean to be implemented later" do
expect { truncation_example.clean }.to raise_error(NotImplementedError)
end
context "private methods" do
it { should_not respond_to(:tables_to_truncate) }
it 'expects #tables_to_truncate to be implemented later' do
expect{ truncation_example.send :tables_to_truncate }.to raise_error(NotImplementedError)
end
it { should_not respond_to(:migration_storage_names) }
its(:migration_storage_names) { should be_empty }
end
describe "initialize" do
it { expect{ subject }.to_not raise_error }
it "should accept a hash of options" do
expect{ TruncationExample.new {} }.to_not raise_error
end
it { expect{ TruncationExample.new( { :a_random_param => "should raise ArgumentError" } ) }.to raise_error(ArgumentError) }
it { expect{ TruncationExample.new( { :except => "something",:only => "something else" } ) }.to raise_error(ArgumentError) }
it { expect{ TruncationExample.new( { :only => "something" } ) }.to_not raise_error }
it { expect{ TruncationExample.new( { :except => "something" } ) }.to_not raise_error }
it { expect{ TruncationExample.new( { :pre_count => "something" } ) }.to_not raise_error }
it { expect{ TruncationExample.new( { :reset_ids => "something" } ) }.to_not raise_error }
context "" do
subject { TruncationExample.new( { :only => ["something"] } ) }
its(:only) { should eq ["something"] }
its(:except) { should eq [] }
end
context "" do
subject { TruncationExample.new( { :except => ["something"] } ) }
its(:only) { should eq nil }
its(:except) { should include("something") }
end
context "" do
subject { TruncationExample.new( { :reset_ids => ["something"] } ) }
its(:reset_ids?) { should eq true }
end
context "" do
subject { TruncationExample.new( { :reset_ids => nil } ) }
its(:reset_ids?) { should eq false }
end
context "" do
subject { TruncationExample.new( { :pre_count => ["something"] } ) }
its(:pre_count?) { should eq true }
end
context "" do
subject { TruncationExample.new( { :pre_count => nil } ) }
its(:pre_count?) { should eq false }
end
context "" do
subject { MigrationExample.new }
its(:only) { should eq nil }
its(:except) { should eq %w[migration_storage_name] }
end
context "" do
EXCEPT_TABLES = ["something"]
subject { MigrationExample.new( { :except => EXCEPT_TABLES } ) }
it "should not modify the array of excepted tables" do
subject.except.should include("migration_storage_name")
EXCEPT_TABLES.should_not include("migration_storage_name")
end
end
end
end
end
end
|