aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionmailer/lib/action_mailer/railtie.rb4
-rw-r--r--actionmailer/lib/action_mailer/railties/log_subscriber.rb (renamed from actionmailer/lib/action_mailer/railties/subscriber.rb)2
-rw-r--r--actionmailer/test/log_subscriber_test.rb (renamed from actionmailer/test/subscriber_test.rb)10
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb7
-rw-r--r--actionpack/lib/action_controller/railtie.rb4
-rw-r--r--actionpack/lib/action_controller/railties/log_subscriber.rb (renamed from actionpack/lib/action_controller/railties/subscriber.rb)2
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb10
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb15
-rw-r--r--actionpack/lib/action_dispatch/testing/test_process.rb2
-rw-r--r--actionpack/lib/action_view/railtie.rb4
-rw-r--r--actionpack/lib/action_view/railties/log_subscriber.rb (renamed from actionpack/lib/action_view/railties/subscriber.rb)2
-rw-r--r--actionpack/test/activerecord/controller_runtime_test.rb18
-rw-r--r--actionpack/test/controller/log_subscriber_test.rb (renamed from actionpack/test/controller/subscriber_test.rb)18
-rw-r--r--actionpack/test/controller/render_test.rb9
-rw-r--r--actionpack/test/dispatch/routing_test.rb11
-rw-r--r--actionpack/test/lib/controller/fake_models.rb1
-rw-r--r--actionpack/test/template/log_subscriber_test.rb (renamed from actionpack/test/template/subscriber_test.rb)12
-rwxr-xr-xactiverecord/lib/active_record/base.rb2
-rw-r--r--activerecord/lib/active_record/railtie.rb4
-rw-r--r--activerecord/lib/active_record/railties/log_subscriber.rb (renamed from activerecord/lib/active_record/railties/subscriber.rb)2
-rw-r--r--activerecord/test/cases/log_subscriber_test.rb (renamed from activerecord/test/cases/subscriber_test.rb)10
-rw-r--r--activeresource/lib/active_resource/railtie.rb4
-rw-r--r--activeresource/lib/active_resource/railties/log_subscriber.rb (renamed from activeresource/lib/active_resource/railties/subscriber.rb)2
-rw-r--r--activeresource/test/cases/log_subscriber_test.rb (renamed from activeresource/test/cases/subscriber_test.rb)10
-rw-r--r--activesupport/lib/active_support/notifications.rb4
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb10
-rw-r--r--activesupport/test/notifications_test.rb6
-rw-r--r--railties/guides/source/3_0_release_notes.textile2
-rw-r--r--railties/lib/generators/rails/app/app_generator.rb9
-rw-r--r--railties/lib/rails.rb2
-rw-r--r--railties/lib/rails/application/bootstrap.rb8
-rw-r--r--railties/lib/rails/log_subscriber.rb (renamed from railties/lib/rails/subscriber.rb)37
-rw-r--r--railties/lib/rails/log_subscriber/test_helper.rb (renamed from railties/lib/rails/subscriber/test_helper.rb)32
-rw-r--r--railties/lib/rails/plugin.rb10
-rw-r--r--railties/lib/rails/rack/logger.rb6
-rw-r--r--railties/lib/rails/railtie.rb4
-rw-r--r--railties/railties.gemspec2
-rw-r--r--railties/test/application/initializers/notifications_test.rb2
-rw-r--r--railties/test/generators/app_generator_test.rb5
-rw-r--r--railties/test/log_subscriber_test.rb125
-rw-r--r--railties/test/railties/plugin_test.rb9
-rw-r--r--railties/test/railties/railtie_test.rb8
-rw-r--r--railties/test/subscriber_test.rb119
43 files changed, 311 insertions, 254 deletions
diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb
index a3afc23e6a..4c48d2bed6 100644
--- a/actionmailer/lib/action_mailer/railtie.rb
+++ b/actionmailer/lib/action_mailer/railtie.rb
@@ -9,8 +9,8 @@ module ActionMailer
ActionMailer::Base.send(:include, ActionController::UrlFor) if defined?(ActionController)
end
- require "action_mailer/railties/subscriber"
- subscriber ActionMailer::Railties::Subscriber.new
+ require "action_mailer/railties/log_subscriber"
+ log_subscriber ActionMailer::Railties::LogSubscriber.new
initializer "action_mailer.logger" do
ActionMailer::Base.logger ||= Rails.logger
diff --git a/actionmailer/lib/action_mailer/railties/subscriber.rb b/actionmailer/lib/action_mailer/railties/log_subscriber.rb
index cff852055c..d1b3dd33af 100644
--- a/actionmailer/lib/action_mailer/railties/subscriber.rb
+++ b/actionmailer/lib/action_mailer/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActionMailer
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def deliver(event)
recipients = Array(event.payload[:to]).join(', ')
info("\nSent mail to #{recipients} (%1.fms)" % event.duration)
diff --git a/actionmailer/test/subscriber_test.rb b/actionmailer/test/log_subscriber_test.rb
index 88a5d2ca34..57b4a6a7f0 100644
--- a/actionmailer/test/subscriber_test.rb
+++ b/actionmailer/test/log_subscriber_test.rb
@@ -2,12 +2,12 @@ railties_path = File.expand_path('../../../railties/lib', __FILE__)
$:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_mailer/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "action_mailer/railties/log_subscriber"
-class AMSubscriberTest < ActionMailer::TestCase
- include Rails::Subscriber::TestHelper
- Rails::Subscriber.add(:action_mailer, ActionMailer::Railties::Subscriber.new)
+class AMLogSubscriberTest < ActionMailer::TestCase
+ include Rails::LogSubscriber::TestHelper
+ Rails::LogSubscriber.add(:action_mailer, ActionMailer::Railties::LogSubscriber.new)
class TestMailer < ActionMailer::Base
def basic
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 0aae9f8579..0bd362fd64 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -36,6 +36,13 @@ module ActionController
super
end
+ def _determine_template(options)
+ if options.key?(:text) && options[:text].respond_to?(:to_text)
+ options[:text] = options[:text].to_text
+ end
+ super
+ end
+
def format_for_text
formats.first
end
diff --git a/actionpack/lib/action_controller/railtie.rb b/actionpack/lib/action_controller/railtie.rb
index 55a5c22ac0..015a8212c4 100644
--- a/actionpack/lib/action_controller/railtie.rb
+++ b/actionpack/lib/action_controller/railtie.rb
@@ -6,8 +6,8 @@ module ActionController
class Railtie < Rails::Railtie
railtie_name :action_controller
- require "action_controller/railties/subscriber"
- subscriber ActionController::Railties::Subscriber.new
+ require "action_controller/railties/log_subscriber"
+ log_subscriber ActionController::Railties::LogSubscriber.new
initializer "action_controller.logger" do
ActionController::Base.logger ||= Rails.logger
diff --git a/actionpack/lib/action_controller/railties/subscriber.rb b/actionpack/lib/action_controller/railties/log_subscriber.rb
index 4499e82292..df9ffa1717 100644
--- a/actionpack/lib/action_controller/railties/subscriber.rb
+++ b/actionpack/lib/action_controller/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActionController
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
INTERNAL_PARAMS = %w(controller action format _method only_path)
def start_processing(event)
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 8de68b3174..0e9291490c 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -367,9 +367,9 @@ module ActionDispatch
def actions
if only = options[:only]
- only.map(&:to_sym)
+ Array(only).map(&:to_sym)
elsif except = options[:except]
- default_actions - except.map(&:to_sym)
+ default_actions - Array(except).map(&:to_sym)
else
default_actions
end
@@ -443,7 +443,7 @@ module ActionDispatch
def resource(*resources, &block)
options = resources.extract_options!
- if verify_common_behavior_for(:resource, resources, options, &block)
+ if apply_common_behavior_for(:resource, resources, options, &block)
return self
end
@@ -468,7 +468,7 @@ module ActionDispatch
def resources(*resources, &block)
options = resources.extract_options!
- if verify_common_behavior_for(:resources, resources, options, &block)
+ if apply_common_behavior_for(:resources, resources, options, &block)
return self
end
@@ -591,7 +591,7 @@ module ActionDispatch
path_names[name.to_sym] || name.to_s
end
- def verify_common_behavior_for(method, resources, options, &block)
+ def apply_common_behavior_for(method, resources, options, &block)
if resources.length > 1
resources.each { |r| send(method, r, options, &block) }
return true
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index ee60112bbc..8778fd2932 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -11,8 +11,8 @@ module ActionDispatch
PARAMETERS_KEY = 'action_dispatch.request.path_parameters'
class Dispatcher
- def initialize(options = {})
- defaults = options[:defaults]
+ def initialize(options={})
+ @defaults = options[:defaults]
@glob_param = options.delete(:glob)
end
@@ -20,7 +20,8 @@ module ActionDispatch
params = env[PARAMETERS_KEY]
prepare_params!(params)
- unless controller = controller(params)
+ # Just raise undefined constant errors if a controller was specified as default.
+ unless controller = controller(params, @defaults.key?(:controller))
return [404, {'X-Cascade' => 'pass'}, []]
end
@@ -39,14 +40,13 @@ module ActionDispatch
end
end
- def controller(params)
+ def controller(params, raise_error=true)
if params && params.has_key?(:controller)
controller = "#{params[:controller].camelize}Controller"
ActiveSupport::Inflector.constantize(controller)
end
rescue NameError => e
- raise unless e.message.include?(controller)
- nil
+ raise ActionController::RoutingError, e.message, e.backtrace if raise_error
end
private
@@ -59,7 +59,6 @@ module ActionDispatch
end
end
-
# A NamedRouteCollection instance is a collection of named routes, and also
# maintains an anonymous module that can be used to install helpers for the
# named routes.
@@ -433,7 +432,7 @@ module ActionDispatch
req = Rack::Request.new(env)
@set.recognize(req) do |route, matches, params|
dispatcher = route.app
- if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params)
+ if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
dispatcher.prepare_params!(params)
return params
end
diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb
index eae703e1b6..d4eecac2de 100644
--- a/actionpack/lib/action_dispatch/testing/test_process.rb
+++ b/actionpack/lib/action_dispatch/testing/test_process.rb
@@ -1,3 +1,5 @@
+require 'action_dispatch/middleware/flash'
+
module ActionDispatch
module TestProcess
def assigns(key = nil)
diff --git a/actionpack/lib/action_view/railtie.rb b/actionpack/lib/action_view/railtie.rb
index d9e2557d89..03f18ac172 100644
--- a/actionpack/lib/action_view/railtie.rb
+++ b/actionpack/lib/action_view/railtie.rb
@@ -5,8 +5,8 @@ module ActionView
class Railtie < Rails::Railtie
railtie_name :action_view
- require "action_view/railties/subscriber"
- subscriber ActionView::Railties::Subscriber.new
+ require "action_view/railties/log_subscriber"
+ log_subscriber ActionView::Railties::LogSubscriber.new
initializer "action_view.cache_asset_timestamps" do |app|
unless app.config.cache_classes
diff --git a/actionpack/lib/action_view/railties/subscriber.rb b/actionpack/lib/action_view/railties/log_subscriber.rb
index 803f19379c..9487a10706 100644
--- a/actionpack/lib/action_view/railties/subscriber.rb
+++ b/actionpack/lib/action_view/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActionView
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def render_template(event)
message = "Rendered #{from_rails_root(event.payload[:identifier])}"
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
diff --git a/actionpack/test/activerecord/controller_runtime_test.rb b/actionpack/test/activerecord/controller_runtime_test.rb
index f044e714d8..ee5fbdb0ae 100644
--- a/actionpack/test/activerecord/controller_runtime_test.rb
+++ b/actionpack/test/activerecord/controller_runtime_test.rb
@@ -4,30 +4,30 @@ $:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(rail
require 'active_record_unit'
require 'active_record/railties/controller_runtime'
require 'fixtures/project'
-require 'rails/subscriber/test_helper'
-require 'action_controller/railties/subscriber'
+require 'rails/log_subscriber/test_helper'
+require 'action_controller/railties/log_subscriber'
ActionController::Base.send :include, ActiveRecord::Railties::ControllerRuntime
-class ControllerRuntimeSubscriberTest < ActionController::TestCase
- class SubscriberController < ActionController::Base
+class ControllerRuntimeLogSubscriberTest < ActionController::TestCase
+ class LogSubscriberController < ActionController::Base
def show
render :inline => "<%= Project.all %>"
end
end
-
- include Rails::Subscriber::TestHelper
- tests SubscriberController
+
+ include Rails::LogSubscriber::TestHelper
+ tests LogSubscriberController
def setup
@old_logger = ActionController::Base.logger
- Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
+ Rails::LogSubscriber.add(:action_controller, ActionController::Railties::LogSubscriber.new)
super
end
def teardown
super
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
ActionController::Base.logger = @old_logger
end
diff --git a/actionpack/test/controller/subscriber_test.rb b/actionpack/test/controller/log_subscriber_test.rb
index 72368df93b..0659a4520e 100644
--- a/actionpack/test/controller/subscriber_test.rb
+++ b/actionpack/test/controller/log_subscriber_test.rb
@@ -2,11 +2,11 @@ railties_path = File.expand_path('../../../../railties/lib', __FILE__)
$:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_controller/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "action_controller/railties/log_subscriber"
module Another
- class SubscribersController < ActionController::Base
+ class LogSubscribersController < ActionController::Base
def show
render :nothing => true
end
@@ -38,9 +38,9 @@ module Another
end
end
-class ACSubscriberTest < ActionController::TestCase
- tests Another::SubscribersController
- include Rails::Subscriber::TestHelper
+class ACLogSubscriberTest < ActionController::TestCase
+ tests Another::LogSubscribersController
+ include Rails::LogSubscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@@ -49,13 +49,13 @@ class ACSubscriberTest < ActionController::TestCase
ActionController::Base.page_cache_directory = @cache_path
ActionController::Base.cache_store = :file_store, @cache_path
- Rails::Subscriber.add(:action_controller, ActionController::Railties::Subscriber.new)
+ Rails::LogSubscriber.add(:action_controller, ActionController::Railties::LogSubscriber.new)
super
end
def teardown
super
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
FileUtils.rm_rf(@cache_path)
ActionController::Base.logger = @old_logger
end
@@ -68,7 +68,7 @@ class ACSubscriberTest < ActionController::TestCase
get :show
wait
assert_equal 2, logs.size
- assert_equal "Processing by Another::SubscribersController#show as HTML", logs.first
+ assert_equal "Processing by Another::LogSubscribersController#show as HTML", logs.first
end
def test_process_action
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 2c3dc2a72d..3cc22cc316 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -214,6 +214,10 @@ class TestController < ActionController::Base
render :text => false
end
+ def render_text_with_resource
+ render :text => Customer.new("David")
+ end
+
# :ported:
def render_nothing_with_appendix
render :text => "appended"
@@ -817,6 +821,11 @@ class RenderTest < ActionController::TestCase
assert_equal 'appended', @response.body
end
+ def test_render_text_with_resource
+ get :render_text_with_resource
+ assert_equal 'name: "David"', @response.body
+ end
+
# :ported:
def test_attempt_to_access_object_method
assert_raise(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb
index bcb97e4ae0..0cd1fddff1 100644
--- a/actionpack/test/dispatch/routing_test.rb
+++ b/actionpack/test/dispatch/routing_test.rb
@@ -104,7 +104,9 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
- resources :posts, :only => [:index, :show]
+ resources :posts, :only => [:index, :show] do
+ resources :comments, :except => :destroy
+ end
match 'sprockets.js' => ::TestRoutingMapper::SprocketsApp
@@ -471,7 +473,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
end
end
- def test_posts
+ def test_resource_routes_with_only_and_except
with_test_routes do
get '/posts'
assert_equal 'posts#index', @response.body
@@ -481,9 +483,14 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
assert_equal 'posts#show', @response.body
assert_equal '/posts/1', post_path(:id => 1)
+ get '/posts/1/comments'
+ assert_equal 'comments#index', @response.body
+ assert_equal '/posts/1/comments', post_comments_path(:post_id => 1)
+
assert_raise(ActionController::RoutingError) { post '/posts' }
assert_raise(ActionController::RoutingError) { put '/posts/1' }
assert_raise(ActionController::RoutingError) { delete '/posts/1' }
+ assert_raise(ActionController::RoutingError) { delete '/posts/1/comments' }
end
end
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index 7346cb22bc..a8c86f70b6 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -21,6 +21,7 @@ class Customer < Struct.new(:name, :id)
def to_js(options={})
"name: #{name.inspect}"
end
+ alias :to_text :to_js
def errors
[]
diff --git a/actionpack/test/template/subscriber_test.rb b/actionpack/test/template/log_subscriber_test.rb
index 8470f3c931..f370810e81 100644
--- a/actionpack/test/template/subscriber_test.rb
+++ b/actionpack/test/template/log_subscriber_test.rb
@@ -2,24 +2,24 @@ railties_path = File.expand_path('../../../../railties/lib', __FILE__)
$:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(railties_path)
require "abstract_unit"
-require "rails/subscriber/test_helper"
-require "action_view/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "action_view/railties/log_subscriber"
require "controller/fake_models"
-class AVSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
+class AVLogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
def setup
@old_logger = ActionController::Base.logger
@view = ActionView::Base.new(ActionController::Base.view_paths, {})
Rails.stubs(:root).returns(File.expand_path(FIXTURE_LOAD_PATH))
- Rails::Subscriber.add(:action_view, ActionView::Railties::Subscriber.new)
+ Rails::LogSubscriber.add(:action_view, ActionView::Railties::LogSubscriber.new)
super
end
def teardown
super
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
ActionController::Base.logger = @old_logger
end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index f30eba4f06..c6dde078ca 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -552,7 +552,7 @@ module ActiveRecord #:nodoc:
def colorize_logging(*args)
ActiveSupport::Deprecation.warn "ActiveRecord::Base.colorize_logging and " <<
"config.active_record.colorize_logging are deprecated. Please use " <<
- "Rails::Subscriber.colorize_logging or config.colorize_logging instead", caller
+ "Rails::LogSubscriber.colorize_logging or config.colorize_logging instead", caller
end
alias :colorize_logging= :colorize_logging
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index e70b0d1bfb..b38bd9a644 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -20,8 +20,8 @@ module ActiveRecord
end
# TODO If we require the wrong file, the error never comes up.
- require "active_record/railties/subscriber"
- subscriber ActiveRecord::Railties::Subscriber.new
+ require "active_record/railties/log_subscriber"
+ log_subscriber ActiveRecord::Railties::LogSubscriber.new
initializer "active_record.initialize_timezone" do
ActiveRecord::Base.time_zone_aware_attributes = true
diff --git a/activerecord/lib/active_record/railties/subscriber.rb b/activerecord/lib/active_record/railties/log_subscriber.rb
index fd873dbff8..48b25032ce 100644
--- a/activerecord/lib/active_record/railties/subscriber.rb
+++ b/activerecord/lib/active_record/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActiveRecord
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def sql(event)
name = '%s (%.1fms)' % [event.payload[:name], event.duration]
sql = event.payload[:sql].squeeze(' ')
diff --git a/activerecord/test/cases/subscriber_test.rb b/activerecord/test/cases/log_subscriber_test.rb
index 3d7a8f5bab..f854499435 100644
--- a/activerecord/test/cases/subscriber_test.rb
+++ b/activerecord/test/cases/log_subscriber_test.rb
@@ -3,12 +3,12 @@ $:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(rail
require "cases/helper"
require "models/developer"
-require "rails/subscriber/test_helper"
-require "active_record/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "active_record/railties/log_subscriber"
-class SubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
- Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
+class LogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+ Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
def setup
@old_logger = ActiveRecord::Base.logger
diff --git a/activeresource/lib/active_resource/railtie.rb b/activeresource/lib/active_resource/railtie.rb
index 7e35fdc0eb..27c88415f6 100644
--- a/activeresource/lib/active_resource/railtie.rb
+++ b/activeresource/lib/active_resource/railtie.rb
@@ -5,8 +5,8 @@ module ActiveResource
class Railtie < Rails::Railtie
railtie_name :active_resource
- require "active_resource/railties/subscriber"
- subscriber ActiveResource::Railties::Subscriber.new
+ require "active_resource/railties/log_subscriber"
+ log_subscriber ActiveResource::Railties::LogSubscriber.new
initializer "active_resource.set_configs" do |app|
app.config.active_resource.each do |k,v|
diff --git a/activeresource/lib/active_resource/railties/subscriber.rb b/activeresource/lib/active_resource/railties/log_subscriber.rb
index fb98061b71..86806a93d0 100644
--- a/activeresource/lib/active_resource/railties/subscriber.rb
+++ b/activeresource/lib/active_resource/railties/log_subscriber.rb
@@ -1,6 +1,6 @@
module ActiveResource
module Railties
- class Subscriber < Rails::Subscriber
+ class LogSubscriber < Rails::LogSubscriber
def request(event)
result = event.payload[:result]
info "#{event.payload[:method].to_s.upcase} #{event.payload[:request_uri]}"
diff --git a/activeresource/test/cases/subscriber_test.rb b/activeresource/test/cases/log_subscriber_test.rb
index c673a0551a..45eb4da8a4 100644
--- a/activeresource/test/cases/subscriber_test.rb
+++ b/activeresource/test/cases/log_subscriber_test.rb
@@ -3,14 +3,14 @@ $:.unshift(railties_path) if File.directory?(railties_path) && !$:.include?(rail
require "abstract_unit"
require "fixtures/person"
-require "rails/subscriber/test_helper"
-require "active_resource/railties/subscriber"
+require "rails/log_subscriber/test_helper"
+require "active_resource/railties/log_subscriber"
require "active_support/core_ext/hash/conversions"
# TODO: This test should be part of Railties
-class SubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
- Rails::Subscriber.add(:active_resource, ActiveResource::Railties::Subscriber.new)
+class LogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+ Rails::LogSubscriber.add(:active_resource, ActiveResource::Railties::LogSubscriber.new)
def setup
@matz = { :id => 1, :name => 'Matz' }.to_xml(:root => 'person')
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb
index 3e96decb8c..06d57765bc 100644
--- a/activesupport/lib/active_support/notifications.rb
+++ b/activesupport/lib/active_support/notifications.rb
@@ -9,7 +9,7 @@ module ActiveSupport
# end
#
# You can consume those events and the information they provide by registering
- # a subscriber. For instance, let's store all instrumented events in an array:
+ # a log subscriber. For instance, let's store all instrumented events in an array:
#
# @events = []
#
@@ -35,7 +35,7 @@ module ActiveSupport
# end
#
# Notifications ships with a queue implementation that consumes and publish events
- # to subscribers in a thread. You can use any queue implementation you want.
+ # to log subscribers in a thread. You can use any queue implementation you want.
#
module Notifications
autoload :Instrumenter, 'active_support/notifications/instrumenter'
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 0ec23da073..05de4946a5 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -1,10 +1,10 @@
module ActiveSupport
module Notifications
# This is a default queue implementation that ships with Notifications. It
- # just pushes events to all registered subscribers.
+ # just pushes events to all registered log subscribers.
class Fanout
def initialize
- @subscribers = []
+ @log_subscribers = []
end
def bind(pattern)
@@ -12,11 +12,11 @@ module ActiveSupport
end
def subscribe(pattern = nil, &block)
- @subscribers << Subscriber.new(pattern, &block)
+ @log_subscribers << LogSubscriber.new(pattern, &block)
end
def publish(*args)
- @subscribers.each { |s| s.publish(*args) }
+ @log_subscribers.each { |s| s.publish(*args) }
end
# This is a sync queue, so there is not waiting.
@@ -41,7 +41,7 @@ module ActiveSupport
end
end
- class Subscriber #:nodoc:
+ class LogSubscriber #:nodoc:
def initialize(pattern, &block)
@pattern = pattern
@block = block
diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb
index 545811a376..779771553c 100644
--- a/activesupport/test/notifications_test.rb
+++ b/activesupport/test/notifications_test.rb
@@ -26,7 +26,7 @@ module Notifications
assert_equal [[:foo]], @events
end
- def test_subscriber_with_pattern
+ def test_log_subscriber_with_pattern
events = []
@notifier.subscribe('1') { |*args| events << args }
@@ -38,7 +38,7 @@ module Notifications
assert_equal [['1'], ['1.a']], events
end
- def test_subscriber_with_pattern_as_regexp
+ def test_log_subscriber_with_pattern_as_regexp
events = []
@notifier.subscribe(/\d/) { |*args| events << args }
@@ -50,7 +50,7 @@ module Notifications
assert_equal [['1'], ['a.1'], ['1.a']], events
end
- def test_multiple_subscribers
+ def test_multiple_log_subscribers
@another = []
@notifier.subscribe { |*args| @another << args }
@notifier.publish :foo
diff --git a/railties/guides/source/3_0_release_notes.textile b/railties/guides/source/3_0_release_notes.textile
index 639e775bf5..4b0dc72908 100644
--- a/railties/guides/source/3_0_release_notes.textile
+++ b/railties/guides/source/3_0_release_notes.textile
@@ -435,7 +435,7 @@ As well as the following deprecations:
* I18n error messages for ActiveRecord should be changed from :en.activerecord.errors.template to <tt>:en.errors.template</tt>.
* <tt>model.errors.on</tt> is deprecated in favour of <tt>model.errors[]</tt>
* validates_presence_of => validates... :presence => true
-* <tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favour of <tt>Rails::Subscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt>
+* <tt>ActiveRecord::Base.colorize_logging</tt> and <tt>config.active_record.colorize_logging</tt> are deprecated in favour of <tt>Rails::LogSubscriber.colorize_logging</tt> or <tt>config.colorize_logging</tt>
NOTE: While an implementation of State Machine has been in Active Record edge for some months now, it has been removed from the Rails 3.0 release.
diff --git a/railties/lib/generators/rails/app/app_generator.rb b/railties/lib/generators/rails/app/app_generator.rb
index c439ed89f5..ea1930a966 100644
--- a/railties/lib/generators/rails/app/app_generator.rb
+++ b/railties/lib/generators/rails/app/app_generator.rb
@@ -7,6 +7,10 @@ module Rails::Generators
# can change in Ruby 1.8.7 when we FileUtils.cd.
RAILS_DEV_PATH = File.expand_path("../../../../..", File.dirname(__FILE__))
+ RESERVED_NAMES = %w[generate console server dbconsole
+ application destroy benchmarker profiler
+ plugin runner test]
+
class AppGenerator < Base
DATABASES = %w( mysql oracle postgresql sqlite3 frontbase ibm_db )
@@ -209,9 +213,10 @@ module Rails::Generators
end
def valid_app_const?
- case app_const
- when /^\d/
+ if app_const =~ /^\d/
raise Error, "Invalid application name #{app_name}. Please give a name which does not start with numbers."
+ elsif RESERVED_NAMES.include?(app_name)
+ raise Error, "Invalid application name #{app_name}. Please give a name which does not match one of the reserved rails words."
end
end
diff --git a/railties/lib/rails.rb b/railties/lib/rails.rb
index b7a39fd5a7..3d3151bd8f 100644
--- a/railties/lib/rails.rb
+++ b/railties/lib/rails.rb
@@ -7,7 +7,7 @@ require 'active_support/core_ext/logger'
require 'rails/application'
require 'rails/version'
require 'rails/deprecation'
-require 'rails/subscriber'
+require 'rails/log_subscriber'
require 'rails/ruby_version_check'
require 'active_support/railtie'
diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb
index b20e53f2de..0714b34b31 100644
--- a/railties/lib/rails/application/bootstrap.rb
+++ b/railties/lib/rails/application/bootstrap.rb
@@ -49,17 +49,17 @@ module Rails
end
end
- # Initialize rails subscriber on top of notifications.
- initializer :initialize_subscriber do
+ # Initialize rails log subscriber on top of notifications.
+ initializer :initialize_log_subscriber do
require 'active_support/notifications'
if config.colorize_logging == false
- Rails::Subscriber.colorize_logging = false
+ Rails::LogSubscriber.colorize_logging = false
config.generators.colorize_logging = false
end
ActiveSupport::Notifications.subscribe do |*args|
- Rails::Subscriber.dispatch(args)
+ Rails::LogSubscriber.dispatch(args)
end
end
diff --git a/railties/lib/rails/subscriber.rb b/railties/lib/rails/log_subscriber.rb
index 8c62f562d9..05cb70690a 100644
--- a/railties/lib/rails/subscriber.rb
+++ b/railties/lib/rails/log_subscriber.rb
@@ -2,15 +2,15 @@ require 'active_support/core_ext/class/inheritable_attributes'
require 'active_support/notifications'
module Rails
- # Rails::Subscriber is an object set to consume ActiveSupport::Notifications
- # on initialization with solely purpose of logging. The subscriber dispatches
+ # Rails::LogSubscriber is an object set to consume ActiveSupport::Notifications
+ # on initialization with solely purpose of logging. The log subscriber dispatches
# notifications to a regirested object based on its given namespace.
#
- # An example would be ActiveRecord subscriber responsible for logging queries:
+ # An example would be ActiveRecord log subscriber responsible for logging queries:
#
# module ActiveRecord
# class Railtie
- # class Subscriber < Rails::Subscriber
+ # class LogSubscriber < Rails::LogSubscriber
# def sql(event)
# "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
# end
@@ -20,19 +20,19 @@ module Rails
#
# It's finally registed as:
#
- # Rails::Subscriber.add :active_record, ActiveRecord::Railtie::Subscriber.new
+ # Rails::LogSubscriber.add :active_record, ActiveRecord::Railtie::LogSubscriber.new
#
- # So whenever a "active_record.sql" notification arrive to Rails::Subscriber,
+ # So whenever a "active_record.sql" notification arrive to Rails::LogSubscriber,
# it will properly dispatch the event (ActiveSupport::Notifications::Event) to
# the sql method.
#
- # This is useful because it avoids spanning several subscribers just for logging
+ # This is useful because it avoids spanning several log subscribers just for logging
# purposes(which slows down the main thread). Besides of providing a centralized
# facility on top of Rails.logger.
#
- # Subscriber also has some helpers to deal with logging and automatically flushes
+ # Log subscriber also has some helpers to deal with logging and automatically flushes
# all logs when the request finishes (via action_dispatch.callback notification).
- class Subscriber
+ class LogSubscriber
mattr_accessor :colorize_logging
self.colorize_logging = true
@@ -50,30 +50,31 @@ module Rails
CYAN = "\e[36m"
WHITE = "\e[37m"
- def self.add(namespace, subscriber)
- subscribers[namespace.to_sym] = subscriber
+ def self.add(namespace, log_subscriber)
+ log_subscribers[namespace.to_sym] = log_subscriber
end
- def self.subscribers
- @subscribers ||= {}
+ def self.log_subscribers
+ @log_subscribers ||= {}
end
def self.dispatch(args)
namespace, name = args[0].split(".")
- subscriber = subscribers[namespace.to_sym]
+ return unless namespace && name
- if subscriber.respond_to?(name) && subscriber.logger
+ log_subscriber = log_subscribers[namespace.to_sym]
+ if log_subscriber.respond_to?(name) && log_subscriber.logger
begin
- subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
+ log_subscriber.send(name, ActiveSupport::Notifications::Event.new(*args))
rescue Exception => e
Rails.logger.error "Could not log #{args[0].inspect} event. #{e.class}: #{e.message}"
end
end
end
- # Flush all subscribers' logger.
+ # Flush all log_subscribers' logger.
def self.flush_all!
- loggers = subscribers.values.map(&:logger)
+ loggers = log_subscribers.values.map(&:logger)
loggers.uniq!
loggers.each { |l| l.flush if l.respond_to?(:flush) }
end
diff --git a/railties/lib/rails/subscriber/test_helper.rb b/railties/lib/rails/log_subscriber/test_helper.rb
index 39b4117372..9ede56cad4 100644
--- a/railties/lib/rails/subscriber/test_helper.rb
+++ b/railties/lib/rails/log_subscriber/test_helper.rb
@@ -1,13 +1,13 @@
-require 'rails/subscriber'
+require 'rails/log_subscriber'
module Rails
- class Subscriber
- # Provides some helpers to deal with testing subscribers by setting up
+ class LogSubscriber
+ # Provides some helpers to deal with testing log subscribers by setting up
# notifications. Take for instance ActiveRecord subscriber tests:
#
- # class SyncSubscriberTest < ActiveSupport::TestCase
- # include Rails::Subscriber::TestHelper
- # Rails::Subscriber.add(:active_record, ActiveRecord::Railties::Subscriber.new)
+ # class SyncLogSubscriberTest < ActiveSupport::TestCase
+ # include Rails::LogSubscriber::TestHelper
+ # Rails::LogSubscriber.add(:active_record, ActiveRecord::Railties::LogSubscriber.new)
#
# def test_basic_query_logging
# Developer.all
@@ -17,18 +17,18 @@ module Rails
# assert_match /SELECT \* FROM "developers"/, @logger.logged(:debug).last
# end
#
- # class SyncSubscriberTest < ActiveSupport::TestCase
- # include Rails::Subscriber::SyncTestHelper
- # include SubscriberTest
+ # class SyncLogSubscriberTest < ActiveSupport::TestCase
+ # include Rails::LogSubscriber::SyncTestHelper
+ # include LogSubscriberTest
# end
#
- # class AsyncSubscriberTest < ActiveSupport::TestCase
- # include Rails::Subscriber::AsyncTestHelper
- # include SubscriberTest
+ # class AsyncLogSubscriberTest < ActiveSupport::TestCase
+ # include Rails::LogSubscriber::AsyncTestHelper
+ # include LogSubscriberTest
# end
# end
#
- # All you need to do is to ensure that your subscriber is added to Rails::Subscriber,
+ # All you need to do is to ensure that your log subscriber is added to Rails::Subscriber,
# as in the second line of the code above. The test helpers is reponsible for setting
# up the queue, subscriptions and turning colors in logs off.
#
@@ -42,8 +42,8 @@ module Rails
@logger = MockLogger.new
@notifier = ActiveSupport::Notifications::Notifier.new(queue)
- Rails::Subscriber.colorize_logging = false
- @notifier.subscribe { |*args| Rails::Subscriber.dispatch(args) }
+ Rails::LogSubscriber.colorize_logging = false
+ @notifier.subscribe { |*args| Rails::LogSubscriber.dispatch(args) }
set_logger(@logger)
ActiveSupport::Notifications.notifier = @notifier
@@ -80,7 +80,7 @@ module Rails
@notifier.wait
end
- # Overwrite if you use another logger in your subscriber:
+ # Overwrite if you use another logger in your log subscriber:
#
# def logger
# ActiveRecord::Base.logger = @logger
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index 64d03e7599..882f2dc28e 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -29,7 +29,7 @@ module Rails
unless extra_tasks.empty?
ActiveSupport::Deprecation.warn "Having rake tasks in PLUGIN_PATH/tasks or " <<
- "PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead"
+ "PLUGIN_PATH/rails/tasks is deprecated. Use PLUGIN_PATH/lib/tasks instead"
extra_tasks.sort.each { |ext| load(ext) }
end
end
@@ -44,7 +44,13 @@ module Rails
end
initializer :load_init_rb, :before => :load_application_initializers do |app|
- file = Dir["#{root}/{rails/init,init}.rb"].first
+ if File.file?(file = File.expand_path("rails/init.rb", root))
+ ActiveSupport::Deprecation.warn "PLUGIN_PATH/rails/init.rb in plugins is deprecated. " <<
+ "Use PLUGIN_PATH/init.rb instead"
+ else
+ file = File.expand_path("init.rb", root)
+ end
+
config = app.config
eval(File.read(file), binding, file) if file && File.file?(file)
end
diff --git a/railties/lib/rails/rack/logger.rb b/railties/lib/rails/rack/logger.rb
index de21fb4f10..2efe224e94 100644
--- a/railties/lib/rails/rack/logger.rb
+++ b/railties/lib/rails/rack/logger.rb
@@ -1,9 +1,9 @@
-require 'rails/subscriber'
+require 'rails/log_subscriber'
module Rails
module Rack
# Log the request started and flush all loggers after it.
- class Logger < Rails::Subscriber
+ class Logger < Rails::LogSubscriber
def initialize(app)
@app = app
end
@@ -26,7 +26,7 @@ module Rails
end
def after_dispatch(env)
- Rails::Subscriber.flush_all!
+ Rails::LogSubscriber.flush_all!
end
end
diff --git a/railties/lib/rails/railtie.rb b/railties/lib/rails/railtie.rb
index c038d0ac70..67afae5862 100644
--- a/railties/lib/rails/railtie.rb
+++ b/railties/lib/rails/railtie.rb
@@ -32,8 +32,8 @@ module Rails
subclasses.map { |p| p.railtie_name }
end
- def subscriber(subscriber)
- Rails::Subscriber.add(railtie_name, subscriber)
+ def log_subscriber(log_subscriber)
+ Rails::LogSubscriber.add(railtie_name, log_subscriber)
end
def rake_tasks(&blk)
diff --git a/railties/railties.gemspec b/railties/railties.gemspec
index 65d2dde89f..9b07fcc30f 100644
--- a/railties/railties.gemspec
+++ b/railties/railties.gemspec
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.has_rdoc = false
s.add_dependency('rake', '>= 0.8.3')
- s.add_dependency('thor', '~> 0.13')
+ s.add_dependency('thor', '~> 0.13.0')
s.add_dependency('activesupport', '= 3.0.0.beta1')
s.add_dependency('actionpack', '= 3.0.0.beta1')
end
diff --git a/railties/test/application/initializers/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb
index 061bb34c19..b99cf5bb4f 100644
--- a/railties/test/application/initializers/notifications_test.rb
+++ b/railties/test/application/initializers/notifications_test.rb
@@ -28,7 +28,7 @@ module ApplicationTests
ActiveSupport::Notifications.notifier.wait
end
- test "rails subscribers are added" do
+ test "rails log_subscribers are added" do
add_to_config <<-RUBY
config.colorize_logging = false
RUBY
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 0a746b200f..01d643cd8c 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -50,6 +50,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
).each{ |path| assert_file path }
end
+ def test_name_collision_raises_an_error
+ content = capture(:stderr){ run_generator [File.join(destination_root, "generate")] }
+ assert_equal "Invalid application name generate. Please give a name which does not match one of the reserved rails words.\n", content
+ end
+
def test_invalid_database_option_raises_an_error
content = capture(:stderr){ run_generator([destination_root, "-d", "unknown"]) }
assert_match /Invalid value for \-\-database option/, content
diff --git a/railties/test/log_subscriber_test.rb b/railties/test/log_subscriber_test.rb
new file mode 100644
index 0000000000..a4de023e65
--- /dev/null
+++ b/railties/test/log_subscriber_test.rb
@@ -0,0 +1,125 @@
+require 'abstract_unit'
+require 'rails/log_subscriber/test_helper'
+
+class MyLogSubscriber < Rails::LogSubscriber
+ attr_reader :event
+
+ def some_event(event)
+ @event = event
+ info event.name
+ end
+
+ def foo(event)
+ debug "debug"
+ info "info"
+ warn "warn"
+ end
+
+ def bar(event)
+ info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
+ end
+
+ def puke(event)
+ raise "puke"
+ end
+end
+
+class SyncLogSubscriberTest < ActiveSupport::TestCase
+ include Rails::LogSubscriber::TestHelper
+
+ def setup
+ super
+ @log_subscriber = MyLogSubscriber.new
+ Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil)
+ end
+
+ def teardown
+ super
+ Rails::LogSubscriber.log_subscribers.clear
+ Rails::LogSubscriber.instance_variable_set(:@log_tailer, nil)
+ end
+
+ def instrument(*args, &block)
+ ActiveSupport::Notifications.instrument(*args, &block)
+ end
+
+ def test_proxies_method_to_rails_logger
+ @log_subscriber.foo(nil)
+ assert_equal %w(debug), @logger.logged(:debug)
+ assert_equal %w(info), @logger.logged(:info)
+ assert_equal %w(warn), @logger.logged(:warn)
+ end
+
+ def test_set_color_for_messages
+ Rails::LogSubscriber.colorize_logging = true
+ @log_subscriber.bar(nil)
+ assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last
+ end
+
+ def test_does_not_set_color_if_colorize_logging_is_set_to_false
+ @log_subscriber.bar(nil)
+ assert_equal "cool, isn't it?", @logger.logged(:info).last
+ end
+
+ def test_event_is_sent_to_the_registered_class
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ assert_equal %w(my_log_subscriber.some_event), @logger.logged(:info)
+ end
+
+ def test_event_is_an_active_support_notifications_event
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ assert_kind_of ActiveSupport::Notifications::Event, @log_subscriber.event
+ end
+
+ def test_does_not_send_the_event_if_it_doesnt_match_the_class
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.unknown_event"
+ wait
+ # If we get here, it means that NoMethodError was not raised.
+ end
+
+ def test_does_not_send_the_event_if_logger_is_nil
+ Rails.logger = nil
+ @log_subscriber.expects(:some_event).never
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.some_event"
+ wait
+ end
+
+ def test_does_not_fail_with_non_namespaced_events
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "whatever"
+ wait
+ end
+
+ def test_flushes_loggers
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ Rails::LogSubscriber.flush_all!
+ assert_equal 1, @logger.flush_count
+ end
+
+ def test_flushes_the_same_logger_just_once
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ Rails::LogSubscriber.add :another, @log_subscriber
+ Rails::LogSubscriber.flush_all!
+ wait
+ assert_equal 1, @logger.flush_count
+ end
+
+ def test_logging_does_not_die_on_failures
+ Rails::LogSubscriber.add :my_log_subscriber, @log_subscriber
+ instrument "my_log_subscriber.puke"
+ instrument "my_log_subscriber.some_event"
+ wait
+
+ assert_equal 1, @logger.logged(:info).size
+ assert_equal 'my_log_subscriber.some_event', @logger.logged(:info).last
+
+ assert_equal 1, @logger.logged(:error).size
+ assert_equal 'Could not log "my_log_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
+ end
+end \ No newline at end of file
diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb
index 09b859dcdd..0f5f29468c 100644
--- a/railties/test/railties/plugin_test.rb
+++ b/railties/test/railties/plugin_test.rb
@@ -94,6 +94,15 @@ module RailtiesTest
assert rescued, "Expected boot rails to fail"
end
+ test "loads deprecated rails/init.rb" do
+ @plugin.write "rails/init.rb", <<-RUBY
+ $loaded = true
+ RUBY
+
+ boot_rails
+ assert $loaded
+ end
+
test "deprecated tasks are also loaded" do
$executed = false
@plugin.write "tasks/foo.rake", <<-RUBY
diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb
index b723e08281..9eb4e9993a 100644
--- a/railties/test/railties/railtie_test.rb
+++ b/railties/test/railties/railtie_test.rb
@@ -51,12 +51,12 @@ module RailtiesTest
assert_equal "bar", Bar.config.foo.bar
end
- test "railtie can add subscribers" do
+ test "railtie can add log subscribers" do
begin
- class Foo < Rails::Railtie ; subscriber(Rails::Subscriber.new) ; end
- assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo]
+ class Foo < Rails::Railtie ; log_subscriber(Rails::LogSubscriber.new) ; end
+ assert_kind_of Rails::LogSubscriber, Rails::LogSubscriber.log_subscribers[:foo]
ensure
- Rails::Subscriber.subscribers.clear
+ Rails::LogSubscriber.log_subscribers.clear
end
end
diff --git a/railties/test/subscriber_test.rb b/railties/test/subscriber_test.rb
deleted file mode 100644
index f6c895093f..0000000000
--- a/railties/test/subscriber_test.rb
+++ /dev/null
@@ -1,119 +0,0 @@
-require 'abstract_unit'
-require 'rails/subscriber/test_helper'
-
-class MySubscriber < Rails::Subscriber
- attr_reader :event
-
- def some_event(event)
- @event = event
- info event.name
- end
-
- def foo(event)
- debug "debug"
- info "info"
- warn "warn"
- end
-
- def bar(event)
- info "#{color("cool", :red)}, #{color("isn't it?", :blue, true)}"
- end
-
- def puke(event)
- raise "puke"
- end
-end
-
-class SyncSubscriberTest < ActiveSupport::TestCase
- include Rails::Subscriber::TestHelper
-
- def setup
- super
- @subscriber = MySubscriber.new
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def teardown
- super
- Rails::Subscriber.subscribers.clear
- Rails::Subscriber.instance_variable_set(:@log_tailer, nil)
- end
-
- def instrument(*args, &block)
- ActiveSupport::Notifications.instrument(*args, &block)
- end
-
- def test_proxies_method_to_rails_logger
- @subscriber.foo(nil)
- assert_equal %w(debug), @logger.logged(:debug)
- assert_equal %w(info), @logger.logged(:info)
- assert_equal %w(warn), @logger.logged(:warn)
- end
-
- def test_set_color_for_messages
- Rails::Subscriber.colorize_logging = true
- @subscriber.bar(nil)
- assert_equal "\e[31mcool\e[0m, \e[1m\e[34misn't it?\e[0m", @logger.logged(:info).last
- end
-
- def test_does_not_set_color_if_colorize_logging_is_set_to_false
- @subscriber.bar(nil)
- assert_equal "cool, isn't it?", @logger.logged(:info).last
- end
-
- def test_event_is_sent_to_the_registered_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_equal %w(my_subscriber.some_event), @logger.logged(:info)
- end
-
- def test_event_is_an_active_support_notifications_event
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- assert_kind_of ActiveSupport::Notifications::Event, @subscriber.event
- end
-
- def test_does_not_send_the_event_if_it_doesnt_match_the_class
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.unknown_event"
- wait
- # If we get here, it means that NoMethodError was raised.
- end
-
- def test_does_not_send_the_event_if_logger_is_nil
- Rails.logger = nil
- @subscriber.expects(:some_event).never
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.some_event"
- wait
- end
-
- def test_flushes_loggers
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.flush_all!
- assert_equal 1, @logger.flush_count
- end
-
- def test_flushes_the_same_logger_just_once
- Rails::Subscriber.add :my_subscriber, @subscriber
- Rails::Subscriber.add :another, @subscriber
- Rails::Subscriber.flush_all!
- wait
- assert_equal 1, @logger.flush_count
- end
-
- def test_logging_does_not_die_on_failures
- Rails::Subscriber.add :my_subscriber, @subscriber
- instrument "my_subscriber.puke"
- instrument "my_subscriber.some_event"
- wait
-
- assert_equal 1, @logger.logged(:info).size
- assert_equal 'my_subscriber.some_event', @logger.logged(:info).last
-
- assert_equal 1, @logger.logged(:error).size
- assert_equal 'Could not log "my_subscriber.puke" event. RuntimeError: puke', @logger.logged(:error).last
- end
-end \ No newline at end of file