mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Configure Orchestra on initialization.
This commit is contained in:
@@ -487,5 +487,16 @@ module Rails
|
||||
Rails::Generators.options.deep_merge! config.generators.options
|
||||
end
|
||||
end
|
||||
|
||||
# For each framework, search for instrument file with Orchestra hooks.
|
||||
#
|
||||
initializer :load_orchestra_instrumentation do
|
||||
config.frameworks.each do |framework|
|
||||
begin
|
||||
require "#{framework}/instrument"
|
||||
rescue LoadError => e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -290,6 +290,14 @@ module Rails
|
||||
end
|
||||
end
|
||||
|
||||
# Allows Orchestra queue to be modified.
|
||||
#
|
||||
# config.orchestra.queue = MyNewQueue.new
|
||||
#
|
||||
def orchestra
|
||||
ActiveSupport::Orchestra
|
||||
end
|
||||
|
||||
class Generators #:nodoc:
|
||||
attr_accessor :aliases, :options, :colorize_logging
|
||||
|
||||
|
||||
49
railties/test/application/orchestra_test.rb
Normal file
49
railties/test/application/orchestra_test.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
require "isolation/abstract_unit"
|
||||
require "active_support/orchestra"
|
||||
|
||||
module ApplicationTests
|
||||
class OrchestraTest < Test::Unit::TestCase
|
||||
|
||||
class MyQueue
|
||||
attr_reader :events, :subscribers
|
||||
|
||||
def initialize
|
||||
@events = []
|
||||
@subscribers = []
|
||||
end
|
||||
|
||||
def publish(name, payload=nil)
|
||||
@events << name
|
||||
end
|
||||
|
||||
def subscribe(pattern=nil, &block)
|
||||
@subscribers << pattern
|
||||
end
|
||||
end
|
||||
|
||||
def setup
|
||||
build_app
|
||||
boot_rails
|
||||
|
||||
Rails::Initializer.run do |c|
|
||||
c.orchestra.queue = MyQueue.new
|
||||
c.orchestra.subscribe(/listening/) do
|
||||
puts "Cool"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "new queue is set" do
|
||||
ActiveSupport::Orchestra.instrument(:foo)
|
||||
assert_equal :foo, ActiveSupport::Orchestra.queue.events.first
|
||||
end
|
||||
|
||||
test "frameworks subscribers are loaded" do
|
||||
assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == "sql" }
|
||||
end
|
||||
|
||||
test "configuration subscribers are loaded" do
|
||||
assert_equal 1, ActiveSupport::Orchestra.queue.subscribers.count { |s| s == /listening/ }
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user