spec/jumpup/heroku/configuration_spec.rb in jumpup-heroku-0.0.1 vs spec/jumpup/heroku/configuration_spec.rb in jumpup-heroku-0.0.2
- old
+ new
@@ -1,214 +1,295 @@
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 do
Jumpup::Heroku.configuration
end
-
its(:app) { should be_nil }
its(:staging_app) { should be_nil }
its(:production_app) { should be_nil }
its(:run_database_tasks) { should be_true }
+ its(:host) { should == 'heroku.com' }
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 do
Jumpup::Heroku.configuration
end
-
its(:app) { should eq('myapp') }
its(:staging_app) { should eq('myapp-staging')}
its(:production_app) { should eq('myapp-production') }
its(:run_database_tasks) { should be_false }
+ its(:host) { should eq('myhost.com') }
end
+ describe "with multiple accounts" do
+ context "first account" do
+ before { ENV.stub(:[]).with("HEROKU_ACCOUNT").and_return("first") }
+ before do
+ Jumpup::Heroku.configure do |config|
+ config.run_database_tasks = false
+ 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
+ end
+ end
+ subject do
+ Jumpup::Heroku.configuration
+ end
+ its(:app) { should eq('myapp1') }
+ its(:staging_app) { should eq('myapp1-staging')}
+ its(:production_app) { should eq('myapp1-production') }
+ its(:run_database_tasks) { should be_false }
+ its(:host) { should eq('heroku.first') }
+ end
+ context "second account with default values" do
+ before { ENV.stub(:[]).with("HEROKU_ACCOUNT").and_return("second") }
+ before do
+ Jumpup::Heroku.configure do |config|
+ config.app = 'myapp1'
+ config.production_app = 'myapp1-production'
+ config.staging_app = 'myapp1-staging'
+ config.run_database_tasks = true
+ config.account(:second) do |second|
+ second.app = 'myapp2'
+ second.production_app = 'myapp2-production'
+ second.staging_app = 'myapp2-staging'
+ second.run_database_tasks = false
+ second.host = 'mysecondhost.com'
+ end
+ end
+ end
+ subject do
+ Jumpup::Heroku.configuration
+ end
+ its(:app) { should eq('myapp2') }
+ its(:staging_app) { should eq('myapp2-staging')}
+ its(:production_app) { should eq('myapp2-production') }
+ its(:run_database_tasks) { should be_false }
+ its(:host) { should eq('mysecondhost.com') }
+ end
+ context "other account" do
+ before { ENV.stub(:[]).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 do
+ Jumpup::Heroku.configuration
+ end
+ its(:app) { should be_nil }
+ its(:staging_app) { should be_nil }
+ its(:production_app) { should be_nil }
+ its(:run_database_tasks) { should be_false }
+ its(:host) { should eq('heroku.com') }
+ end
+ context "without heroku accounts installed" do
+ before { Jumpup::Heroku::Configuration.any_instance.stub(: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 do
+ Jumpup::Heroku.configuration
+ end
+ its(:app) { should be_nil }
+ its(:staging_app) { should be_nil }
+ its(:production_app) { should be_nil }
+ its(:run_database_tasks) { should be_true }
+ its(:host) { should eq('heroku.com') }
+ end
+ context "without herou accounts installed and default values" do
+ before { Jumpup::Heroku::Configuration.any_instance.stub(:current_account).and_return(:"") }
+ before do
+ Jumpup::Heroku.configure do |config|
+ config.app = 'myapp1'
+ config.production_app = 'myapp1-production'
+ config.staging_app = 'myapp1-staging'
+ config.run_database_tasks = true
+ 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 do
+ Jumpup::Heroku.configuration
+ end
+ its(:app) { should eq('myapp1') }
+ its(:staging_app) { should eq('myapp1-staging')}
+ its(:production_app) { should eq('myapp1-production') }
+ its(:run_database_tasks) { should be_true }
+ end
+ end
end
-
describe "#valid?" 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
-
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
-
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
pending "The bug is raised when have no config/initialier/heroku-deploy.rb file"
expect(Jumpup::Heroku.configuration).to_not be_valid
end
end
end
end
-