simply the installation screens + fix all the broken tests + add tests for bushido

This commit is contained in:
did 2011-04-05 02:18:17 +02:00
parent 60df5c19f9
commit 551ef03ff6
30 changed files with 456 additions and 206 deletions

View File

@ -62,7 +62,7 @@ GEM
bson (1.2.4)
bson_ext (1.2.4)
builder (2.1.2)
bushido (0.0.11)
bushido (0.0.12)
highline (>= 1.6.1)
json (>= 1.4.6)
rest-client (>= 1.6.1)
@ -125,7 +125,7 @@ GEM
net-ssh (~> 2.0.23)
nokogiri (~> 1.4.3.1)
ruby-hmac
formatador (0.1.2)
formatador (0.1.3)
formtastic (1.2.3)
actionpack (>= 2.3.7)
activesupport (>= 2.3.7)
@ -156,7 +156,7 @@ GEM
configuration (>= 0.0.5)
rake (>= 0.8.1)
linecache (0.43)
linecache19 (0.5.11)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
locomotive_carrierwave (0.5.0.1.beta3)
activesupport (~> 3.0)
@ -231,7 +231,7 @@ GEM
ruby-debug-base (~> 0.10.4.0)
ruby-debug-base (0.10.4)
linecache (>= 0.3)
ruby-debug-base19 (0.11.24)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
@ -240,7 +240,7 @@ GEM
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby-hmac (0.4.0)
ruby_core_source (0.1.4)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
rubyzip (0.9.4)
s3 (0.3.8)

View File

@ -22,7 +22,7 @@ module Admin
end
def new_host_if_subdomain_changed
if @site.domains.include?(request.host)
if !Locomotive.config.multi_sites? || @site.domains.include?(request.host)
{}
else
{ :host => "#{@site.subdomain}.#{Locomotive.config.default_domain}:#{request.port}" }

View File

@ -23,25 +23,23 @@ module Admin
def handle_get
case params[:step].to_i
when 2 then @account = Account.new
when 3 then @site = Site.new
when 1 then @account = Account.new
when 2 then @site = Site.new
end
render "step_#{params[:step]}"
end
def handle_post
case params[:step].to_i
when 2 # create account
when 1 # create account
@account = Account.create(params[:account])
if @account.valid?
redirect_to admin_installation_step_url(3)
else
render 'step_2'
render 'step_1'
end
when 3 # create site
@site = Site.new(params[:site])
@site.memberships.build :account => Account.first, :admin => true
@site.save
when 2 # create site
@site = Site.create_first_one(params[:site])
if @site.valid?
begin
@ -52,19 +50,19 @@ module Admin
logger.error "Import failed because of #{e.message}"
end
redirect_to admin_session_url(:host => Site.first.domains.first, :port => request.port)
redirect_to last_url
else
render 'step_3'
render 'step_2'
end
end
end
def is_step_already_done?
case params[:step].to_i
when 2 # already an account in db
when 1 # already an account in db
if Account.count > 0
@step_done = t('admin.installation.step_2.done', Account.first.attributes)
render 'step_2' and return false
@step_done = t('admin.installation.step_1.done', Account.first.attributes)
render 'step_1' and return false
end
else
true
@ -75,5 +73,13 @@ module Admin
redirect_to admin_pages_url if Site.count > 0 && Account.count > 0
end
def last_url
if Locomotive.config.manage_domains?
admin_session_url(:host => Site.first.domains.first, :port => request.port)
else
admin_session_url
end
end
end
end

View File

@ -30,6 +30,10 @@ module Admin::SitesHelper
Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains?
end
def manage_subdomain?
Locomotive.config.manage_subdomain?
end
def manage_domains?
Locomotive.config.manage_domains?
end

View File

@ -0,0 +1,18 @@
module Extensions
module Site
module FirstInstallation
# only called during the installation workflow, just after the admin account has been created
def create_first_one(attributes)
site = self.new(attributes)
site.memberships.build :account => Account.first, :admin => true
site.save
site
end
end
end
end

View File

@ -3,7 +3,9 @@ module Extensions
module SubdomainDomains
def enable_subdomain_n_domains_if_multi_sites
if Locomotive.config.multi_sites? || Locomotive.config.manage_subdomain_n_domains?
# puts "multi_sites? #{Locomotive.config.multi_sites?} / manage_domains? #{Locomotive.config.manage_domains?} / heroku? #{Locomotive.heroku?} / bushido? #{Locomotive.bushido?}"
if Locomotive.config.multi_sites? || Locomotive.config.manage_domains?
## fields ##
field :subdomain
@ -15,7 +17,7 @@ module Extensions
## validations ##
validates_presence_of :subdomain
validates_uniqueness_of :subdomain
validates_exclusion_of :subdomain, :in => Locomotive.config.multi_sites.reserved_subdomains
validates_exclusion_of :subdomain, :in => Locomotive.config.reserved_subdomains
validates_format_of :subdomain, :with => Locomotive::Regexps::SUBDOMAIN, :allow_blank => true
validate :domains_must_be_valid_and_unique
@ -29,7 +31,6 @@ module Extensions
}
send :include, InstanceMethods
end
end

View File

@ -4,6 +4,7 @@ class Site
## Extensions ##
extend Extensions::Site::SubdomainDomains
extend Extensions::Site::FirstInstallation
## fields ##
field :name

View File

@ -6,19 +6,21 @@
- content_for :head do
= include_stylesheets :installation
.inner
%p.explanations
= t('.explanations')
- if @step_done.blank?
= semantic_form_for(@account, :url => admin_installation_step_url(1)) do |f|
.inner
= f.inputs do
= f.input :name, :label => t('.name'), :required => false
= f.input :email, :label => t('.email'), :required => false
= f.input :password, :label => t('.password'), :required => false
= f.input :password_confirmation, :label => t('.password_confirmation'), :required => false
%dl
%dt!= t('.database.label', :name => Mongoid.config.database.name)
%dd
%p.notes!= t('.database.notes')
.footer
= box_button_tag t('.next')
- else
.inner
%p.done
!= @step_done
%dt!= t('.default_domain.label', :name => Locomotive.config.default_domain)
%dd
%p.notes!= t('.default_domain.notes', :domain => Locomotive.config.default_domain)
.footer
.footer
= next_installation_step_link(2)

View File

@ -6,21 +6,20 @@
- content_for :head do
= include_stylesheets :installation
- if @step_done.blank?
= semantic_form_for(@account, :url => admin_installation_step_url(2)) do |f|
= semantic_form_for(@site, :url => admin_installation_step_url(2), :html => { :multipart => true }) do |f|
.inner
%p.explanations
!= t('.explanations')
= f.inputs do
= f.input :name, :label => t('.name'), :required => false
= f.input :email, :label => t('.email'), :required => false
= f.input :password, :label => t('.password'), :required => false
= f.input :password_confirmation, :label => t('.password_confirmation'), :required => false
= f.input :name, :required => true
- if manage_subdomain?
= f.input :subdomain, :required => true
%li{ :class => 'string optional', :id => 'zipfile_input' }
%label{ :for => 'zipfile' }= t('formtastic.labels.import.new.source')
= file_field_tag 'zipfile'
.footer
= box_button_tag t('.next')
- else
.inner
%p.done
!= @step_done
.footer
= next_installation_step_link(3)

View File

@ -1,23 +0,0 @@
- content_for :head_title do
= t('admin.installation.common.title')
- title t('.title')
- content_for :head do
= include_stylesheets :installation
= semantic_form_for(@site, :url => admin_installation_step_url(3), :html => { :multipart => true }) do |f|
.inner
%p.explanations
!= t('.explanations')
= f.inputs do
= f.input :name, :required => false
= f.input :subdomain, :required => false
%li{ :class => 'string optional', :id => 'zipfile_input' }
%label{ :for => 'zipfile' }= t('formtastic.labels.import.new.source')
= file_field_tag 'zipfile'
.footer
= box_button_tag t('.next')

View File

@ -22,6 +22,7 @@
= f.input :password, :input_html => { :autocomplete => "off" }
= f.input :password_confirmation, :input_html => { :autocomplete => "off" }
- if multi_sites?
= f.foldable_inputs :name => :sites, :class => 'sites off' do
- @account.sites.each do |site|
%li{ :class => 'item' }

View File

@ -273,23 +273,14 @@ de:
title: Erst-Installation von getbenga
next: Weiter
step_1:
title: Schritt 1/3
explanations: Dies ist der erste Schritt zur Installation von getbenga. Bitte lies die folgenden Texte genau durch.
database:
label: "Datenbank-Name: <em>%{name}</em>"
notes: "All Verbindungseinstellungen für mongodb findest du in der <b>config/mongoid.yml</b> Datei."
default_domain:
label: "Standard Domain-Name: <em>%{name}</em>"
notes: "Basically, Locomotive is a multi websites platform. Each site instance has a default entry, also called subdomain and based on the default domain name. Obviously, you are free to map other domains to your site instance working like aliases. <br/>The default domain name value can be found in the <b>config/initializers/locomotive.rb</b> file."
step_2:
title: "Schritt 2/3 &mdash; Account erstellen"
title: "Schritt 1/2 &mdash; Account erstellen"
name: Account-Name
email: Email
password: Passwort
password_confirmation: Passwort-Bestätigung
done: "Du hast bereits einen Account hinzugefügt:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Account erstellen
step_3:
title: "Schritt 3/3 &mdash; Erstelle deine erste Webseite"
step_2:
title: "Schritt 2/2 &mdash; Erstelle deine erste Webseite"
explanations: "Dies ist der letzte Schritt der Installation. Du kannst nun ein fertiges Template als zip-Datei hochladen. <a href=\'http://www.locomotivecms.com/support/themes\'>Hier</a> findest du ein paar kostenlose Templates, die du gerne kostenlos verwenden kannst."
next: Webseite erstellen

View File

@ -279,23 +279,14 @@ en:
title: First Locomotive Installation
next: Next
step_1:
title: Step 1/3
explanations: Here is the first step of the Locomotive installation. Please read carefully what is written below.
database:
label: "Database name: <em>%{name}</em>"
notes: "All the mongodb connection settings can be found in the <b>config/mongoid.yml</b> file of your application."
default_domain:
label: "Default domain name: <em>%{name}</em>"
notes: "Basically, Locomotive is a multi websites platform. Each site instance has a default entry, also called subdomain and based on the default domain name. Obviously, you are free to map other domains to your site instance working like aliases. <br/>The default domain name value can be found in the <b>config/initializers/locomotive.rb</b> file."
step_2:
title: "Step 2/3 &mdash; Create account"
title: "Step 1/2 &mdash; Create account"
name: Account name
email: Email
password: Password
password_confirmation: Password confirmation
done: "You have already added an account:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Create account
step_3:
title: "Step 3/3 &mdash; Create first site"
step_2:
title: "Step 2/2 &mdash; Create your first site"
explanations: "This is the last step of the installation. You can upload a theme as a zip file. We have free available themes <a href=\"http://www.locomotivecms.com/support/themes\">here</a>."
next: Create site

View File

@ -278,25 +278,14 @@ fr:
title: Première installation de Locomotive
next: Suivant
step_1:
title: "Étape 1/3"
explanations: "Voici la première étape de l'installation de Locomotive. Veuillez lire attentivement ce qui est écrit ci-dessous."
database:
label: "Nom base de données: <em>%{name}</em>"
notes: "Les paramètres de la connection à MongoDB se trouvent dans le fichier <b>config/mongoid.yml</b> de votre application."
default_domain:
label: "Nom du domaine par défaut: <em>%{name}</em>"
notes:
"Locomotive est une plate-forme multi-sites. Chaque instance de site a une entrée par défaut appelée aussi sous-domaine et qui est aussi fonction du nom de domaine par défaut. Evidemment, vous êtes libres d'associer d'autres noms de domaines, sortes d'alias.
<br/>La valeur du nom de domaine par défaut se trouve dans le fichier <b>config/initializers/locomotive.rb</b>."
step_2:
title: "Étape 2/3 &mdash; Créer un compte"
title: "Étape 1/2 &mdash; Créer un compte"
name: Nom du compte
email: E-mail
password: Mot de passe
password_confirmation: Confirmation mot de passe
done: "Vous avez déjà ajouté un compte:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Créer compte
step_3:
title: "Étape 3/3 &mdash; Créer premier site"
step_2:
title: "Étape 2/2 &mdash; Créer votre premier site"
explanations: "C'est la dernière étape de l'installation. Vous pouvez uploader un theme sous forme d'un fichier zip. Nous avons quelques themes disponibles <a href=\"http://www.locomotivecms.com/support/themes\">ici</a>."
next: Créer site

View File

@ -273,23 +273,14 @@ pt-BR:
title: Primeira instalação do Locomotive
next: Próximo
step_1:
title: Passo 1/3
explanations: "Este é o primeiro passo da instalação do Locomotive. Por favor , leia com atenção o que está escrito"
database:
label: "Nome da Base de Dados: <em>%{name}</em>"
notes: "Todas as configurações de conexão do mongodb podem ser encontradas no arquivo <b>config/mongoid.yml</b> da sua aplicação."
default_domain:
label: "Domínio padrão: <em>%{name}</em>"
notes: "Basicamente, Locomotive é uma plataforma multi-site. Cada instância de site tem uma entrada padrão, , também chamada de sub-domínio e baseada no dominio principal. Obviamente, você pode mapear outros domínios para a instância do seu site , como uma referência. <br/>O nome do domínio principal pode ser encontrado no arquivo <b>config/initializers/locomotive.rb</b>."
step_2:
title: "Passo 2/3 &mdash; Criar conta"
title: "Passo 1/2 &mdash; Criar conta"
name: Nome da Conta
email: Email
password: Senha
password_confirmation: Confirmação da Senha
done: "Você ja adicionou uma conta com:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Criar Conta
step_3:
title: "Passo 3/3 &mdash; Criar primeiro site"
step_2:
title: "Passo 2/2 &mdash; Criar primeiro site"
explanations: "Este é o último passo da instalação. Você pode enviar um tema como um arquivo zip. Nós temos alguns temas de graça para download <a href=\"http://www.locomotivecms.com/support/themes\">aqui</a>."
next: Criar Site

View File

@ -44,4 +44,4 @@ Capybara.default_host = 'test.example.com'
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/carrierwave')
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/locomotive')
Locomotive.configure_for_test
Locomotive.configure_for_test(true)

View File

@ -5,16 +5,16 @@ Locomotive.configure do |config|
# your own domain name (ex: locomotivehosting.com).
#
# Ex:
config.multi_sites do |multi_sites|
# each new website you add will have a default entry based on a subdomain
# and the multi_site_domain value (ex: website_1.locomotivehosting.com).
multi_sites.domain = 'example.com' #'myhostingplatform.com'
# define the reserved subdomains
# Ex:
multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
end
# config.multi_sites = false
# config.multi_sites do |multi_sites|
# # each new website you add will have a default entry based on a subdomain
# # and the multi_site_domain value (ex: website_1.locomotivehosting.com).
# multi_sites.domain = 'example.com' #'myhostingplatform.com'
#
# # define the reserved subdomains
# # Ex:
# multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
# end
config.multi_sites = false
# configure the hosting target for the production environment. Locomotive can be installed in:
# - your own server

View File

@ -44,6 +44,8 @@ module Locomotive
end
def self.after_configure
self.define_subdomain_and_domains_options
# multi sites support
self.configure_multi_sites
@ -59,8 +61,6 @@ module Locomotive
:key => self.config.cookie_key
}
self.define_subdomain_and_domains_options
# Load all the dynamic classes (custom fields)
begin
ContentType.all.collect(&:fetch_content_klass)

View File

@ -4,16 +4,12 @@ module Locomotive
@@defaults = {
:name => 'LocomotiveApp',
:domain => 'example.com',
# :multi_sites => false,
# :default_domain => 'example.com',
# :reserved_subdomains => %w{www admin email blog webmail mail support help site sites},
:reserved_subdomains => %w{www admin email blog webmail mail support help site sites},
# :forbidden_paths => %w{layouts snippets stylesheets javascripts assets admin system api},
:reserved_slugs => %w{stylesheets javascripts assets admin images api pages edit},
:locales => %w{en de fr pt-BR},
:cookie_key => '_locomotive_session',
:enable_logs => false,
# :heroku => false,
# :bushido => false,
:hosting => :auto,
:delayed_job => true,
:default_locale => :en,
@ -48,6 +44,18 @@ module Locomotive
self.manage_subdomain? && self.manage_domains?
end
def reserved_domains
if self.multi_sites?
if self.multi_sites.reserved_subdomains.blank?
@@defaults[:reserved_subdomains]
else
self.multi_sites.reserved_subdomains
end
else
[]
end
end
def method_missing(name, *args, &block)
self.settings.send(name, *args, &block)
end
@ -77,7 +85,14 @@ module Locomotive
# retrieves the specified key and yields it
# if a block is provided
def [](key, &block)
block_given? ? yield(super(key)) : super(key)
if block_given?
self.delete(key) unless super(key).respond_to?(:keys)
yield(super(key))
else
super(key)
end
# block_given? ? yield(super(key)) : super(key)
end
# provides member-based access to keys

View File

@ -1,5 +1,6 @@
require 'bushido'
require 'locomotive/hosting/bushido/custom_domain'
require 'locomotive/hosting/bushido/first_installation'
module Locomotive
module Hosting
@ -22,7 +23,7 @@ module Locomotive
end
def enable_bushido
self.config.domain = ENV['APP_TLD']
self.config.domain = ENV['APP_TLD'] unless self.config.multi_sites?
self.enhance_site_model_with_bushido
@ -32,6 +33,7 @@ module Locomotive
def enhance_site_model_with_bushido
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
Site.send :include, Locomotive::Hosting::Bushido::FirstInstallation
end
# manage domains
@ -45,7 +47,6 @@ module Locomotive
end
end
def remove_bushido_domain(name)
Locomotive.logger "[remove bushido domain] #{name}"
::Bushido::App.remove_domain(name)
@ -55,7 +56,6 @@ module Locomotive
end
end
def set_bushido_subdomain(name)
Locomotive.logger "[set bushido subdomain] #{name}.bushi.do"
::Bushido::App.set_subdomain(name)

View File

@ -6,10 +6,12 @@ module Locomotive
extend ActiveSupport::Concern
included do
validate :subdomain_availability
before_save :check_subdomain_change
after_save :add_bushido_domains
after_update :record_new_subdomain
after_destroy :remove_bushido_domains
alias_method_chain :add_subdomain_to_domains, :bushido
@ -54,6 +56,17 @@ module Locomotive
end
end
def check_subdomain_change
@new_bushido_subdomain = !Locomotive.config.multi_sites? && self.subdomain_changed?
true
end
def record_new_subdomain
if @new_bushido_subdomain == true
Locomotive.set_bushido_subdomain(self.subdomain)
end
end
end
end

View File

@ -0,0 +1,29 @@
module Locomotive
module Hosting
module Bushido
module FirstInstallation
extend ActiveSupport::Concern
included do
class << self
alias_method_chain :create_first_one, :bushido
end
end
module ClassMethods
def create_first_one_with_bushido(attributes)
unless Locomotive.config.multi_sites?
attributes[:subdomain] = ENV['BUSHIDO_APP']
end
self.create_first_one_without_bushido(attributes)
end
end
end
end
end
end

View File

@ -1,6 +1,7 @@
require 'heroku'
require 'heroku/client'
require 'locomotive/hosting/heroku/custom_domain'
require 'locomotive/hosting/heroku/first_installation'
module Locomotive
module Hosting
@ -23,7 +24,7 @@ module Locomotive
end
def enable_heroku
self.config.domain = 'heroku.com'
self.config.domain = 'heroku.com' unless self.config.multi_sites?
self.config.heroku ||= {}
self.config.heroku[:name] = ENV['APP_NAME']
@ -47,6 +48,7 @@ module Locomotive
def enhance_site_model_with_heroku
Site.send :include, Locomotive::Hosting::Heroku::CustomDomain
Site.send :include, Locomotive::Hosting::Heroku::FirstInstallation
end
# manage domains

View File

@ -0,0 +1,29 @@
module Locomotive
module Hosting
module Heroku
module FirstInstallation
extend ActiveSupport::Concern
included do
class << self
alias_method_chain :create_first_one, :heroku
end
end
module ClassMethods
def create_first_one_with_heroku(attributes)
attributes[:subdomain] = ENV['APP_NAME']
self.create_first_one_without_heroku(attributes)
end
end
end
end
end
end

View File

@ -7,7 +7,7 @@ module Locomotive
domain, subdomain = domain_and_subdomain(request)
subdomain = 'www' if subdomain.blank?
domain == Locomotive.config.domain && Locomotive.config.multi_sites.reserved_subdomains.include?(subdomain)
domain == Locomotive.config.domain && Locomotive.config.reserved_subdomains.include?(subdomain)
else
false
end

View File

@ -0,0 +1,172 @@
require 'spec_helper'
describe 'Bushido support' do
before(:each) do
::Bushido::App.stubs(:subdomain_available?).returns(true)
end
context '#loaded' do
it 'has method to enable bushido' do
Locomotive.respond_to?(:enable_bushido).should be_true
end
it 'tells bushido is disabled' do
Locomotive.bushido?.should be_false
end
it 'does not add instance methods to Site' do
Site.instance_methods.include?('add_bushido_domains').should be_false
Site.instance_methods.include?('remove_bushido_domains').should be_false
Site.methods.include?('create_first_one_with_bushido').should be_false
end
end
context '#disabled' do
before(:each) do
Locomotive.configure do |config|
config.hosting = :none
end
end
it 'tells bushido is disabled' do
Locomotive.bushido?.should be_false
end
it 'does not add methods to Site' do
Site.instance_methods.include?('add_bushido_domains').should be_false
Site.instance_methods.include?('remove_bushido_domains').should be_false
end
end
context '#enabled' do
it 'tells bushido is enabled from ENV' do
ENV['HOSTING_PLATFORM'] = 'bushido'
Locomotive.config.hosting = :auto
Locomotive.bushido?.should be_true
end
it 'adds a method to automatically create a site with Bushido settings' do
configure_locomotive_with_bushido
Site.methods.include?('create_first_one_with_bushido').should be_true
end
it 'tells bushido is enabled when forcing it' do
configure_locomotive_with_bushido
Locomotive.bushido?.should be_true
end
context 'enhancing site' do
before(:each) do
configure_locomotive_with_bushido
(@site = Factory.build(:site)).stubs(:valid?).returns(true)
end
it 'calls add_bushido_domains after saving a site' do
@site.expects(:add_bushido_domains)
@site.save
end
it 'calls remove_bushido_domains after saving a site' do
@site.expects(:remove_bushido_domains)
@site.destroy
end
context 'adding domain' do
it 'does not add new domain if no delta' do
::Bushido::App.expects(:add_domain).never
@site.save
end
it 'adds a new domain if new one' do
@site.domains = ['www.acme.fr']
::Bushido::App.expects(:add_domain).with('www.acme.fr')
@site.save
Locomotive.bushido_domains.should include('www.acme.fr')
end
end
context 'changing subdomain' do
it 'does not change it if not modified' do
::Bushido::App.expects(:set_subdomain).never
@site.save
end
it 'does not change it if Locomotive is launched with multi sites' do
@site.save
@site.subdomain = 'rope'
::Bushido::App.expects(:set_subdomain).never
@site.save
end
it 'changes the bushido name' do
configure_locomotive_with_bushido do |config|
config.multi_sites = false
end
@site.save
@site.subdomain = 'rope'
::Bushido::App.expects(:set_subdomain).with('rope')
@site.save
end
end
context 'removing domain' do
it 'does not remove domain if no delta' do
::Bushido::App.expects(:remove_domain).never
@site.destroy
end
it 'removes domains if we destroy a site' do
@site.stubs(:domains_without_subdomain).returns(['www.acme.com'])
::Bushido::App.expects(:remove_domain).with('www.acme.com')
@site.destroy
Locomotive.bushido_domains.should_not include('www.acme.com')
end
it 'removes domain if removed' do
::Bushido::App.stubs(:add_domain)
@site.domains = ['www.acme.fr']; @site.save
@site.domains = ['www.acme.com']
::Bushido::App.expects(:remove_domain).with('www.acme.fr')
@site.save
Locomotive.bushido_domains.should_not include('www.acme.fr')
end
end
end
end
def configure_locomotive_with_bushido(&block)
::Bushido::App.stubs(:subdomain).returns('locomotive')
::Bushido::App.stubs(:domains).returns(['www.acme.com', 'example.com', 'www.example.com'])
Locomotive.configure do |config|
config.hosting = :bushido
block.call(config) if block_given?
Locomotive.define_subdomain_and_domains_options
Object.send(:remove_const, 'Site') if Object.const_defined?('Site')
load 'site.rb'
end
end
after(:all) do
ENV['HOSTING_PLATFORM'] = ENV['APP_TLD'] = nil
Locomotive.configure_for_test(true)
end
end

View File

@ -18,8 +18,9 @@ describe 'Heroku support' do
end
it 'does not add instance methods to Site' do
Site.instance_methods.include?(:add_heroku_domains).should be_false
Site.instance_methods.include?(:remove_heroku_domains).should be_false
Site.instance_methods.include?('add_heroku_domains').should be_false
Site.instance_methods.include?('remove_heroku_domains').should be_false
Site.methods.include?('create_first_one_with_heroku').should be_false
end
end
@ -41,8 +42,8 @@ describe 'Heroku support' do
end
it 'does not add methods to Site' do
Site.instance_methods.include?(:add_heroku_domains).should be_false
Site.instance_methods.include?(:remove_heroku_domains).should be_false
Site.instance_methods.include?('add_heroku_domains').should be_false
Site.instance_methods.include?('remove_heroku_domains').should be_false
end
end
@ -55,6 +56,11 @@ describe 'Heroku support' do
Locomotive.heroku?.should be_true
end
it 'adds a method to automatically create a site with Heroku settings' do
configure_locomotive_with_heroku
Site.methods.include?('create_first_one_with_heroku').should be_true
end
it 'tells heroku is enabled when forcing it' do
configure_locomotive_with_heroku
Locomotive.heroku?.should be_true
@ -158,12 +164,17 @@ describe 'Heroku support' do
Locomotive.configure do |config|
config.hosting = :heroku
config.heroku = { :login => 'john@doe.net', :password => 'easyone' }.merge(options)
Locomotive.define_subdomain_and_domains_options
Object.send(:remove_const, 'Site') if Object.const_defined?('Site')
load 'site.rb'
end
end
after(:all) do
ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
Locomotive.configure_for_test
Locomotive.configure_for_test(true)
end
end

View File

@ -2,10 +2,6 @@ require 'spec_helper'
describe Site do
before(:each) do
Locomotive.stubs(:add_heroku_domain).returns(true)
end
it 'should have a valid factory' do
Factory.build(:site).should be_valid
end

View File

@ -1,11 +1,11 @@
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
Dir[Rails.root.join('spec/support/**/*.rb')].each {|f| require f}
Locomotive.configure_for_test
@ -34,7 +34,7 @@ RSpec.configure do |config|
require 'database_cleaner'
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid"
DatabaseCleaner.orm = 'mongoid'
end
config.before(:each) do

View File

@ -1,10 +1,22 @@
def Locomotive.configure_for_test
def Locomotive.configure_for_test(force = false)
Locomotive.configure do |config|
config.multi_sites do |multi_sites|
multi_sites.domain = 'example.com'
multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
end
config.hosting = :none
config.enable_logs = true
if force
Locomotive.define_subdomain_and_domains_options
Object.send(:remove_const, 'Site') if Object.const_defined?('Site')
load 'site.rb'
Factory.factories.clear
load File.join(Rails.root, 'spec', 'factories.rb')
end
end
end