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

View File

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

View File

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

View File

@ -30,6 +30,10 @@ module Admin::SitesHelper
Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains? Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains?
end end
def manage_subdomain?
Locomotive.config.manage_subdomain?
end
def manage_domains? def manage_domains?
Locomotive.config.manage_domains? Locomotive.config.manage_domains?
end 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 module SubdomainDomains
def enable_subdomain_n_domains_if_multi_sites 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 ## ## fields ##
field :subdomain field :subdomain
@ -15,7 +17,7 @@ module Extensions
## validations ## ## validations ##
validates_presence_of :subdomain validates_presence_of :subdomain
validates_uniqueness_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 validates_format_of :subdomain, :with => Locomotive::Regexps::SUBDOMAIN, :allow_blank => true
validate :domains_must_be_valid_and_unique validate :domains_must_be_valid_and_unique
@ -29,7 +31,6 @@ module Extensions
} }
send :include, InstanceMethods send :include, InstanceMethods
end end
end end

View File

@ -4,6 +4,7 @@ class Site
## Extensions ## ## Extensions ##
extend Extensions::Site::SubdomainDomains extend Extensions::Site::SubdomainDomains
extend Extensions::Site::FirstInstallation
## fields ## ## fields ##
field :name field :name
@ -19,7 +20,7 @@ class Site
embeds_many :memberships embeds_many :memberships
## validations ## ## validations ##
validates_presence_of :name validates_presence_of :name
## callbacks ## ## callbacks ##
after_create :create_default_pages! after_create :create_default_pages!

View File

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

View File

@ -6,21 +6,20 @@
- content_for :head do - content_for :head do
= include_stylesheets :installation = include_stylesheets :installation
- if @step_done.blank? = semantic_form_for(@site, :url => admin_installation_step_url(2), :html => { :multipart => true }) do |f|
= semantic_form_for(@account, :url => admin_installation_step_url(2)) 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
.footer
= box_button_tag t('.next')
- else
.inner .inner
%p.done %p.explanations
!= @step_done != t('.explanations')
= f.inputs do
= 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 .footer
= next_installation_step_link(3) = box_button_tag t('.next')

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,15 +22,16 @@
= f.input :password, :input_html => { :autocomplete => "off" } = f.input :password, :input_html => { :autocomplete => "off" }
= f.input :password_confirmation, :input_html => { :autocomplete => "off" } = f.input :password_confirmation, :input_html => { :autocomplete => "off" }
= f.foldable_inputs :name => :sites, :class => 'sites off' do - if multi_sites?
- @account.sites.each do |site| = f.foldable_inputs :name => :sites, :class => 'sites off' do
%li{ :class => 'item' } - @account.sites.each do |site|
%strong= link_to site.name, main_site_url(site, :uri => true) %li{ :class => 'item' }
%em= site.domains.join(', ') %strong= link_to site.name, main_site_url(site, :uri => true)
%em= site.domains.join(', ')
- if admin_on?(site) && site != current_site - if admin_on?(site) && site != current_site
%span{ :class => 'actions' } %span{ :class => 'actions' }
= link_to image_tag('admin/form/icons/trash.png'), admin_site_url(site), :class => 'remove first', :confirm => t('admin.messages.confirm'), :method => :delete = link_to image_tag('admin/form/icons/trash.png'), admin_site_url(site), :class => 'remove first', :confirm => t('admin.messages.confirm'), :method => :delete
= f.foldable_inputs :name => :language, :class => 'language' do = f.foldable_inputs :name => :language, :class => 'language' do
= f.custom_input :language, { :css => 'full', :with_label => false } do = f.custom_input :language, { :css => 'full', :with_label => false } do

View File

@ -273,23 +273,14 @@ de:
title: Erst-Installation von getbenga title: Erst-Installation von getbenga
next: Weiter next: Weiter
step_1: step_1:
title: Schritt 1/3 title: "Schritt 1/2 — Account erstellen"
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"
name: Account-Name name: Account-Name
email: Email email: Email
password: Passwort password: Passwort
password_confirmation: Passwort-Bestätigung password_confirmation: Passwort-Bestätigung
done: "Du hast bereits einen Account hinzugefügt:<br/><strong>%{name}</strong>, <em>%{email}</em>" done: "Du hast bereits einen Account hinzugefügt:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Account erstellen next: Account erstellen
step_3: step_2:
title: "Schritt 3/3 &mdash; Erstelle deine erste Webseite" 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." 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 next: Webseite erstellen

View File

@ -279,23 +279,14 @@ en:
title: First Locomotive Installation title: First Locomotive Installation
next: Next next: Next
step_1: step_1:
title: Step 1/3 title: "Step 1/2 &mdash; Create account"
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"
name: Account name name: Account name
email: Email email: Email
password: Password password: Password
password_confirmation: Password confirmation password_confirmation: Password confirmation
done: "You have already added an account:<br/><strong>%{name}</strong>, <em>%{email}</em>" done: "You have already added an account:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Create account next: Create account
step_3: step_2:
title: "Step 3/3 &mdash; Create first site" 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>." 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 next: Create site

View File

@ -278,25 +278,14 @@ fr:
title: Première installation de Locomotive title: Première installation de Locomotive
next: Suivant next: Suivant
step_1: step_1:
title: "Étape 1/3" title: "Étape 1/2 &mdash; Créer un compte"
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"
name: Nom du compte name: Nom du compte
email: E-mail email: E-mail
password: Mot de passe password: Mot de passe
password_confirmation: Confirmation mot de passe password_confirmation: Confirmation mot de passe
done: "Vous avez déjà ajouté un compte:<br/><strong>%{name}</strong>, <em>%{email}</em>" done: "Vous avez déjà ajouté un compte:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Créer compte next: Créer compte
step_3: step_2:
title: "Étape 3/3 &mdash; Créer premier site" 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>." 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 next: Créer site

View File

@ -273,23 +273,14 @@ pt-BR:
title: Primeira instalação do Locomotive title: Primeira instalação do Locomotive
next: Próximo next: Próximo
step_1: step_1:
title: Passo 1/3 title: "Passo 1/2 &mdash; Criar conta"
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"
name: Nome da Conta name: Nome da Conta
email: Email email: Email
password: Senha password: Senha
password_confirmation: Confirmação da Senha password_confirmation: Confirmação da Senha
done: "Você ja adicionou uma conta com:<br/><strong>%{name}</strong>, <em>%{email}</em>" done: "Você ja adicionou uma conta com:<br/><strong>%{name}</strong>, <em>%{email}</em>"
next: Criar Conta next: Criar Conta
step_3: step_2:
title: "Passo 3/3 &mdash; Criar primeiro site" 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>." 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 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/carrierwave')
require File.expand_path(File.dirname(__FILE__) + '/../../spec/support/locomotive') 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). # your own domain name (ex: locomotivehosting.com).
# #
# Ex: # Ex:
config.multi_sites do |multi_sites| # config.multi_sites do |multi_sites|
# each new website you add will have a default entry based on a subdomain # # 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). # # and the multi_site_domain value (ex: website_1.locomotivehosting.com).
multi_sites.domain = 'example.com' #'myhostingplatform.com' # multi_sites.domain = 'example.com' #'myhostingplatform.com'
#
# define the reserved subdomains # # define the reserved subdomains
# Ex: # # Ex:
multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites) # multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
end # end
# config.multi_sites = false config.multi_sites = false
# configure the hosting target for the production environment. Locomotive can be installed in: # configure the hosting target for the production environment. Locomotive can be installed in:
# - your own server # - your own server

View File

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

View File

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

View File

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

View File

@ -6,10 +6,12 @@ module Locomotive
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
validate :subdomain_availability validate :subdomain_availability
before_save :check_subdomain_change
after_save :add_bushido_domains after_save :add_bushido_domains
after_update :record_new_subdomain
after_destroy :remove_bushido_domains after_destroy :remove_bushido_domains
alias_method_chain :add_subdomain_to_domains, :bushido alias_method_chain :add_subdomain_to_domains, :bushido
@ -54,6 +56,17 @@ module Locomotive
end end
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
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'
require 'heroku/client' require 'heroku/client'
require 'locomotive/hosting/heroku/custom_domain' require 'locomotive/hosting/heroku/custom_domain'
require 'locomotive/hosting/heroku/first_installation'
module Locomotive module Locomotive
module Hosting module Hosting
@ -23,7 +24,7 @@ module Locomotive
end end
def enable_heroku def enable_heroku
self.config.domain = 'heroku.com' self.config.domain = 'heroku.com' unless self.config.multi_sites?
self.config.heroku ||= {} self.config.heroku ||= {}
self.config.heroku[:name] = ENV['APP_NAME'] self.config.heroku[:name] = ENV['APP_NAME']
@ -47,6 +48,7 @@ module Locomotive
def enhance_site_model_with_heroku def enhance_site_model_with_heroku
Site.send :include, Locomotive::Hosting::Heroku::CustomDomain Site.send :include, Locomotive::Hosting::Heroku::CustomDomain
Site.send :include, Locomotive::Hosting::Heroku::FirstInstallation
end end
# manage domains # 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) domain, subdomain = domain_and_subdomain(request)
subdomain = 'www' if subdomain.blank? 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 else
false false
end 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

@ -8,43 +8,44 @@ describe 'Heroku support' do
end end
context '#loaded' do context '#loaded' do
it 'has method to enable heroku' do it 'has method to enable heroku' do
Locomotive.respond_to?(:enable_heroku).should be_true Locomotive.respond_to?(:enable_heroku).should be_true
end end
it 'tells heroku is disabled' do it 'tells heroku is disabled' do
Locomotive.heroku?.should be_false Locomotive.heroku?.should be_false
end end
it 'does not add instance methods to Site' do it 'does not add instance methods to Site' do
Site.instance_methods.include?(:add_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.instance_methods.include?('remove_heroku_domains').should be_false
Site.methods.include?('create_first_one_with_heroku').should be_false
end end
end end
context '#disabled' do context '#disabled' do
before(:each) do before(:each) do
Locomotive.configure do |config| Locomotive.configure do |config|
config.hosting = :none config.hosting = :none
end end
end end
it 'has a nil connection' do it 'has a nil connection' do
Locomotive.heroku_connection.should be_nil Locomotive.heroku_connection.should be_nil
end end
it 'tells heroku is disabled' do it 'tells heroku is disabled' do
Locomotive.heroku?.should be_false Locomotive.heroku?.should be_false
end end
it 'does not add methods to Site' do it 'does not add methods to Site' do
Site.instance_methods.include?(:add_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.instance_methods.include?('remove_heroku_domains').should be_false
end end
end end
context '#enabled' do context '#enabled' do
@ -54,60 +55,65 @@ describe 'Heroku support' do
Locomotive.config.hosting = :auto Locomotive.config.hosting = :auto
Locomotive.heroku?.should be_true Locomotive.heroku?.should be_true
end 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 it 'tells heroku is enabled when forcing it' do
configure_locomotive_with_heroku configure_locomotive_with_heroku
Locomotive.heroku?.should be_true Locomotive.heroku?.should be_true
end end
it 'raises an exception if no app name is given' do it 'raises an exception if no app name is given' do
lambda { lambda {
configure_locomotive_with_heroku(:name => nil) configure_locomotive_with_heroku(:name => nil)
}.should raise_error }.should raise_error
end end
context 'dealing with heroku connection' do context 'dealing with heroku connection' do
it 'opens a heroku connection with provided credentials' do it 'opens a heroku connection with provided credentials' do
configure_locomotive_with_heroku configure_locomotive_with_heroku
Locomotive.heroku_connection.user.should == 'john@doe.net' Locomotive.heroku_connection.user.should == 'john@doe.net'
Locomotive.heroku_connection.password.should == 'easyone' Locomotive.heroku_connection.password.should == 'easyone'
end end
it 'opens a heroku connection with env credentials' do it 'opens a heroku connection with env credentials' do
::Heroku::Client.any_instance.stubs(:list_domains).returns([]) ::Heroku::Client.any_instance.stubs(:list_domains).returns([])
ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'; ENV['APP_NAME'] = 'test' ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'; ENV['APP_NAME'] = 'test'
Locomotive.configure { |config| config.hosting = :heroku; config.heroku = {} } Locomotive.configure { |config| config.hosting = :heroku; config.heroku = {} }
Locomotive.heroku_connection.user.should == 'john@doe.net' Locomotive.heroku_connection.user.should == 'john@doe.net'
Locomotive.heroku_connection.password.should == 'easyone' Locomotive.heroku_connection.password.should == 'easyone'
end end
end end
context 'enhancing site' do context 'enhancing site' do
before(:each) do before(:each) do
configure_locomotive_with_heroku configure_locomotive_with_heroku
(@site = Factory.build(:site)).stubs(:valid?).returns(true) (@site = Factory.build(:site)).stubs(:valid?).returns(true)
end end
it 'calls add_heroku_domains after saving a site' do it 'calls add_heroku_domains after saving a site' do
@site.expects(:add_heroku_domains) @site.expects(:add_heroku_domains)
@site.save @site.save
end end
it 'calls remove_heroku_domains after saving a site' do it 'calls remove_heroku_domains after saving a site' do
@site.expects(:remove_heroku_domains) @site.expects(:remove_heroku_domains)
@site.destroy @site.destroy
end end
context 'adding domain' do context 'adding domain' do
it 'does not add new domain if no delta' do it 'does not add new domain if no delta' do
Locomotive.heroku_connection.expects(:add_domain).never Locomotive.heroku_connection.expects(:add_domain).never
@site.save @site.save
end end
it 'adds a new domain if new one' do it 'adds a new domain if new one' do
@site.domains = ['www.acme.fr'] @site.domains = ['www.acme.fr']
Locomotive.heroku_connection.expects(:add_domain).with('locomotive', 'www.acme.fr') Locomotive.heroku_connection.expects(:add_domain).with('locomotive', 'www.acme.fr')
@ -115,21 +121,21 @@ describe 'Heroku support' do
Locomotive.heroku_domains.should include('www.acme.fr') Locomotive.heroku_domains.should include('www.acme.fr')
end end
end end
context 'removing domain' do context 'removing domain' do
it 'does not remove domain if no delta' do it 'does not remove domain if no delta' do
Locomotive.heroku_connection.expects(:remove_domain).never Locomotive.heroku_connection.expects(:remove_domain).never
@site.destroy @site.destroy
end end
it 'removes domains if we destroy a site' do it 'removes domains if we destroy a site' do
@site.stubs(:domains_without_subdomain).returns(['www.acme.com']) @site.stubs(:domains_without_subdomain).returns(['www.acme.com'])
Locomotive.heroku_connection.expects(:remove_domain).with('locomotive', 'www.acme.com') Locomotive.heroku_connection.expects(:remove_domain).with('locomotive', 'www.acme.com')
@site.destroy @site.destroy
Locomotive.heroku_domains.should_not include('www.acme.com') Locomotive.heroku_domains.should_not include('www.acme.com')
end end
it 'removes domain if removed' do it 'removes domain if removed' do
@site.domains = ['www.acme.fr']; @site.save @site.domains = ['www.acme.fr']; @site.save
@site.domains = ['www.acme.com'] @site.domains = ['www.acme.com']
@ -137,11 +143,11 @@ describe 'Heroku support' do
@site.save @site.save
Locomotive.heroku_domains.should_not include('www.acme.fr') Locomotive.heroku_domains.should_not include('www.acme.fr')
end end
end end
end end
end end
def configure_locomotive_with_heroku(options = {}, domains = nil) def configure_locomotive_with_heroku(options = {}, domains = nil)
@ -150,20 +156,25 @@ describe 'Heroku support' do
else else
ENV['APP_NAME'] = 'locomotive' ENV['APP_NAME'] = 'locomotive'
end end
::Heroku::Client.any_instance.stubs(:list_domains).with(ENV['APP_NAME']).returns(domains || [ ::Heroku::Client.any_instance.stubs(:list_domains).with(ENV['APP_NAME']).returns(domains || [
{ :domain => "www.acme.com" }, { :domain => "example.com" }, { :domain => "www.example.com" } { :domain => "www.acme.com" }, { :domain => "example.com" }, { :domain => "www.example.com" }
]) ])
Locomotive.configure do |config| Locomotive.configure do |config|
config.hosting = :heroku config.hosting = :heroku
config.heroku = { :login => 'john@doe.net', :password => 'easyone' }.merge(options) config.heroku = { :login => 'john@doe.net', :password => 'easyone' }.merge(options)
end
Locomotive.define_subdomain_and_domains_options
Object.send(:remove_const, 'Site') if Object.const_defined?('Site')
load 'site.rb'
end
end end
after(:all) do after(:all) do
ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
Locomotive.configure_for_test Locomotive.configure_for_test(true)
end end
end end

View File

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

View File

@ -1,11 +1,11 @@
# This file is copied to spec/ when you run 'rails generate rspec:install' # This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test' ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__) require File.expand_path('../../config/environment', __FILE__)
require 'rspec/rails' require 'rspec/rails'
# Requires supporting ruby files with custom matchers and macros, etc, # Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories. # 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 Locomotive.configure_for_test
@ -34,7 +34,7 @@ RSpec.configure do |config|
require 'database_cleaner' require 'database_cleaner'
config.before(:suite) do config.before(:suite) do
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation
DatabaseCleaner.orm = "mongoid" DatabaseCleaner.orm = 'mongoid'
end end
config.before(:each) do 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| Locomotive.configure do |config|
config.multi_sites do |multi_sites| config.multi_sites do |multi_sites|
multi_sites.domain = 'example.com' multi_sites.domain = 'example.com'
multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites) multi_sites.reserved_subdomains = %w(www admin email blog webmail mail support help site sites)
end end
config.hosting = :none config.hosting = :none
config.enable_logs = true 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
end end