-
Notifications
You must be signed in to change notification settings - Fork 123
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
Showing
3 changed files
with
80 additions
and
3 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,71 @@ | ||
describe 'Ridgepole::Client#diff -> migrate', condition: '>= 5.1.0' do | ||
let(:actual_dsl) do | ||
erbh(<<-ERB) | ||
create_table "employees", id: false, force: :cascade do |t| | ||
t.string "name" | ||
end | ||
ERB | ||
end | ||
|
||
before do | ||
subject.diff('').migrate | ||
subject.diff(actual_dsl).migrate | ||
end | ||
subject { client(allow_pk_change: allow_pk_change) } | ||
|
||
context 'when allow_pk_change option is false' do | ||
let(:allow_pk_change) { false } | ||
|
||
context 'with difference' do | ||
let(:expected_dsl) do | ||
erbh(<<-ERB) | ||
create_table "employees", id: :bigint, force: :cascade do |t| | ||
t.string "name" | ||
end | ||
ERB | ||
end | ||
|
||
it { | ||
expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-MSG) | ||
[WARNING] Primary key definition of `employees` differ but `allow_pk_change` option is false | ||
from: {:id=>false} | ||
to: {:id=>:bigint} | ||
MSG | ||
|
||
delta = subject.diff(expected_dsl) | ||
expect(delta.differ?).to be_falsey | ||
delta.migrate | ||
expect(subject.dump).to match_ruby actual_dsl | ||
} | ||
end | ||
|
||
context 'with no difference' do | ||
let(:expected_dsl) { actual_dsl } | ||
|
||
it { | ||
expect(Ridgepole::Logger.instance).to_not receive(:warn) | ||
|
||
delta = subject.diff(expected_dsl) | ||
expect(delta.differ?).to be_falsey | ||
} | ||
end | ||
end | ||
|
||
context 'when allow_pk_change option is true' do | ||
let(:allow_pk_change) { true } | ||
let(:expected_dsl) do | ||
erbh(<<-ERB) | ||
create_table "employees", id: :serial, force: :cascade do |t| | ||
t.string "name" | ||
end | ||
ERB | ||
end | ||
|
||
it { | ||
delta = subject.diff(expected_dsl) | ||
expect(delta.differ?).to be_truthy | ||
delta.migrate | ||
expect(subject.dump).to match_ruby expected_dsl | ||
} | ||
end | ||
end |