diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/log_subscriber.rb | 26 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 10 | ||||
-rw-r--r-- | activesupport/test/inflector_test_cases.rb | 2 |
3 files changed, 23 insertions, 15 deletions
diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb index 8c3921c423..e5b4ca2738 100644 --- a/activesupport/lib/active_support/log_subscriber.rb +++ b/activesupport/lib/active_support/log_subscriber.rb @@ -58,7 +58,6 @@ module ActiveSupport def attach_to(namespace, log_subscriber=new, notifier=ActiveSupport::Notifications) log_subscribers << log_subscriber - @@flushable_loggers = nil log_subscriber.public_methods(false).each do |event| next if %w{ start finish }.include?(event.to_s) @@ -71,23 +70,14 @@ module ActiveSupport @@log_subscribers ||= [] end - def flushable_loggers - @@flushable_loggers ||= begin - loggers = log_subscribers.map(&:logger) - loggers.uniq! - loggers.select! { |l| l.respond_to?(:flush) } - loggers - end - end - # Flush all log_subscribers' logger. def flush_all! - flushable_loggers.each { |log| log.flush } + logger.flush if logger.respond_to?(:flush) end end def initialize - @event_stack = [] + @queue_key = [self.class.name, object_id].join "-" super end @@ -99,17 +89,17 @@ module ActiveSupport return unless logger e = ActiveSupport::Notifications::Event.new(name, Time.now, nil, id, payload) - parent = @event_stack.last + parent = event_stack.last parent << e if parent - @event_stack.push e + event_stack.push e end def finish(name, id, payload) return unless logger finished = Time.now - event = @event_stack.pop + event = event_stack.pop event.end = finished event.payload.merge!(payload) @@ -142,5 +132,11 @@ module ActiveSupport bold = bold ? BOLD : "" "#{bold}#{color}#{text}#{CLEAR}" end + + private + + def event_stack + Thread.current[@queue_key] ||= [] + end end end diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index 91ae6bc189..1f32e4ff92 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -413,6 +413,16 @@ class InflectorTest < ActiveSupport::TestCase end end + Irregularities.each do |irregularity| + singular, plural = *irregularity + ActiveSupport::Inflector.inflections do |inflect| + define_method("test_singularize_of_irregularity_#{singular}_should_be_the_same") do + inflect.irregular(singular, plural) + assert_equal singular, ActiveSupport::Inflector.singularize(singular) + end + end + end + [ :all, [] ].each do |scope| ActiveSupport::Inflector.inflections do |inflect| define_method("test_clear_inflections_with_#{scope.kind_of?(Array) ? "no_arguments" : scope}") do diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 9fa1f417e4..ca4efd2e59 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -308,5 +308,7 @@ module InflectorTestCases 'child' => 'children', 'sex' => 'sexes', 'move' => 'moves', + 'cow' => 'kine', + 'zombie' => 'zombies', } end |