diff --git a/.ruby-version b/.ruby-version index 6a6a3d8e..a603bb50 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.1 +2.7.5 diff --git a/.travis.yml b/.travis.yml index 8fd64fc0..48b62194 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,14 @@ language: ruby rvm: - - 2.6 - 2.7 + - 3.0 script: bundle exec rspec gemfile: - - gemfiles/rails_5.1.gemfile - gemfiles/rails_5.2.gemfile - gemfiles/rails_6.0.gemfile - gemfiles/rails_6.1.gemfile -matrix: + - gemfiles/rails_7.0.gemfile +jobs: exclude: - - rvm: 2.4.4 - gemfile: gemfiles/rails_6.0.gemfile - - rvm: 2.4.4 - gemfile: gemfiles/rails_6.1.gemfile + - rvm: 3.0 + gemfile: gemfiles/rails_5.2.gemfile diff --git a/Appraisals b/Appraisals index a24f9e5f..d2457013 100644 --- a/Appraisals +++ b/Appraisals @@ -1,11 +1,3 @@ -appraise 'rails-5.0' do - gem 'rails', '5.0.7.2' -end - -appraise 'rails-5.1' do - gem 'rails', '5.1.7' -end - appraise 'rails-5.2' do gem 'rails', '~> 5.2.3' end @@ -17,3 +9,7 @@ end appraise 'rails-6.1' do gem 'rails', '~> 6.1.0' end + +appraise 'rails-7.0' do + gem 'rails', '~> 7.0' +end diff --git a/Changelog.md b/Changelog.md index 3556e183..6f554a66 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## 8.0.0.rc1 +Add support for Rails 7 +Removed support for Rails versions below 5.2. Now are supported only versions Rails 5.2 and up + ## 7.0.2 Remove magic comment in migration files [y-yagi](https://github.com/y-yagi) diff --git a/Gemfile b/Gemfile index 47257826..6a4aedc4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,4 @@ source "http://rubygems.org" -# Specify your gem's dependencies in data_migrate.gemspec -%w[ - activerecord - railties -].each do |rails_gem| - gem rails_gem, '~> 6.0.0' -end gem 'sqlite3', "~> 1.4" gemspec diff --git a/Gemfile.rails5 b/Gemfile.rails5 deleted file mode 100644 index b137c48d..00000000 --- a/Gemfile.rails5 +++ /dev/null @@ -1,10 +0,0 @@ -source "http://rubygems.org" - -# Specify your gem's dependencies in data_migrate.gemspec -gemspec -%w[ - activerecord - railties -].each do |rails_gem| - gem rails_gem, '~> 5.0.0' -end diff --git a/Gemfile.rails5.1 b/Gemfile.rails5.1 deleted file mode 100644 index 5c16bb30..00000000 --- a/Gemfile.rails5.1 +++ /dev/null @@ -1,10 +0,0 @@ -source "http://rubygems.org" - -# Specify your gem's dependencies in data_migrate.gemspec -gemspec -%w[ - activerecord - railties -].each do |rails_gem| - gem rails_gem, '~> 5.1.7' -end diff --git a/gemfiles/rails_4.1.gemfile b/gemfiles/rails_4.1.gemfile deleted file mode 100644 index 00ece251..00000000 --- a/gemfiles/rails_4.1.gemfile +++ /dev/null @@ -1,7 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "4.1.16" - -gemspec path: "../" diff --git a/gemfiles/rails_4.2.gemfile b/gemfiles/rails_4.2.gemfile deleted file mode 100644 index 35e54423..00000000 --- a/gemfiles/rails_4.2.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "4.2.11.1" -gem "nokogiri", "1.6.8.1" -gem "bundler" , "< 2.0" - -gemspec path: "../" diff --git a/gemfiles/rails_5.0.gemfile b/gemfiles/rails_5.0.gemfile deleted file mode 100644 index a8778c74..00000000 --- a/gemfiles/rails_5.0.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -# This file was generated by Appraisal - -source "http://rubygems.org" - -gem "rails", "5.0.7.2" -gem "sqlite3", "~> 1.4" - -gemspec path: "../" diff --git a/gemfiles/rails_5.1.gemfile b/gemfiles/rails_7.0.gemfile similarity index 83% rename from gemfiles/rails_5.1.gemfile rename to gemfiles/rails_7.0.gemfile index e6e585e3..88cdc430 100644 --- a/gemfiles/rails_5.1.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -2,7 +2,7 @@ source "http://rubygems.org" -gem "rails", "5.1.7" gem "sqlite3", "~> 1.4" +gem "rails", "~> 7.0" gemspec path: "../" diff --git a/lib/data_migrate.rb b/lib/data_migrate.rb index bfc566f8..47096479 100644 --- a/lib/data_migrate.rb +++ b/lib/data_migrate.rb @@ -1,44 +1,22 @@ # frozen_string_literal: true -if Rails::VERSION::MAJOR == 6 - require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five") -elsif Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2 - require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five") -else - require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator") -end -require File.join(File.dirname(__FILE__), "data_migrate", - "data_schema_migration") +require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five") +require File.join(File.dirname(__FILE__), "data_migrate", "data_schema_migration") require File.join(File.dirname(__FILE__), "data_migrate", "data_schema") require File.join(File.dirname(__FILE__), "data_migrate", "database_tasks") require File.join(File.dirname(__FILE__), "data_migrate", "schema_dumper") -if Rails::VERSION::MAJOR == 6 - require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five") - require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_six") -elsif Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2 - require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five") - require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_five") -else - require File.join(File.dirname(__FILE__), "data_migrate", "status_service") - require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration") -end - -if Rails::VERSION::MAJOR == 6 - require File.join(File.dirname(__FILE__), "data_migrate", "migration_context") - # require File.join(File.dirname(__FILE__), "data_migrate", "migration_five") -elsif Rails::VERSION::MAJOR == 5 - if Rails::VERSION::MINOR == 2 - require File.join(File.dirname(__FILE__), "data_migrate", "migration_context") - else - require File.join(File.dirname(__FILE__), "data_migrate", "migration_five") - end -else - require File.join(File.dirname(__FILE__), "data_migrate", "migration") -end +require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five") +require File.join(File.dirname(__FILE__), "data_migrate", "migration_context") require File.join(File.dirname(__FILE__), "data_migrate", "railtie") require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks") require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator") require File.join(File.dirname(__FILE__), "data_migrate", "config") +if Rails::VERSION::MAJOR == 5 + require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_five") +else + require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_six") +end + module DataMigrate end diff --git a/lib/data_migrate/data_migrator.rb b/lib/data_migrate/data_migrator.rb deleted file mode 100644 index 56e71eda..00000000 --- a/lib/data_migrate/data_migrator.rb +++ /dev/null @@ -1,101 +0,0 @@ -# frozen_string_literal: true - -require "active_record" - -module DataMigrate - class DataMigrator < ActiveRecord::Migrator - - def record_version_state_after_migrating(version) - if down? - migrated.delete(version) - DataMigrate::DataSchemaMigration.where(version: version.to_s).delete_all - else - migrated << version - DataMigrate::DataSchemaMigration.create!(version: version.to_s) - end - end - - def load_migrated(connection = ActiveRecord::Base.connection) - self.class.get_all_versions(connection) - end - - class << self - alias_method :migrations_status_orig, :migrations_status - - def migrations_status - migrations_status_orig([DataMigrate.config.data_migrations_path]) - end - - def current_version(connection = ActiveRecord::Base.connection) - get_all_versions(connection).max || 0 - end - - def get_all_versions(connection = ActiveRecord::Base.connection) - if table_exists?(connection, schema_migrations_table_name) - DataMigrate::DataSchemaMigration.all.map { |x| x.version.to_i }.sort - else - [] - end - end - - def schema_migrations_table_name - ActiveRecord::Base.table_name_prefix + "data_migrations" + - ActiveRecord::Base.table_name_suffix - end - - def migrations_path - DataMigrate.config.data_migrations_path - end - - ## - # Provides the full migrations_path filepath - # @return (String) - def full_migrations_path - File.join(Rails.root, *migrations_path.split(File::SEPARATOR)) - end - - def assure_data_schema_table - ActiveRecord::Base.establish_connection(db_config) - sm_table = DataMigrate::DataMigrator.schema_migrations_table_name - - unless table_exists?(ActiveRecord::Base.connection, sm_table) - create_table(sm_table) - end - end - - ## - # Compares the given filename with what we expect data migration - # filenames to be, eg the "20091231235959_some_name.rb" pattern - # @param (String) filename - # @return (MatchData) - def match(filename) - /(\d{14})_(.+)\.rb$/.match(filename) - end - - private - - def create_table(sm_table) - ActiveRecord::Base.connection.create_table(sm_table, id: false) do |schema_migrations_table| - schema_migrations_table.string :version, primary_key: true - end - end - - def table_exists?(connection, table_name) - # Avoid the warning that table_exists? prints in Rails 5.0 due a - # change in behavior between Rails 5.0 and Rails 5.1 of this method - # with respect to database views. - if ActiveRecord.version >= Gem::Version.new("5.0") && - ActiveRecord.version < Gem::Version.new("5.1") - connection.data_source_exists?(table_name) - else - connection.table_exists?(schema_migrations_table_name) - end - end - - def db_config - ActiveRecord::Base.configurations[Rails.env || "development"] || - ENV["DATABASE_URL"] - end - end - end -end diff --git a/lib/data_migrate/database_tasks.rb b/lib/data_migrate/database_tasks.rb index 5b91bbd9..6a31caef 100644 --- a/lib/data_migrate/database_tasks.rb +++ b/lib/data_migrate/database_tasks.rb @@ -23,6 +23,20 @@ def dump_filename(namespace, format = ActiveRecord::Base.schema_format) ENV["DATA_SCHEMA"] || File.join(schema_location, filename) end + def schema_dump_path(db_config, format = ActiveRecord.schema_format) + return ENV["DATA_SCHEMA"] if ENV["DATA_SCHEMA"] + + filename = if db_config.primary? + schema_file_type(format) + else + [db_config.name, schema_file_type(format)].join("_") + end + + return unless filename + + File.dirname(filename) == schema_location ? filename : File.join(schema_location, filename) + end + def schema_location db_dir end diff --git a/lib/data_migrate/migration.rb b/lib/data_migrate/migration.rb deleted file mode 100644 index 52fd9883..00000000 --- a/lib/data_migrate/migration.rb +++ /dev/null @@ -1,26 +0,0 @@ -module DataMigrate - class Migration < ::ActiveRecord::Migration - - class << self - def check_pending!(connection = ::ActiveRecord::Base.connection) - raise ActiveRecord::PendingMigrationError if DataMigrator::Migrator.needs_migration?(connection) - end - - def migrate(direction) - new.migrate direction - end - - def table_name - ActiveRecord::Base.table_name_prefix + "data_migrations" + ActiveRecord::Base.table_name_suffix - end - - def primary_key - "version" - end - end - - def initialize(name = self.class.name, version = nil) - super(name, version) - end - end -end diff --git a/lib/data_migrate/migration_five.rb b/lib/data_migrate/migration_five.rb deleted file mode 100644 index d125dc3f..00000000 --- a/lib/data_migrate/migration_five.rb +++ /dev/null @@ -1,26 +0,0 @@ -module DataMigrate - class MigrationFive < ::ActiveRecord::Migration[5.0] - - class << self - def check_pending!(connection = ::ActiveRecord::Base.connection) - raise ActiveRecord::PendingMigrationError if DataMigrator::Migrator.needs_migration?(connection) - end - - def migrate(direction) - new.migrate direction - end - - def table_name - ActiveRecord::Base.table_name_prefix + 'data_migrations' + ActiveRecord::Base.table_name_suffix - end - - def primary_key - "version" - end - end - - def initialize(name = self.class.name, version = nil) - super(name, version) - end - end -end diff --git a/lib/data_migrate/schema_migration.rb b/lib/data_migrate/schema_migration.rb deleted file mode 100644 index 25da4a53..00000000 --- a/lib/data_migrate/schema_migration.rb +++ /dev/null @@ -1,31 +0,0 @@ -module DataMigrate - # Helper class to getting access to db schema - # to allow data/schema combiation tasks - class SchemaMigration - def self.pending_schema_migrations - all_migrations = DataMigrate::DataMigrator.migrations(migrations_paths) - sort_migrations( - ActiveRecord::Migrator.new(:up, all_migrations). - pending_migrations. - map {|m| { version: m.version, name: m.name, kind: :schema }} - ) - end - - def self.run(direction, migration_paths, version) - ActiveRecord::Migrator.run(direction, migration_paths, version) - end - - def self.sort_migrations(set1, set2 = nil) - migrations = set1 + (set2 || []) - migrations.sort {|a, b| sort_string(a) <=> sort_string(b)} - end - - def self.migrations_paths - Rails.application.config.paths["db/migrate"].to_a - end - - def self.sort_string(migration) - "#{migration[:version]}_#{migration[:kind] == :data ? 1 : 0}" - end - end -end diff --git a/lib/data_migrate/status_service.rb b/lib/data_migrate/status_service.rb deleted file mode 100644 index 920021f3..00000000 --- a/lib/data_migrate/status_service.rb +++ /dev/null @@ -1,65 +0,0 @@ -module DataMigrate - class StatusService - class << self - def dump(connection = ActiveRecord::Base.connection, stream = STDOUT) - new(connection).dump(stream) - stream - end - end - - def initialize(connection) - @connection = connection - end - - def root_folder - Rails.root - end - - def dump(stream) - unless @connection.table_exists?(table_name) - stream.puts "Data migrations table does not exist yet." - return - end - sql = "SELECT version FROM #{DataMigrate::DataMigrator.schema_migrations_table_name}" - db_list = ActiveRecord::Base.connection.select_values(sql) - output(stream, db_list) - end - - private - - def table_name - DataMigrate::DataMigrator.schema_migrations_table_name - end - - def output(stream, db_list) - stream.puts "#{"Status".center(8)} #{"Migration ID".ljust(14)} Migration Name" - stream.puts "-" * 50 - list = migration_files(db_list) + migration_list(db_list) - list.sort! {|line1, line2| line1[1] <=> line2[1]} - list.each do |file| - stream.puts "#{file[0].center(8)} #{file[1].ljust(14)} #{file[2]}" - end - stream.puts - end - - def migration_list(db_list) - list = [] - db_list.each do |version| - list << ["up", version, "********** NO FILE *************"] - end - list - end - - def migration_files(db_list) - file_list = [] - Dir.foreach(File.join(root_folder, DataMigrate.config.data_migrations_path)) do |file| - # only files matching "20091231235959_some_name.rb" pattern - if match_data = DataMigrate::DataMigrator.match(file) - status = db_list.delete(match_data[1]) ? "up" : "down" - file_list << [status, match_data[1], match_data[2].humanize] - end - end - file_list - end - end -end diff --git a/lib/data_migrate/status_service_five.rb b/lib/data_migrate/status_service_five.rb index 59eb77ee..ef0558cf 100644 --- a/lib/data_migrate/status_service_five.rb +++ b/lib/data_migrate/status_service_five.rb @@ -32,7 +32,11 @@ def output(stream) end # output - stream.puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n" + if ActiveRecord.version >= Gem::Version.new('7.0') + stream.puts "\ndatabase: #{ActiveRecord::Base.connection_db_config.configuration_hash[:database]}\n\n" + else + stream.puts "\ndatabase: #{ActiveRecord::Base.connection_config[:database]}\n\n" + end stream.puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} Migration Name" stream.puts "-" * 50 db_list.each do |status, version, name| diff --git a/lib/data_migrate/tasks/data_migrate_tasks.rb b/lib/data_migrate/tasks/data_migrate_tasks.rb index 1d840316..7ea89a35 100644 --- a/lib/data_migrate/tasks/data_migrate_tasks.rb +++ b/lib/data_migrate/tasks/data_migrate_tasks.rb @@ -7,7 +7,7 @@ def migrations_paths end def dump - if ActiveRecord::Base.dump_schema_after_migration + if dump_schema_after_migration? filename = DataMigrate::DatabaseTasks.schema_file ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration File.open(filename, "w:utf-8") do |file| @@ -17,14 +17,10 @@ def dump end def migrate - DataMigrate::DataMigrator.assure_data_schema_table target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil - if (Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 2) || - Rails::VERSION::MAJOR == 6 - DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version) - else - DataMigrate::DataMigrator.migrate(migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) - end + + DataMigrate::DataMigrator.assure_data_schema_table + DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version) end def abort_if_pending_migrations(migrations, message) @@ -36,6 +32,14 @@ def abort_if_pending_migrations(migrations, message) abort message end end + + def dump_schema_after_migration? + if ActiveRecord.respond_to?(:dump_schema_after_migration) + ActiveRecord.dump_schema_after_migration + else + ActiveRecord::Base.dump_schema_after_migration + end + end end end end diff --git a/lib/data_migrate/version.rb b/lib/data_migrate/version.rb index d5f720d0..5499dba4 100644 --- a/lib/data_migrate/version.rb +++ b/lib/data_migrate/version.rb @@ -1,3 +1,3 @@ module DataMigrate - VERSION = "7.0.2".freeze + VERSION = "8.0.0.rc1".freeze end diff --git a/lib/generators/data_migration/data_migration_generator.rb b/lib/generators/data_migration/data_migration_generator.rb index 7b026e0e..f8279545 100644 --- a/lib/generators/data_migration/data_migration_generator.rb +++ b/lib/generators/data_migration/data_migration_generator.rb @@ -27,13 +27,7 @@ def set_local_assigns! end def migration_base_class_name - if ActiveRecord.version >= Gem::Version.new("5.0") - "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]" - elsif ActiveRecord.version >= Gem::Version.new("5.2") - "DataMigrate::MigrationContext" - else - "ActiveRecord::Migration" - end + "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]" end def data_migrations_file_path diff --git a/spec/data_migrate/database_tasks_spec.rb b/spec/data_migrate/database_tasks_spec.rb index a614852d..8c9c3d73 100644 --- a/spec/data_migrate/database_tasks_spec.rb +++ b/spec/data_migrate/database_tasks_spec.rb @@ -5,16 +5,10 @@ describe DataMigrate::DatabaseTasks do let(:subject) { DataMigrate::DatabaseTasks } let(:migration_path) { - if Rails::VERSION::MAJOR == 6 - "spec/db/migrate/6.0" - elsif Rails::VERSION::MAJOR == 5 - if Rails::VERSION::MINOR == 2 - "spec/db/migrate/5.2" - else - "spec/db/migrate/5.0" - end + if Rails::VERSION::MAJOR == 5 + "spec/db/migrate/5.2" else - "spec/db/migrate/4.2" + "spec/db/migrate/6.0" end } let(:data_migrations_path) { @@ -32,6 +26,7 @@ # Rails.application.config.paths["db"].first # @see https://github.com/rails/rails/blob/a7d49ef78c36df2d1ca876451f30915ada1079a5/activerecord/lib/active_record/tasks/database_tasks.rb#L54 allow(subject).to receive(:db_dir).and_return("db") + allow(ActiveRecord::Tasks::DatabaseTasks).to receive(:db_dir).and_return("db") end before do diff --git a/spec/data_migrate/migration_context_spec.rb b/spec/data_migrate/migration_context_spec.rb index 2466b788..b6947660 100644 --- a/spec/data_migrate/migration_context_spec.rb +++ b/spec/data_migrate/migration_context_spec.rb @@ -2,28 +2,20 @@ describe DataMigrate::DataMigrator do let(:context) { - if (Rails::VERSION::MAJOR == 6) - DataMigrate::MigrationContext.new("spec/db/data-6.0") - else + if (Rails::VERSION::MAJOR == 5) DataMigrate::MigrationContext.new("spec/db/data") + else + DataMigrate::MigrationContext.new("spec/db/data-6.0") end } let(:schema_context) { - if (Rails::VERSION::MAJOR == 6) - ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration) - else + if (Rails::VERSION::MAJOR == 5) ActiveRecord::MigrationContext.new("spec/db/migrate/5.2") + else + ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration) end } - before do - unless (Rails::VERSION::MAJOR == 5 and - Rails::VERSION::MINOR == 2) || - Rails::VERSION::MAJOR == 6 - skip("Tests are only applicable for Rails 5.2") - end - end - after do begin ActiveRecord::Migration.drop_table("data_migrations") diff --git a/spec/data_migrate/schema_migration_spec.rb b/spec/data_migrate/schema_migration_spec.rb index 2ac05842..fed0b06d 100644 --- a/spec/data_migrate/schema_migration_spec.rb +++ b/spec/data_migrate/schema_migration_spec.rb @@ -4,16 +4,10 @@ describe DataMigrate::SchemaMigration do let(:migration_path) { - if Rails::VERSION::MAJOR == 6 - "spec/db/migrate/6.0" - elsif Rails::VERSION::MAJOR == 5 - if Rails::VERSION::MINOR == 2 - "spec/db/migrate/5.2" - else - "spec/db/migrate/5.0" - end + if Rails::VERSION::MAJOR == 5 + "spec/db/migrate/5.2" else - "spec/db/migrate/4.2" + "spec/db/migrate/6.0" end } @@ -72,22 +66,27 @@ if Rails.version > '6' describe :migrations_paths do context 'when a db_name is configured' do + let(:config) { double(:config) } let(:paths) { ['spec/db/migrate/6.0', 'spec/db/components/migrate/6.0'] } - - if Rails.version > '6.1' - before do - allow(ActiveRecord::Base.configurations.configs_for(env_name: 'test', name: 'primary')).to receive(:migrations_paths).and_return(paths) - DataMigrate.configure do |config| - config.spec_name = 'primary' - end + let(:config_options) do + if Rails.version > '6.1' + { env_name: 'test', name: 'primary' } + else + { env_name: 'test', spec_name: 'primary' } end - else - before do - allow(ActiveRecord::Base.configurations.configs_for(env_name: 'test', spec_name: 'primary')).to receive(:migrations_paths).and_return(paths) - DataMigrate.configure do |config| - config.spec_name = 'primary' - end + end + + before do + DataMigrate.configure do |config| + config.spec_name = 'primary' end + + allow(ActiveRecord::Base.configurations) + .to receive(:configs_for) + .with(config_options) + .and_return(config) + + allow(config).to receive(:migrations_paths).and_return(paths) end it 'lists schema migration paths' do diff --git a/spec/db/5.0/20091231235959_some_name.rb b/spec/db/5.0/20091231235959_some_name.rb deleted file mode 100644 index 12d03acf..00000000 --- a/spec/db/5.0/20091231235959_some_name.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SomeName < ActiveRecord::Migration[5.0] - def up - puts "Doing data migration" - end - - def down - raise ActiveRecord::IrreversibleMigration - end -end diff --git a/spec/db/5.0/20171231235959_super_update.rb b/spec/db/5.0/20171231235959_super_update.rb deleted file mode 100644 index 1003f1ce..00000000 --- a/spec/db/5.0/20171231235959_super_update.rb +++ /dev/null @@ -1,9 +0,0 @@ -class SuperUpdate < ActiveRecord::Migration[5.0] - def up - puts "Doing data migration" - end - - def down - raise ActiveRecord::IrreversibleMigration - end -end diff --git a/spec/db/migrate/4.2/20131111111111_late_migration.rb b/spec/db/migrate/4.2/20131111111111_late_migration.rb deleted file mode 100644 index b6fb5253..00000000 --- a/spec/db/migrate/4.2/20131111111111_late_migration.rb +++ /dev/null @@ -1,9 +0,0 @@ -class LateMigration < ActiveRecord::Migration - def up - puts "Doing schema LateMigration" - end - - def down - puts "Undoing LateMigration" - end -end diff --git a/spec/db/migrate/4.2/20202020202011_db_migration.rb b/spec/db/migrate/4.2/20202020202011_db_migration.rb deleted file mode 100644 index 13979817..00000000 --- a/spec/db/migrate/4.2/20202020202011_db_migration.rb +++ /dev/null @@ -1,9 +0,0 @@ -class DbMigration < ActiveRecord::Migration - def up - puts "Doing schema migration" - end - - def down - puts "Undoing DbMigration" - end -end diff --git a/spec/db/migrate/5.0/20131111111111_late_migration.rb b/spec/db/migrate/5.0/20131111111111_late_migration.rb deleted file mode 100644 index 4cec3f72..00000000 --- a/spec/db/migrate/5.0/20131111111111_late_migration.rb +++ /dev/null @@ -1,9 +0,0 @@ -class LateMigration < ActiveRecord::Migration[5.0] - def up - puts "Doing schema LateMigration" - end - - def down - puts "Undoing LateMigration" - end -end diff --git a/spec/db/migrate/5.0/20202020202011_db_migration.rb b/spec/db/migrate/5.0/20202020202011_db_migration.rb deleted file mode 100644 index 65973ecf..00000000 --- a/spec/db/migrate/5.0/20202020202011_db_migration.rb +++ /dev/null @@ -1,9 +0,0 @@ -class DbMigration < ActiveRecord::Migration[5.0] - def up - puts "Doing schema migration" - end - - def down - puts "Undoing DbMigration" - end -end diff --git a/spec/generators/data_migration/data_migration_generator_spec.rb b/spec/generators/data_migration/data_migration_generator_spec.rb index 685bb125..aa870651 100644 --- a/spec/generators/data_migration/data_migration_generator_spec.rb +++ b/spec/generators/data_migration/data_migration_generator_spec.rb @@ -8,8 +8,12 @@ describe :next_migration_number do it "next migration" do Timecop.freeze("2016-12-03 22:15:26 -0800") do - expect(ActiveRecord::Base).to receive(:timestamped_migrations) { true } - expect(subject.next_migration_number(1)).to eq("20161204061526") + if ActiveRecord.version >= Gem::Version.new('7.0') + expect(ActiveRecord).to receive(:timestamped_migrations) { true } + else + expect(ActiveRecord::Base).to receive(:timestamped_migrations) { true } + end + expect(subject.next_migration_number(1).to_s).to eq("20161204061526") end end end @@ -17,11 +21,7 @@ describe :migration_base_class_name do let(:subject) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) } it "returns the correct base class name" do - if ActiveRecord.version >= Gem::Version.new('5.0') - expect(subject.send(:migration_base_class_name)).to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]") - else - expect(subject.send(:migration_base_class_name)).to eq('ActiveRecord::Migration') - end + expect(subject.send(:migration_base_class_name)).to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]") end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d7fb24ce..7e2d0361 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,23 +20,13 @@ if example.metadata[:no_override] else @prev_data_migrations_path = DataMigrate.config.data_migrations_path - if Rails::VERSION::MAJOR == 6 + if Rails::VERSION::MAJOR == 5 DataMigrate.configure do |config| - config.data_migrations_path = "spec/db/6.0" - end - elsif Rails::VERSION::MAJOR == 5 - if Rails::VERSION::MINOR == 2 - DataMigrate.configure do |config| - config.data_migrations_path = "spec/db/data" - end - else - DataMigrate.configure do |config| - config.data_migrations_path = "spec/db/5.0" - end + config.data_migrations_path = "spec/db/data" end else DataMigrate.configure do |config| - config.data_migrations_path = "spec/db/5.0" + config.data_migrations_path = "spec/db/6.0" end end end