diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/load_error.rb | 14 | ||||
-rw-r--r-- | activesupport/lib/active_support/file_update_checker.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/i18n.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/ordered_hash.rb | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/tagged_logging.rb | 2 | ||||
-rw-r--r-- | activesupport/test/abstract_unit.rb | 8 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 39 | ||||
-rw-r--r-- | activesupport/test/ordered_hash_test.rb | 10 |
9 files changed, 89 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/core_ext/load_error.rb b/activesupport/lib/active_support/core_ext/load_error.rb index 8bdfa0c5bc..bc575ee176 100644 --- a/activesupport/lib/active_support/core_ext/load_error.rb +++ b/activesupport/lib/active_support/core_ext/load_error.rb @@ -6,12 +6,14 @@ class LoadError /^cannot load such file -- (.+)$/i, ] - def path - @path ||= begin - REGEXPS.find do |regex| - message =~ regex + unless method_defined?(:path) + def path + @path ||= begin + REGEXPS.find do |regex| + message =~ regex + end + $1 end - $1 end end @@ -20,4 +22,4 @@ class LoadError end end -MissingSourceFile = LoadError
\ No newline at end of file +MissingSourceFile = LoadError diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index a4ad2da137..2e0e873fda 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -95,7 +95,7 @@ module ActiveSupport def updated_at #:nodoc: @updated_at || begin all = [] - all.concat @files.select { |f| File.exists?(f) } + all.concat @files.select { |f| File.exist?(f) } all.concat Dir[@glob] if @glob all.map { |path| File.mtime(path) }.max || Time.at(0) end diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 9dc93de5a9..c02bd60fde 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -153,6 +153,16 @@ module ActiveSupport def symbolize_keys; to_hash.symbolize_keys end def to_options!; self end + if RUBY_VERSION > '1.9' + def select(*args, &block) + dup.tap { |hash| hash.select!(*args, &block) } + end + + def reject(*args, &block) + dup.tap { |hash| hash.reject!(*args, &block) } + end + end + # Convert to a Hash with String keys. def to_hash Hash.new(default).merge!(self) diff --git a/activesupport/lib/active_support/i18n.rb b/activesupport/lib/active_support/i18n.rb index f9c5e5e2f8..978e87beda 100644 --- a/activesupport/lib/active_support/i18n.rb +++ b/activesupport/lib/active_support/i18n.rb @@ -1,3 +1,7 @@ +require 'active_support/core_ext/hash/deep_merge' +require 'active_support/core_ext/hash/except' +require 'active_support/core_ext/hash/slice' + begin require 'i18n' require 'active_support/lazy_load_hooks' diff --git a/activesupport/lib/active_support/ordered_hash.rb b/activesupport/lib/active_support/ordered_hash.rb index b0d4f2bd86..0f9caca892 100644 --- a/activesupport/lib/active_support/ordered_hash.rb +++ b/activesupport/lib/active_support/ordered_hash.rb @@ -52,6 +52,16 @@ module ActiveSupport true end + if RUBY_VERSION > '1.9' + def select(*args, &block) + dup.tap { |hash| hash.select!(*args, &block) } + end + + def reject(*args, &block) + dup.tap { |hash| hash.reject!(*args, &block) } + end + end + # Hash is ordered in Ruby 1.9! if RUBY_VERSION < '1.9' diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index 232c367d26..19a003757f 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -78,7 +78,7 @@ module ActiveSupport end else def respond_to_missing?(*args) - @logger.respond_to? *args + @logger.respond_to?(*args) end end diff --git a/activesupport/test/abstract_unit.rb b/activesupport/test/abstract_unit.rb index c26a48a490..cbe491eb73 100644 --- a/activesupport/test/abstract_unit.rb +++ b/activesupport/test/abstract_unit.rb @@ -22,13 +22,17 @@ if "ruby".encoding_aware? end end +ENV['NO_RELOAD'] = '1' +require 'active_support' +require 'active_support/time' + require 'test/unit' require 'empty_bool' silence_warnings { require 'mocha/setup' } -ENV['NO_RELOAD'] = '1' -require 'active_support' +# Disable available locale checks to avoid warnings running the test suite. +I18n.enforce_available_locales = false # Include shims until we get off 1.8.6 require 'active_support/ruby/shim' if RUBY_VERSION < '1.8.7' diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index c3a59540fb..f29b91a324 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -259,6 +259,45 @@ class HashExtTest < Test::Unit::TestCase assert_equal hash.delete('a'), nil end + def test_indifferent_select + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).select { |k, v| v == 1 } + + if RUBY_VERSION > '1.9' + assert_equal({ "a" => 1 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + else + # Ruby 1.8.7 returns an Array from Hash#select + assert_equal([["a", 1]], hash) + assert_instance_of Array, hash + end + end + + if RUBY_VERSION > '1.9' + # Hash#select! was added in Ruby 1.9 + def test_indifferent_select_bang + indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) + indifferent_strings.select! { |k, v| v == 1 } + + assert_equal({ "a" => 1 }, indifferent_strings) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings + end + end + + def test_indifferent_reject + hash = ActiveSupport::HashWithIndifferentAccess.new(@strings).reject { |k, v| v != 1 } + + assert_equal({ "a" => 1 }, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, hash + end + + def test_indifferent_reject_bang + indifferent_strings = ActiveSupport::HashWithIndifferentAccess.new(@strings) + indifferent_strings.reject! { |k, v| v != 1 } + + assert_equal({ "a" => 1 }, indifferent_strings) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings + end + def test_indifferent_to_hash # Should convert to a Hash with String keys. assert_equal @strings, @mixed.with_indifferent_access.to_hash diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index a7fd9402c8..31eeb7f565 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -125,6 +125,15 @@ class OrderedHashTest < Test::Unit::TestCase def test_select assert_equal @keys, @ordered_hash.select { true }.map(&:first) + new_ordered_hash = @ordered_hash.select { true } + assert_equal @keys, new_ordered_hash.map(&:first) + + if RUBY_VERSION > '1.9' + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash + else + # Ruby 1.8.7 returns an Array from Hash#select + assert_instance_of Array, new_ordered_hash + end end def test_delete_if @@ -147,6 +156,7 @@ class OrderedHashTest < Test::Unit::TestCase assert_equal copy, @ordered_hash assert !new_ordered_hash.keys.include?('pink') assert @ordered_hash.keys.include?('pink') + assert_instance_of ActiveSupport::OrderedHash, new_ordered_hash end def test_clear |