Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/database_rewinder/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ def clean_all
reset
end

def clean_with(_strategy, only: nil, except: nil, **)
def clean_with(*args)
options = args.extract_options!
originals = @only, @except
@only, @except = Array(only), Array(except)
@only, @except = Array(options[:only]), Array(options[:except])
clean_all
ensure
@only, @except = originals
Expand Down
56 changes: 43 additions & 13 deletions spec/database_rewinder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,54 @@
@except = @cleaner.instance_variable_get(:@except)
Foo.create! name: 'foo1'
Bar.create! name: 'bar1'
DatabaseRewinder.clean_with :truncation, options
end

context 'with only option' do
let(:options) { { only: ['foos'] } }
it 'should clean with only option and restore original one' do
Foo.count.should == 0
Bar.count.should == 1
expect(@cleaner.instance_variable_get(:@only)).to eq(@only)
context 'simple arguments' do
before do
DatabaseRewinder.clean_with options
end

context 'with only option' do
let(:options) { { only: ['foos'] } }
it 'should clean with only option and restore original one' do
Foo.count.should == 0
Bar.count.should == 1
expect(@cleaner.instance_variable_get(:@only)).to eq(@only)
end
end

context 'with except option' do
let(:options) { { except: ['bars'] } }
it 'should clean with except option and restore original one' do
Foo.count.should == 0
Bar.count.should == 1
expect(@cleaner.instance_variable_get(:@except)).to eq(@except)
end
end
end

context 'with except option' do
let(:options) { { except: ['bars'] } }
it 'should clean with except option and restore original one' do
Foo.count.should == 0
Bar.count.should == 1
expect(@cleaner.instance_variable_get(:@except)).to eq(@except)

context 'compatible arguments' do
before do
DatabaseRewinder.clean_with :truncation, options
end

context 'with only option' do
let(:options) { { only: ['foos'] } }
it 'should clean with only option and restore original one' do
Foo.count.should == 0
Bar.count.should == 1
expect(@cleaner.instance_variable_get(:@only)).to eq(@only)
end
end

context 'with except option' do
let(:options) { { except: ['bars'] } }
it 'should clean with except option and restore original one' do
Foo.count.should == 0
Bar.count.should == 1
expect(@cleaner.instance_variable_get(:@except)).to eq(@except)
end
end
end
end
Expand Down