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
7 changes: 7 additions & 0 deletions lib/database_rewinder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ def all=(v)
@clean_all = v
end

def filter_options=(options)
return unless options.is_a?(Hash)
@only = options[:only] if options.key?(:only)
@except = options[:except] if options.key?(:except)
@cleaners.each {|c| c.only, c.except = Array(@only), Array(@except)}
end

def cleaners
create_cleaner 'test' if @cleaners.empty?
@cleaners
Expand Down
40 changes: 40 additions & 0 deletions spec/database_rewinder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,46 @@
it { should == ['foo'] }
end

describe '.filter_options=' do
before do
@dbr_only = DatabaseRewinder.instance_variable_set(:@only, ['foos'])
@dbr_except = DatabaseRewinder.instance_variable_set(:@except, ['bars'])
@cleaner = DatabaseRewinder.cleaners.first
@cleaner_only, @cleaner_except = @cleaner.only, @cleaner.except
DatabaseRewinder.filter_options = filter_options
end

context 'with only option' do
let(:filter_options) { { only: ['bazs'] } }
it 'should set only option and keep except option' do
expect(DatabaseRewinder.instance_variable_get(:@only)).to eq(['bazs'])
expect(DatabaseRewinder.instance_variable_get(:@except)).to eq(@dbr_except)
expect(@cleaner.only).to eq(['bazs'])
expect(@cleaner.except).to eq(@cleaner_except)
end
end

context 'with except option' do
let(:filter_options) { { except: ['bazs'] } }
it 'should set except option and keep only option' do
expect(DatabaseRewinder.instance_variable_get(:@only)).to eq(@dbr_only)
expect(DatabaseRewinder.instance_variable_get(:@except)).to eq(['bazs'])
expect(@cleaner.only).to eq(@cleaner_only)
expect(@cleaner.except).to eq(['bazs'])
end
end

context 'with only and except options' do
let(:filter_options) { { only: ['bazs'], except: [] } }
it 'should set only and except options' do
expect(DatabaseRewinder.instance_variable_get(:@only)).to eq(['bazs'])
expect(DatabaseRewinder.instance_variable_get(:@except)).to eq([])
expect(@cleaner.only).to eq(['bazs'])
expect(@cleaner.except).to eq([])
end
end
end

describe '.record_inserted_table' do
before do
DatabaseRewinder.database_configuration = {'foo' => {'adapter' => 'sqlite3', 'database' => 'db/test.sqlite3'}}
Expand Down