spec/spec_helper.rb in deimos-ruby-1.6.4 vs spec/spec_helper.rb in deimos-ruby-1.7.0.pre.beta1

- old
+ new

@@ -98,21 +98,38 @@ end end end end - # Set up the given database. - def setup_db(options) - ActiveRecord::Base.establish_connection(options) + # :nodoc: + def run_db_backend_migration migration_class_name = 'DbBackendMigration' migration_version = '[5.2]' migration = ERB.new( File.read('lib/generators/deimos/db_backend/templates/migration') ).result(binding) eval(migration) # rubocop:disable Security/Eval ActiveRecord::Migration.new.run(DbBackendMigration, direction: :up) + end + # :nodoc: + def run_db_poller_migration + migration_class_name = 'DbPollerMigration' + migration_version = '[5.2]' + migration = ERB.new( + File.read('lib/generators/deimos/db_poller/templates/migration') + ).result(binding) + eval(migration) # rubocop:disable Security/Eval + ActiveRecord::Migration.new.run(DbPollerMigration, direction: :up) + end + + # Set up the given database. + def setup_db(options) + ActiveRecord::Base.establish_connection(options) + run_db_backend_migration + run_db_poller_migration + ActiveRecord::Base.descendants.each do |klass| klass.reset_sequence_name if klass.respond_to?(:reset_sequence_name) # reset internal variables - terrible hack to trick Rails into doing this table_name = klass.table_name klass.table_name = "#{table_name}2" @@ -129,22 +146,20 @@ # true by default for RSpec 4.0 config.shared_context_metadata_behavior = :apply_to_host_groups config.before(:all) do - Time.zone = 'EST' + Time.zone = 'Eastern Time (US & Canada)' ActiveRecord::Base.logger = Logger.new('/dev/null') ActiveRecord::Base.establish_connection( 'adapter' => 'sqlite3', 'database' => 'test.sqlite3' ) end config.include Deimos::TestHelpers config.include ActiveSupport::Testing::TimeHelpers config.before(:suite) do - Time.zone = 'EST' - ActiveRecord::Base.logger = Logger.new('/dev/null') setup_db(DbConfigs::DB_OPTIONS.last) end config.mock_with(:rspec) do |mocks| mocks.yield_receiver_to_any_instance_implementation_blocks = true @@ -161,9 +176,32 @@ deimos_config.kafka.seed_brokers = ENV['KAFKA_SEED_BROKER'] || 'localhost:9092' deimos_config.logger = Logger.new('/dev/null') deimos_config.logger.level = Logger::INFO deimos_config.schema.backend = :avro_validation end + end +end + +RSpec.shared_context('with widgets') do + before(:all) do + ActiveRecord::Base.connection.create_table(:widgets, force: true) do |t| + t.string(:test_id) + t.integer(:some_int) + t.boolean(:some_bool) + t.timestamps + end + + # :nodoc: + class Widget < ActiveRecord::Base + # @return [String] + def generated_id + 'generated_id' + end + end + end + + after(:all) do + ActiveRecord::Base.connection.drop_table(:widgets) end end RSpec.shared_context('with DB') do before(:all) do