single site / multi sites option in progress + integrating bushi.do + revert back to mongoid rc.7
This commit is contained in:
parent
551d8a5761
commit
c0a5a4b443
2
Gemfile
2
Gemfile
@ -7,7 +7,7 @@ gem 'rails', '>= 3.0.5'
|
|||||||
gem 'warden'
|
gem 'warden'
|
||||||
gem 'devise', '= 1.1.3'
|
gem 'devise', '= 1.1.3'
|
||||||
|
|
||||||
gem 'mongoid', '~> 2.0.0.rc.7'
|
gem 'mongoid', '2.0.0.rc.7'
|
||||||
gem 'bson_ext', '~> 1.2.1'
|
gem 'bson_ext', '~> 1.2.1'
|
||||||
gem 'locomotive_mongoid_acts_as_tree', '0.1.5.5', :require => 'mongoid_acts_as_tree'
|
gem 'locomotive_mongoid_acts_as_tree', '0.1.5.5', :require => 'mongoid_acts_as_tree'
|
||||||
gem 'will_paginate'
|
gem 'will_paginate'
|
||||||
|
@ -177,7 +177,7 @@ GEM
|
|||||||
mimetype-fu (0.1.2)
|
mimetype-fu (0.1.2)
|
||||||
mongo (1.2.4)
|
mongo (1.2.4)
|
||||||
bson (>= 1.2.4)
|
bson (>= 1.2.4)
|
||||||
mongoid (2.0.0)
|
mongoid (2.0.0.rc.7)
|
||||||
activemodel (~> 3.0)
|
activemodel (~> 3.0)
|
||||||
mongo (~> 1.2)
|
mongo (~> 1.2)
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
@ -256,7 +256,7 @@ GEM
|
|||||||
treetop (1.4.9)
|
treetop (1.4.9)
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
trollop (1.16.2)
|
trollop (1.16.2)
|
||||||
tzinfo (0.3.25)
|
tzinfo (0.3.26)
|
||||||
unicorn (3.5.0)
|
unicorn (3.5.0)
|
||||||
kgio (~> 2.3)
|
kgio (~> 2.3)
|
||||||
rack
|
rack
|
||||||
@ -299,7 +299,7 @@ DEPENDENCIES
|
|||||||
locomotive_mongoid_acts_as_tree (= 0.1.5.5)
|
locomotive_mongoid_acts_as_tree (= 0.1.5.5)
|
||||||
mimetype-fu
|
mimetype-fu
|
||||||
mocha!
|
mocha!
|
||||||
mongoid (~> 2.0.0.rc.7)
|
mongoid (= 2.0.0.rc.7)
|
||||||
pickle
|
pickle
|
||||||
rails (>= 3.0.5)
|
rails (>= 3.0.5)
|
||||||
rmagick (= 2.12.2)
|
rmagick (= 2.12.2)
|
||||||
|
@ -8,7 +8,7 @@ module Admin::SitesHelper
|
|||||||
|
|
||||||
def main_site_url(site = current_site, options = {})
|
def main_site_url(site = current_site, options = {})
|
||||||
# TODO: to be refactored
|
# TODO: to be refactored
|
||||||
if multi_sites_enabled?
|
if multi_sites?
|
||||||
url = "http://#{site.subdomain}.#{Locomotive.config.domain}"
|
url = "http://#{site.subdomain}.#{Locomotive.config.domain}"
|
||||||
url += ":#{request.port}" if request.port != 80
|
url += ":#{request.port}" if request.port != 80
|
||||||
else
|
else
|
||||||
@ -27,15 +27,15 @@ module Admin::SitesHelper
|
|||||||
end
|
end
|
||||||
|
|
||||||
def manage_subdomain_or_domains?
|
def manage_subdomain_or_domains?
|
||||||
Locomotive.config.manage_subdomain || Locomotive.config.manage_domains
|
Locomotive.config.manage_subdomain? || Locomotive.config.manage_domains?
|
||||||
end
|
end
|
||||||
|
|
||||||
def manage_domains?
|
def manage_domains?
|
||||||
Locomotive.config.manage_domains
|
Locomotive.config.manage_domains?
|
||||||
end
|
end
|
||||||
|
|
||||||
def multi_sites_enabled?
|
def multi_sites?
|
||||||
Locomotive.multi_sites_enabled?
|
Locomotive.config.multi_sites?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -2,11 +2,8 @@ module Extensions
|
|||||||
module Site
|
module Site
|
||||||
module SubdomainDomains
|
module SubdomainDomains
|
||||||
|
|
||||||
unloadable
|
def enable_subdomain_n_domains_if_multi_sites
|
||||||
|
if Locomotive.config.multi_sites? || Locomotive.config.manage_subdomain_n_domains?
|
||||||
extend ActiveSupport::Concern
|
|
||||||
|
|
||||||
included do
|
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :subdomain
|
field :subdomain
|
||||||
@ -31,6 +28,9 @@ module Extensions
|
|||||||
{ :any_in => { :domains => [*domain] }, :where => { :_id.ne => site.id } }
|
{ :any_in => { :domains => [*domain] }, :where => { :_id.ne => site.id } }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send :include, InstanceMethods
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module InstanceMethods
|
module InstanceMethods
|
||||||
@ -53,7 +53,7 @@ module Extensions
|
|||||||
end
|
end
|
||||||
|
|
||||||
def full_subdomain
|
def full_subdomain
|
||||||
"#{self.subdomain}.#{Locomotive.config.default_domain}"
|
"#{self.subdomain}.#{Locomotive.config.domain}"
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
@ -2,6 +2,9 @@ class Site
|
|||||||
|
|
||||||
include Locomotive::Mongoid::Document
|
include Locomotive::Mongoid::Document
|
||||||
|
|
||||||
|
## Extensions ##
|
||||||
|
extend Extensions::Site::SubdomainDomains
|
||||||
|
|
||||||
## fields ##
|
## fields ##
|
||||||
field :name
|
field :name
|
||||||
field :meta_keywords
|
field :meta_keywords
|
||||||
@ -22,6 +25,9 @@ class Site
|
|||||||
after_create :create_default_pages!
|
after_create :create_default_pages!
|
||||||
after_destroy :destroy_pages
|
after_destroy :destroy_pages
|
||||||
|
|
||||||
|
## behaviours ##
|
||||||
|
enable_subdomain_n_domains_if_multi_sites
|
||||||
|
|
||||||
## methods ##
|
## methods ##
|
||||||
|
|
||||||
def all_pages_in_once
|
def all_pages_in_once
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
- content_for :submenu do
|
- content_for :submenu do
|
||||||
= render 'admin/shared/menu/settings'
|
= render 'admin/shared/menu/settings'
|
||||||
|
|
||||||
- if multi_sites_enabled?
|
- if multi_sites?
|
||||||
- content_for :buttons do
|
- content_for :buttons do
|
||||||
= admin_button_tag t('.new_site'), new_admin_site_url, :class => 'new'
|
= admin_button_tag t('.new_site'), new_admin_site_url, :class => 'new'
|
||||||
|
|
||||||
|
@ -16,8 +16,7 @@ module Locomotive
|
|||||||
|
|
||||||
# Add additional load paths for your own custom dirs
|
# Add additional load paths for your own custom dirs
|
||||||
# config.load_paths += %W( #{config.root}/extras )
|
# config.load_paths += %W( #{config.root}/extras )
|
||||||
# config.autoload_paths += %W( #{config.root}/app/models/extensions #{config.root}/app/models/extensions/site #{config.root}/app/models/extensions/page #{config.root}/app/models/extensions/asset)
|
config.autoload_paths += %W( #{config.root}/app/models/extensions #{config.root}/app/models/extensions/site #{config.root}/app/models/extensions/page #{config.root}/app/models/extensions/asset)
|
||||||
# config.autoload_paths += %W( #{config.root}/app/models/extensions/site )
|
|
||||||
|
|
||||||
# Only load the plugins named here, in the order given (default is alphabetical).
|
# Only load the plugins named here, in the order given (default is alphabetical).
|
||||||
# :all can be used as a placeholder for all plugins not explicitly named
|
# :all can be used as a placeholder for all plugins not explicitly named
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
require File.dirname(__FILE__) + '/../../lib/locomotive.rb'
|
require File.dirname(__FILE__) + '/../../lib/locomotive.rb'
|
||||||
# require_or_load 'extensions/site/subdomain_domains'
|
|
||||||
|
|
||||||
Locomotive.configure do |config|
|
Locomotive.configure do |config|
|
||||||
|
|
||||||
@ -61,64 +60,4 @@ Locomotive.configure do |config|
|
|||||||
# config.mailer_sender = 'support'
|
# config.mailer_sender = 'support'
|
||||||
# # => 'support@heroku.com' (Heroku), 'support@bushi.do' (Bushido), 'support@example.com' (Dev) or 'support@<your_hosting_platform>' (Multi-sites)
|
# # => 'support@heroku.com' (Heroku), 'support@bushi.do' (Bushido), 'support@example.com' (Dev) or 'support@<your_hosting_platform>' (Multi-sites)
|
||||||
config.mailer_sender = 'support'
|
config.mailer_sender = 'support'
|
||||||
|
|
||||||
# ===================================================
|
|
||||||
|
|
||||||
# do |deployment|
|
|
||||||
#
|
|
||||||
# # the possible options are: server, heroku, bushido or auto (default)
|
|
||||||
# # if you select 'auto', Locomotive will look after specific ENV variables to check
|
|
||||||
# # the matching platform (Heroku and Bushido set their own ENV variable).
|
|
||||||
# deployment.target = :auto
|
|
||||||
#
|
|
||||||
# # in case you select heroku, it requires your Heroku credentials in order to manage domains.
|
|
||||||
# # If you do not want to store the credentials here, you can add them directly into the Heroku ENV
|
|
||||||
# # (see Heroku documentation)
|
|
||||||
# # deployment.heroku = {
|
|
||||||
# # :login => '<your_heroku_login>'
|
|
||||||
# # :password => '<your_heroku_password>'
|
|
||||||
# # }
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
|
|
||||||
# # define the domain name used in production.cn
|
|
||||||
# deployment.domain = 'example.com'
|
|
||||||
|
|
||||||
|
|
||||||
# set the default domain name used in development/test. By default, 'example.com' is used.
|
|
||||||
# config.local_domain = 'example.com'
|
|
||||||
|
|
||||||
# Locomotive can serve one single site or many. The "many sites" option requires more constraints for
|
|
||||||
# the domain name (see config.domain for more explanation)
|
|
||||||
#
|
|
||||||
# Ex:
|
|
||||||
# config.site_mode = :single
|
|
||||||
# or
|
|
||||||
# config.site_mode = :many
|
|
||||||
# config.site_mode = :single
|
|
||||||
|
|
||||||
# if not defined, locomotive will use example.com as main domain name. Remove prefix www from your domain name.
|
|
||||||
# Ex:
|
|
||||||
# config.default_domain = Rails.env.production? ? 'mydomain.com' : 'example.com'
|
|
||||||
#
|
|
||||||
# If you use locomotive for a single site in Heroku, use "heroku.com" as default domain name.bzc,
|
|
||||||
|
|
||||||
# tell if the application is hosted on Bushido.
|
|
||||||
# If enabled, there's no further configuration needed.
|
|
||||||
# Bushido will take care of eveything
|
|
||||||
#
|
|
||||||
# Ex:
|
|
||||||
# config.bushido = true
|
|
||||||
# config.bushido = ENV['HOSTING_PLATFORM'] == 'bushido'
|
|
||||||
|
|
||||||
# Locomotive uses the DelayedJob gem for the theme import module.
|
|
||||||
# In case you want to deploy to Heroku, you will have to pay for an extra dyno.
|
|
||||||
# If you do not mind about importing theme without DelayedJob, disable it.
|
|
||||||
# config.delayed_job = false
|
|
||||||
#
|
|
||||||
# # default locale (for now, only en, de, fr and pt-BR are supported)
|
|
||||||
# config.default_locale = :en
|
|
||||||
#
|
|
||||||
# # Configure the e-mail address which will be shown in the DeviseMailer, NotificationMailer, ...etc
|
|
||||||
# config.mailer_sender = ENV['BUSHIDO_DOMAIN'] ? "support@#{ENV['BUSHIDO_DOMAIN']}" : 'support@example.com'
|
|
||||||
end
|
end
|
||||||
|
@ -38,11 +38,10 @@ Capybara.javascript_driver = :selenium
|
|||||||
# of your scenarios, as this makes it hard to discover errors in your application.
|
# of your scenarios, as this makes it hard to discover errors in your application.
|
||||||
ActionController::Base.allow_rescue = false
|
ActionController::Base.allow_rescue = false
|
||||||
|
|
||||||
Locomotive.configure do |config|
|
|
||||||
config.default_domain = 'example.com'
|
|
||||||
end
|
|
||||||
|
|
||||||
Capybara.default_host = 'test.example.com'
|
Capybara.default_host = 'test.example.com'
|
||||||
# Capybara.app_host = 'http://test.example.com'
|
# Capybara.app_host = 'http://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')
|
||||||
|
|
||||||
|
Locomotive.configure_for_test
|
@ -44,8 +44,6 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.after_configure
|
def self.after_configure
|
||||||
# ActionMailer::Base.default_url_options[:host] = self.config.default_domain + (Rails.env.development? ? ':3000' : '')
|
|
||||||
|
|
||||||
# multi sites support
|
# multi sites support
|
||||||
self.configure_multi_sites
|
self.configure_multi_sites
|
||||||
|
|
||||||
@ -61,7 +59,7 @@ module Locomotive
|
|||||||
:key => self.config.cookie_key
|
:key => self.config.cookie_key
|
||||||
}
|
}
|
||||||
|
|
||||||
self.define_various_helpers
|
self.define_subdomain_and_domains_options
|
||||||
|
|
||||||
# Load all the dynamic classes (custom fields)
|
# Load all the dynamic classes (custom fields)
|
||||||
begin
|
begin
|
||||||
@ -73,41 +71,33 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.configure_multi_sites
|
def self.configure_multi_sites
|
||||||
if self.multi_sites_enabled?
|
if self.config.multi_sites?
|
||||||
domain_name = self.config.multi_sites.domain
|
domain_name = self.config.multi_sites.domain
|
||||||
|
|
||||||
raise '[Error] Locomotive needs a domain name when used as a multi sites platform' if domain_name.blank?
|
raise '[Error] Locomotive needs a domain name when used as a multi sites platform' if domain_name.blank?
|
||||||
|
|
||||||
# Site.send :include, Extensions::Site::SubdomainDomains
|
|
||||||
|
|
||||||
self.config.domain = domain_name
|
self.config.domain = domain_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.configure_hosting
|
def self.configure_hosting
|
||||||
if Rails.env.production?
|
|
||||||
# Heroku support
|
# Heroku support
|
||||||
self.enable_heroku if self.heroku?
|
self.enable_heroku if self.heroku?
|
||||||
|
|
||||||
# Bushido support
|
# Bushido support
|
||||||
self.enable_bushido if self.bushido?
|
self.enable_bushido if self.bushido?
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def self.define_various_helpers
|
def self.define_subdomain_and_domains_options
|
||||||
if self.multi_sites_enabled?
|
if self.config.multi_sites?
|
||||||
self.config.manage_subdomain = self.config.manage_domains = true
|
self.config.manage_subdomain = self.config.manage_domains = true
|
||||||
else
|
else
|
||||||
# FIXME: (Did) modify the code below if Locomotive handles a new hosting solution
|
# Note: (Did) modify the code below if Locomotive handles a new hosting solution
|
||||||
self.config.manage_domains = self.heroku? || self.bushido?
|
self.config.manage_domains = self.heroku? || self.bushido?
|
||||||
self.config.manage_subdomain = self.bushido?
|
self.config.manage_subdomain = self.bushido?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.multi_sites_enabled?
|
|
||||||
self.config.multi_sites != false
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.logger(message)
|
def self.logger(message)
|
||||||
if self.config.enable_logs == true
|
if self.config.enable_logs == true
|
||||||
Rails.logger.info(message)
|
Rails.logger.info(message)
|
||||||
|
@ -14,9 +14,12 @@ module Locomotive
|
|||||||
:enable_logs => false,
|
:enable_logs => false,
|
||||||
# :heroku => false,
|
# :heroku => false,
|
||||||
# :bushido => false,
|
# :bushido => false,
|
||||||
|
:hosting => :auto,
|
||||||
:delayed_job => true,
|
:delayed_job => true,
|
||||||
:default_locale => :en,
|
:default_locale => :en,
|
||||||
:mailer_sender => 'support' #support@example.com'
|
:mailer_sender => 'support', #support@example.com'
|
||||||
|
:manage_subdomain => false,
|
||||||
|
:manage_manage_domains => false
|
||||||
}
|
}
|
||||||
|
|
||||||
cattr_accessor :settings
|
cattr_accessor :settings
|
||||||
@ -29,6 +32,22 @@ module Locomotive
|
|||||||
@@settings
|
@@settings
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def multi_sites?
|
||||||
|
self.multi_sites != false
|
||||||
|
end
|
||||||
|
|
||||||
|
def manage_subdomain?
|
||||||
|
self.manage_subdomain == true
|
||||||
|
end
|
||||||
|
|
||||||
|
def manage_domains?
|
||||||
|
self.manage_domains == true
|
||||||
|
end
|
||||||
|
|
||||||
|
def manage_subdomain_n_domains?
|
||||||
|
self.manage_subdomain? && self.manage_domains?
|
||||||
|
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
|
||||||
|
@ -24,14 +24,13 @@ module Locomotive
|
|||||||
def enable_bushido
|
def enable_bushido
|
||||||
self.config.domain = ENV['APP_TLD']
|
self.config.domain = ENV['APP_TLD']
|
||||||
|
|
||||||
self.enhance_site_model
|
self.enhance_site_model_with_bushido
|
||||||
|
|
||||||
self.bushido_domains = ::Bushido::App.domains
|
self.bushido_domains = ::Bushido::App.domains
|
||||||
self.bushido_subdomain = ::Bushido::App.subdomain
|
self.bushido_subdomain = ::Bushido::App.subdomain
|
||||||
end
|
end
|
||||||
|
|
||||||
def enhance_site_model
|
def enhance_site_model_with_bushido
|
||||||
Site.send :include, Extensions::Site::SubdomainDomains
|
|
||||||
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
|
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -23,14 +23,16 @@ module Locomotive
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enable_heroku
|
def enable_heroku
|
||||||
# raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
|
||||||
self.config.domain = 'heroku.com'
|
self.config.domain = 'heroku.com'
|
||||||
|
|
||||||
self.config.heroku ||= {}
|
self.config.heroku ||= {}
|
||||||
self.config.heroku[:name] = ENV['APP_NAME']
|
self.config.heroku[:name] = ENV['APP_NAME']
|
||||||
|
|
||||||
|
raise 'Heroku application name is mandatory' if self.config.heroku[:name].blank?
|
||||||
|
|
||||||
self.open_heroku_connection
|
self.open_heroku_connection
|
||||||
self.enhance_site_model
|
|
||||||
|
self.enhance_site_model_with_heroku
|
||||||
|
|
||||||
# "cache" domains for better performance
|
# "cache" domains for better performance
|
||||||
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
self.heroku_domains = self.heroku_connection.list_domains(self.config.heroku[:name]).collect { |h| h[:domain] }
|
||||||
@ -38,13 +40,12 @@ module Locomotive
|
|||||||
|
|
||||||
def open_heroku_connection
|
def open_heroku_connection
|
||||||
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
login = self.config.heroku[:login] || ENV['HEROKU_LOGIN']
|
||||||
password = self.config.heroku[:password] rescue ENV['HEROKU_PASSWORD']
|
password = self.config.heroku[:password] || ENV['HEROKU_PASSWORD']
|
||||||
|
|
||||||
self.heroku_connection = ::Heroku::Client.new(login, password)
|
self.heroku_connection = ::Heroku::Client.new(login, password)
|
||||||
end
|
end
|
||||||
|
|
||||||
def enhance_site_model
|
def enhance_site_model_with_heroku
|
||||||
Site.send :include, Extensions::Site::SubdomainDomains
|
|
||||||
Site.send :include, Locomotive::Hosting::Heroku::CustomDomain
|
Site.send :include, Locomotive::Hosting::Heroku::CustomDomain
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ module Locomotive
|
|||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
included do
|
included do
|
||||||
|
|
||||||
after_save :add_heroku_domains
|
after_save :add_heroku_domains
|
||||||
after_destroy :remove_heroku_domains
|
after_destroy :remove_heroku_domains
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ module Locomotive
|
|||||||
class DefaultConstraint
|
class DefaultConstraint
|
||||||
|
|
||||||
def self.matches?(request)
|
def self.matches?(request)
|
||||||
if Locomotive.multi_sites_enabled?
|
if Locomotive.config.multi_sites?
|
||||||
domain, subdomain = domain_and_subdomain(request)
|
domain, subdomain = domain_and_subdomain(request)
|
||||||
subdomain = 'www' if subdomain.blank?
|
subdomain = 'www' if subdomain.blank?
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ module Locomotive
|
|||||||
def fetch_site
|
def fetch_site
|
||||||
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
||||||
|
|
||||||
if Locomotive.multi_sites_enabled?
|
if Locomotive.config.multi_sites?
|
||||||
@current_site ||= Site.match_domain(request.host).first
|
@current_site ||= Site.match_domain(request.host).first
|
||||||
else
|
else
|
||||||
@current_site ||= Site.first
|
@current_site ||= Site.first
|
||||||
|
@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|||||||
s.add_dependency "rails", ">= 3.0.5"
|
s.add_dependency "rails", ">= 3.0.5"
|
||||||
s.add_dependency "warden"
|
s.add_dependency "warden"
|
||||||
s.add_dependency "devise", "1.1.3"
|
s.add_dependency "devise", "1.1.3"
|
||||||
s.add_dependency "mongoid", "~> 2.0.0.rc.7"
|
s.add_dependency "mongoid", "2.0.0.rc.7"
|
||||||
s.add_dependency "bson_ext", "~> 1.2.0"
|
s.add_dependency "bson_ext", "~> 1.2.0"
|
||||||
s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.5"
|
s.add_dependency "locomotive_mongoid_acts_as_tree", "0.1.5.5"
|
||||||
s.add_dependency "will_paginate"
|
s.add_dependency "will_paginate"
|
||||||
|
@ -28,7 +28,7 @@ describe 'Heroku support' do
|
|||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Locomotive.configure do |config|
|
Locomotive.configure do |config|
|
||||||
config.heroku = false
|
config.hosting = :none
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -49,7 +49,13 @@ describe 'Heroku support' do
|
|||||||
|
|
||||||
context '#enabled' do
|
context '#enabled' do
|
||||||
|
|
||||||
it 'tells heroku is disabled' do
|
it 'tells heroku is enabled from ENV' do
|
||||||
|
ENV['HEROKU_SLUG'] = 'test'
|
||||||
|
Locomotive.config.hosting = :auto
|
||||||
|
Locomotive.heroku?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
@ -69,8 +75,9 @@ describe 'Heroku support' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it 'opens a heroku connection with env credentials' do
|
it 'opens a heroku connection with env credentials' do
|
||||||
ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'
|
::Heroku::Client.any_instance.stubs(:list_domains).returns([])
|
||||||
Locomotive.configure { |config| config.heroku = true }
|
ENV['HEROKU_LOGIN'] = 'john@doe.net'; ENV['HEROKU_PASSWORD'] = 'easyone'; ENV['APP_NAME'] = 'test'
|
||||||
|
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
|
||||||
@ -138,12 +145,25 @@ describe 'Heroku support' do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def configure_locomotive_with_heroku(options = {}, domains = nil)
|
def configure_locomotive_with_heroku(options = {}, domains = nil)
|
||||||
::Heroku::Client.any_instance.stubs(:list_domains).with('locomotive').returns(domains || [
|
if options.has_key?(:name)
|
||||||
|
ENV['APP_NAME'] = options.delete(:name)
|
||||||
|
else
|
||||||
|
ENV['APP_NAME'] = 'locomotive'
|
||||||
|
end
|
||||||
|
|
||||||
|
::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.heroku = { :name => 'locomotive', :login => 'john@doe.net', :password => 'easyone' }.merge(options)
|
config.hosting = :heroku
|
||||||
|
config.heroku = { :login => 'john@doe.net', :password => 'easyone' }.merge(options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
after(:all) do
|
||||||
|
ENV['HEROKU_SLUG'] = ENV['APP_NAME'] = ENV['HEROKU_LOGIN'] = ENV['HEROKU_PASSWORD'] = nil
|
||||||
|
Locomotive.configure_for_test
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -7,6 +7,8 @@ require 'rspec/rails'
|
|||||||
# 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
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
# == Mock Framework
|
# == Mock Framework
|
||||||
#
|
#
|
||||||
|
32
spec/support/controller.rb
Normal file
32
spec/support/controller.rb
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
module Locomotive
|
||||||
|
class TestController < ApplicationController
|
||||||
|
|
||||||
|
include Locomotive::Render
|
||||||
|
|
||||||
|
attr_accessor :output, :status, :current_site, :current_admin
|
||||||
|
|
||||||
|
def render(options = {})
|
||||||
|
self.output = options[:text]
|
||||||
|
self.status = options[:status]
|
||||||
|
end
|
||||||
|
|
||||||
|
def response
|
||||||
|
@_response ||= TestResponse.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def request
|
||||||
|
@_request ||= TestRequest.new
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestResponse < ActionDispatch::TestResponse
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class TestRequest < ActionDispatch::TestRequest
|
||||||
|
|
||||||
|
attr_accessor :fullpath
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
@ -1,37 +1,10 @@
|
|||||||
|
def Locomotive.configure_for_test
|
||||||
Locomotive.configure do |config|
|
Locomotive.configure do |config|
|
||||||
config.default_domain = 'example.com'
|
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
|
config.enable_logs = true
|
||||||
end
|
end
|
||||||
|
|
||||||
module Locomotive
|
|
||||||
class TestController < ApplicationController
|
|
||||||
|
|
||||||
include Locomotive::Render
|
|
||||||
|
|
||||||
attr_accessor :output, :status, :current_site, :current_admin
|
|
||||||
|
|
||||||
def render(options = {})
|
|
||||||
self.output = options[:text]
|
|
||||||
self.status = options[:status]
|
|
||||||
end
|
|
||||||
|
|
||||||
def response
|
|
||||||
@_response ||= TestResponse.new
|
|
||||||
end
|
|
||||||
|
|
||||||
def request
|
|
||||||
@_request ||= TestRequest.new
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
class TestResponse < ActionDispatch::TestResponse
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
class TestRequest < ActionDispatch::TestRequest
|
|
||||||
|
|
||||||
attr_accessor :fullpath
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user