Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1257eb1
commit 4d4dcce
Showing
9 changed files
with
229 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
module Pragma | ||
module Migration | ||
module Hooks | ||
module Operation | ||
def rolled_migrations(options) | ||
build_migration_bond(options).rolled_migrations | ||
end | ||
|
||
def applying_migrations(options) | ||
build_migration_bond(options).applying_migrations | ||
end | ||
|
||
def pending_migrations(options) | ||
build_migration_bond(options).pending_migrations | ||
end | ||
|
||
def migration_rolled?(options, migration) | ||
build_migration_bond(options).migration_rolled?(migration) | ||
end | ||
|
||
def migration_applies?(options, migration) | ||
build_migration_bond(options).migration_applies?(migration) | ||
end | ||
|
||
def migration_pending?(options, migration) | ||
build_migration_bond(options).migration_pending?(migration) | ||
end | ||
|
||
private | ||
|
||
def build_migration_bond(options) | ||
Bond.new( | ||
repository: Pragma::Migration.repository, | ||
request: options['rack.request'], | ||
user_version: Pragma::Migration.user_version_from(options['rack.request']) | ||
) | ||
end | ||
|
||
::Pragma::Operation::Base.prepend(self) if defined?(::Pragma::Operation::Base) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pragma::Migration::Hooks::Operation do | ||
subject(:result) do | ||
operation_klass.call( | ||
{}, | ||
{ | ||
'rack.request' => Rack::Request.new('X-Test-Api-Version' => api_version) | ||
} | ||
) | ||
end | ||
|
||
before(:all) do | ||
module API | ||
module Migration | ||
class SendNewsletterAutomatically < Pragma::Migration::Base | ||
end | ||
end | ||
|
||
class MigrationRepository < Pragma::Migration::Repository | ||
version '2018-07-15' | ||
|
||
version '2018-07-16', [ | ||
API::Migration::SendNewsletterAutomatically | ||
] | ||
end | ||
end | ||
|
||
Pragma::Migration.repository = API::MigrationRepository | ||
|
||
Pragma::Migration.user_version_proc = lambda do |request| | ||
request.get_header 'X-Test-Api-Version' | ||
end | ||
end | ||
|
||
let(:operation_klass) do | ||
Class.new(Pragma::Operation::Base) do | ||
success :check_migrations! | ||
|
||
def check_migrations!(options, **) | ||
options['result.migration_rolled'] = migration_rolled?( | ||
options, | ||
API::Migration::SendNewsletterAutomatically | ||
) | ||
|
||
options['result.migration_pending'] = migration_pending?( | ||
options, | ||
API::Migration::SendNewsletterAutomatically | ||
) | ||
|
||
options['result.migration_applies'] = migration_applies?( | ||
options, | ||
API::Migration::SendNewsletterAutomatically | ||
) | ||
|
||
options['result.rolled_migrations'] = rolled_migrations(options) | ||
|
||
options['result.applying_migrations'] = applying_migrations(options) | ||
|
||
options['result.pending_migrations'] = pending_migrations(options) | ||
end | ||
end | ||
end | ||
|
||
context 'when the migration is not rolled' do | ||
let(:api_version) { '2018-07-15' } | ||
|
||
it 'computes whether a migration was rolled' do | ||
expect(result['result.migration_rolled']).to eq(false) | ||
end | ||
|
||
it 'computes whether the migration is pending' do | ||
expect(result['result.migration_pending']).to eq(true) | ||
end | ||
|
||
it 'computes whether a migration applies' do | ||
expect(result['result.migration_applies']).to eq(false) | ||
end | ||
|
||
it 'returns the correct rolled migrations' do | ||
expect(result['result.rolled_migrations']).to eq([]) | ||
end | ||
|
||
it 'returns the correct applying migrations' do | ||
expect(result['result.applying_migrations']).to eq([]) | ||
end | ||
|
||
it 'returns the correct pending migrations' do | ||
expect(result['result.pending_migrations']).to eq([API::Migration::SendNewsletterAutomatically]) | ||
end | ||
end | ||
|
||
context 'when the migration is rolled' do | ||
let(:api_version) { '2018-07-16' } | ||
|
||
it 'computes whether a migration was rolled' do | ||
expect(result['result.migration_rolled']).to eq(true) | ||
end | ||
|
||
it 'computes whether the migration is pending' do | ||
expect(result['result.migration_pending']).to eq(false) | ||
end | ||
|
||
it 'computes whether a migration applies' do | ||
expect(result['result.migration_applies']).to eq(false) | ||
end | ||
|
||
it 'returns the correct rolled migrations' do | ||
expect(result['result.rolled_migrations']).to eq([API::Migration::SendNewsletterAutomatically]) | ||
end | ||
|
||
it 'returns the correct applying migrations' do | ||
expect(result['result.applying_migrations']).to eq([]) | ||
end | ||
|
||
it 'returns the correct pending migrations' do | ||
expect(result['result.pending_migrations']).to eq([]) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe Pragma::Migration do | ||
describe '#repository=' do | ||
it 'changes the repository' do | ||
expect { | ||
subject.repository = 'test' | ||
}.to change(subject, :repository).to('test') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require "bundler/setup" | ||
require 'pragma/operation' | ||
require "pragma/migration" | ||
|
||
require 'coveralls' | ||
|