describe 'Ridgepole::Client#diff -> migrate' do context 'when change column (no change)' do let(:actual_dsl) do erbh(<<-ERB) create_table "employees", primary_key: "emp_no", force: :cascade do |t| t.date "birth_date", null: false t.string "first_name", limit: 14, null: false t.string "last_name", limit: 16, null: false t.string "gender", limit: 1, null: false t.date "hire_date", null: false t.index ["gender"], name: "gender", <%= i cond(5.0, using: :btree) %> end ERB end let(:expected_dsl) do erbh(<<-ERB) create_table :employees, primary_key: :emp_no, force: :cascade do |t| t.date "birth_date", null: false t.string "first_name", limit: 14, null: false t.string "last_name", limit: 16, null: false t.string "gender", limit: 1, null: false t.date :hire_date, null: false t.index :gender, name: :gender, <%= 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_falsey } end context 'when change column (change)' do let(:actual_dsl) do erbh(<<-ERB) create_table "employees", primary_key: "emp_no", force: :cascade do |t| t.date "birth_date", null: false t.string "first_name", limit: 14, null: false t.string "last_name", limit: 16, null: false t.string "gender", limit: 1, null: false t.date "hire_date", null: false t.index ["gender"], name: "gender", <%= i cond(5.0, using: :btree) %> end ERB end let(:dsl) do erbh(<<-ERB) create_table :employees, primary_key: :emp_no, force: :cascade do |t| t.date "birth_date", null: false t.string "first_name", limit: 14, null: false t.string "last_name", limit: 16, null: false t.string "gender", limit: 1, null: false t.date :hire_date2, null: false t.index :last_name, name: :last_name, <%= i cond(5.0, using: :btree) %> end ERB end let(:expected_dsl) do erbh(<<-ERB) create_table "employees", primary_key: "emp_no", force: :cascade do |t| t.date "birth_date", null: false t.string "first_name", limit: 14, null: false t.string "last_name", limit: 16, null: false t.string "gender", limit: 1, null: false t.date "hire_date2", null: false t.index ["last_name"], name: "last_name", <%= i cond(5.0, using: :btree) %> end ERB end before { subject.diff(actual_dsl).migrate } subject { client } it { delta = subject.diff(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