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.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +34 -0
- data/.github/workflows/gempush.yml +6 -7
- data/.gitignore +3 -1
- data/Appraisals +0 -4
- data/Changelog.md +52 -0
- data/README.md +10 -7
- data/data_migrate.gemspec +1 -10
- data/lib/data_migrate/config.rb +10 -1
- data/lib/data_migrate/{data_migrator_five.rb → data_migrator.rb} +1 -12
- data/lib/data_migrate/data_schema.rb +1 -1
- data/lib/data_migrate/data_schema_migration.rb +1 -1
- data/lib/data_migrate/database_tasks.rb +61 -67
- data/lib/data_migrate/{schema_migration_six.rb → schema_migration.rb} +4 -2
- data/lib/data_migrate/{status_service_five.rb → status_service.rb} +12 -6
- data/lib/data_migrate/tasks/data_migrate_tasks.rb +15 -36
- data/lib/data_migrate/version.rb +1 -1
- data/lib/data_migrate.rb +6 -8
- data/lib/generators/data_migrate.rb +15 -2
- data/lib/generators/data_migration/data_migration_generator.rb +5 -1
- data/spec/data_migrate/config_spec.rb +48 -6
- data/spec/data_migrate/data_migrator_spec.rb +13 -34
- data/spec/data_migrate/data_spec.rb +0 -11
- data/spec/data_migrate/database_tasks_spec.rb +10 -59
- data/spec/data_migrate/legacy_migrator_spec.rb +6 -18
- data/spec/data_migrate/migration.rb +11 -13
- data/spec/data_migrate/migration_context_spec.rb +11 -37
- data/spec/data_migrate/schema_dumper_spec.rb +10 -23
- data/spec/data_migrate/schema_migration_spec.rb +40 -42
- data/spec/data_migrate/status_service_spec.rb +26 -55
- data/spec/data_migrate/tasks/data_migrate_tasks_spec.rb +31 -66
- data/spec/db/data/20091231235959_some_name.rb +1 -1
- data/spec/db/data/20171231235959_super_update.rb +1 -1
- data/spec/generators/data_migration/data_migration_generator_spec.rb +47 -6
- data/spec/spec_helper.rb +2 -8
- data/tasks/databases.rake +37 -85
- metadata +14 -31
- data/.ruby-version +0 -1
- data/.travis.yml +0 -14
- data/Gemfile.rails5.2 +0 -10
- data/gemfiles/rails_5.2.gemfile +0 -8
- data/lib/data_migrate/schema_migration_five.rb +0 -31
- data/spec/db/6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20091231235959_some_name.rb +0 -9
- data/spec/db/data-6.0/20171231235959_super_update.rb +0 -9
- data/spec/db/data-6.0/20181128000207_excluded_file.rb.other_ext +0 -1
- data/spec/db/migrate/5.2/20131111111111_late_migration.rb +0 -9
- data/spec/db/migrate/5.2/20202020202011_db_migration.rb +0 -9
- /data/spec/db/migrate/{6.0/20131111111111_late_migration.rb → 20131111111111_late_migration.rb} +0 -0
- /data/spec/db/migrate/{6.0/20202020202011_db_migration.rb → 20202020202011_db_migration.rb} +0 -0
@@ -3,32 +3,20 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe DataMigrate::SchemaMigration do
|
6
|
-
let(:migration_path) {
|
7
|
-
if Rails::VERSION::MAJOR == 5
|
8
|
-
"spec/db/migrate/5.2"
|
9
|
-
else
|
10
|
-
"spec/db/migrate/6.0"
|
11
|
-
end
|
12
|
-
}
|
13
|
-
|
14
6
|
let(:subject) { DataMigrate::SchemaMigration }
|
15
|
-
let(:
|
16
|
-
{
|
17
|
-
adapter: "sqlite3",
|
18
|
-
database: "spec/db/test.db"
|
19
|
-
}
|
20
|
-
end
|
7
|
+
let(:migration_path) { "spec/db/migrate" }
|
21
8
|
let(:fixture_file_timestamps) do
|
22
9
|
%w[20091231235959 20101231235959 20111231235959]
|
23
10
|
end
|
24
11
|
|
25
12
|
before do
|
26
|
-
ActiveRecord::Base.establish_connection(db_config)
|
27
13
|
ActiveRecord::SchemaMigration.create_table
|
14
|
+
DataMigrate::DataSchemaMigration.create_table
|
28
15
|
end
|
29
16
|
|
30
17
|
after do
|
31
|
-
ActiveRecord::Migration.drop_table("
|
18
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
19
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
32
20
|
end
|
33
21
|
|
34
22
|
describe :pending_schema_migrations do
|
@@ -36,6 +24,7 @@ describe DataMigrate::SchemaMigration do
|
|
36
24
|
expect(subject).to receive(:migrations_paths) {
|
37
25
|
migration_path
|
38
26
|
}
|
27
|
+
|
39
28
|
migrations = subject.pending_schema_migrations
|
40
29
|
|
41
30
|
expect(migrations.count).to eq 2
|
@@ -45,7 +34,7 @@ describe DataMigrate::SchemaMigration do
|
|
45
34
|
end
|
46
35
|
|
47
36
|
describe :run do
|
48
|
-
it do
|
37
|
+
it "can run up task" do
|
49
38
|
expect {
|
50
39
|
subject.run(:up, migration_path, 20202020202011)
|
51
40
|
}.to output(/20202020202011 DbMigration: migrating/).to_stdout
|
@@ -53,47 +42,56 @@ describe DataMigrate::SchemaMigration do
|
|
53
42
|
expect(versions.first).to eq("20202020202011")
|
54
43
|
end
|
55
44
|
|
56
|
-
it "
|
45
|
+
it "can run down task" do
|
57
46
|
subject.run(:up, migration_path, 20202020202011)
|
47
|
+
|
58
48
|
expect {
|
59
49
|
subject.run(:down, migration_path, 20202020202011)
|
60
50
|
}.to output(/Undoing DbMigration/).to_stdout
|
51
|
+
|
61
52
|
versions = ActiveRecord::SchemaMigration.normalized_versions
|
53
|
+
|
62
54
|
expect(versions.count).to eq(0)
|
63
55
|
end
|
64
56
|
end
|
65
57
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
58
|
+
describe :migrations_paths do
|
59
|
+
context 'when a db_name is configured' do
|
60
|
+
let(:config) { double(:config) }
|
61
|
+
let(:paths) { ['spec/db/migrate', 'spec/db/migrate/other'] }
|
62
|
+
let(:specification_name) { "primary" }
|
63
|
+
let(:config_options) do
|
64
|
+
if Gem::Dependency.new("railties", "~> 6.0").match?("railties", Gem.loaded_specs["railties"].version)
|
65
|
+
{ env_name: Rails.env, spec_name: specification_name }
|
66
|
+
elsif Gem::Dependency.new("railties", "~> 7.0").match?("railties", Gem.loaded_specs["railties"].version)
|
67
|
+
{ env_name: Rails.env, name: specification_name }
|
77
68
|
end
|
69
|
+
end
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
config.spec_name = 'primary'
|
82
|
-
end
|
83
|
-
|
84
|
-
allow(ActiveRecord::Base.configurations)
|
85
|
-
.to receive(:configs_for)
|
86
|
-
.with(config_options)
|
87
|
-
.and_return(config)
|
71
|
+
before do
|
72
|
+
@original_config_spec_name = DataMigrate.config.spec_name
|
88
73
|
|
89
|
-
|
74
|
+
DataMigrate.configure do |config|
|
75
|
+
config.spec_name = specification_name
|
90
76
|
end
|
91
77
|
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
allow(ActiveRecord::Base.configurations)
|
79
|
+
.to receive(:configs_for)
|
80
|
+
.with(config_options)
|
81
|
+
.and_return(config)
|
82
|
+
allow(config).to receive(:migrations_paths).and_return(paths)
|
83
|
+
end
|
84
|
+
|
85
|
+
after do
|
86
|
+
DataMigrate.configure do |config|
|
87
|
+
config.spec_name = @original_config_spec_name
|
95
88
|
end
|
96
89
|
end
|
90
|
+
|
91
|
+
it 'lists schema migration paths' do
|
92
|
+
expect(subject.migrations_paths.size).to eq(paths.count)
|
93
|
+
expect(subject.migrations_paths).to eq(paths)
|
94
|
+
end
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
@@ -1,30 +1,29 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "spec_helper"
|
3
4
|
|
4
5
|
describe DataMigrate::StatusService do
|
5
|
-
let(:subject) { DataMigrate::
|
6
|
-
let(:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
let(:subject) { DataMigrate::StatusService }
|
7
|
+
let(:stream) { StringIO.new }
|
8
|
+
let(:stream_data) { stream.read }
|
9
|
+
let(:connection_db_config) do
|
10
|
+
if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
|
11
|
+
ActiveRecord::Base.connection_db_config
|
12
|
+
else
|
13
|
+
ActiveRecord::Base.configurations.configs_for.first
|
14
|
+
end
|
11
15
|
end
|
12
|
-
let(:service) { DataMigrate::StatusService }
|
13
16
|
|
14
17
|
context "table does not exists" do
|
15
18
|
before do
|
16
|
-
|
19
|
+
allow_any_instance_of(subject).to receive(:table_name) { "bogus"}
|
20
|
+
|
21
|
+
subject.dump(connection_db_config, stream)
|
22
|
+
stream.rewind
|
17
23
|
end
|
18
24
|
|
19
25
|
it "show error message" do
|
20
|
-
|
21
|
-
stream = StringIO.new
|
22
|
-
|
23
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
24
|
-
|
25
|
-
stream.rewind
|
26
|
-
expected = "Data migrations table does not exist"
|
27
|
-
expect(stream.read).to include expected
|
26
|
+
expect(stream_data).to include("Data migrations table does not exist")
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
@@ -34,69 +33,41 @@ describe DataMigrate::StatusService do
|
|
34
33
|
end
|
35
34
|
|
36
35
|
before do
|
37
|
-
allow(DataMigrate::DataMigrator).
|
38
|
-
to receive(:db_config) { db_config }.at_least(:once)
|
39
|
-
ActiveRecord::Base.establish_connection(db_config)
|
40
|
-
|
41
36
|
ActiveRecord::SchemaMigration.create_table
|
42
|
-
DataMigrate::
|
37
|
+
DataMigrate::DataSchemaMigration.create_table
|
38
|
+
DataMigrate::DataSchemaMigration.create(fixture_file_timestamps.map { |t| { version: t } })
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
VALUES #{fixture_file_timestamps.map { |t| "(#{t})" }.join(', ')}
|
47
|
-
SQL
|
48
|
-
|
49
|
-
allow_any_instance_of(service).to receive(:root_folder) { "./" }
|
40
|
+
subject.dump(connection_db_config, stream)
|
41
|
+
stream.rewind
|
50
42
|
end
|
51
43
|
|
52
44
|
after do
|
53
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
45
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
46
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
54
47
|
end
|
55
48
|
|
56
49
|
it "shows successfully executed migration" do
|
57
|
-
stream = StringIO.new
|
58
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
59
|
-
stream.rewind
|
60
|
-
|
61
50
|
expected = " up 20091231235959 Some name"
|
62
|
-
expect(
|
51
|
+
expect(stream_data).to include expected
|
63
52
|
end
|
64
53
|
|
65
54
|
it "excludes files without .rb extension" do
|
66
|
-
stream = StringIO.new
|
67
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
68
|
-
stream.rewind
|
69
|
-
|
70
55
|
expected = "20181128000207 Excluded file"
|
71
|
-
expect(
|
56
|
+
expect(stream_data).to_not include expected
|
72
57
|
end
|
73
58
|
|
74
59
|
it "shows missing file migration" do
|
75
|
-
stream = StringIO.new
|
76
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
77
|
-
stream.rewind
|
78
|
-
|
79
60
|
expected = " up 20101231235959 ********** NO FILE **********"
|
80
|
-
|
81
|
-
expect(s).to include expected
|
61
|
+
expect(stream_data).to include expected
|
82
62
|
end
|
83
63
|
|
84
64
|
it "shows migration that has not run yet" do
|
85
|
-
stream = StringIO.new
|
86
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
87
|
-
stream.rewind
|
88
|
-
|
89
65
|
expected = " down 20171231235959 Super update"
|
90
|
-
|
91
|
-
expect(s).to include expected
|
66
|
+
expect(stream_data).to include expected
|
92
67
|
end
|
93
68
|
|
94
69
|
it "outputs migrations in chronological order" do
|
95
|
-
|
96
|
-
service.dump(ActiveRecord::Base.connection, stream)
|
97
|
-
stream.rewind
|
98
|
-
s = stream.read
|
99
|
-
expect(s.index("20091231235959")).to be < s.index("20111231235959")
|
70
|
+
expect(stream_data.index("20091231235959")).to be < stream_data.index("20111231235959")
|
100
71
|
end
|
101
72
|
end
|
102
73
|
end
|
@@ -3,33 +3,40 @@
|
|
3
3
|
require "spec_helper"
|
4
4
|
|
5
5
|
describe DataMigrate::Tasks::DataMigrateTasks do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
}
|
6
|
+
let(:connection_db_config) do
|
7
|
+
if Gem::Dependency.new("railties", ">= 6.1").match?("railties", Gem.loaded_specs["railties"].version)
|
8
|
+
ActiveRecord::Base.connection_db_config
|
9
|
+
else
|
10
|
+
ActiveRecord::Base.configurations.configs_for.first
|
12
11
|
end
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
ActiveRecord::SchemaMigration.create_table
|
16
|
+
DataMigrate::DataSchemaMigration.create_table
|
17
|
+
end
|
13
18
|
|
19
|
+
after do
|
20
|
+
ActiveRecord::Migration.drop_table("data_migrations") rescue nil
|
21
|
+
ActiveRecord::Migration.drop_table("schema_migrations") rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :dump do
|
14
25
|
before do
|
15
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
16
26
|
allow(DataMigrate::DatabaseTasks).to receive(:db_dir).and_return("spec/db")
|
17
|
-
|
18
|
-
|
19
|
-
after do
|
20
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
27
|
+
DataMigrate::Tasks::DataMigrateTasks.migrate
|
21
28
|
end
|
22
29
|
|
23
30
|
context 'when not given a separate db config' do
|
24
31
|
it 'does not override the default connection' do
|
25
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
26
32
|
expect(ActiveRecord::Base).not_to receive(:establish_connection)
|
27
33
|
expect(DataMigrate::SchemaDumper).to receive(:dump)
|
34
|
+
|
28
35
|
DataMigrate::Tasks::DataMigrateTasks.dump
|
29
36
|
end
|
30
37
|
end
|
31
38
|
|
32
|
-
context 'when given ' do
|
39
|
+
context 'when given a separate db config' do
|
33
40
|
let(:override_config) do
|
34
41
|
{
|
35
42
|
'host' => '127.0.0.1',
|
@@ -39,6 +46,7 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
39
46
|
'password' => nil,
|
40
47
|
}
|
41
48
|
end
|
49
|
+
let(:paths) { ["spec/db/migrate"] }
|
42
50
|
|
43
51
|
before do
|
44
52
|
DataMigrate.configure do |config|
|
@@ -47,7 +55,6 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
47
55
|
end
|
48
56
|
|
49
57
|
it 'overrides the default connection' do
|
50
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
51
58
|
expect(ActiveRecord::Base).to receive(:establish_connection).with(override_config)
|
52
59
|
DataMigrate::Tasks::DataMigrateTasks.dump
|
53
60
|
end
|
@@ -55,32 +62,12 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
55
62
|
end
|
56
63
|
|
57
64
|
describe :migrate do
|
58
|
-
|
59
|
-
{
|
60
|
-
adapter: "sqlite3",
|
61
|
-
database: "spec/db/test.db"
|
62
|
-
}
|
63
|
-
end
|
64
|
-
|
65
|
-
before do
|
66
|
-
allow(DataMigrate::DataMigrator).to receive(:db_config) { db_config }
|
67
|
-
ActiveRecord::Base.establish_connection(db_config)
|
65
|
+
it "first run should run the first pending migration" do
|
66
|
+
expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20091231235959 SomeName: migrating/).to_stdout
|
68
67
|
end
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
it do
|
75
|
-
expect {
|
76
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
77
|
-
}.to output(/20091231235959 SomeName: migrating/).to_stdout
|
78
|
-
end
|
79
|
-
|
80
|
-
it do
|
81
|
-
expect {
|
82
|
-
DataMigrate::Tasks::DataMigrateTasks.migrate
|
83
|
-
}.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
|
69
|
+
it "second run should run the second pending migration" do
|
70
|
+
expect { DataMigrate::Tasks::DataMigrateTasks.migrate }.to output(/20171231235959 SuperUpdate: migrating/).to_stdout
|
84
71
|
end
|
85
72
|
end
|
86
73
|
|
@@ -111,43 +98,21 @@ describe DataMigrate::Tasks::DataMigrateTasks do
|
|
111
98
|
it "should abort with given message and print names and versions of pending migrations" do
|
112
99
|
expect { subject }
|
113
100
|
.to raise_error(SystemExit, message)
|
114
|
-
.and output(
|
101
|
+
.and output(match(/You have #{migrations.count} pending migrations:/)
|
102
|
+
.and match(Regexp.new(migrations.map { |m| m.slice(:version, :name)
|
103
|
+
.values.join("\\W+") }.join("\\W+")))).to_stdout
|
115
104
|
end
|
116
105
|
end
|
117
106
|
end
|
118
107
|
|
119
|
-
describe
|
120
|
-
let(:db_config) do
|
121
|
-
{
|
122
|
-
adapter: "sqlite3",
|
123
|
-
database: "spec/db/test.db"
|
124
|
-
}
|
125
|
-
end
|
126
|
-
|
108
|
+
describe ".status" do
|
127
109
|
before do
|
128
|
-
|
129
|
-
|
130
|
-
else
|
131
|
-
hash_config = ActiveRecord::DatabaseConfigurations::HashConfig.new('test', 'test', db_config)
|
132
|
-
config_obj = ActiveRecord::DatabaseConfigurations.new([hash_config])
|
133
|
-
allow(ActiveRecord::Base).to receive(:configurations).and_return(config_obj)
|
134
|
-
end
|
135
|
-
|
136
|
-
allow(Rails).to receive(:root) { '.' }
|
137
|
-
|
138
|
-
if Rails::VERSION::MAJOR == 5
|
139
|
-
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:schema_migrations_path) { 'spec/db/migrate/5.2' }
|
140
|
-
else
|
141
|
-
allow(DataMigrate::Tasks::DataMigrateTasks).to receive(:schema_migrations_path) { 'spec/db/migrate/6.0' }
|
142
|
-
end
|
110
|
+
allow(Rails).to receive(:root) { "." }
|
111
|
+
allow(Rails).to receive(:application) { OpenStruct.new(config: OpenStruct.new(paths: { "db/migrate" => ["spec/db/migrate"] })) }
|
143
112
|
|
144
113
|
DataMigrate::Tasks::DataMigrateTasks.migrate
|
145
114
|
end
|
146
115
|
|
147
|
-
after do
|
148
|
-
ActiveRecord::Migration.drop_table("data_migrations")
|
149
|
-
end
|
150
|
-
|
151
116
|
it "should display data migration status" do
|
152
117
|
expect {
|
153
118
|
DataMigrate::Tasks::DataMigrateTasks.status
|
@@ -4,7 +4,8 @@ require 'rails/generators/migration'
|
|
4
4
|
require 'generators/data_migration/data_migration_generator'
|
5
5
|
|
6
6
|
describe DataMigrate::Generators::DataMigrationGenerator do
|
7
|
-
|
7
|
+
subject { DataMigrate::Generators::DataMigrationGenerator }
|
8
|
+
|
8
9
|
describe :next_migration_number do
|
9
10
|
it "next migration" do
|
10
11
|
Timecop.freeze("2016-12-03 22:15:26 -0800") do
|
@@ -19,14 +20,18 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
19
20
|
end
|
20
21
|
|
21
22
|
describe :migration_base_class_name do
|
22
|
-
|
23
|
+
subject { generator.send(:migration_base_class_name) }
|
24
|
+
|
25
|
+
let(:generator) { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
|
26
|
+
|
23
27
|
it "returns the correct base class name" do
|
24
|
-
|
28
|
+
is_expected.to eq("ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]")
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
32
|
describe :create_data_migration do
|
29
|
-
|
33
|
+
subject { DataMigrate::Generators::DataMigrationGenerator.new(['my_migration']) }
|
34
|
+
|
30
35
|
let(:data_migrations_file_path) { 'abc/my_migration.rb' }
|
31
36
|
|
32
37
|
context 'when custom data migrations path has a trailing slash' do
|
@@ -35,7 +40,7 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
35
40
|
end
|
36
41
|
|
37
42
|
it 'returns correct file path' do
|
38
|
-
|
43
|
+
is_expected.to receive(:migration_template).with(
|
39
44
|
'data_migration.rb', data_migrations_file_path
|
40
45
|
)
|
41
46
|
|
@@ -49,7 +54,7 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
49
54
|
end
|
50
55
|
|
51
56
|
it 'returns correct file path' do
|
52
|
-
|
57
|
+
is_expected.to receive(:migration_template).with(
|
53
58
|
'data_migration.rb', data_migrations_file_path
|
54
59
|
)
|
55
60
|
|
@@ -57,4 +62,40 @@ describe DataMigrate::Generators::DataMigrationGenerator do
|
|
57
62
|
end
|
58
63
|
end
|
59
64
|
end
|
65
|
+
|
66
|
+
describe ".source_root" do
|
67
|
+
subject { described_class.source_root }
|
68
|
+
|
69
|
+
let(:default_source_root) do
|
70
|
+
File.expand_path(
|
71
|
+
File.dirname(File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb"))
|
72
|
+
)
|
73
|
+
end
|
74
|
+
|
75
|
+
it { is_expected.to eq default_source_root }
|
76
|
+
|
77
|
+
context "when DateMigrate.config.data_template_path is set" do
|
78
|
+
before do
|
79
|
+
@before = DataMigrate.config.data_template_path
|
80
|
+
DataMigrate.configure do |config|
|
81
|
+
config.data_template_path = data_template_path
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
let(:data_template_path) do
|
86
|
+
File.join(DataMigrate.root, "generators", "data_migration", "templates", "data_migration.rb")
|
87
|
+
end
|
88
|
+
let(:expected_source_root) { File.dirname(data_template_path) }
|
89
|
+
|
90
|
+
after do
|
91
|
+
DataMigrate.configure do |config|
|
92
|
+
config.data_template_path = @before
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it "reads directory from config data template path" do
|
97
|
+
is_expected.to eq expected_source_root
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
60
101
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -20,14 +20,8 @@ RSpec.configure do |config|
|
|
20
20
|
if example.metadata[:no_override]
|
21
21
|
else
|
22
22
|
@prev_data_migrations_path = DataMigrate.config.data_migrations_path
|
23
|
-
|
24
|
-
|
25
|
-
config.data_migrations_path = "spec/db/data"
|
26
|
-
end
|
27
|
-
else
|
28
|
-
DataMigrate.configure do |config|
|
29
|
-
config.data_migrations_path = "spec/db/6.0"
|
30
|
-
end
|
23
|
+
DataMigrate.configure do |config|
|
24
|
+
config.data_migrations_path = "spec/db/data"
|
31
25
|
end
|
32
26
|
end
|
33
27
|
end
|