Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamoid test database cleaner
# Prevent wiping out data in non-test environments
raise "Test should be run in 'test' environment only" if Rails.env != 'test'
module DynamoidReset
def self.all
Dynamoid.adapter.list_tables.each do |table|
# Only delete tables in our namespace
if table =~ /^#{Dynamoid::Config.namespace}/
Dynamoid.adapter.delete_table(table)
end
end
Dynamoid.adapter.tables.clear
# Recreate all tables to avoid `Cannot do operations on a non-existent table` error
Dynamoid.included_models.each(&:create_table)
end
end
# Reduce noise in test output
Dynamoid.logger.level = Logger::FATAL
# invoke it before each test in RSpec
RSpec.configure do |config|
config.before(:each) do
DynamoidReset.all
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.