diff options
Diffstat (limited to 'activesupport')
7 files changed, 65 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 621358d701..d83e259a2a 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -41,7 +41,7 @@ module ActiveSupport value else # forcing the value to be immutable - value.dup + value.duplicable? ? value.dup : value end end diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 7ce9adec2c..2badad5f5f 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -51,6 +51,9 @@ module ActiveSupport #:nodoc: mattr_accessor :constant_watch_stack self.constant_watch_stack = [] + mattr_accessor :constant_watch_stack_mutex + self.constant_watch_stack_mutex = Mutex.new + # Module includes this module module ModuleConstMissing #:nodoc: def self.included(base) #:nodoc: @@ -509,7 +512,9 @@ module ActiveSupport #:nodoc: [mod_name, initial_constants] end - constant_watch_stack.concat watch_frames + constant_watch_stack_mutex.synchronize do + constant_watch_stack.concat watch_frames + end aborting = true begin @@ -526,8 +531,10 @@ module ActiveSupport #:nodoc: new_constants = mod.local_constant_names - prior_constants # Make sure no other frames takes credit for these constants. - constant_watch_stack.each do |frame_name, constants| - constants.concat new_constants if frame_name == mod_name + constant_watch_stack_mutex.synchronize do + constant_watch_stack.each do |frame_name, constants| + constants.concat new_constants if frame_name == mod_name + end end new_constants.collect do |suffix| @@ -549,8 +556,10 @@ module ActiveSupport #:nodoc: # Remove the stack frames that we added. if defined?(watch_frames) && ! watch_frames.blank? frame_ids = watch_frames.collect { |frame| frame.object_id } - constant_watch_stack.delete_if do |watch_frame| - frame_ids.include? watch_frame.object_id + constant_watch_stack_mutex.synchronize do + constant_watch_stack.delete_if do |watch_frame| + frame_ids.include? watch_frame.object_id + end end end end diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index 25ea505813..66aab9e562 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -92,6 +92,10 @@ module ActiveSupport dup.merge!(other_hash) end + def inspect + "#<OrderedHash #{self.to_hash.inspect}>" + end + private def sync_keys! diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb index b5ad094d0e..76361bed90 100755 --- a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n.rb @@ -45,6 +45,11 @@ module I18n Thread.current[:locale] = locale end + # Returns an array of locales for which translations are available + def available_locales + backend.available_locales + end + # Sets the exception handler. def exception_handler=(exception_handler) @@exception_handler = exception_handler diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb index d298b3a85a..b54164d496 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/lib/i18n/backend/simple.rb @@ -69,6 +69,12 @@ module I18n @initialized ||= false end + # Returns an array of locales for which translations are available + def available_locales + init_translations unless initialized? + translations.keys + end + def reload! @initialized = false @translations = nil @@ -76,7 +82,7 @@ module I18n protected def init_translations - load_translations(*I18n.load_path) + load_translations(*I18n.load_path.flatten) @initialized = true end diff --git a/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb b/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb index e181975f38..8ba7036abf 100644 --- a/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb +++ b/activesupport/lib/active_support/vendor/i18n-0.1.1/test/simple_backend_test.rb @@ -124,6 +124,16 @@ class I18nSimpleBackendTranslationsTest < Test::Unit::TestCase end end +class I18nSimpleBackendAvailableLocalesTest < Test::Unit::TestCase + def test_available_locales + @backend = I18n::Backend::Simple.new + @backend.store_translations 'de', :foo => 'bar' + @backend.store_translations 'en', :foo => 'foo' + + assert_equal ['de', 'en'], @backend.available_locales.map{|locale| locale.to_s }.sort + end +end + class I18nSimpleBackendTranslateTest < Test::Unit::TestCase include I18nSimpleBackendTestSetup @@ -472,6 +482,18 @@ class I18nSimpleBackendLoadTranslationsTest < Test::Unit::TestCase end end +class I18nSimpleBackendLoadPathTest < Test::Unit::TestCase + include I18nSimpleBackendTestSetup + + def test_nested_load_paths_do_not_break_locale_loading + @backend = I18n::Backend::Simple.new + I18n.load_path = [[File.dirname(__FILE__) + '/locale/en.yml']] + assert_nil backend_get_translations + assert_nothing_raised { @backend.send :init_translations } + assert_not_nil backend_get_translations + end +end + class I18nSimpleBackendReloadTranslationsTest < Test::Unit::TestCase include I18nSimpleBackendTestSetup diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index e8e0b41d4d..4e212f1661 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -81,6 +81,11 @@ module CacheStoreBehavior assert_equal({:a => "b"}, @cache.read('foo')) end + def test_should_read_and_write_integer + @cache.write('foo', 1) + assert_equal 1, @cache.read('foo') + end + def test_should_read_and_write_nil @cache.write('foo', nil) assert_equal nil, @cache.read('foo') @@ -200,6 +205,13 @@ uses_memcached 'memcached backed store' do end end + def test_local_cache_should_read_and_write_integer + @cache.with_local_cache do + @cache.write('foo', 1) + assert_equal 1, @cache.read('foo') + end + end + def test_local_cache_of_delete @cache.with_local_cache do @cache.write('foo', 'bar') |