Skip to content

Commit

Permalink
Merge pull request #39 from hlascelles/do-nothing-if-que-testing-is-p…
Browse files Browse the repository at this point in the history
…resent

Do nothing if migrate! is called on a test DB when que-testing is present
  • Loading branch information
hlascelles authored Aug 1, 2018
2 parents f22c05f + bec689b commit 860fe1d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ Style/Documentation:
Enabled: false
Style/FrozenStringLiteralComment:
Enabled: false
Style/StringLiterals:
EnforcedStyle: single_quotes
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- Do nothing if `migrate!` is called on a test database. [#39](https://github.com/hlascelles/que-scheduler/pull/39)

## 3.2.1 (2018-07-01)

- Add support for ruby 2.5
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activesupport_4.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
que-scheduler (3.1.1)
que-scheduler (3.2.1)
activesupport (>= 4.0)
backports (~> 3.10)
fugit (~> 1.1)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activesupport_5.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
que-scheduler (3.1.1)
que-scheduler (3.2.1)
activesupport (>= 4.0)
backports (~> 3.10)
fugit (~> 1.1)
Expand Down
3 changes: 3 additions & 0 deletions lib/que/scheduler/migrations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module Migrations

class << self
def migrate!(version:)
# Like que, Do not migrate test DBs.
return if defined?(Que::Testing)

Que::Scheduler::Db.transaction do
current = db_version
if current < version
Expand Down
11 changes: 11 additions & 0 deletions spec/que/scheduler/migrations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,16 @@ def audit_table_exists?
def enqueued_table_exists?
ActiveRecord::Base.connection.table_exists?(Que::Scheduler::Audit::ENQUEUED_TABLE_NAME)
end

# When que-testing is present, calls to Que.execute do nothing and return an empty array.
# Thus, trying to migrate a test database will always fail. It is safer to do nothing and not
# create the que-scheduler tables. This follows the logic of que, which does not create its
# tables either.
it "does nothing, and doesn't error, when using que-testing" do
described_class.migrate!(version: 0)
stub_const('Que::Testing', true)
described_class.migrate!(version: 4)
expect(audit_table_exists?).to be false
end
end
end

0 comments on commit 860fe1d

Please sign in to comment.