require 'spec_helper' describe Jumpup::Heroku::Integrate do before do Jumpup::Heroku.configuration = nil end describe '#deploy_to_production' do before do allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:run_database_checks) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:confirm_deploy) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:spec) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:confirm_maintenance) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:maintenance) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:backup) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:tag) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:push) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:migrate) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:seed) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:close_maintenance) allow_any_instance_of(Jumpup::Heroku::Integrate).to receive(:restart) Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = false end end subject { Jumpup::Heroku::Integrate.new(double(:app)) } context 'with database tasks disabled' do %I(confirm_deploy spec confirm_maintenance maintenance tag push close_maintenance restart).each do |task| it "runs #{task}" do expect_any_instance_of(Jumpup::Heroku::Integrate).to receive(task) subject.deploy_to_production end end %I(run_database_checks backup migrate seed).each do |task| it "#does not run #{task}" do expect_any_instance_of(Jumpup::Heroku::Integrate).to_not receive(task) subject.deploy_to_production end end end context 'with database migrations' do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = true end end %I(run_database_checks backup migrate seed).each do |task| it "runs #{task}" do expect_any_instance_of(Jumpup::Heroku::Integrate).to receive(task) subject.deploy_to_production end end end describe 'skipping steps' do before { allow(ENV).to receive(:[]) } after { subject.deploy_to_production } context 'skip spec' do context 'present' do before { allow(ENV).to receive(:[]).with('SKIP_SPEC').and_return('1') } it { expect_any_instance_of(Jumpup::Heroku::Integrate).to_not receive(:spec) } end context 'not set' do before { allow(ENV).to receive(:[]).with('SKIP_SPEC').and_return(nil) } it { expect_any_instance_of(Jumpup::Heroku::Integrate).to receive(:spec) } end end describe 'skip backup' do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = true end end context 'present' do before { allow(ENV).to receive(:[]).with('SKIP_BACKUP').and_return('1') } it { expect_any_instance_of(Jumpup::Heroku::Integrate).to_not receive(:backup) } end context 'not set' do before { allow(ENV).to receive(:[]).with('SKIP_BACKUP').and_return(nil) } it { expect_any_instance_of(Jumpup::Heroku::Integrate).to receive(:backup) } end end end end end