describe 'Ridgepole::Client#diff -> migrate' do let(:template_variables) { opts = { unsigned: {} } if condition(:mysql_awesome_enabled) opts[:unsigned] = {unsigned: true} end opts } context 'when database and definition are same (default null / nothing -> null:true)' do let(:actual_dsl) { erbh(<<-EOS, template_variables) create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> 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" end EOS } let(:expected_dsl) { erbh(<<-EOS, template_variables) create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> 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: true end EOS } before { subject.diff(actual_dsl).migrate } subject { client } it { delta = subject.diff(expected_dsl) expect(delta.differ?).to be_falsey expect(subject.dump).to match_fuzzy actual_dsl delta.migrate expect(subject.dump).to match_fuzzy expected_dsl.gsub(/\s*,\s*null: true/, '') } end context 'when database and definition are same (default null / null:true -> nothing)' do let(:actual_dsl) { erbh(<<-EOS, template_variables) create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> 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: true end EOS } let(:expected_dsl) { erbh(<<-EOS, template_variables) create_table "employees", primary_key: "emp_no", <%= {force: :cascade}.unshift(@unsigned).i %> 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" end EOS } before { subject.diff(actual_dsl).migrate } subject { client } it { delta = subject.diff(expected_dsl) expect(delta.differ?).to be_falsey expect(subject.dump).to match_fuzzy actual_dsl.gsub(/\s*,\s*null: true/, '') delta.migrate expect(subject.dump).to match_fuzzy expected_dsl } end end