require 'spec_helper' describe Jumpup::Heroku::Configuration do before do Jumpup::Heroku.configuration = nil end describe ".configure" do describe "without configuration" do before do Jumpup::Heroku.configure do |config| end end subject { Jumpup::Heroku.configuration } it { expect(subject.app).to be_nil } it { expect(subject.staging_app).to be_nil } it { expect(subject.production_app).to be_nil } it { expect(subject.run_database_tasks).to be_truthy } it { expect(subject.host).to eq('heroku.com') } it { expect(subject.deploy_branch).to eq('master') } it { expect(subject.deploy_to_production_branch).to eq('master') } end describe "with configurations" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.production_app = 'myapp-production' config.staging_app = 'myapp-staging' config.run_database_tasks = false config.host = 'myhost.com' end end subject { Jumpup::Heroku.configuration } it { expect(subject.app).to eq('myapp') } it { expect(subject.staging_app).to eq('myapp-staging')} it { expect(subject.production_app).to eq('myapp-production') } it { expect(subject.run_database_tasks).to be_falsey } it { expect(subject.host).to eq('myhost.com') } it { expect(subject.deploy_branch).to eq('master') } it { expect(subject.deploy_to_production_branch).to eq('production') } end describe "with multiple accounts" do context "first account" do before { allow(ENV).to receive(:[]).with("HEROKU_ACCOUNT").and_return("first") } before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = false config.account(:first) do |first| first.production_app = 'myapp1-production' first.staging_app = 'myapp1-staging' end config.account(:second) do |second| second.production_app = 'myapp2-production' second.staging_app = 'myapp2-staging' end end end subject { Jumpup::Heroku.configuration } it { expect(subject.valid?).to be_truthy } it { expect(subject.app).to be_nil } it { expect(subject.staging_app).to eq('myapp1-staging')} it { expect(subject.production_app).to eq('myapp1-production') } it { expect(subject.run_database_tasks).to be_falsey } it { expect(subject.host).to eq('heroku.first') } end context "second account with default values" do before { allow(ENV).to receive(:[]).with("HEROKU_ACCOUNT").and_return("second") } before do Jumpup::Heroku.configure do |config| config.production_app = 'myapp1-production' config.staging_app = 'myapp1-staging' config.run_database_tasks = true config.account(:second) do |second| second.production_app = 'myapp2-production' second.staging_app = 'myapp2-staging' second.run_database_tasks = false second.host = 'mysecondhost.com' end end end subject { Jumpup::Heroku.configuration } it { expect(subject.valid?).to be_truthy } it { expect(subject.app).to be_nil } it { expect(subject.staging_app).to eq('myapp2-staging')} it { expect(subject.production_app).to eq('myapp2-production') } it { expect(subject.run_database_tasks).to be_falsey } it { expect(subject.host).to eq('mysecondhost.com') } end context "other account" do before { allow(ENV).to receive(:[]).with("HEROKU_ACCOUNT").and_return("third") } before do Jumpup::Heroku.configure do |config| config.account(:first) do |first| first.app = 'myapp1' first.production_app = 'myapp1-production' first.staging_app = 'myapp1-staging' end config.account(:second) do |second| second.app = 'myapp2' second.production_app = 'myapp2-production' second.staging_app = 'myapp2-staging' end config.run_database_tasks = false end end subject { Jumpup::Heroku.configuration } it { expect(subject.valid?).to be_falsey } it { expect(subject.app).to be_nil } it { expect(subject.staging_app).to be_nil } it { expect(subject.production_app).to be_nil } it { expect(subject.run_database_tasks).to be_falsey } it { expect(subject.host).to eq('heroku.com') } end context "without heroku accounts installed" do before { allow_any_instance_of(Jumpup::Heroku::Configuration).to receive(:current_account).and_return(:"") } before do Jumpup::Heroku.configure do |config| config.account(:second) do |second| second.app = 'myapp2' second.production_app = 'myapp2-production' second.staging_app = 'myapp2-staging' config.run_database_tasks = false end end end subject { Jumpup::Heroku.configuration } it { expect(subject.valid?).to be_falsey } it { expect(subject.app).to be_nil } it { expect(subject.staging_app).to be_nil } it { expect(subject.production_app).to be_nil } it { expect(subject.run_database_tasks).to be_truthy } it { expect(subject.host).to eq('heroku.com') } end context "without heroku accounts installed and default values" do before { allow_any_instance_of(Jumpup::Heroku::Configuration).to receive(:current_account).and_return(:"") } before do Jumpup::Heroku.configure do |config| config.production_app = 'myapp1-production' config.staging_app = 'myapp1-staging' config.run_database_tasks = true config.account(:second) do |second| second.production_app = 'myapp2-production' second.staging_app = 'myapp2-staging' config.run_database_tasks = false end end end subject { Jumpup::Heroku.configuration } it { expect(subject.valid?).to be_truthy } it { expect(subject.app).to be_nil } it { expect(subject.staging_app).to eq('myapp1-staging')} it { expect(subject.production_app).to eq('myapp1-production') } it { expect(subject.run_database_tasks).to be_truthy } end end end describe "#valid?" do describe 'app configs' do describe "with app" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' end end it 'be valid' do expect(Jumpup::Heroku.configuration).to be_valid end end describe "with staging_app and production_app" do before do Jumpup::Heroku.configure do |config| config.production_app = 'myapp-production' config.staging_app = 'myapp-staging' end end it 'be valid' do expect(Jumpup::Heroku.configuration).to be_valid end end describe "with app, staging_app and production_app" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.production_app = 'myapp-production' config.staging_app = 'myapp-staging' end end it 'not be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end describe "with staging_app" do before do Jumpup::Heroku.configure do |config| config.staging_app = 'myapp-staging' end end it 'not be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end describe "with production_app" do before do Jumpup::Heroku.configure do |config| config.production_app = 'myapp-production' end end it 'not be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end describe "with app and production_app" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.production_app = 'myapp-production' end end it 'not be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end describe "with app and staging_app" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.staging_app = 'myapp-staging' end end it 'not be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end end describe 'run_database_tasks configs' do describe "with true run_database_tasks" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = true end end it 'be valid' do expect(Jumpup::Heroku.configuration).to be_valid end end describe "with false run_database_tasks" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = false end end it 'be valid' do expect(Jumpup::Heroku.configuration).to be_valid end end describe "with invalid run_database_tasks" do before do Jumpup::Heroku.configure do |config| config.app = 'myapp' config.run_database_tasks = 'a' end end it 'be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end end describe "without configuration" do before do Jumpup::Heroku.configure do |config| end end it 'not be valid' do expect(Jumpup::Heroku.configuration).to_not be_valid end end describe "with configuration nil" do before do Jumpup::Heroku.configuration = nil end it 'not be valid' do skip "The bug is raised when have no config/initializer/heroku-deploy.rb file" expect(Jumpup::Heroku.configuration).to_not be_valid end end end end