Sha256: 73c02a137624adce52ba13c19ecc12b699de93fe63e605837f7a9d623f7c9879
Contents?: true
Size: 1.36 KB
Versions: 7
Compression:
Stored size: 1.36 KB
Contents
require 'test_helper' class Comment < ActiveRecord::Base has_archive_table end migration_class = if ActiveRecord::VERSION::MAJOR >= 5 ActiveRecord::Migration[4.2] else ActiveRecord::Migration end class CreateComments < migration_class def up create_table :comments do |t| t.string :author t.text :body end create_archive_table :comments end end class MigrationTest < ActiveSupport::TestCase def connection ActiveRecord::Base.connection end def drop_tables connection.drop_table(:comments) if table_exists?(:comments) connection.drop_table(:comments_archive) if table_exists?(:comments_archive) end setup do drop_tables end teardown do drop_tables end test "create_archive_table" do CreateComments.new.up assert table_exists?(:comments_archive), "Expected table 'comments_archive' to exist." assert_equal Comment.attribute_names, Comment.archive.attribute_names end test "ignore existing archive table" do CreateComments.new.up CreateComments.new.create_archive_table :comments # we can re-run archive table creator without errors end private def table_exists?(table_name) if connection.respond_to?(:data_source_exists?) connection.data_source_exists?(table_name) else connection.table_exists?(table_name) end end end
Version data entries
7 entries across 7 versions & 1 rubygems