Skip to content

Commit

Permalink
Add check const tests for MySQL 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Sep 24, 2022
1 parent 8e40fa8 commit 320757a
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
39 changes: 39 additions & 0 deletions spec/mysql/migrate/migrate_add_check_constraint_spec.rb
@@ -0,0 +1,39 @@
# frozen_string_literal: true

describe 'Ridgepole::Client#diff -> migrate', condition: [['>= 6.1', :mysql80]] do
context 'when add check constraint' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "salaries", id: false, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "salary", null: false
t.date "from_date", null: false
t.date "to_date", null: false
end
ERB
end

let(:expected_dsl) do
erbh(<<-ERB)
create_table "salaries", id: false, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "salary", null: false
t.date "from_date", null: false
t.date "to_date", null: false
t.check_constraint "`salary` > 100", name: "salary_check"
end
ERB
end

before { subject.diff(actual_dsl).migrate }
subject { client }

it {
delta = subject.diff(expected_dsl)
expect(delta.differ?).to be_truthy
expect(subject.dump).to match_ruby actual_dsl
delta.migrate
expect(subject.dump).to match_ruby expected_dsl
}
end
end
40 changes: 40 additions & 0 deletions spec/mysql/migrate/migrate_change_check_constraint_spec.rb
@@ -0,0 +1,40 @@
# frozen_string_literal: true

describe 'Ridgepole::Client#diff -> migrate', condition: [['>= 6.1', :mysql80]] do
context 'when add check constraint' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "salaries", id: false, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "salary", null: false
t.date "from_date", null: false
t.date "to_date", null: false
t.check_constraint "`salary` > 100", name: "salary_check"
end
ERB
end

let(:expected_dsl) do
erbh(<<-ERB)
create_table "salaries", id: false, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "salary", null: false
t.date "from_date", null: false
t.date "to_date", null: false
t.check_constraint "`salary` > 200", name: "salary_check"
end
ERB
end

before { subject.diff(actual_dsl).migrate }
subject { client }

it {
delta = subject.diff(expected_dsl)
expect(delta.differ?).to be_truthy
expect(subject.dump).to match_ruby actual_dsl
delta.migrate
expect(subject.dump).to match_ruby expected_dsl
}
end
end
39 changes: 39 additions & 0 deletions spec/mysql/migrate/migrate_drop_check_constraint_spec.rb
@@ -0,0 +1,39 @@
# frozen_string_literal: true

describe 'Ridgepole::Client#diff -> migrate', condition: [['>= 6.1', :mysql80]] do
context 'when add check constraint' do
let(:actual_dsl) do
erbh(<<-ERB)
create_table "salaries", id: false, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "salary", null: false
t.date "from_date", null: false
t.date "to_date", null: false
t.check_constraint "`salary` > 100", name: "salary_check"
end
ERB
end

let(:expected_dsl) do
erbh(<<-ERB)
create_table "salaries", id: false, force: :cascade do |t|
t.integer "emp_no", null: false
t.integer "salary", null: false
t.date "from_date", null: false
t.date "to_date", null: false
end
ERB
end

before { subject.diff(actual_dsl).migrate }
subject { client }

it {
delta = subject.diff(expected_dsl)
expect(delta.differ?).to be_truthy
expect(subject.dump).to match_ruby actual_dsl
delta.migrate
expect(subject.dump).to match_ruby expected_dsl
}
end
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Expand Up @@ -41,7 +41,7 @@
conds = example.metadata[:condition]

if conds
skip unless Array(conds).any? { |c| condition(*c) }
skip unless Array(conds).any? { |c| condition(c) }
end

case example.metadata[:file_path]
Expand Down

0 comments on commit 320757a

Please sign in to comment.