diff options
author | Aaron Patterson <tenderlove@github.com> | 2019-01-11 11:21:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-11 11:21:53 -0800 |
commit | 74bef0970fff60eaf5faefde30a23f3c36c0b3ee (patch) | |
tree | 628b6013130e0d2868b2afbac3f00f24629dbb9c /activesupport | |
parent | 1e923b498492424ae627d7a2c61339148f887503 (diff) | |
parent | 3a1b2a21965c0cd7bcccff586ce04b029eb4c359 (diff) | |
download | rails-74bef0970fff60eaf5faefde30a23f3c36c0b3ee.tar.gz rails-74bef0970fff60eaf5faefde30a23f3c36c0b3ee.tar.bz2 rails-74bef0970fff60eaf5faefde30a23f3c36c0b3ee.zip |
Merge branch 'master' into ac_params_exists
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 10 | ||||
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 18 | ||||
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector/methods.rb | 2 | ||||
-rw-r--r-- | activesupport/test/autoloading_fixtures/raises_load_error.rb | 4 | ||||
-rw-r--r-- | activesupport/test/cache/behaviors/cache_store_behavior.rb | 10 | ||||
-rw-r--r-- | activesupport/test/constantize_test_cases.rb | 10 | ||||
-rw-r--r-- | activesupport/test/test_case_test.rb | 2 |
8 files changed, 49 insertions, 12 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index e678f48244..d4eaee9f6d 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,13 @@ +* Fix `String#safe_constantize` throwing a `LoadError` for incorrectly cased constant references. + + *Keenan Brock* + +* Preserve key order passed to `ActiveSupport::CacheStore#fetch_multi`. + + `fetch_multi(*names)` now returns its results in the same order as the `*names` requested, rather than returning cache hits followed by cache misses. + + *Gannon McGibbon* + * If the same block is `included` multiple times for a Concern, an exception is no longer raised. *Mark J. Titorenko*, *Vlad Bokov* diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index e8518645d9..30a69c550b 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -438,18 +438,18 @@ module ActiveSupport options = merged_options(options) instrument :read_multi, names, options do |payload| - read_multi_entries(names, options).tap do |results| - payload[:hits] = results.keys - payload[:super_operation] = :fetch_multi + reads = read_multi_entries(names, options) + writes = {} + ordered = names.each_with_object({}) do |name, hash| + hash[name] = reads.fetch(name) { writes[name] = yield(name) } + end - writes = {} + payload[:hits] = reads.keys + payload[:super_operation] = :fetch_multi - (names - results.keys).each do |name| - results[name] = writes[name] = yield(name) - end + write_multi(writes, options) - write_multi writes, options - end + ordered end end diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 314c926ac0..97b4634d7b 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -214,8 +214,11 @@ module ActiveSupport end def coerce(other) #:nodoc: - if Scalar === other + case other + when Scalar [other, self] + when Duration + [Scalar.new(other.value), self] else [Scalar.new(other), self] end diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 1af9833d46..ee193add6f 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -328,6 +328,8 @@ module ActiveSupport e.name.to_s == camel_cased_word.to_s) rescue ArgumentError => e raise unless /not missing constant #{const_regexp(camel_cased_word)}!$/.match?(e.message) + rescue LoadError => e + raise unless /Unable to autoload constant #{const_regexp(camel_cased_word)}/.match?(e.message) end # Returns the suffix that should be added to a number to denote the position diff --git a/activesupport/test/autoloading_fixtures/raises_load_error.rb b/activesupport/test/autoloading_fixtures/raises_load_error.rb new file mode 100644 index 0000000000..f97be29b71 --- /dev/null +++ b/activesupport/test/autoloading_fixtures/raises_load_error.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +# raises a load error typical of the dynamic code that manually raises load errors +raise LoadError, "required gem not present kind of error" diff --git a/activesupport/test/cache/behaviors/cache_store_behavior.rb b/activesupport/test/cache/behaviors/cache_store_behavior.rb index 9f54b1e7de..a696760bb2 100644 --- a/activesupport/test/cache/behaviors/cache_store_behavior.rb +++ b/activesupport/test/cache/behaviors/cache_store_behavior.rb @@ -130,7 +130,7 @@ module CacheStoreBehavior assert_equal("fufu", @cache.read("fu")) end - def test_multi_with_objects + def test_fetch_multi_with_objects cache_struct = Struct.new(:cache_key, :title) foo = cache_struct.new("foo", "FOO!") bar = cache_struct.new("bar") @@ -142,6 +142,14 @@ module CacheStoreBehavior assert_equal({ foo => "FOO!", bar => "BAM!" }, values) end + def test_fetch_multi_returns_ordered_names + @cache.write("bam", "BAM") + + values = @cache.fetch_multi("foo", "bar", "bam") { |key| key.upcase } + + assert_equal(%w(foo bar bam), values.keys) + end + def test_fetch_multi_without_block assert_raises(ArgumentError) do @cache.fetch_multi("foo") diff --git a/activesupport/test/constantize_test_cases.rb b/activesupport/test/constantize_test_cases.rb index 2c6145940b..cdb8441b81 100644 --- a/activesupport/test/constantize_test_cases.rb +++ b/activesupport/test/constantize_test_cases.rb @@ -112,6 +112,16 @@ module ConstantizeTestCases assert_nil yield("A::Object::B") assert_nil yield("A::Object::Object::Object::B") + with_autoloading_fixtures do + assert_nil yield("Em") + end + + assert_raises(LoadError) do + with_autoloading_fixtures do + yield("RaisesLoadError") + end + end + assert_raises(NameError) do with_autoloading_fixtures do yield("RaisesNameError") diff --git a/activesupport/test/test_case_test.rb b/activesupport/test/test_case_test.rb index 8698c66e6d..56cd2665e0 100644 --- a/activesupport/test/test_case_test.rb +++ b/activesupport/test/test_case_test.rb @@ -104,7 +104,7 @@ class AssertionsTest < ActiveSupport::TestCase def test_expression_is_evaluated_in_the_appropriate_scope silence_warnings do local_scope = "foo" - local_scope = local_scope # to suppress unused variable warning + _ = local_scope # to suppress unused variable warning assert_difference("local_scope; @object.num") { @object.increment } end end |