describe 'Ridgepole::Client#diff -> migrate' do context 'when change index (unique: false)' do let(:actual_dsl) do erbh(<<-ERB) 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 ERB end let(:expected_dsl) do erbh(<<-ERB) 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", unique: false, <%= i cond(5.0, using: :btree) %> end ERB end before { subject.diff(actual_dsl).migrate } subject { client } it { delta = subject.diff(expected_dsl) expect(delta.differ?).to be_falsy } end context 'when change index (unique: true)' do let(:actual_dsl) do erbh(<<-ERB) 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 ERB end let(:expected_dsl) do erbh(<<-ERB) 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", unique: true, <%= i cond(5.0, using: :btree) %> 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