Module: Dynamoid::TestHelper
- Defined in:
- lib/dynamoid/test_helper.rb
Class Method Summary collapse
-
.create_tables(*models) ⇒ Object
Provision tables for all loaded models (or specified models).
-
.drop_tables ⇒ Object
Delete all tables belonging to the current namespace.
-
.truncate_tables(*models) ⇒ Object
Fast item cleanup between tests.
Class Method Details
.create_tables(*models) ⇒ Object
Provision tables for all loaded models (or specified models).
Dynamoid::TestHelper.create_tables
Dynamoid::TestHelper.create_tables(User, Post)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dynamoid/test_helper.rb', line 12 def create_tables(*models) if models.empty? models_dir = Dynamoid.config.models_dir if models_dir unless Dir.exist?(models_dir) raise Dynamoid::Errors::Error, "Dynamoid.config.models_dir #{models_dir.inspect} does not exist" end Dir[File.join(models_dir, '**/*.rb')].sort.each { |f| require f } end models = Dynamoid.included_models end models.uniq(&:table_name).each do |model| model.create_table(sync: true) end end |
.drop_tables ⇒ Object
Delete all tables belonging to the current namespace.
Dynamoid::TestHelper.drop_tables
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dynamoid/test_helper.rb', line 49 def drop_tables namespace = Dynamoid.config.namespace if namespace.to_s.empty? raise Dynamoid::Errors::Error, 'Dynamoid.config.namespace must be set to prevent dropping non-test tables' end prefix = "#{namespace}_" tables = Dynamoid.adapter.list_tables.select { |t| t.start_with?(prefix) } tables.each { |t| Dynamoid.adapter.delete_table(t) } Dynamoid.adapter.tables.clear end |
.truncate_tables(*models) ⇒ Object
Fast item cleanup between tests.
Dynamoid::TestHelper.truncate_tables
Dynamoid::TestHelper.truncate_tables(User, Post)
37 38 39 40 41 42 43 |
# File 'lib/dynamoid/test_helper.rb', line 37 def truncate_tables(*models) models = Dynamoid.included_models if models.empty? models.map(&:table_name).uniq.each do |table| Dynamoid.adapter.truncate(table) end end |