summaryrefslogtreecommitdiff
path: root/spec/support/matchers/background_migrations_matchers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/matchers/background_migrations_matchers.rb')
-rw-r--r--spec/support/matchers/background_migrations_matchers.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/support/matchers/background_migrations_matchers.rb b/spec/support/matchers/background_migrations_matchers.rb
new file mode 100644
index 00000000000..f4127efc6ae
--- /dev/null
+++ b/spec/support/matchers/background_migrations_matchers.rb
@@ -0,0 +1,26 @@
+RSpec::Matchers.define :be_scheduled_delayed_migration do |delay, *expected|
+ match do |migration|
+ BackgroundMigrationWorker.jobs.any? do |job|
+ job['args'] == [migration, expected] &&
+ job['at'].to_i == (delay.to_i + Time.now.to_i)
+ end
+ end
+
+ failure_message do |migration|
+ "Migration `#{migration}` with args `#{expected.inspect}` " \
+ 'not scheduled in expected time!'
+ end
+end
+
+RSpec::Matchers.define :be_scheduled_migration do |*expected|
+ match do |migration|
+ BackgroundMigrationWorker.jobs.any? do |job|
+ args = job['args'].size == 1 ? [BackgroundMigrationWorker.jobs[0]['args'][0], []] : job['args']
+ args == [migration, expected]
+ end
+ end
+
+ failure_message do |migration|
+ "Migration `#{migration}` with args `#{expected.inspect}` not scheduled!"
+ end
+end