diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-24 01:33:18 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-24 01:33:18 +0530 |
commit | efd0bd3b7390ebb8526b981169025f2860f6a113 (patch) | |
tree | 1cb3bcd8f9534f64e8a764af1010ce65303b42b0 /activesupport | |
parent | f4571e3617ccd9cc9e5ee9f7431066bd80395e22 (diff) | |
parent | 8ff2fb6f3aa6140f5a8bd018d5919a8a1e707cda (diff) | |
download | rails-efd0bd3b7390ebb8526b981169025f2860f6a113.tar.gz rails-efd0bd3b7390ebb8526b981169025f2860f6a113.tar.bz2 rails-efd0bd3b7390ebb8526b981169025f2860f6a113.zip |
Merge remote branch 'mainstream/master'
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/load_error.rb | 46 | ||||
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 36 | ||||
-rw-r--r-- | activesupport/lib/active_support/values/time_zone.rb | 7 | ||||
-rw-r--r-- | activesupport/test/core_ext/load_error_test.rb | 15 | ||||
-rw-r--r-- | activesupport/test/notifications_test.rb | 18 | ||||
-rw-r--r-- | activesupport/test/time_zone_test.rb | 6 |
7 files changed, 46 insertions, 84 deletions
diff --git a/activesupport/lib/active_support/core_ext/load_error.rb b/activesupport/lib/active_support/core_ext/load_error.rb index cc6287b100..615ebe9588 100644 --- a/activesupport/lib/active_support/core_ext/load_error.rb +++ b/activesupport/lib/active_support/core_ext/load_error.rb @@ -1,36 +1,22 @@ -class MissingSourceFile < LoadError #:nodoc: - attr_reader :path - def initialize(message, path) - super(message) - @path = path - end - - def is_missing?(path) - path.gsub(/\.rb$/, '') == self.path.gsub(/\.rb$/, '') - end +class LoadError + REGEXPS = [ + /^no such file to load -- (.+)$/i, + /^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i, + /^Missing API definition file in (.+)$/i, + ] - def self.from_message(message) - REGEXPS.each do |regexp, capture| - match = regexp.match(message) - return MissingSourceFile.new(message, match[capture]) unless match.nil? + def path + @path ||= begin + REGEXPS.find do |regex| + message =~ regex + end + $1 end - nil end - REGEXPS = [ - [/^no such file to load -- (.+)$/i, 1], - [/^Missing \w+ (file\s*)?([^\s]+.rb)$/i, 2], - [/^Missing API definition file in (.+)$/i, 1], - [/win32/, 0] - ] unless defined?(REGEXPS) -end - -class LoadError - def self.new(*args) - if self == LoadError - MissingSourceFile.from_message(args.first) - else - super - end + def is_missing?(location) + location.sub(/\.rb$/, '') == path.sub(/\.rb$/, '') end end + +MissingSourceFile = LoadError
\ No newline at end of file diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index e858bcdc80..8ded9f8b2d 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -236,7 +236,7 @@ module ActiveSupport #:nodoc: rescue LoadError => load_error unless swallow_load_errors if file_name = load_error.message[/ -- (.*?)(\.rb)?$/, 1] - raise MissingSourceFile.new(message % file_name, load_error.path).copy_blame!(load_error) + raise LoadError.new(message % file_name).copy_blame!(load_error) end raise end diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index bb07e4765c..ac482a2ec8 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -3,11 +3,9 @@ require 'thread' module ActiveSupport module Notifications # This is a default queue implementation that ships with Notifications. It - # consumes events in a thread and publish them to all registered subscribers. - # + # just pushes events to all registered subscribers. class Fanout - def initialize(sync = false) - @subscriber_klass = sync ? Subscriber : AsyncSubscriber + def initialize @subscribers = [] end @@ -16,7 +14,7 @@ module ActiveSupport end def subscribe(pattern = nil, &block) - @subscribers << @subscriber_klass.new(pattern, &block) + @subscribers << Subscriber.new(pattern, &block) end def publish(*args) @@ -68,34 +66,6 @@ module ActiveSupport @block.call(*args) end end - - # Used for internal implementation only. - class AsyncSubscriber < Subscriber #:nodoc: - def initialize(pattern, &block) - super - @events = Queue.new - start_consumer - end - - def drained? - @events.empty? - end - - private - def start_consumer - Thread.new { consume } - end - - def consume - while args = @events.shift - @block.call(*args) - end - end - - def push(*args) - @events << args - end - end end end end diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index cbb8e890ae..245d3ce051 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -172,7 +172,7 @@ module ActiveSupport MAPPING.freeze end - UTC_OFFSET_WITH_COLON = '%+03d:%02d' + UTC_OFFSET_WITH_COLON = '%s%02d:%02d' UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '') # Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset) @@ -181,9 +181,10 @@ module ActiveSupport # TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00" def self.seconds_to_utc_offset(seconds, colon = true) format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON - hours = seconds / 3600 + sign = (seconds < 0 ? '-' : '+') + hours = seconds.abs / 3600 minutes = (seconds.abs % 3600) / 60 - format % [hours, minutes] + format % [sign, hours, minutes] end include Comparable diff --git a/activesupport/test/core_ext/load_error_test.rb b/activesupport/test/core_ext/load_error_test.rb index b775b65f9f..d7b8f602ca 100644 --- a/activesupport/test/core_ext/load_error_test.rb +++ b/activesupport/test/core_ext/load_error_test.rb @@ -15,3 +15,18 @@ class TestMissingSourceFile < Test::Unit::TestCase end end end + +class TestLoadError < Test::Unit::TestCase + def test_with_require + assert_raise(LoadError) { require 'no_this_file_don\'t_exist' } + end + def test_with_load + assert_raise(LoadError) { load 'nor_does_this_one' } + end + def test_path + begin load 'nor/this/one.rb' + rescue LoadError => e + assert_equal 'nor/this/one.rb', e.path + end + end +end
\ No newline at end of file diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index c41d81fe7e..d3af535c26 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -3,18 +3,12 @@ require 'abstract_unit' module Notifications class TestCase < ActiveSupport::TestCase def setup - Thread.abort_on_exception = true - ActiveSupport::Notifications.notifier = nil @notifier = ActiveSupport::Notifications.notifier @events = [] @notifier.subscribe { |*args| @events << event(*args) } end - def teardown - Thread.abort_on_exception = false - end - private def event(*args) ActiveSupport::Notifications::Event.new(*args) @@ -25,7 +19,7 @@ module Notifications end end - class PubSubTest < TestCase + class SyncPubSubTest < TestCase def test_events_are_published_to_a_listener @notifier.publish :foo @notifier.wait @@ -72,16 +66,6 @@ module Notifications end end - class SyncPubSubTest < PubSubTest - def setup - Thread.abort_on_exception = true - - @notifier = ActiveSupport::Notifications::Notifier.new(ActiveSupport::Notifications::Fanout.new(true)) - @events = [] - @notifier.subscribe { |*args| @events << event(*args) } - end - end - class InstrumentationTest < TestCase delegate :instrument, :instrument!, :to => ActiveSupport::Notifications diff --git a/activesupport/test/time_zone_test.rb b/activesupport/test/time_zone_test.rb index 99c4310854..ce43c6507d 100644 --- a/activesupport/test/time_zone_test.rb +++ b/activesupport/test/time_zone_test.rb @@ -208,6 +208,12 @@ class TimeZoneTest < Test::Unit::TestCase assert_equal "+0000", ActiveSupport::TimeZone.seconds_to_utc_offset(0, false) assert_equal "+0500", ActiveSupport::TimeZone.seconds_to_utc_offset(18_000, false) end + + def test_seconds_to_utc_offset_with_negative_offset + assert_equal "-01:00", ActiveSupport::TimeZone.seconds_to_utc_offset(-3_600) + assert_equal "-00:59", ActiveSupport::TimeZone.seconds_to_utc_offset(-3_599) + assert_equal "-05:30", ActiveSupport::TimeZone.seconds_to_utc_offset(-19_800) + end def test_formatted_offset_positive zone = ActiveSupport::TimeZone['Moscow'] |