2010-06-14 13:04:01 +00:00
|
|
|
require 'spec_helper'
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
describe 'Heroku support' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
before(:each) do
|
|
|
|
::Heroku::Client.any_instance.stubs(:post).returns(true)
|
|
|
|
::Heroku::Client.any_instance.stubs(:delete).returns(true)
|
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context '#loaded' do
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'has method to enable heroku' do
|
2010-07-23 20:09:54 +00:00
|
|
|
Locomotive.respond_to?(:enable_heroku).should be_true
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'tells heroku is disabled' do
|
|
|
|
Locomotive.heroku?.should be_false
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'does not add instance methods to Site' do
|
2011-04-28 21:47:01 +00:00
|
|
|
Site.should_not include_instance_method :add_heroku_domains
|
|
|
|
Site.should_not include_instance_method :remove_heroku_domains
|
|
|
|
|
|
|
|
Site.should_not include_class_method :create_first_one_with_heroku
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context '#disabled' do
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
before(:each) do
|
|
|
|
Locomotive.configure do |config|
|
2011-04-03 23:59:41 +00:00
|
|
|
config.hosting = :none
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'has a nil connection' do
|
2011-06-21 00:39:59 +00:00
|
|
|
Locomotive.respond_to?(:heroku_connection).should be_false
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'tells heroku is disabled' do
|
|
|
|
Locomotive.heroku?.should be_false
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'does not add methods to Site' do
|
2011-04-28 21:47:01 +00:00
|
|
|
Site.should_not include_instance_method :add_heroku_domains
|
|
|
|
Site.should_not include_instance_method :remove_heroku_domains
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context '#enabled' do
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
it 'tells heroku is enabled from ENV' do
|
|
|
|
ENV['HEROKU_SLUG'] = 'test'
|
|
|
|
Locomotive.config.hosting = :auto
|
|
|
|
Locomotive.heroku?.should be_true
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
|
|
|
it 'adds a method to automatically create a site with Heroku settings' do
|
|
|
|
configure_locomotive_with_heroku
|
2011-04-28 21:47:01 +00:00
|
|
|
Site.should include_class_method :create_first_one_with_heroku
|
2011-04-05 00:18:17 +00:00
|
|
|
end
|
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
it 'tells heroku is enabled when forcing it' do
|
2010-06-14 13:04:01 +00:00
|
|
|
configure_locomotive_with_heroku
|
|
|
|
Locomotive.heroku?.should be_true
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'raises an exception if no app name is given' do
|
|
|
|
lambda {
|
|
|
|
configure_locomotive_with_heroku(:name => nil)
|
2010-07-23 20:09:54 +00:00
|
|
|
}.should raise_error
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context 'dealing with heroku connection' do
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'opens a heroku connection with provided credentials' do
|
|
|
|
configure_locomotive_with_heroku
|
|
|
|
Locomotive.heroku_connection.user.should == 'john@doe.net'
|
|
|
|
Locomotive.heroku_connection.password.should == 'easyone'
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'opens a heroku connection with env credentials' do
|
2011-04-03 23:59:41 +00:00
|
|
|
::Heroku::Client.any_instance.stubs(:list_domains).returns([])
|
|
|
|
ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'; ENV['APP_NAME'] = 'test'
|
2011-04-05 00:18:17 +00:00
|
|
|
Locomotive.configure { |config| config.hosting = :heroku; config.heroku = {} }
|
2010-06-14 13:04:01 +00:00
|
|
|
Locomotive.heroku_connection.user.should == 'john@doe.net'
|
|
|
|
Locomotive.heroku_connection.password.should == 'easyone'
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context 'enhancing site' do
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
before(:each) do
|
|
|
|
configure_locomotive_with_heroku
|
|
|
|
(@site = Factory.build(:site)).stubs(:valid?).returns(true)
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'calls add_heroku_domains after saving a site' do
|
|
|
|
@site.expects(:add_heroku_domains)
|
2010-07-23 20:09:54 +00:00
|
|
|
@site.save
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
it 'calls remove_heroku_domains after saving a site' do
|
2010-06-14 13:04:01 +00:00
|
|
|
@site.expects(:remove_heroku_domains)
|
|
|
|
@site.destroy
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context 'adding domain' do
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-07-23 20:09:54 +00:00
|
|
|
it 'does not add new domain if no delta' do
|
2010-06-14 13:04:01 +00:00
|
|
|
Locomotive.heroku_connection.expects(:add_domain).never
|
|
|
|
@site.save
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'adds a new domain if new one' do
|
|
|
|
@site.domains = ['www.acme.fr']
|
|
|
|
Locomotive.heroku_connection.expects(:add_domain).with('locomotive', 'www.acme.fr')
|
|
|
|
@site.save
|
|
|
|
Locomotive.heroku_domains.should include('www.acme.fr')
|
|
|
|
end
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
context 'removing domain' do
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'does not remove domain if no delta' do
|
|
|
|
Locomotive.heroku_connection.expects(:remove_domain).never
|
|
|
|
@site.destroy
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'removes domains if we destroy a site' do
|
|
|
|
@site.stubs(:domains_without_subdomain).returns(['www.acme.com'])
|
|
|
|
Locomotive.heroku_connection.expects(:remove_domain).with('locomotive', 'www.acme.com')
|
|
|
|
@site.destroy
|
|
|
|
Locomotive.heroku_domains.should_not include('www.acme.com')
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
it 'removes domain if removed' do
|
|
|
|
@site.domains = ['www.acme.fr']; @site.save
|
|
|
|
@site.domains = ['www.acme.com']
|
|
|
|
Locomotive.heroku_connection.expects(:remove_domain).with('locomotive', 'www.acme.fr')
|
|
|
|
@site.save
|
|
|
|
Locomotive.heroku_domains.should_not include('www.acme.fr')
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
def configure_locomotive_with_heroku(options = {}, domains = nil)
|
2011-04-03 23:59:41 +00:00
|
|
|
if options.has_key?(:name)
|
|
|
|
ENV['APP_NAME'] = options.delete(:name)
|
|
|
|
else
|
|
|
|
ENV['APP_NAME'] = 'locomotive'
|
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
::Heroku::Client.any_instance.stubs(:list_domains).with(ENV['APP_NAME']).returns(domains || [
|
2010-06-14 13:04:01 +00:00
|
|
|
{ :domain => "www.acme.com" }, { :domain => "example.com" }, { :domain => "www.example.com" }
|
|
|
|
])
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2010-06-14 13:04:01 +00:00
|
|
|
Locomotive.configure do |config|
|
2011-04-03 23:59:41 +00:00
|
|
|
config.hosting = :heroku
|
|
|
|
config.heroku = { :login => 'john@doe.net', :password => 'easyone' }.merge(options)
|
2011-04-05 00:18:17 +00:00
|
|
|
|
|
|
|
Locomotive.define_subdomain_and_domains_options
|
|
|
|
|
|
|
|
Object.send(:remove_const, 'Site') if Object.const_defined?('Site')
|
|
|
|
load 'site.rb'
|
|
|
|
end
|
2011-04-03 23:59:41 +00:00
|
|
|
end
|
2011-04-05 00:18:17 +00:00
|
|
|
|
2011-04-03 23:59:41 +00:00
|
|
|
after(:all) do
|
|
|
|
ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
|
2011-04-05 00:18:17 +00:00
|
|
|
Locomotive.configure_for_test(true)
|
2010-06-14 13:04:01 +00:00
|
|
|
end
|
2010-07-23 20:09:54 +00:00
|
|
|
|
|
|
|
end
|