data_migrate 8.2.0 → 9.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +34 -0
  3. data/.github/workflows/gempush.yml +6 -7
  4. data/.gitignore +3 -1
  5. data/Appraisals +0 -4
  6. data/Changelog.md +52 -0
  7. data/README.md +10 -7
  8. data/data_migrate.gemspec +1 -10
  9. data/lib/data_migrate/config.rb +10 -1
  10. data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +1 -12
  11. data/lib/data_migrate/data_schema.rb +1 -1
  12. data/lib/data_migrate/data_schema_migration.rb +1 -1
  13. data/lib/data_migrate/database_tasks.rb +61 -67
  14. data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +4 -2
  15. data/lib/data_migrate/{status_service_five.rb → status_service.rb} +12 -6
  16. data/lib/data_migrate/tasks/data_migrate_tasks.rb +15 -36
  17. data/lib/data_migrate/version.rb +1 -1
  18. data/lib/data_migrate.rb +6 -8
  19. data/lib/generators/data_migrate.rb +15 -2
  20. data/lib/generators/data_migration/data_migration_generator.rb +5 -1
  21. data/spec/data_migrate/config_spec.rb +48 -6
  22. data/spec/data_migrate/data_migrator_spec.rb +13 -34
  23. data/spec/data_migrate/data_spec.rb +0 -11
  24. data/spec/data_migrate/database_tasks_spec.rb +10 -59
  25. data/spec/data_migrate/legacy_migrator_spec.rb +6 -18
  26. data/spec/data_migrate/migration.rb +11 -13
  27. data/spec/data_migrate/migration_context_spec.rb +11 -37
  28. data/spec/data_migrate/schema_dumper_spec.rb +10 -23
  29. data/spec/data_migrate/schema_migration_spec.rb +40 -42
  30. data/spec/data_migrate/status_service_spec.rb +26 -55
  31. data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +31 -66
  32. data/spec/db/data/20091231235959_some_name.rb +1 -1
  33. data/spec/db/data/20171231235959_super_update.rb +1 -1
  34. data/spec/generators/data_migration/data_migration_generator_spec.rb +47 -6
  35. data/spec/spec_helper.rb +2 -8
  36. data/tasks/databases.rake +37 -85
  37. metadata +14 -31
  38. data/.ruby-version +0 -1
  39. data/.travis.yml +0 -14
  40. data/Gemfile.rails5.2 +0 -10
  41. data/gemfiles/rails_5.2.gemfile +0 -8
  42. data/lib/data_migrate/schema_migration_five.rb +0 -31
  43. data/spec/db/6.0/20091231235959_some_name.rb +0 -9
  44. data/spec/db/6.0/20171231235959_super_update.rb +0 -9
  45. data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
  46. data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
  47. data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
  48. data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
  49. data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
  50. /data/spec/db/migrate/{6.0/20131111111111_late_migration.rb → 20131111111111_late_migration.rb} +0 -0
  51. /data/spec/db/migrate/{6.0/20202020202011_db_migration.rb → 20202020202011_db_migration.rb} +0 -0
data/lib/data_migrate.rb CHANGED
@@ -1,22 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator_five")
3
+ require File.join(File.dirname(__FILE__), "data_migrate", "data_migrator")
4
4
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema_migration")
5
5
  require File.join(File.dirname(__FILE__), "data_migrate", "data_schema")
6
6
  require File.join(File.dirname(__FILE__), "data_migrate", "database_tasks")
7
7
  require File.join(File.dirname(__FILE__), "data_migrate", "schema_dumper")
8
- require File.join(File.dirname(__FILE__), "data_migrate", "status_service_five")
8
+ require File.join(File.dirname(__FILE__), "data_migrate", "status_service")
9
9
  require File.join(File.dirname(__FILE__), "data_migrate", "migration_context")
10
10
  require File.join(File.dirname(__FILE__), "data_migrate", "railtie")
11
11
  require File.join(File.dirname(__FILE__), "data_migrate", "tasks/data_migrate_tasks")
12
12
  require File.join(File.dirname(__FILE__), "data_migrate", "legacy_migrator")
13
13
  require File.join(File.dirname(__FILE__), "data_migrate", "config")
14
-
15
- if Rails::VERSION::MAJOR == 5
16
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_five")
17
- else
18
- require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration_six")
19
- end
14
+ require File.join(File.dirname(__FILE__), "data_migrate", "schema_migration")
20
15
 
21
16
  module DataMigrate
17
+ def self.root
18
+ File.dirname(__FILE__)
19
+ end
22
20
  end
@@ -1,9 +1,22 @@
1
1
  require 'rails/generators/named_base'
2
+
2
3
  module DataMigrate
3
4
  module Generators
4
5
  class DataMigrationGenerator < Rails::Generators::NamedBase #:nodoc:
5
- def self.source_root
6
- @_data_migrate_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), generator_name, 'templates'))
6
+ class << self
7
+ def source_root
8
+ build_data_migrate_source_root
9
+ end
10
+
11
+ private
12
+
13
+ def build_data_migrate_source_root
14
+ if DataMigrate.config.data_template_path == DataMigrate::Config::DEFAULT_DATA_TEMPLATE_PATH
15
+ File.expand_path(File.join(File.dirname(__FILE__), generator_name, 'templates'))
16
+ else
17
+ File.expand_path(File.dirname(DataMigrate.config.data_template_path))
18
+ end
19
+ end
7
20
  end
8
21
  end
9
22
  end
@@ -14,7 +14,7 @@ module DataMigrate
14
14
 
15
15
  def create_data_migration
16
16
  set_local_assigns!
17
- migration_template "data_migration.rb", data_migrations_file_path
17
+ migration_template template_path, data_migrations_file_path
18
18
  end
19
19
 
20
20
  protected
@@ -26,6 +26,10 @@ module DataMigrate
26
26
  end
27
27
  end
28
28
 
29
+ def template_path
30
+ DataMigrate.config.data_template_path
31
+ end
32
+
29
33
  def migration_base_class_name
30
34
  "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
31
35
  end
@@ -1,27 +1,69 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DataMigrate::Config do
4
-
5
6
  it "sets default data_migrations_path path", :no_override do
6
7
  expect(DataMigrate.config.data_migrations_path).to eq "db/data/"
7
8
  end
8
9
 
10
+ it "sets default data_template_path path", :no_override do
11
+ expect(DataMigrate.config.data_template_path).to eq DataMigrate::Config::DEFAULT_DATA_TEMPLATE_PATH
12
+ end
13
+
9
14
  describe "data migration path configured" do
15
+ subject { DataMigrate.config.data_migrations_path }
16
+ let(:data_migrations_path) { "db/awesome/" }
17
+
18
+ before do
19
+ @original_data_migrations_path = DataMigrate.config.data_migrations_path
20
+
21
+ DataMigrate.configure do |config|
22
+ config.data_migrations_path = data_migrations_path
23
+ end
24
+ end
25
+
26
+ after do
27
+ DataMigrate.configure do |config|
28
+ config.data_migrations_path = @original_data_migrations_path
29
+ end
30
+ end
31
+
32
+ it "equals the custom data migration path" do
33
+ is_expected.to eq(data_migrations_path)
34
+ end
35
+ end
36
+
37
+ describe "data template path configured" do
38
+ subject { DataMigrate.config.data_template_path }
39
+ let(:data_template_path) { File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb") }
40
+
10
41
  before do
11
- @before = DataMigrate.config.data_migrations_path
42
+ @original_data_migrations_path = DataMigrate.config.data_template_path
43
+
12
44
  DataMigrate.configure do |config|
13
- config.data_migrations_path = "db/awesome/"
45
+ config.data_template_path = data_template_path
14
46
  end
15
47
  end
16
48
 
17
49
  after do
18
50
  DataMigrate.configure do |config|
19
- config.data_migrations_path = @before
51
+ config.data_template_path = @original_data_migrations_path
20
52
  end
21
53
  end
22
54
 
23
- it do
24
- expect(DataMigrate.config.data_migrations_path).to eq "db/awesome/"
55
+ it "equals the custom data template path" do
56
+ is_expected.to eq data_template_path
57
+ end
58
+
59
+ context "when path does not exist" do
60
+ subject { DataMigrate.config.data_template_path = invalid_path }
61
+
62
+ let(:invalid_path) { "lib/awesome/templates/data_migration.rb" }
63
+
64
+ it "checks that file exists on setting config var" do
65
+ expect { subject }.to raise_error { ArgumentError.new("File not found: '#{data_template_path}'") }
66
+ end
25
67
  end
26
68
  end
27
69
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DataMigrate::DataMigrator do
@@ -10,25 +12,18 @@ describe DataMigrate::DataMigrator do
10
12
  end
11
13
 
12
14
  before do
13
- allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
14
15
  ActiveRecord::Base.establish_connection(db_config)
16
+ ::ActiveRecord::SchemaMigration.create_table
17
+ DataMigrate::DataSchemaMigration.create_table
15
18
  end
16
19
 
17
- describe :load_migrated do
18
- before do
19
- allow(subject).to receive(:db_config) { db_config }.at_least(:once)
20
- ActiveRecord::Base.establish_connection(db_config)
21
- ::ActiveRecord::SchemaMigration.create_table
22
- DataMigrate::DataSchemaMigration.create_table
23
- end
24
-
25
- after do
26
- ActiveRecord::Migration.drop_table("data_migrations")
27
- ActiveRecord::Migration.drop_table("schema_migrations")
28
- end
20
+ after do
21
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
22
+ ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
23
+ end
29
24
 
30
- it do
31
- subject.assure_data_schema_table
25
+ describe ".load_migrated" do
26
+ it "loads migrated versions" do
32
27
  DataMigrate::DataSchemaMigration.create(version: 20090000000000)
33
28
  ::ActiveRecord::SchemaMigration.create(version: 20100000000000)
34
29
  DataMigrate::DataSchemaMigration.create(version: 20110000000000)
@@ -40,19 +35,10 @@ describe DataMigrate::DataMigrator do
40
35
  end
41
36
  end
42
37
 
43
- describe :assure_data_schema_table do
44
- before do
45
- allow(subject).to receive(:db_config) { db_config }.at_least(:once)
46
- ActiveRecord::Base.establish_connection(db_config)
47
- end
48
-
49
- after do
50
- ActiveRecord::Migration.drop_table("data_migrations")
51
- end
52
-
53
- it do
38
+ describe :create_data_schema_table do
39
+ it "creates the data_migrations table" do
54
40
  ActiveRecord::Migration.drop_table("data_migrations") rescue nil
55
- subject.assure_data_schema_table
41
+ subject.create_data_schema_table
56
42
  expect(
57
43
  ActiveRecord::Base.connection.table_exists?("data_migrations")
58
44
  ).to eq true
@@ -60,13 +46,6 @@ describe DataMigrate::DataMigrator do
60
46
  end
61
47
 
62
48
  describe "#migrations_status" do
63
- before do
64
- allow(subject).to receive(:db_config) { db_config }.at_least(:once)
65
- ActiveRecord::Base.establish_connection(db_config)
66
- ::ActiveRecord::SchemaMigration.create_table
67
- DataMigrate::DataSchemaMigration.create_table
68
- end
69
-
70
49
  it "returns all migrations statuses" do
71
50
  status = subject.migrations_status
72
51
  expect(status.length).to eq 2
@@ -4,12 +4,6 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::Data do
6
6
  let(:subject) { DataMigrate::Data }
7
- let(:db_config) do
8
- {
9
- adapter: "sqlite3",
10
- database: "spec/db/test.db"
11
- }
12
- end
13
7
  let(:fixture_file_timestamps) do
14
8
  %w[20091231235959 20101231235959 20111231235959]
15
9
  end
@@ -28,11 +22,6 @@ describe DataMigrate::Data do
28
22
  end
29
23
 
30
24
  describe :define do
31
- before do
32
- allow(DataMigrate::DataMigrator).
33
- to receive(:db_config) { db_config }
34
- end
35
-
36
25
  after do
37
26
  ActiveRecord::Migration.drop_table("data_migrations")
38
27
  end
@@ -4,13 +4,7 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::DatabaseTasks do
6
6
  let(:subject) { DataMigrate::DatabaseTasks }
7
- let(:migration_path) {
8
- if Rails::VERSION::MAJOR == 5
9
- "spec/db/migrate/5.2"
10
- else
11
- "spec/db/migrate/6.0"
12
- end
13
- }
7
+ let(:migration_path) { "spec/db/migrate" }
14
8
  let(:data_migrations_path) {
15
9
  DataMigrate.config.data_migrations_path
16
10
  }
@@ -33,9 +27,8 @@ describe DataMigrate::DatabaseTasks do
33
27
  allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:migrations_paths) {
34
28
  data_migrations_path
35
29
  }
36
- allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
37
30
  ActiveRecord::Base.establish_connection(db_config)
38
- if Rails.version >= '6.1'
31
+ if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
39
32
  hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
40
33
  config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
41
34
  allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
@@ -44,19 +37,10 @@ describe DataMigrate::DatabaseTasks do
44
37
  end
45
38
  end
46
39
 
47
- describe :schema_file do
48
- it "returns the correct data schema file path" do
49
- expect(subject.schema_file(nil)).to eq "db/data_schema.rb"
50
- end
51
- end
52
-
53
40
  context "migrations" do
54
41
  after do
55
- begin
56
- ActiveRecord::Migration.drop_table("data_migrations")
57
- rescue ActiveRecord::StatementInvalid
58
- end
59
- ActiveRecord::Migration.drop_table("schema_migrations")
42
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
43
+ ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
60
44
  end
61
45
 
62
46
  before do
@@ -68,56 +52,23 @@ describe DataMigrate::DatabaseTasks do
68
52
  allow(DataMigrate::DatabaseTasks).to receive(:data_migrations_path) {
69
53
  data_migrations_path
70
54
  }.at_least(:once)
71
- allow(DataMigrate::DatabaseTasks).to receive(:schema_migrations_path) {
72
- migration_path
73
- }.at_least(:once)
74
55
  end
75
56
 
76
57
  describe :past_migrations do
77
- it do
58
+ it "returns past migration records" do
78
59
  subject.forward
79
- m = subject.past_migrations
80
- expect(m.count).to eq 1
81
- expect(m.first[:version]).to eq 20091231235959
60
+ migrations = subject.past_migrations
61
+ expect(migrations.count).to eq 1
62
+ expect(migrations.first[:version]).to eq 20091231235959
82
63
  end
83
64
 
84
65
  it "shows nothing without any migrations" do
85
- m = subject.past_migrations
86
- expect(m.count).to eq 0
87
- end
88
- end
89
-
90
- describe :load_schema_current do
91
- before do
92
- allow(DataMigrate::DataMigrator).to receive(:full_migrations_path).and_return(migration_path)
93
- end
94
-
95
- it "loads the current schema file" do
96
- if Rails::VERSION::MAJOR < 6
97
- skip("Not implemented for Rails lower than 6")
98
- end
99
- allow(subject).to receive(:schema_location).and_return("spec/db/data/schema/")
100
-
101
- subject.load_schema_current
102
- versions = DataMigrate::DataSchemaMigration.normalized_versions
103
- expect(versions.count).to eq(2)
104
- end
105
-
106
- it "loads schema file that has not been update with latest data migrations" do
107
- if Rails::VERSION::MAJOR < 6
108
- skip("Not implemented for Rails lower than 6")
109
- end
110
-
111
- allow(subject).to receive(:schema_location).and_return("spec/db/data/partial_schema/")
112
-
113
- subject.load_schema_current
114
- versions = DataMigrate::DataSchemaMigration.normalized_versions
115
- expect(versions.count).to eq(1)
66
+ migrations = subject.past_migrations
67
+ expect(migrations.count).to eq 0
116
68
  end
117
69
  end
118
70
 
119
71
  describe :forward do
120
-
121
72
  it "run forward default amount of times" do
122
73
  subject.forward
123
74
  versions = DataMigrate::DataSchemaMigration.normalized_versions
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DataMigrate::LegacyMigrator do
@@ -5,30 +7,17 @@ describe DataMigrate::LegacyMigrator do
5
7
  DataMigrate::MigrationContext.new("spec/db/data")
6
8
  }
7
9
 
8
- after do
9
- begin
10
- ActiveRecord::Migration.drop_table("data_migrations")
11
- ActiveRecord::Migration.drop_table("schema_migrations")
12
- rescue StandardError
13
- nil
14
- end
15
- end
16
-
17
10
  before do
18
- ActiveRecord::Base.establish_connection(db_config)
19
11
  ActiveRecord::SchemaMigration.create_table
20
12
  DataMigrate::DataSchemaMigration.create_table
21
13
  end
22
14
 
23
- let(:db_config) do
24
- {
25
- adapter: "sqlite3",
26
- database: "spec/db/test.db"
27
- }
15
+ after do
16
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
17
+ ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
28
18
  end
29
19
 
30
20
  it "migrate legacy migrations to be in correct table" do
31
- DataMigrate::DataSchemaMigration.create_table
32
21
  # simulate creation of legacy data migration when
33
22
  # it was recorded in schema table
34
23
  ActiveRecord::SchemaMigration.create(version: "20091231235959")
@@ -36,7 +25,7 @@ describe DataMigrate::LegacyMigrator do
36
25
  # create one migration in correct place
37
26
  DataMigrate::DataSchemaMigration.create(version: "20171231235959")
38
27
 
39
- migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
28
+ migrated = DataMigrate::DataMigrator.new(:up, []).load_migrated
40
29
  expect(migrated.count).to eq 1
41
30
 
42
31
  DataMigrate::LegacyMigrator.new("spec/db/data").migrate
@@ -46,5 +35,4 @@ describe DataMigrate::LegacyMigrator do
46
35
  migrated = DataMigrate::DataMigrator .new(:up, []).load_migrated
47
36
  expect(migrated.count).to eq 2
48
37
  end
49
-
50
38
  end
@@ -1,19 +1,17 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- if Rails::VERSION::MAJOR >= 5
4
- subject = DataMigrate::MigrationFive
5
- else
6
- subject = DataMigrate::Migration
7
- end
3
+ require 'spec_helper'
8
4
 
9
- describe subject do
10
- it "uses correct table name" do
11
- expect(subject.table_name).to eq("data_migrations")
5
+ describe DataMigrate::Migration do
6
+ describe ".table_name" do
7
+ it "returns correct table name" do
8
+ expect(subject.table_name).to eq("data_migrations")
9
+ end
12
10
  end
13
11
 
14
- it "uses correct index name" do
15
- expect(subject).to receive(:table_name_prefix) { "" }
16
- expect(subject).to receive(:table_name_suffix) { "" }
17
- expect(subject.primary_key).to eq("version")
12
+ describe ".index_name" do
13
+ it "returns correct primary key name" do
14
+ expect(subject.primary_key).to eq("version")
15
+ end
18
16
  end
19
17
  end
@@ -1,48 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe DataMigrate::DataMigrator do
4
- let(:context) {
5
- if (Rails::VERSION::MAJOR == 5)
6
- DataMigrate::MigrationContext.new("spec/db/data")
7
- else
8
- DataMigrate::MigrationContext.new("spec/db/data-6.0")
9
- end
10
- }
11
- let(:schema_context) {
12
- if (Rails::VERSION::MAJOR == 5)
13
- ActiveRecord::MigrationContext.new("spec/db/migrate/5.2")
14
- else
15
- ActiveRecord::MigrationContext.new("spec/db/migrate/6.0", ActiveRecord::Base.connection.schema_migration)
16
- end
17
- }
6
+ let(:context) { DataMigrate::MigrationContext.new("spec/db/data") }
7
+ let(:schema_context) { ActiveRecord::MigrationContext.new("spec/db/migrate", ActiveRecord::Base.connection.schema_migration) }
18
8
 
19
- after do
20
- begin
21
- ActiveRecord::Migration.drop_table("data_migrations")
22
- ActiveRecord::Migration.drop_table("schema_migrations")
23
- rescue StandardError
24
- nil
25
- end
9
+ before do
10
+ ActiveRecord::SchemaMigration.create_table
11
+ DataMigrate::DataSchemaMigration.create_table
26
12
  end
27
13
 
28
- let(:db_config) do
29
- {
30
- adapter: "sqlite3",
31
- database: "spec/db/test.db"
32
- }
14
+ after do
15
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
16
+ ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
33
17
  end
34
18
 
35
- describe :migrate do
36
- before do
37
- ActiveRecord::Base.establish_connection(db_config)
38
- ActiveRecord::SchemaMigration.create_table
39
- end
40
-
41
- after do
42
- ActiveRecord::Migration.drop_table("data_migrations")
43
- ActiveRecord::Migration.drop_table("schema_migrations")
44
- end
45
-
19
+ describe "migrate" do
46
20
  it "migrates existing file" do
47
21
  context.migrate(nil)
48
22
  context.migrations_status
@@ -4,35 +4,22 @@ require "spec_helper"
4
4
 
5
5
  describe DataMigrate::SchemaDumper do
6
6
  let(:subject) { DataMigrate::SchemaDumper }
7
- let(:db_config) do
8
- {
9
- adapter: "sqlite3",
10
- database: "spec/db/test.db"
11
- }
12
- end
13
7
  let(:fixture_file_timestamps) do
14
8
  %w[20091231235959 20101231235959 20111231235959]
15
9
  end
16
10
 
17
- describe :dump do
18
- before do
19
- allow(DataMigrate::DataMigrator).
20
- to receive(:db_config) { db_config }.at_least(:once)
21
- ActiveRecord::Base.establish_connection(db_config)
22
-
23
- ActiveRecord::SchemaMigration.create_table
24
- DataMigrate::DataMigrator.assure_data_schema_table
25
-
26
- ActiveRecord::Base.connection.execute <<-SQL
27
- INSERT INTO #{DataMigrate::DataSchemaMigration.table_name}
28
- VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
29
- SQL
30
- end
11
+ before do
12
+ ActiveRecord::SchemaMigration.create_table
13
+ DataMigrate::DataSchemaMigration.create_table
14
+ DataMigrate::DataSchemaMigration.create(fixture_file_timestamps.map { |t| { version: t } })
15
+ end
31
16
 
32
- after do
33
- ActiveRecord::Migration.drop_table("data_migrations")
34
- end
17
+ after do
18
+ ActiveRecord::Migration.drop_table("data_migrations") rescue nil
19
+ ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
20
+ end
35
21
 
22
+ describe ".dump" do
36
23
  it "writes the define method with the version key to the stream" do
37
24
  stream = StringIO.new
38
25
  DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, stream)