diff --git a/spec/mysql/migrate/migrate_add_check_constraint_spec.rb b/spec/mysql/migrate/migrate_add_check_constraint_spec.rb new file mode 100644 index 00000000..bce3740e --- /dev/null +++ b/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 diff --git a/spec/mysql/migrate/migrate_change_check_constraint_spec.rb b/spec/mysql/migrate/migrate_change_check_constraint_spec.rb new file mode 100644 index 00000000..6c22407c --- /dev/null +++ b/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 diff --git a/spec/mysql/migrate/migrate_drop_check_constraint_spec.rb b/spec/mysql/migrate/migrate_drop_check_constraint_spec.rb new file mode 100644 index 00000000..9a66b5f8 --- /dev/null +++ b/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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 710f16e6..14253312 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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]