diff options
Diffstat (limited to 'railties/test/application/notifications_test.rb')
-rw-r--r-- | railties/test/application/notifications_test.rb | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/notifications_test.rb index 62ed4f4ad4..b57e829cca 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/notifications_test.rb @@ -1,46 +1,39 @@ require "isolation/abstract_unit" module ApplicationTests - class NotificationsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - class MyQueue - attr_reader :events, :subscribers - - def initialize - @events = [] - @subscribers = [] - end - - def publish(name, *args) - @events << name - end + class MyQueue + def publish(name, *args) + raise name + end - def subscribe(pattern=nil, &block) - @subscribers << pattern - end + # Not a full queue implementation + def method_missing(name, *args, &blk) + self end + end + + class NotificationsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation def setup build_app boot_rails - require "rails" + FileUtils.rm_rf("#{app_path}/config/environments") require "active_support/notifications" - Rails::Initializer.run do |c| - c.notifications.queue = MyQueue.new - c.notifications.subscribe(/listening/) do - puts "Cool" - end - end + @events = [] + + add_to_config <<-RUBY + config.notifications.notifier = ActiveSupport::Notifications::Notifier.new(ApplicationTests::MyQueue.new) + RUBY end test "new queue is set" do - ActiveSupport::Notifications.instrument(:foo) - assert_equal :foo, ActiveSupport::Notifications.queue.events.first - end + use_frameworks [] + require "#{app_path}/config/environment" - test "configuration subscribers are loaded" do - assert_equal 1, ActiveSupport::Notifications.queue.subscribers.count { |s| s == /listening/ } + assert_raise RuntimeError do + ActiveSupport::Notifications.publish('foo') + end end end end |