Skip to content

Instantly share code, notes, and snippets.

@elado
Last active April 8, 2021 08:25
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save elado/c95a4ffa952809865ee8 to your computer and use it in GitHub Desktop.
Save elado/c95a4ffa952809865ee8 to your computer and use it in GitHub Desktop.
Cequel + DatabaseCleaner and RSpec
# 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