Last active
April 8, 2021 08:25
-
-
Save elado/c95a4ffa952809865ee8 to your computer and use it in GitHub Desktop.
Cequel + DatabaseCleaner and RSpec
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
# in spec_helper.rb | |
RSpec.configure do |config| | |
records = [] | |
config.before :suite do | |
Cequel::Record.descendants.each do |klass| | |
klass.after_create {|r| records << r } | |
end | |
end | |
config.after :each do | |
records.each(&:destroy) | |
records.clear | |
end | |
def clean_cequel! | |
Cequel::Record.descendants.each { |klass| Cequel::Record.connection.schema.truncate_table(klass.table_name) } | |
end | |
config.before :suite do | |
clean_cequel! | |
end | |
config.after :suite do | |
clean_cequel! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment