diff options
author | José Valim <jose.valim@gmail.com> | 2009-10-09 09:17:08 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2009-10-15 18:19:25 -0300 |
commit | aeaabc6d2d6f9faaa98057f33c0635d8add54461 (patch) | |
tree | e4779db2dc0853fae9415b9a2345e568598409f4 | |
parent | 8f59d7a8d8e736d7f4b6730020c197d008fb0779 (diff) | |
download | rails-aeaabc6d2d6f9faaa98057f33c0635d8add54461.tar.gz rails-aeaabc6d2d6f9faaa98057f33c0635d8add54461.tar.bz2 rails-aeaabc6d2d6f9faaa98057f33c0635d8add54461.zip |
Configure Orchestra on initialization.
-rw-r--r-- | railties/lib/rails/application.rb | 11 | ||||
-rw-r--r-- | railties/lib/rails/configuration.rb | 8 | ||||
-rw-r--r-- | railties/test/application/orchestra_test.rb | 49 |
3 files changed, 68 insertions, 0 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index a0e5d6a5a5..8e0e28c362 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -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 diff --git a/railties/lib/rails/configuration.rb b/railties/lib/rails/configuration.rb index 322590f108..3d9ae46786 100644 --- a/railties/lib/rails/configuration.rb +++ b/railties/lib/rails/configuration.rb @@ -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 diff --git a/railties/test/application/orchestra_test.rb b/railties/test/application/orchestra_test.rb new file mode 100644 index 0000000000..38a06be741 --- /dev/null +++ b/railties/test/application/orchestra_test.rb @@ -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 |