Created
September 8, 2016 15:02
-
-
Save tadast/d5b9d184615ed1d27e8204b2691970a0 to your computer and use it in GitHub Desktop.
Dynamoid test database cleaner
This file contains hidden or 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
# 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