data-migration 1.2.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/README.md +38 -8
  4. data/data-migration.gemspec +27 -15
  5. data/lib/data-migration.rb +1 -1
  6. data/lib/data_migration/config.rb +1 -1
  7. data/lib/data_migration/job.rb +27 -9
  8. data/lib/data_migration/task.rb +22 -19
  9. data/lib/generators/data_migration/install_generator.rb +28 -0
  10. data/lib/generators/{templates → data_migration/templates}/install_data_migration_tasks.rb.tt +4 -0
  11. metadata +187 -67
  12. data/.editorconfig +0 -14
  13. data/.github/dependabot.yml +0 -27
  14. data/.github/workflows/_trunk_check.yml +0 -15
  15. data/.github/workflows/test.yml +0 -42
  16. data/.gitignore +0 -24
  17. data/.ruby-version +0 -1
  18. data/.trunk/.gitignore +0 -9
  19. data/.trunk/configs/.markdownlint.yaml +0 -2
  20. data/.trunk/configs/.shellcheckrc +0 -7
  21. data/.trunk/configs/.yamllint.yaml +0 -7
  22. data/.trunk/trunk.yaml +0 -39
  23. data/.vscode/extensions.json +0 -18
  24. data/.vscode/settings.json +0 -7
  25. data/Gemfile +0 -3
  26. data/Gemfile.lock +0 -246
  27. data/lib/generators/install_generator.rb +0 -17
  28. data/spec/data_migration/config_spec.rb +0 -116
  29. data/spec/data_migration/job_spec.rb +0 -96
  30. data/spec/data_migration/task_spec.rb +0 -152
  31. data/spec/data_migration_spec.rb +0 -65
  32. data/spec/fixtures/data_migrations/20241206200111_create_users.rb +0 -17
  33. data/spec/fixtures/data_migrations/20241206200112_create_bad_users.rb +0 -5
  34. data/spec/fixtures/data_migrations/20241206200113_change_users.rb +0 -5
  35. data/spec/fixtures/data_migrations/20241206200114_create_batch_users.rb +0 -9
  36. data/spec/fixtures/schema.rb +0 -26
  37. data/spec/generators/install_generator_spec.rb +0 -48
  38. data/spec/generators/migration_generator_spec.rb +0 -50
  39. data/spec/rails_helper.rb +0 -21
  40. data/spec/spec_helper.rb +0 -30
  41. data/spec/support/junit_formatter.rb +0 -6
  42. data/spec/support/rails_helpers.rb +0 -53
  43. data/usr/bin/release.sh +0 -35
data/Gemfile.lock DELETED
@@ -1,246 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- data-migration (1.2.0)
5
- activejob (> 5)
6
- activerecord (> 5)
7
- activesupport (> 5)
8
- rails (> 5)
9
-
10
- GEM
11
- remote: https://rubygems.org/
12
- specs:
13
- actioncable (8.0.0)
14
- actionpack (= 8.0.0)
15
- activesupport (= 8.0.0)
16
- nio4r (~> 2.0)
17
- websocket-driver (>= 0.6.1)
18
- zeitwerk (~> 2.6)
19
- actionmailbox (8.0.0)
20
- actionpack (= 8.0.0)
21
- activejob (= 8.0.0)
22
- activerecord (= 8.0.0)
23
- activestorage (= 8.0.0)
24
- activesupport (= 8.0.0)
25
- mail (>= 2.8.0)
26
- actionmailer (8.0.0)
27
- actionpack (= 8.0.0)
28
- actionview (= 8.0.0)
29
- activejob (= 8.0.0)
30
- activesupport (= 8.0.0)
31
- mail (>= 2.8.0)
32
- rails-dom-testing (~> 2.2)
33
- actionpack (8.0.0)
34
- actionview (= 8.0.0)
35
- activesupport (= 8.0.0)
36
- nokogiri (>= 1.8.5)
37
- rack (>= 2.2.4)
38
- rack-session (>= 1.0.1)
39
- rack-test (>= 0.6.3)
40
- rails-dom-testing (~> 2.2)
41
- rails-html-sanitizer (~> 1.6)
42
- useragent (~> 0.16)
43
- actiontext (8.0.0)
44
- actionpack (= 8.0.0)
45
- activerecord (= 8.0.0)
46
- activestorage (= 8.0.0)
47
- activesupport (= 8.0.0)
48
- globalid (>= 0.6.0)
49
- nokogiri (>= 1.8.5)
50
- actionview (8.0.0)
51
- activesupport (= 8.0.0)
52
- builder (~> 3.1)
53
- erubi (~> 1.11)
54
- rails-dom-testing (~> 2.2)
55
- rails-html-sanitizer (~> 1.6)
56
- activejob (8.0.0)
57
- activesupport (= 8.0.0)
58
- globalid (>= 0.3.6)
59
- activemodel (8.0.0)
60
- activesupport (= 8.0.0)
61
- activerecord (8.0.0)
62
- activemodel (= 8.0.0)
63
- activesupport (= 8.0.0)
64
- timeout (>= 0.4.0)
65
- activestorage (8.0.0)
66
- actionpack (= 8.0.0)
67
- activejob (= 8.0.0)
68
- activerecord (= 8.0.0)
69
- activesupport (= 8.0.0)
70
- marcel (~> 1.0)
71
- activesupport (8.0.0)
72
- base64
73
- benchmark (>= 0.3)
74
- bigdecimal
75
- concurrent-ruby (~> 1.0, >= 1.3.1)
76
- connection_pool (>= 2.2.5)
77
- drb
78
- i18n (>= 1.6, < 2)
79
- logger (>= 1.4.2)
80
- minitest (>= 5.1)
81
- securerandom (>= 0.3)
82
- tzinfo (~> 2.0, >= 2.0.5)
83
- uri (>= 0.13.1)
84
- base64 (0.2.0)
85
- benchmark (0.4.0)
86
- bigdecimal (3.1.8)
87
- bigdecimal (3.1.8-java)
88
- builder (3.3.0)
89
- concurrent-ruby (1.3.4)
90
- connection_pool (2.4.1)
91
- crass (1.0.6)
92
- date (3.4.1)
93
- date (3.4.1-java)
94
- diff-lcs (1.5.1)
95
- docile (1.4.1)
96
- drb (2.2.1)
97
- erubi (1.13.0)
98
- globalid (1.2.1)
99
- activesupport (>= 6.1)
100
- i18n (1.14.6)
101
- concurrent-ruby (~> 1.0)
102
- io-console (0.8.0)
103
- io-console (0.8.0-java)
104
- irb (1.14.1)
105
- rdoc (>= 4.0.0)
106
- reline (>= 0.4.2)
107
- jar-dependencies (0.5.0)
108
- logger (1.6.2)
109
- loofah (2.23.1)
110
- crass (~> 1.0.2)
111
- nokogiri (>= 1.12.0)
112
- mail (2.8.1)
113
- mini_mime (>= 0.1.1)
114
- net-imap
115
- net-pop
116
- net-smtp
117
- marcel (1.0.4)
118
- mini_mime (1.1.5)
119
- mini_portile2 (2.8.8)
120
- minitest (5.25.4)
121
- net-imap (0.5.1)
122
- date
123
- net-protocol
124
- net-pop (0.1.2)
125
- net-protocol
126
- net-protocol (0.2.2)
127
- timeout
128
- net-smtp (0.5.0)
129
- net-protocol
130
- nio4r (2.7.4)
131
- nio4r (2.7.4-java)
132
- nokogiri (1.16.8-arm64-darwin)
133
- racc (~> 1.4)
134
- nokogiri (1.16.8-java)
135
- racc (~> 1.4)
136
- nokogiri (1.16.8-x86_64-linux)
137
- racc (~> 1.4)
138
- psych (5.2.1)
139
- date
140
- stringio
141
- psych (5.2.1-java)
142
- date
143
- jar-dependencies (>= 0.1.7)
144
- racc (1.8.1)
145
- racc (1.8.1-java)
146
- rack (3.1.8)
147
- rack-session (2.0.0)
148
- rack (>= 3.0.0)
149
- rack-test (2.1.0)
150
- rack (>= 1.3)
151
- rackup (2.2.1)
152
- rack (>= 3)
153
- rails (8.0.0)
154
- actioncable (= 8.0.0)
155
- actionmailbox (= 8.0.0)
156
- actionmailer (= 8.0.0)
157
- actionpack (= 8.0.0)
158
- actiontext (= 8.0.0)
159
- actionview (= 8.0.0)
160
- activejob (= 8.0.0)
161
- activemodel (= 8.0.0)
162
- activerecord (= 8.0.0)
163
- activestorage (= 8.0.0)
164
- activesupport (= 8.0.0)
165
- bundler (>= 1.15.0)
166
- railties (= 8.0.0)
167
- rails-dom-testing (2.2.0)
168
- activesupport (>= 5.0.0)
169
- minitest
170
- nokogiri (>= 1.6)
171
- rails-html-sanitizer (1.6.1)
172
- loofah (~> 2.21)
173
- nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
174
- railties (8.0.0)
175
- actionpack (= 8.0.0)
176
- activesupport (= 8.0.0)
177
- irb (~> 1.13)
178
- rackup (>= 1.0.0)
179
- rake (>= 12.2)
180
- thor (~> 1.0, >= 1.2.2)
181
- zeitwerk (~> 2.6)
182
- rake (13.2.1)
183
- rdoc (6.8.1)
184
- psych (>= 4.0.0)
185
- reline (0.5.12)
186
- io-console (~> 0.5)
187
- rexml (3.3.9)
188
- rspec (3.13.0)
189
- rspec-core (~> 3.13.0)
190
- rspec-expectations (~> 3.13.0)
191
- rspec-mocks (~> 3.13.0)
192
- rspec-core (3.13.2)
193
- rspec-support (~> 3.13.0)
194
- rspec-expectations (3.13.3)
195
- diff-lcs (>= 1.2.0, < 2.0)
196
- rspec-support (~> 3.13.0)
197
- rspec-mocks (3.13.2)
198
- diff-lcs (>= 1.2.0, < 2.0)
199
- rspec-support (~> 3.13.0)
200
- rspec-support (3.13.2)
201
- rspec_junit_formatter (0.6.0)
202
- rspec-core (>= 2, < 4, != 2.12.0)
203
- securerandom (0.4.0)
204
- simplecov (0.22.0)
205
- docile (~> 1.1)
206
- simplecov-html (~> 0.11)
207
- simplecov_json_formatter (~> 0.1)
208
- simplecov-cobertura (2.1.0)
209
- rexml
210
- simplecov (~> 0.19)
211
- simplecov-html (0.13.1)
212
- simplecov_json_formatter (0.1.4)
213
- sqlite3 (2.4.0)
214
- mini_portile2 (~> 2.8.0)
215
- sqlite3 (2.4.0-arm64-darwin)
216
- sqlite3 (2.4.0-x86_64-linux-gnu)
217
- stringio (3.1.2)
218
- thor (1.3.2)
219
- timeout (0.4.2)
220
- tzinfo (2.0.6)
221
- concurrent-ruby (~> 1.0)
222
- uri (1.0.2)
223
- useragent (0.16.11)
224
- websocket-driver (0.7.6)
225
- websocket-extensions (>= 0.1.0)
226
- websocket-driver (0.7.6-java)
227
- websocket-extensions (>= 0.1.0)
228
- websocket-extensions (0.1.5)
229
- zeitwerk (2.7.1)
230
-
231
- PLATFORMS
232
- arm64-darwin
233
- universal-java-11
234
- x86_64-linux
235
-
236
- DEPENDENCIES
237
- bundler (~> 2)
238
- data-migration!
239
- rspec (~> 3)
240
- rspec_junit_formatter (~> 0.6)
241
- simplecov (~> 0.21)
242
- simplecov-cobertura (~> 2)
243
- sqlite3 (~> 2.4)
244
-
245
- BUNDLED WITH
246
- 2.5.20
@@ -1,17 +0,0 @@
1
- require "rails/generators"
2
- require "rails/generators/active_record"
3
- require "rails/generators/active_record/migration/migration_generator"
4
-
5
- class InstallGenerator < ActiveRecord::Generators::MigrationGenerator
6
- source_root File.expand_path("../templates", __FILE__)
7
-
8
- def create_migration_file
9
- set_local_assigns!
10
- validate_file_name!
11
- migration_template "install_#{name}.rb", "#{DataMigration.config.schema_migrations_path}/#{file_name}.rb"
12
- end
13
-
14
- def migration_parent
15
- "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
16
- end
17
- end
@@ -1,116 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigration::Config do
4
- subject(:config) { described_class.new }
5
-
6
- let(:current_user) do
7
- User.new(id: 1)
8
- end
9
- let(:action_reporter) do
10
- Class.new do
11
- def current_user
12
- User.new(id: 3)
13
- end
14
-
15
- def context(**kwargs)
16
- kwargs
17
- end
18
- end.new
19
- end
20
- let(:audited) do
21
- Class.new do
22
- def store
23
- { audited_user: User.new(id: 4) }
24
- end
25
- end.new
26
- end
27
- let(:logger) do
28
- Class.new do
29
- def info(message)
30
- puts message
31
- end
32
- end.new
33
- end
34
- let(:other_user) do
35
- User.new(id: 2)
36
- end
37
- let(:migration) do
38
- DataMigration::Task.new(id: 1, name: "test", operator: other_user)
39
- end
40
-
41
- before do
42
- allow(Rails).to receive(:root).and_return(rails_root)
43
- allow(Rails).to receive(:logger).and_return(logger)
44
- end
45
-
46
- it "has default schema migrations path" do
47
- expect(config.schema_migrations_path).to eq "db/migrate"
48
- end
49
-
50
- it "has default data migrations path" do
51
- expect(config.data_migrations_path).to eq "db/data_migrations"
52
- end
53
-
54
- it "has default data migrations full path" do
55
- expect(config.data_migrations_full_path).to eq Rails.root.join("db/data_migrations")
56
- end
57
-
58
- it "has default data migrations path glob" do
59
- expect(config.data_migrations_path_glob).to eq Rails.root.join("db/data_migrations/*.rb").to_s
60
- end
61
-
62
- it "has default generate spec" do
63
- expect(config.generate_spec?).to be true
64
- end
65
-
66
- it "has default task class" do
67
- expect(config.task_class).to eq DataMigration::Task
68
- end
69
-
70
- it "has default job class" do
71
- expect(config.job_class).to eq DataMigration::Job
72
- end
73
-
74
- it "has default job queue name" do
75
- expect(config.job_queue_name).to eq :default
76
- end
77
-
78
- it "has default default jobs limit" do
79
- expect(config.default_jobs_limit).to eq 10
80
- end
81
-
82
- it "has default monitoring context" do
83
- expect(config.monitoring_context).to be_a Proc
84
-
85
- expect(Rails.logger).to receive(:info).with("Data migration context: {:data_migration_name=>\"test\", :data_migration_id=>1, :data_migration_operator_id=>2}")
86
- expect { config.monitoring_context.call(migration) }.not_to raise_error
87
- end
88
-
89
- context "when ActionReporter is defined" do
90
- before do
91
- stub_const("ActionReporter", action_reporter)
92
- end
93
-
94
- it "sets monitoring context" do
95
- expect(ActionReporter).to receive(:context).with(
96
- data_migration_name: "test",
97
- data_migration_id: 1,
98
- data_migration_operator_id: 2
99
- )
100
- expect(ActionReporter).to receive(:current_user).and_return(nil)
101
- expect(ActionReporter).to receive(:current_user=).with(other_user)
102
- expect { config.monitoring_context.call(migration) }.not_to raise_error
103
- end
104
- end
105
-
106
- context "when Audited is defined" do
107
- before do
108
- stub_const("Audited", audited)
109
- end
110
-
111
- it "sets monitoring context" do
112
- expect(Audited).to receive(:store).and_return(audited_user: User.new(id: 5))
113
- expect { config.monitoring_context.call(migration) }.not_to raise_error
114
- end
115
- end
116
- end
@@ -1,96 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigration::Job do
4
- subject(:job) { DataMigration::Job.new }
5
-
6
- let(:operator) { User.create!(email: "test@example.com") }
7
- let(:task) { DataMigration::Task.create!(name: migration_name, operator: operator) }
8
-
9
- let(:migration_name) { "20241206200111_create_users" }
10
- let(:data_migrations_full_path) { File.expand_path("../fixtures/data_migrations", __dir__) }
11
-
12
- before do
13
- allow(Rails).to receive(:env).and_return(rails_env)
14
- allow(Rails).to receive(:logger).and_return(rails_logger)
15
- allow(DataMigration.config).to receive(:data_migrations_full_path).and_return(data_migrations_full_path)
16
- end
17
-
18
- it "runs rspec spec/fixtures/data_migrations/20241206200111_create_users.rb" do
19
- output = `RUN_MIGRATION_TESTS=1 rspec #{data_migrations_full_path}/#{migration_name}.rb`
20
- expect(output).to include("1 example, 0 failures")
21
- end
22
-
23
- describe "#perform" do
24
- subject(:perform) { job.perform(task.id, **job_kwargs) }
25
-
26
- let(:job_kwargs) { {} }
27
-
28
- it "updates the task status to completed" do
29
- expect { perform }.to change { task.reload.status }.to("completed")
30
- end
31
-
32
- context "when migration file is not found" do
33
- before do
34
- task
35
- allow_any_instance_of(DataMigration::Task).to receive(:file_exists?).and_return(false)
36
- end
37
-
38
- it "updates the task status to failed" do
39
- expect(DataMigration).to receive(:notify).with("#{migration_name} not found")
40
- expect { perform }.not_to raise_error
41
- end
42
- end
43
-
44
- context "when migration class is not found" do
45
- let(:migration_name) { "20241206200112_create_bad_users" }
46
-
47
- it "raises an error" do
48
- expect { perform }.to raise_error("Data migration class #{migration_name.gsub(/^[0-9_]+/, "").camelize} not found")
49
- end
50
- end
51
-
52
- context "when migration class does not implement perform method" do
53
- let(:migration_name) { "20241206200113_change_users" }
54
-
55
- it "raises an error" do
56
- expect { perform }.to raise_error("Data migration class #{migration_name.gsub(/^[0-9_]+/, "").camelize} must implement `perform` method")
57
- end
58
- end
59
-
60
- context "when there is an enqueue call" do
61
- let(:migration_name) { "20241206200114_create_batch_users" }
62
-
63
- it "runs the migration in foreground" do
64
- expect { perform }.to change { User.count }.by(3)
65
- expect(task.reload.current_jobs.count).to eq(0)
66
- expect(task.status).to eq("completed")
67
- expect(User.pluck(:email)).to match_array(["test@example.com", "test_1@example.com", "test_2@example.com"])
68
- end
69
-
70
- context "when background is true" do
71
- let(:job_kwargs) { { background: true } }
72
-
73
- before do
74
- operator
75
- end
76
-
77
- it "runs the migration in background" do
78
- expect { perform }.to change(User, :count).by(1)
79
- expect(task.reload.status).to eq("performing")
80
- expect(task.current_jobs.count).to eq(0)
81
- expect(task.kwargs).to eq({})
82
-
83
- expect { job.perform(task.id, index: 2, background: true) }.to change(User, :count).by(1)
84
- expect(task.reload.status).to eq("performing")
85
- expect(task.reload.current_jobs.count).to eq(0)
86
- expect(task.kwargs).to eq({})
87
-
88
- expect { job.perform(task.id, index: 3, background: true) }.to change(User, :count).by(0)
89
- expect(task.reload.status).to eq("completed")
90
- expect(task.reload.current_jobs.count).to eq(0)
91
- expect(task.kwargs).to eq({})
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,152 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigration::Task do
4
- subject(:task) { DataMigration::Task.create!(name: migration_name) }
5
-
6
- let(:migration_name) { "20241206200111_create_users" }
7
- let(:data_migrations_full_path) { File.expand_path("../fixtures/data_migrations", __dir__) }
8
-
9
- before do
10
- # allow(Rails).to receive(:root).and_return(rails_root)
11
- # allow(Rails).to receive(:logger).and_return(rails_logger)
12
- allow(DataMigration.config).to receive(:data_migrations_full_path).and_return(data_migrations_full_path)
13
- end
14
-
15
- describe "#file_path" do
16
- it "returns the full path to the migration file" do
17
- expect(task.file_path).to eq("#{data_migrations_full_path}/#{migration_name}.rb")
18
- end
19
- end
20
-
21
- describe "#file_exists?" do
22
- it "returns true if the file exists" do
23
- expect(task.file_exists?).to be(true)
24
- expect(task.valid?).to be(true)
25
- end
26
-
27
- context "when the file does not exist" do
28
- let(:migration_name) { "20241206200111_create_something_else" }
29
- let(:task) { DataMigration::Task.new(name: migration_name) }
30
-
31
- it "returns false" do
32
- expect(task.file_exists?).to be(false)
33
- expect(task.valid?).to be(false)
34
- end
35
- end
36
- end
37
-
38
- describe "#requires_pause?" do
39
- before do
40
- task.status = :started
41
- task.pause_minutes = 10
42
- end
43
-
44
- it "returns true if pause_minutes is positive and status is not paused" do
45
- expect(task.requires_pause?).to be(true)
46
- end
47
-
48
- context "when pause_minutes is 0" do
49
- before do
50
- task.pause_minutes = 0
51
- end
52
-
53
- it "returns false" do
54
- expect(task.requires_pause?).to be(false)
55
- end
56
- end
57
-
58
- context "when status is paused" do
59
- before do
60
- task.status = :paused
61
- end
62
-
63
- it "returns false" do
64
- expect(task.requires_pause?).to be(false)
65
- end
66
- end
67
- end
68
-
69
- describe "#perform_now" do
70
- it "calls the job class with the task and arguments" do
71
- kwargs = { foo: "bar" }
72
- expect(DataMigration::Job).to receive(:perform_now).with(task.id, **kwargs)
73
- task.perform_now(**kwargs)
74
- end
75
- end
76
-
77
- describe "#perform_later" do
78
- it "calls the job class with the task and arguments" do
79
- kwargs = { foo: "bar" }
80
- expect(DataMigration::Job).to receive(:perform_later).with(task.id, **kwargs)
81
- task.perform_later(**kwargs)
82
- end
83
- end
84
-
85
- describe "#prepare" do
86
- subject(:task) { DataMigration::Task.prepare(migration_name, pause_minutes: 10, jobs_limit: 5) }
87
-
88
- it "creates a new task with the given name, pause, and jobs_limit" do
89
- expect { task }.to change(DataMigration::Task, :count).by(1)
90
- expect(task.name).to eq(migration_name)
91
- expect(task.status).to be_nil
92
- expect(task.pause_minutes).to eq(10)
93
- expect(task.jobs_limit).to eq(5)
94
- end
95
-
96
- context "when chained with perform_now" do
97
- it "calls the job class with the task and arguments" do
98
- perform_args = { "foo" => "bar" }
99
- expect(DataMigration::Job).to receive(:perform_now).with(task.id, **perform_args)
100
- task.perform_now(**perform_args)
101
- expect(task.kwargs).to eq(perform_args)
102
- end
103
- end
104
- end
105
-
106
- describe "#job_check_in!" do
107
- subject(:job_check_in!) { task.job_check_in!(job_id, job_args: ["foo"], job_kwargs: { bar: "baz" }) }
108
-
109
- let(:job_id) { "123" }
110
-
111
- it "adds the job to the current_jobs hash" do
112
- expect { job_check_in! }.to change { task.current_jobs.size }.by(1)
113
- end
114
-
115
- context "when there is a job with the same id" do
116
- before do
117
- task.job_check_in!(job_id, job_args: ["foo"], job_kwargs: { bar: "baz" })
118
- end
119
-
120
- it "raises a JobConflictError" do
121
- expect { job_check_in! }.to raise_error(DataMigration::JobConflictError)
122
- end
123
- end
124
-
125
- context "when default_jobs_limit is 1 and there are jobs" do
126
- before do
127
- DataMigration.config.default_jobs_limit = 1
128
- task.job_check_in!("321", job_args: ["foo"], job_kwargs: { bar: "baz" })
129
- end
130
-
131
- it "raises a JobConcurrencyLimitError" do
132
- expect { job_check_in! }.to raise_error(DataMigration::JobConcurrencyLimitError)
133
- end
134
- end
135
- end
136
-
137
- describe "#job_check_out!" do
138
- subject(:job_check_out!) { task.job_check_out!(job_id) }
139
-
140
- let(:job_id) { "123" }
141
-
142
- before do
143
- task.save!
144
- task.job_check_in!(job_id, job_args: ["foo"], job_kwargs: { bar: "baz" })
145
- end
146
-
147
- it "removes the job from the current_jobs hash" do
148
- expect { job_check_out! }.to change { task.current_jobs.size }.by(-1)
149
- expect(task.current_jobs).not_to have_key(job_id)
150
- end
151
- end
152
- end
@@ -1,65 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe DataMigration do
4
- let(:gem_specification) { Gem::Specification.load(File.expand_path("../../data-migration.gemspec", __FILE__)) }
5
-
6
- it "has a version number" do
7
- expect(described_class::VERSION).to eq gem_specification.version.to_s
8
- end
9
-
10
- let(:changelog_file) { File.expand_path("../../CHANGELOG.md", __FILE__) }
11
- it "has changelog for the version" do
12
- expect(File.exist?(changelog_file)).to be true
13
- expect(File.read(changelog_file)).to include("# #{gem_specification.version}")
14
- end
15
-
16
- let(:license_file) { File.expand_path("../../LICENSE.md", __FILE__) }
17
- it "has license" do
18
- expect(File.exist?(license_file)).to be true
19
- end
20
-
21
- let(:readme_file) { File.expand_path("../../README.md", __FILE__) }
22
- it "has readme" do
23
- expect(File.exist?(readme_file)).to be true
24
- end
25
-
26
- describe ".notify" do
27
- subject(:notify) { DataMigration.notify("test") }
28
- let(:action_reporter) { Class.new }
29
- before do
30
- stub_const("ActionReporter", action_reporter)
31
- end
32
-
33
- it "sends message to ActionReporter" do
34
- expect(action_reporter).to receive(:notify).with("test", context: {})
35
- expect { notify }.not_to raise_error
36
- end
37
- end
38
-
39
- describe ".perform_now" do
40
- subject(:perform_now) { DataMigration.perform_now("test_perform_now") }
41
-
42
- it "delegates to DataMigration::Task.perform_now" do
43
- expect(DataMigration::Task).to receive(:perform_now).with("test_perform_now")
44
- expect { perform_now }.not_to raise_error
45
- end
46
- end
47
-
48
- describe ".perform_later" do
49
- subject(:perform_later) { DataMigration.perform_later("test_perform_later") }
50
-
51
- it "delegates to DataMigration::Task.perform_later" do
52
- expect(DataMigration::Task).to receive(:perform_later).with("test_perform_later")
53
- expect { perform_later }.not_to raise_error
54
- end
55
- end
56
-
57
- describe ".prepare" do
58
- subject(:prepare) { DataMigration.prepare("test_prepare") }
59
-
60
- it "delegates to DataMigration::Task.prepare" do
61
- expect(DataMigration::Task).to receive(:prepare).with("test_prepare")
62
- expect { prepare }.not_to raise_error
63
- end
64
- end
65
- end
@@ -1,17 +0,0 @@
1
- class CreateUsers
2
- def perform(**kwargs)
3
- User.find_or_create_by(email: "test@example.com")
4
- end
5
- end
6
-
7
- if ENV["RUN_MIGRATION_TESTS"] && Object.const_defined?(:RSpec)
8
- require "rails_helper"
9
-
10
- RSpec.describe CreateUsers, type: :data_migration do
11
- subject(:perform) { described_class.new.perform }
12
-
13
- it do
14
- expect { perform }.not_to raise_error
15
- end
16
- end
17
- end