Skip to content

Instantly share code, notes, and snippets.

@tadast
Created September 8, 2016 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadast/d5b9d184615ed1d27e8204b2691970a0 to your computer and use it in GitHub Desktop.
Save tadast/d5b9d184615ed1d27e8204b2691970a0 to your computer and use it in GitHub Desktop.
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