write tests for the last cells menu + write tests for the bushi.do events + refactor the locomotive logger + add the cas_extra_attributes hook
This commit is contained in:
parent
5e3a4ffa0f
commit
e05586d387
2
Gemfile
2
Gemfile
@ -56,7 +56,7 @@ group :test, :development do
|
||||
gem 'ruby-debug', :platforms => :mri_18
|
||||
gem 'ruby-debug19', :platforms => :mri_19
|
||||
|
||||
gem 'bushido_stub', :git => 'git://github.com/did/bushido_stub.git'
|
||||
gem 'bushido_stub', '0.0.3'
|
||||
|
||||
gem 'cucumber-rails', '1.0.2'
|
||||
end
|
||||
|
11
Gemfile.lock
11
Gemfile.lock
@ -17,13 +17,6 @@ GIT
|
||||
devise (>= 1.0.6)
|
||||
rubycas-client (>= 2.2.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/did/bushido_stub.git
|
||||
revision: 87f64541b4444dd3ff9fd1c1c44ac20c549ce2c6
|
||||
specs:
|
||||
bushido_stub (0.0.1)
|
||||
activesupport (>= 3.0.7)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/floehopper/mocha.git
|
||||
revision: d03843e763f4e5ceadb66bcb4c530d6c5d0cb293
|
||||
@ -77,6 +70,8 @@ GEM
|
||||
bson (1.3.1)
|
||||
bson_ext (1.3.1)
|
||||
builder (2.1.2)
|
||||
bushido_stub (0.0.3)
|
||||
activesupport (>= 3.0.7)
|
||||
cancan (1.6.5)
|
||||
capybara (1.0.0)
|
||||
mime-types (>= 1.16)
|
||||
@ -303,7 +298,7 @@ DEPENDENCIES
|
||||
autotest
|
||||
bson_ext (~> 1.3.0)
|
||||
bushido!
|
||||
bushido_stub!
|
||||
bushido_stub (= 0.0.3)
|
||||
cancan
|
||||
capybara
|
||||
carrierwave (~> 0.5.5)
|
||||
|
@ -29,7 +29,7 @@ module Admin
|
||||
respond_to :html
|
||||
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
::Locomotive::Logger.info "[CanCan::AccessDenied] #{exception.inspect}"
|
||||
::Locomotive.log "[CanCan::AccessDenied] #{exception.inspect}"
|
||||
|
||||
if request.xhr?
|
||||
render :json => { :error => exception.message }
|
||||
|
@ -4,7 +4,7 @@ Locomotive::Application.configure do
|
||||
# In the development environment your application's code is reloaded on
|
||||
# every request. This slows down response time but is perfect for development
|
||||
# since you don't have to restart the webserver when you make code changes.
|
||||
config.cache_classes = true
|
||||
config.cache_classes = false
|
||||
|
||||
# Log error messages when you accidentally call methods on nil.
|
||||
config.whiny_nils = true
|
||||
@ -30,12 +30,12 @@ Locomotive::Application.configure do
|
||||
|
||||
# set up the bushido stub (uncomment it)
|
||||
# config.bushido_stub_env = false
|
||||
config.bushido_stub_env = {
|
||||
'APP_TLD' => 'bushi.do',
|
||||
'BUSHIDO_APP' => 'san_francisco',
|
||||
'BUSHIDO_HOST' => 'bushi.do',
|
||||
'LOCOMOTIVE_SITE_NAME' => 'Locomotive TEST',
|
||||
'BUSHIDO_CLAIMED' => 'true',
|
||||
'BUSHIDO_METRICS_TOKEN' => 'foobar'
|
||||
}
|
||||
# config.bushido_stub_env = {
|
||||
# 'APP_TLD' => 'bushi.do',
|
||||
# 'BUSHIDO_APP' => 'san_francisco',
|
||||
# 'BUSHIDO_HOST' => 'bushi.do',
|
||||
# 'LOCOMOTIVE_SITE_NAME' => 'Locomotive TEST',
|
||||
# 'BUSHIDO_CLAIMED' => 'true',
|
||||
# 'BUSHIDO_METRICS_TOKEN' => 'foobar'
|
||||
# }
|
||||
end
|
||||
|
@ -126,10 +126,11 @@ module Locomotive
|
||||
end
|
||||
end
|
||||
|
||||
def self.logger(message)
|
||||
if self.config.enable_logs == true
|
||||
Rails.logger.info(message)
|
||||
end
|
||||
def self.log(*args)
|
||||
level = args.size == 1 ? 'info' : args.first
|
||||
message = args.size == 1 ? args.first : args.last
|
||||
|
||||
::Locomotive::Logger.send(level.to_sym, message)
|
||||
end
|
||||
|
||||
# rack_cache: needed by default
|
||||
|
@ -21,7 +21,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
else
|
||||
Locomotive.logger.warning "Unable to resize on the fly: #{source.inspect}"
|
||||
Locomotive.log :error, "Unable to resize on the fly: #{source.inspect}"
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -321,7 +321,7 @@ module Locomotive
|
||||
def log(message, domain = '')
|
||||
head = "[export_template][#{@site.name}]"
|
||||
head += "[#{domain}]" unless domain.blank?
|
||||
::Locomotive::Logger.info "\t#{head} #{message}"
|
||||
::Locomotive.log "\t#{head} #{message}"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -12,6 +12,21 @@ module Locomotive
|
||||
|
||||
end
|
||||
|
||||
module InstanceMethods
|
||||
|
||||
def cas_extra_attributes=(extra_attributes)
|
||||
return if extra_attributes.blank?
|
||||
|
||||
self.update_attributes({
|
||||
:email => extra_attributes['email'],
|
||||
:name => "#{extra_attributes['first_name']} #{extra_attributes['last_name']}",
|
||||
:bushido_user_id => extra_attributes['ido_id'],
|
||||
:locale => extra_attributes['locale'],
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
require 'bushido'
|
||||
require 'locomotive/hosting/bushido/hooks'
|
||||
require 'locomotive/hosting/bushido/custom_domain'
|
||||
require 'locomotive/hosting/bushido/first_installation'
|
||||
require 'locomotive/hosting/bushido/account_ext'
|
||||
@ -26,8 +27,6 @@ module Locomotive
|
||||
end
|
||||
|
||||
def enable_bushido!
|
||||
require './lib/locomotive/hosting/bushido/hooks'
|
||||
|
||||
self.config.domain = ENV['APP_TLD'] unless self.config.multi_sites?
|
||||
|
||||
self.config.devise_modules = [:cas_authenticatable, :rememberable, :trackable]
|
||||
@ -38,6 +37,8 @@ module Locomotive
|
||||
|
||||
self.setup_cas_client
|
||||
|
||||
self.subscribe_to_events
|
||||
|
||||
self.setup_smtp_settings
|
||||
|
||||
self.add_middlewares
|
||||
@ -77,6 +78,7 @@ module Locomotive
|
||||
config.cas_base_url = 'https://auth.bushi.do/cas'
|
||||
config.cas_logout_url = 'https://auth.bushi.do/cas/logout'
|
||||
config.cas_create_user = false
|
||||
config.cas_username_column = :email
|
||||
end
|
||||
|
||||
Admin::SessionsController.class_eval do
|
||||
@ -106,7 +108,7 @@ module Locomotive
|
||||
# manage domains
|
||||
|
||||
def add_bushido_domain(name)
|
||||
Locomotive.logger "[add bushido domain] #{name}"
|
||||
Locomotive.log "[add bushido domain] #{name}"
|
||||
::Bushido::App.add_domain(name)
|
||||
|
||||
if ::Bushido::Command.last_command_successful?
|
||||
@ -115,7 +117,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def remove_bushido_domain(name)
|
||||
Locomotive.logger "[remove bushido domain] #{name}"
|
||||
Locomotive.log "[remove bushido domain] #{name}"
|
||||
::Bushido::App.remove_domain(name)
|
||||
|
||||
if ::Bushido::Command.last_command_successful?
|
||||
@ -124,7 +126,7 @@ module Locomotive
|
||||
end
|
||||
|
||||
def set_bushido_subdomain(name)
|
||||
Locomotive.logger "[set bushido subdomain] #{name}.bushi.do"
|
||||
Locomotive.log "[set bushido subdomain] #{name}.bushi.do"
|
||||
::Bushido::App.set_subdomain(name)
|
||||
|
||||
if ::Bushido::Command.last_command_successful?
|
||||
|
@ -1,8 +1,25 @@
|
||||
Bushido::Data.listen("app.claimed") do |event|
|
||||
puts "Saving #{Account.first.inspect} with incoming data #{event.inspect}"
|
||||
require 'bushido'
|
||||
|
||||
module Locomotive
|
||||
module Hosting
|
||||
module Bushido
|
||||
module Enabler
|
||||
|
||||
module ClassMethods
|
||||
|
||||
def subscribe_to_events
|
||||
::Bushido::Data.listen('app.claimed') do |event|
|
||||
Locomotive.log "Saving #{Account.first.inspect} with incoming data #{event.inspect}"
|
||||
|
||||
account = Account.first
|
||||
account.email = event["data"].try(:[], "email")
|
||||
account.username = account.email
|
||||
account.email = event['data'].try(:[], 'email')
|
||||
account.name = account.email.split('@').first
|
||||
account.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -60,13 +60,13 @@ module Locomotive
|
||||
# manage domains
|
||||
|
||||
def add_heroku_domain(name)
|
||||
Locomotive.logger "[add heroku domain] #{name}"
|
||||
Locomotive.log "[add heroku domain] #{name}"
|
||||
self.heroku_connection.add_domain(self.config.heroku[:name], name)
|
||||
self.heroku_domains << name
|
||||
end
|
||||
|
||||
def remove_heroku_domain(name)
|
||||
Locomotive.logger "[remove heroku domain] #{name}"
|
||||
Locomotive.log "[remove heroku domain] #{name}"
|
||||
self.heroku_connection.remove_domain(self.config.heroku[:name], name)
|
||||
self.heroku_domains.delete(name)
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ module Locomotive
|
||||
def log(message, domain = '')
|
||||
head = "[import_template]"
|
||||
head += "[#{domain}]" unless domain.blank?
|
||||
::Locomotive::Logger.info "\t#{head} #{message}"
|
||||
::Locomotive.log "\t#{head} #{message}"
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ module Locomotive
|
||||
end
|
||||
render_element(context, element)
|
||||
else
|
||||
Locomotive.logger "[editable element] missing element `#{context['block'].try(:name)}` / #{@slug} on #{current_page.fullpath}"
|
||||
Locomotive.log :error, "[editable element] missing element `#{context['block'].try(:name)}` / #{@slug} on #{current_page.fullpath}"
|
||||
''
|
||||
end
|
||||
end
|
||||
|
@ -1,9 +1,9 @@
|
||||
module Locomotive
|
||||
module Logger
|
||||
|
||||
def self.method_missing(meth, args, &block)
|
||||
def self.method_missing(meth, message, &block)
|
||||
if Locomotive.config.enable_logs == true
|
||||
Rails.logger.send(meth, args)
|
||||
Rails.logger.send(meth, "[LocomotiveCMS] #{message}")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -17,7 +17,7 @@ module Locomotive
|
||||
protected
|
||||
|
||||
def fetch_site
|
||||
Locomotive.logger "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
||||
Locomotive.log "[fetch site] host = #{request.host} / #{request.env['HTTP_HOST']}"
|
||||
|
||||
if Locomotive.config.multi_sites?
|
||||
@current_site ||= Site.match_domain(request.host).first
|
||||
|
@ -1,101 +1,101 @@
|
||||
# require 'spec_helper'
|
||||
#
|
||||
# module Resetter
|
||||
#
|
||||
# @@original_global_actions_cell_klass = Admin::GlobalActionsCell
|
||||
#
|
||||
# def self.original_global_actions_cell_klass
|
||||
# @@original_global_actions_cell_klass
|
||||
# end
|
||||
#
|
||||
# def self.reset_global_actions_cell_klass
|
||||
# ::Admin.send(:remove_const, 'GlobalActionsCell')
|
||||
# ::Admin.const_set('GlobalActionsCell', self.original_global_actions_cell_klass.clone)
|
||||
# ::Admin::GlobalActionsCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' })
|
||||
# end
|
||||
#
|
||||
# end
|
||||
#
|
||||
# describe Admin::GlobalActionsCell do
|
||||
#
|
||||
# render_views
|
||||
#
|
||||
# let(:menu) { render_cell('admin/global_actions', :show) }
|
||||
#
|
||||
# describe 'show menu' do
|
||||
#
|
||||
# before(:each) do
|
||||
# Resetter.reset_global_actions_cell_klass
|
||||
# end
|
||||
#
|
||||
# it 'has 3 links' do
|
||||
# menu.should have_selector('li', :count => 3)
|
||||
# end
|
||||
#
|
||||
# it 'has a link to edit my account' do
|
||||
# menu.should have_link('Site')
|
||||
# end
|
||||
#
|
||||
# it 'has a link to edit the template files' do
|
||||
# menu.should have_link('Theme files')
|
||||
# end
|
||||
#
|
||||
# it 'has a link to edit my account' do
|
||||
# menu.should have_link('My account')
|
||||
# end
|
||||
#
|
||||
# end
|
||||
#
|
||||
# describe 'add a new menu item' do
|
||||
#
|
||||
# before(:each) do
|
||||
# Resetter.reset_global_actions_cell_klass
|
||||
# Admin::GlobalActionsCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'My link', :url => 'http://www.locomotivecms.com') }
|
||||
# end
|
||||
#
|
||||
# it 'has 4 items' do
|
||||
# menu.should have_selector('li', :count => 4)
|
||||
# end
|
||||
#
|
||||
# it 'has a new link' do
|
||||
# menu.should have_link('My link')
|
||||
# end
|
||||
#
|
||||
# end
|
||||
#
|
||||
# describe 'remove a new menu item' do
|
||||
#
|
||||
# before(:each) do
|
||||
# Resetter.reset_global_actions_cell_klass
|
||||
# Admin::GlobalActionsCell.update_for(:testing_remove) { |m| m.remove(:theme_assets) }
|
||||
# end
|
||||
#
|
||||
# it 'has 2 items' do
|
||||
# menu.should have_selector('li', :count => 2)
|
||||
# end
|
||||
#
|
||||
# it 'does not have the link to edit the template files' do
|
||||
# menu.should_not have_link('Theme files')
|
||||
# end
|
||||
#
|
||||
# end
|
||||
#
|
||||
# describe 'modify an existing menu item' do
|
||||
#
|
||||
# before(:each) do
|
||||
# Resetter.reset_global_actions_cell_klass
|
||||
# Admin::GlobalActionsCell.update_for(:testing_update) { |m| m.modify(:theme_assets, { :label => 'Modified !' }) }
|
||||
# end
|
||||
#
|
||||
# it 'still has 3 items' do
|
||||
# menu.should have_selector('li', :count => 3)
|
||||
# end
|
||||
#
|
||||
# it 'has a modified menu item' do
|
||||
# menu.should_not have_link('Theme files')
|
||||
# menu.should have_link('Modified !')
|
||||
# end
|
||||
#
|
||||
# end
|
||||
#
|
||||
# end
|
||||
require 'spec_helper'
|
||||
|
||||
module Resetter
|
||||
|
||||
@@original_global_actions_cell_klass = Admin::GlobalActionsCell
|
||||
|
||||
def self.original_global_actions_cell_klass
|
||||
@@original_global_actions_cell_klass
|
||||
end
|
||||
|
||||
def self.reset_global_actions_cell_klass
|
||||
::Admin.send(:remove_const, 'GlobalActionsCell')
|
||||
::Admin.const_set('GlobalActionsCell', self.original_global_actions_cell_klass.clone)
|
||||
::Admin::GlobalActionsCell.any_instance.stubs(:sections).returns({ :main => 'settings', :sub => 'site' })
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe Admin::GlobalActionsCell do
|
||||
|
||||
render_views
|
||||
|
||||
let(:menu) { render_cell('admin/global_actions', :show, :current_admin => Factory.build('admin user'), :current_site_url => 'http://www.yahoo.fr') }
|
||||
|
||||
describe 'show menu' do
|
||||
|
||||
before(:each) do
|
||||
Resetter.reset_global_actions_cell_klass
|
||||
end
|
||||
|
||||
it 'has 3 links' do
|
||||
menu.should have_selector('a', :count => 4)
|
||||
end
|
||||
|
||||
it 'has a link to edit my account' do
|
||||
menu.should have_link('Admin')
|
||||
end
|
||||
|
||||
it 'has a link to see my website' do
|
||||
menu.should have_link('See website')
|
||||
end
|
||||
|
||||
it 'has a link to log out' do
|
||||
menu.should have_link('Log out')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'add a new menu item' do
|
||||
|
||||
before(:each) do
|
||||
Resetter.reset_global_actions_cell_klass
|
||||
Admin::GlobalActionsCell.update_for(:testing_add) { |m| m.add(:my_link, :label => 'My link', :url => 'http://www.locomotivecms.com') }
|
||||
end
|
||||
|
||||
it 'has 4 items' do
|
||||
menu.should have_selector('a', :count => 5)
|
||||
end
|
||||
|
||||
it 'has a new link' do
|
||||
menu.should have_link('My link')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'remove a new menu item' do
|
||||
|
||||
before(:each) do
|
||||
Resetter.reset_global_actions_cell_klass
|
||||
Admin::GlobalActionsCell.update_for(:testing_remove) { |m| m.remove(:see) }
|
||||
end
|
||||
|
||||
it 'has 2 items' do
|
||||
menu.should have_selector('a', :count => 3)
|
||||
end
|
||||
|
||||
it 'does not have the link to see my website' do
|
||||
menu.should_not have_link('See website')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'modify an existing menu item' do
|
||||
|
||||
before(:each) do
|
||||
Resetter.reset_global_actions_cell_klass
|
||||
Admin::GlobalActionsCell.update_for(:testing_update) { |m| m.modify(:see, { :label => 'Modified !' }) }
|
||||
end
|
||||
|
||||
it 'still has 3 items' do
|
||||
menu.should have_selector('a', :count => 4)
|
||||
end
|
||||
|
||||
it 'has a modified menu item' do
|
||||
menu.should_not have_link('See website')
|
||||
menu.should have_link('Modified !')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -62,6 +62,23 @@ describe 'Bushido support' do
|
||||
Locomotive.bushido?.should be_true
|
||||
end
|
||||
|
||||
describe 'events' do
|
||||
|
||||
before(:each) do
|
||||
configure_locomotive_with_bushido
|
||||
@site = Factory.build('test site')
|
||||
@account = @site.memberships.first.account
|
||||
Account.stubs(:first).returns(@account)
|
||||
end
|
||||
|
||||
it 'responds to the app.claimed event' do
|
||||
::Bushido::Data.call('app.claimed')
|
||||
@account.name.should == 'san_francisco'
|
||||
@account.email.should == 'san_francisco@bushi.do'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'enhancing site' do
|
||||
|
||||
before(:each) do
|
||||
|
@ -177,4 +177,9 @@ describe 'Locomotive rendering system' do
|
||||
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ENV['APP_TLD'] = nil
|
||||
Locomotive.configure_for_test(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -88,7 +88,11 @@ describe Account do
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ENV['APP_TLD'] = nil
|
||||
Locomotive.configure_for_test(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -149,6 +149,11 @@ describe ContentInstance do
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ENV['APP_TLD'] = nil
|
||||
Locomotive.configure_for_test(true)
|
||||
end
|
||||
|
||||
def build_content(options = {})
|
||||
@content_type.contents.build({ :title => 'Locomotive', :description => 'Lorem ipsum....' }.merge(options))
|
||||
end
|
||||
|
@ -260,6 +260,11 @@ describe ContentType do
|
||||
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ENV['APP_TLD'] = nil
|
||||
Locomotive.configure_for_test(true)
|
||||
end
|
||||
|
||||
def build_content(content_type)
|
||||
content_type.contents.build(:name => 'Asset on steroids', :description => 'Lorem ipsum', :active => true)
|
||||
end
|
||||
|
@ -231,4 +231,9 @@ describe Page do
|
||||
@page.errors[:redirect_url].should == ["is invalid"]
|
||||
end
|
||||
end
|
||||
|
||||
after(:all) do
|
||||
ENV['APP_TLD'] = nil
|
||||
Locomotive.configure_for_test(true)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user