describe 'Ridgepole::Client#diff -> migrate' do context 'when change index (same name)' do let(:actual_dsl) { erbh(<<-EOS) create_table "salaries", 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.index ["emp_no", "id"], name: "emp_no", <%= i cond(5.0, using: :btree) %> end EOS } let(:expected_dsl) { erbh(<<-EOS) create_table "salaries", 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.index ["salary", "id"], name: "emp_no", <%= i cond(5.0, using: :btree) %> end EOS } 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_fuzzy actual_dsl delta.migrate expect(subject.dump).to match_fuzzy expected_dsl } end context 'when change index (same name) (2)' do let(:actual_dsl) { erbh(<<-EOS) 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.index ["emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %> end EOS } let(:expected_dsl) { erbh(<<-EOS) 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.index ["salary"], name: "emp_no", <%= i cond(5.0, using: :btree) %> end EOS } 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_fuzzy actual_dsl delta.migrate expect(subject.dump).to match_fuzzy expected_dsl } end context 'when change index (same name) (3)' do let(:actual_dsl) { erbh(<<-EOS) create_table "salaries", primary_key: "emp_no", force: :cascade do |t| t.integer "salary", null: false t.date "from_date", null: false t.date "to_date", null: false t.index ["salary", "emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %> end EOS } let(:expected_dsl) { erbh(<<-EOS) create_table "salaries", primary_key: "emp_no", force: :cascade do |t| t.integer "salary", null: false t.date "from_date", null: false t.date "to_date", null: false t.index ["from_date", "emp_no"], name: "emp_no", <%= i cond(5.0, using: :btree) %> end EOS } 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_fuzzy actual_dsl delta.migrate expect(subject.dump).to match_fuzzy expected_dsl } end end