diff options
Diffstat (limited to 'activesupport')
26 files changed, 220 insertions, 104 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 62c0f612a8..91818c3112 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,29 @@ +* Allow Range#=== and Range#cover? on Range + + `Range#cover?` can now accept a range argument like `Range#include?` and + `Range#===`. `Range#===` works correctly on Ruby 2.6. `Range#include?` is moved + into a new file, with these two methods. + + *Requiring active_support/core_ext/range/include_range is now deprecated.* + *Use `require "active_support/core_ext/range/compare_range"` instead.* + + *utilum* + +* Add `index_with` to Enumerable. + + Allows creating a hash from an enumerable with the value from a passed block + or a default argument. + + %i( title body ).index_with { |attr| post.public_send(attr) } + # => { title: "hey", body: "what's up?" } + + %i( title body ).index_with(nil) + # => { title: nil, body: nil } + + Closely linked with its brethen `index_by`. + + *Kasper Timm Hansen* + * Fix bug where `ActiveSupport::Timezone.all` would fail when tzinfo data for any timezone defined in `ActiveSupport::TimeZone::MAPPING` is missing. diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index edde4f46b9..7713c52cb1 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true module Enumerable + INDEX_WITH_DEFAULT = Object.new + private_constant :INDEX_WITH_DEFAULT + # Enumerable#sum was added in Ruby 2.4, but it only works with Numeric elements # when we omit an identity. @@ -37,10 +40,11 @@ module Enumerable end end - # Convert an enumerable to a hash. + # Convert an enumerable to a hash keying it by the block return value. # # people.index_by(&:login) # # => { "nextangle" => <Person ...>, "chade-" => <Person ...>, ...} + # # people.index_by { |person| "#{person.first_name} #{person.last_name}" } # # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...} def index_by @@ -53,6 +57,26 @@ module Enumerable end end + # Convert an enumerable to a hash keying it with the enumerable items and with the values returned in the block. + # + # post = Post.new(title: "hey there", body: "what's up?") + # + # %i( title body ).index_with { |attr_name| post.public_send(attr_name) } + # # => { title: "hey there", body: "what's up?" } + def index_with(default = INDEX_WITH_DEFAULT) + if block_given? + result = {} + each { |elem| result[elem] = yield(elem) } + result + elsif default != INDEX_WITH_DEFAULT + result = {} + each { |elem| result[elem] = default } + result + else + to_enum(:index_with) { size if respond_to?(:size) } + end + end + # Returns +true+ if the enumerable has more than 1 element. Functionally # equivalent to <tt>enum.to_a.size > 1</tt>. Can be called with a block too, # much like any?, so <tt>people.many? { |p| p.age > 26 }</tt> returns +true+ diff --git a/activesupport/lib/active_support/core_ext/load_error.rb b/activesupport/lib/active_support/core_ext/load_error.rb index 750f858fcc..6b0dcab905 100644 --- a/activesupport/lib/active_support/core_ext/load_error.rb +++ b/activesupport/lib/active_support/core_ext/load_error.rb @@ -4,6 +4,6 @@ class LoadError # Returns true if the given path name (except perhaps for the ".rb" # extension) is the missing file which caused the exception to be raised. def is_missing?(location) - location.sub(/\.rb$/, "".freeze) == path.sub(/\.rb$/, "".freeze) + location.sub(/\.rb$/, "".freeze) == path.to_s.sub(/\.rb$/, "".freeze) end end diff --git a/activesupport/lib/active_support/core_ext/range.rb b/activesupport/lib/active_support/core_ext/range.rb index 4074e91d17..78814fd189 100644 --- a/activesupport/lib/active_support/core_ext/range.rb +++ b/activesupport/lib/active_support/core_ext/range.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "active_support/core_ext/range/conversions" -require "active_support/core_ext/range/include_range" +require "active_support/core_ext/range/compare_range" require "active_support/core_ext/range/include_time_with_zone" require "active_support/core_ext/range/overlaps" require "active_support/core_ext/range/each" diff --git a/activesupport/lib/active_support/core_ext/range/compare_range.rb b/activesupport/lib/active_support/core_ext/range/compare_range.rb new file mode 100644 index 0000000000..704041f6de --- /dev/null +++ b/activesupport/lib/active_support/core_ext/range/compare_range.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +module ActiveSupport + module CompareWithRange #:nodoc: + # Extends the default Range#=== to support range comparisons. + # (1..5) === (1..5) # => true + # (1..5) === (2..3) # => true + # (1..5) === (2..6) # => false + # + # The native Range#=== behavior is untouched. + # ('a'..'f') === ('c') # => true + # (5..9) === (11) # => false + def ===(value) + if value.is_a?(::Range) + # 1...10 includes 1..9 but it does not include 1..10. + operator = exclude_end? && !value.exclude_end? ? :< : :<= + super(value.first) && value.last.send(operator, last) + else + super + end + end + + # Extends the default Range#include? to support range comparisons. + # (1..5).include?(1..5) # => true + # (1..5).include?(2..3) # => true + # (1..5).include?(2..6) # => false + # + # The native Range#include? behavior is untouched. + # ('a'..'f').include?('c') # => true + # (5..9).include?(11) # => false + def include?(value) + if value.is_a?(::Range) + # 1...10 includes 1..9 but it does not include 1..10. + operator = exclude_end? && !value.exclude_end? ? :< : :<= + super(value.first) && value.last.send(operator, last) + else + super + end + end + + # Extends the default Range#cover? to support range comparisons. + # (1..5).cover?(1..5) # => true + # (1..5).cover?(2..3) # => true + # (1..5).cover?(2..6) # => false + # + # The native Range#cover? behavior is untouched. + # ('a'..'f').cover?('c') # => true + # (5..9).cover?(11) # => false + def cover?(value) + if value.is_a?(::Range) + # 1...10 covers 1..9 but it does not cover 1..10. + operator = exclude_end? && !value.exclude_end? ? :< : :<= + super(value.first) && value.last.send(operator, last) + else + super + end + end + end +end + +Range.prepend(ActiveSupport::CompareWithRange) diff --git a/activesupport/lib/active_support/core_ext/range/include_range.rb b/activesupport/lib/active_support/core_ext/range/include_range.rb index 7ba1011921..2da2c587a3 100644 --- a/activesupport/lib/active_support/core_ext/range/include_range.rb +++ b/activesupport/lib/active_support/core_ext/range/include_range.rb @@ -1,25 +1,9 @@ # frozen_string_literal: true -module ActiveSupport - module IncludeWithRange #:nodoc: - # Extends the default Range#include? to support range comparisons. - # (1..5).include?(1..5) # => true - # (1..5).include?(2..3) # => true - # (1..5).include?(2..6) # => false - # - # The native Range#include? behavior is untouched. - # ('a'..'f').include?('c') # => true - # (5..9).include?(11) # => false - def include?(value) - if value.is_a?(::Range) - # 1...10 includes 1..9 but it does not include 1..10. - operator = exclude_end? && !value.exclude_end? ? :< : :<= - super(value.first) && value.last.send(operator, last) - else - super - end - end - end -end +require "active_support/deprecation" -Range.prepend(ActiveSupport::IncludeWithRange) +ActiveSupport::Deprecation.warn "You have required `active_support/core_ext/range/include_range`. " \ +"This file will be removed in Rails 6.1. You should require `active_support/core_ext/range/compare_range` " \ + "instead." + +require "active_support/core_ext/range/compare_range" diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 0f59558bb5..a02cefc78e 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -224,6 +224,8 @@ module ActiveSupport #:nodoc: Dependencies.require_or_load(file_name) end + # :doc: + # Interprets a file using <tt>mechanism</tt> and marks its defined # constants as autoloaded. <tt>file_name</tt> can be either a string or # respond to <tt>to_path</tt>. @@ -242,6 +244,8 @@ module ActiveSupport #:nodoc: Dependencies.depend_on(file_name, message) end + # :nodoc: + def load_dependency(file) if Dependencies.load? && Dependencies.constant_watch_stack.watching? Dependencies.new_constants_in(Object) { yield } diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index 66d6f3225a..3abd25aa85 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -94,6 +94,10 @@ module ActiveSupport private def arity_coerce(behavior) + unless behavior.respond_to?(:call) + raise ArgumentError, "#{behavior.inspect} is not a valid deprecation behavior." + end + if behavior.arity == 4 || behavior.arity == -1 behavior else diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 1339c75ffe..de1b8ac8cf 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -54,9 +54,13 @@ module ActiveSupport class EscapedString < String #:nodoc: def to_json(*) if Encoding.escape_html_entities_in_json - super.gsub ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS + s = super + s.gsub! ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS + s else - super.gsub ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS + s = super + s.gsub! ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS + s end end diff --git a/activesupport/lib/active_support/locale/en.rb b/activesupport/lib/active_support/locale/en.rb index 26c2280c95..a2a7ea7ae1 100644 --- a/activesupport/lib/active_support/locale/en.rb +++ b/activesupport/lib/active_support/locale/en.rb @@ -5,16 +5,19 @@ number: { nth: { ordinals: lambda do |_key, number:, **_options| - abs_number = number.to_i.abs - - if (11..13).cover?(abs_number % 100) - "th" + case number + when 1; "st" + when 2; "nd" + when 3; "rd" + when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else - case abs_number % 10 - when 1 then "st" - when 2 then "nd" - when 3 then "rd" - else "th" + num_modulo = number.to_i.abs % 100 + num_modulo %= 10 if num_modulo > 13 + case num_modulo + when 1; "st" + when 2; "nd" + when 3; "rd" + else "th" end end end, diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index 8561cba9f1..b069ac94d4 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -52,7 +52,9 @@ module ActiveSupport def tags_text tags = current_tags - if tags.any? + if tags.one? + "[#{tags[0]}] " + elsif tags.any? tags.collect { |tag| "[#{tag}] " }.join end end diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 4e42db4500..f17743b6db 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -130,7 +130,7 @@ module ActiveSupport alias_method :method_name, :name include ActiveSupport::Testing::TaggedLogging - include ActiveSupport::Testing::SetupAndTeardown + prepend ActiveSupport::Testing::SetupAndTeardown include ActiveSupport::Testing::Assertions include ActiveSupport::Testing::Deprecation include ActiveSupport::Testing::TimeHelpers diff --git a/activesupport/lib/active_support/testing/setup_and_teardown.rb b/activesupport/lib/active_support/testing/setup_and_teardown.rb index 35236f1401..35321cd157 100644 --- a/activesupport/lib/active_support/testing/setup_and_teardown.rb +++ b/activesupport/lib/active_support/testing/setup_and_teardown.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require "active_support/concern" require "active_support/callbacks" module ActiveSupport @@ -19,11 +18,10 @@ module ActiveSupport # end # end module SetupAndTeardown - extend ActiveSupport::Concern - - included do - include ActiveSupport::Callbacks - define_callbacks :setup, :teardown + def self.prepended(klass) + klass.include ActiveSupport::Callbacks + klass.define_callbacks :setup, :teardown + klass.extend ClassMethods end module ClassMethods @@ -47,12 +45,10 @@ module ActiveSupport begin run_callbacks :teardown rescue => e - error = e + self.failures << Minitest::UnexpectedError.new(e) end super - ensure - raise error if error end end end diff --git a/activesupport/test/cache/behaviors/connection_pool_behavior.rb b/activesupport/test/cache/behaviors/connection_pool_behavior.rb index 701cd75595..4d1901a173 100644 --- a/activesupport/test/cache/behaviors/connection_pool_behavior.rb +++ b/activesupport/test/cache/behaviors/connection_pool_behavior.rb @@ -4,13 +4,13 @@ module ConnectionPoolBehavior def test_connection_pool Thread.report_on_exception, original_report_on_exception = false, Thread.report_on_exception + threads = [] + emulating_latency do begin cache = ActiveSupport::Cache.lookup_store(store, { pool_size: 2, pool_timeout: 1 }.merge(store_options)) cache.clear - threads = [] - assert_raises Timeout::Error do # One of the three threads will fail in 1 second because our pool size # is only two. @@ -31,13 +31,13 @@ module ConnectionPoolBehavior end def test_no_connection_pool + threads = [] + emulating_latency do begin cache = ActiveSupport::Cache.lookup_store(store, store_options) cache.clear - threads = [] - assert_nothing_raised do # Default connection pool size is 5, assuming 10 will make sure that # the connection pool isn't used at all. diff --git a/activesupport/test/cache/cache_entry_test.rb b/activesupport/test/cache/cache_entry_test.rb index d7baaa5c72..ec20a288e1 100644 --- a/activesupport/test/cache/cache_entry_test.rb +++ b/activesupport/test/cache/cache_entry_test.rb @@ -6,9 +6,9 @@ require "active_support/cache" class CacheEntryTest < ActiveSupport::TestCase def test_expired entry = ActiveSupport::Cache::Entry.new("value") - assert !entry.expired?, "entry not expired" + assert_not entry.expired?, "entry not expired" entry = ActiveSupport::Cache::Entry.new("value", expires_in: 60) - assert !entry.expired?, "entry not expired" + assert_not entry.expired?, "entry not expired" Time.stub(:now, Time.now + 61) do assert entry.expired?, "entry is expired" end diff --git a/activesupport/test/cache/stores/memory_store_test.rb b/activesupport/test/cache/stores/memory_store_test.rb index 340fb517cb..4c0a4f549d 100644 --- a/activesupport/test/cache/stores/memory_store_test.rb +++ b/activesupport/test/cache/stores/memory_store_test.rb @@ -33,9 +33,9 @@ class MemoryStorePruningTest < ActiveSupport::TestCase @cache.prune(@record_size * 3) assert @cache.exist?(5) assert @cache.exist?(4) - assert !@cache.exist?(3), "no entry" + assert_not @cache.exist?(3), "no entry" assert @cache.exist?(2) - assert !@cache.exist?(1), "no entry" + assert_not @cache.exist?(1), "no entry" end def test_prune_size_on_write @@ -57,12 +57,12 @@ class MemoryStorePruningTest < ActiveSupport::TestCase assert @cache.exist?(9) assert @cache.exist?(8) assert @cache.exist?(7) - assert !@cache.exist?(6), "no entry" - assert !@cache.exist?(5), "no entry" + assert_not @cache.exist?(6), "no entry" + assert_not @cache.exist?(5), "no entry" assert @cache.exist?(4) - assert !@cache.exist?(3), "no entry" + assert_not @cache.exist?(3), "no entry" assert @cache.exist?(2) - assert !@cache.exist?(1), "no entry" + assert_not @cache.exist?(1), "no entry" end def test_prune_size_on_write_based_on_key_length @@ -82,11 +82,11 @@ class MemoryStorePruningTest < ActiveSupport::TestCase assert @cache.exist?(8) assert @cache.exist?(7) assert @cache.exist?(6) - assert !@cache.exist?(5), "no entry" - assert !@cache.exist?(4), "no entry" - assert !@cache.exist?(3), "no entry" - assert !@cache.exist?(2), "no entry" - assert !@cache.exist?(1), "no entry" + assert_not @cache.exist?(5), "no entry" + assert_not @cache.exist?(4), "no entry" + assert_not @cache.exist?(3), "no entry" + assert_not @cache.exist?(2), "no entry" + assert_not @cache.exist?(1), "no entry" end def test_pruning_is_capped_at_a_max_time diff --git a/activesupport/test/core_ext/enumerable_test.rb b/activesupport/test/core_ext/enumerable_test.rb index 8d71320931..b63464a36a 100644 --- a/activesupport/test/core_ext/enumerable_test.rb +++ b/activesupport/test/core_ext/enumerable_test.rb @@ -179,6 +179,21 @@ class EnumerableTests < ActiveSupport::TestCase payments.index_by.each(&:price)) end + def test_index_with + payments = GenericEnumerable.new([ Payment.new(5), Payment.new(15), Payment.new(10) ]) + + assert_equal({ Payment.new(5) => 5, Payment.new(15) => 15, Payment.new(10) => 10 }, payments.index_with(&:price)) + + assert_equal({ title: nil, body: nil }, %i( title body ).index_with(nil)) + assert_equal({ title: [], body: [] }, %i( title body ).index_with([])) + assert_equal({ title: {}, body: {} }, %i( title body ).index_with({})) + + assert_equal Enumerator, payments.index_with.class + assert_nil payments.index_with.size + assert_equal 42, (1..42).index_with.size + assert_equal({ Payment.new(5) => 5, Payment.new(15) => 15, Payment.new(10) => 10 }, payments.index_with.each(&:price)) + end + def test_many assert_equal false, GenericEnumerable.new([]).many? assert_equal false, GenericEnumerable.new([ 1 ]).many? diff --git a/activesupport/test/core_ext/load_error_test.rb b/activesupport/test/core_ext/load_error_test.rb index 41b11d0c33..126aa51cb4 100644 --- a/activesupport/test/core_ext/load_error_test.rb +++ b/activesupport/test/core_ext/load_error_test.rb @@ -7,13 +7,20 @@ class TestLoadError < ActiveSupport::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 + + def test_is_missing_with_nil_path + error = LoadError.new(nil) + assert_nothing_raised { error.is_missing?("anything") } + end end diff --git a/activesupport/test/core_ext/object/duplicable_test.rb b/activesupport/test/core_ext/object/duplicable_test.rb index 635dd7f281..5203434ae6 100644 --- a/activesupport/test/core_ext/object/duplicable_test.rb +++ b/activesupport/test/core_ext/object/duplicable_test.rb @@ -19,7 +19,7 @@ class DuplicableTest < ActiveSupport::TestCase "* https://github.com/rubinius/rubinius/issues/3089" RAISE_DUP.each do |v| - assert !v.duplicable?, "#{ v.inspect } should not be duplicable" + assert_not v.duplicable?, "#{ v.inspect } should not be duplicable" assert_raises(TypeError, v.class.name) { v.dup } end diff --git a/activesupport/test/core_ext/regexp_ext_test.rb b/activesupport/test/core_ext/regexp_ext_test.rb index 5737bdafda..7d18297b64 100644 --- a/activesupport/test/core_ext/regexp_ext_test.rb +++ b/activesupport/test/core_ext/regexp_ext_test.rb @@ -9,28 +9,4 @@ class RegexpExtAccessTests < ActiveSupport::TestCase assert_equal false, //.multiline? assert_equal false, /(?m:)/.multiline? end - - # Based on https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb. - def test_match_p - /back(...)/ =~ "backref" - # must match here, but not in a separate method, e.g., assert_send, - # to check if $~ is affected or not. - assert_equal false, //.match?(nil) - assert_equal true, //.match?("") - assert_equal true, /.../.match?(:abc) - assert_raise(TypeError) { /.../.match?(Object.new) } - assert_equal true, /b/.match?("abc") - assert_equal true, /b/.match?("abc", 1) - assert_equal true, /../.match?("abc", 1) - assert_equal true, /../.match?("abc", -2) - assert_equal false, /../.match?("abc", -4) - assert_equal false, /../.match?("abc", 4) - assert_equal true, /\z/.match?("") - assert_equal true, /\z/.match?("abc") - assert_equal true, /R.../.match?("Ruby") - assert_equal false, /R.../.match?("Ruby", 1) - assert_equal false, /P.../.match?("Ruby") - assert_equal "backref", $& - assert_equal "ref", $1 - end end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index a4fbab7b55..84cb64a7c2 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -755,7 +755,7 @@ class DependenciesTest < ActiveSupport::TestCase Object.const_set :EM, Class.new with_autoloading_fixtures do require_dependency "em" - assert ! ActiveSupport::Dependencies.autoloaded?(:EM), "EM shouldn't be marked autoloaded!" + assert_not ActiveSupport::Dependencies.autoloaded?(:EM), "EM shouldn't be marked autoloaded!" ActiveSupport::Dependencies.clear end ensure @@ -782,7 +782,7 @@ class DependenciesTest < ActiveSupport::TestCase Object.const_set :M, Module.new ActiveSupport::Dependencies.clear - assert ! defined?(M), "Dependencies should unload unloadable constants each time" + assert_not defined?(M), "Dependencies should unload unloadable constants each time" end end @@ -980,10 +980,10 @@ class DependenciesTest < ActiveSupport::TestCase def test_autoload_doesnt_shadow_no_method_error_with_relative_constant with_autoloading_fixtures do - assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it hasn't been referenced yet!" + assert_not defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it hasn't been referenced yet!" 2.times do assert_raise(NoMethodError) { RaisesNoMethodError } - assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!" + assert_not defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!" end end ensure @@ -992,10 +992,10 @@ class DependenciesTest < ActiveSupport::TestCase def test_autoload_doesnt_shadow_no_method_error_with_absolute_constant with_autoloading_fixtures do - assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it hasn't been referenced yet!" + assert_not defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it hasn't been referenced yet!" 2.times do assert_raise(NoMethodError) { ::RaisesNoMethodError } - assert !defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!" + assert_not defined?(::RaisesNoMethodError), "::RaisesNoMethodError is defined but it should have failed!" end end ensure @@ -1020,13 +1020,13 @@ class DependenciesTest < ActiveSupport::TestCase ::RaisesNameError::FooBarBaz.object_id end assert_equal "uninitialized constant RaisesNameError::FooBarBaz", e.message - assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!" + assert_not defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!" end assert_not defined?(::RaisesNameError) 2.times do assert_raise(NameError) { ::RaisesNameError } - assert !defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!" + assert_not defined?(::RaisesNameError), "::RaisesNameError is defined but it should have failed!" end end ensure diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index 60673c032b..105153584d 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -182,6 +182,14 @@ class DeprecationTest < ActiveSupport::TestCase end end + def test_default_invalid_behavior + e = assert_raises(ArgumentError) do + ActiveSupport::Deprecation.behavior = :invalid + end + + assert_equal ":invalid is not a valid deprecation behavior.", e.message + end + def test_deprecated_instance_variable_proxy assert_not_deprecated { @dtc.request.size } diff --git a/activesupport/test/gzip_test.rb b/activesupport/test/gzip_test.rb index 05ce12fe86..3d790f69c4 100644 --- a/activesupport/test/gzip_test.rb +++ b/activesupport/test/gzip_test.rb @@ -18,7 +18,7 @@ class GzipTest < ActiveSupport::TestCase compressed = ActiveSupport::Gzip.compress("") assert_equal Encoding.find("binary"), compressed.encoding - assert !compressed.blank?, "a compressed blank string should not be blank" + assert_not compressed.blank?, "a compressed blank string should not be blank" end def test_compress_should_return_gzipped_string_by_compression_level diff --git a/activesupport/test/hash_with_indifferent_access_test.rb b/activesupport/test/hash_with_indifferent_access_test.rb index a20c428bf8..eebff18ef1 100644 --- a/activesupport/test/hash_with_indifferent_access_test.rb +++ b/activesupport/test/hash_with_indifferent_access_test.rb @@ -606,7 +606,7 @@ class HashWithIndifferentAccessTest < ActiveSupport::TestCase def test_assorted_keys_not_stringified original = { Object.new => 2, 1 => 2, [] => true } indiff = original.with_indifferent_access - assert(!indiff.keys.any? { |k| k.kind_of? String }, "A key was converted to a string!") + assert_not(indiff.keys.any? { |k| k.kind_of? String }, "A key was converted to a string!") end def test_deep_merge_on_indifferent_access diff --git a/activesupport/test/safe_buffer_test.rb b/activesupport/test/safe_buffer_test.rb index 1c19c92bb0..9456bb8753 100644 --- a/activesupport/test/safe_buffer_test.rb +++ b/activesupport/test/safe_buffer_test.rb @@ -141,13 +141,13 @@ class SafeBufferTest < ActiveSupport::TestCase x = "foo".html_safe.gsub!("f", '<script>alert("lolpwnd");</script>') # calling gsub! makes the dirty flag true - assert !x.html_safe?, "should not be safe" + assert_not x.html_safe?, "should not be safe" # getting a slice of it y = x[0..-1] # should still be unsafe - assert !y.html_safe?, "should not be safe" + assert_not y.html_safe?, "should not be safe" end test "Should work with interpolation (array argument)" do diff --git a/activesupport/test/testing/after_teardown_test.rb b/activesupport/test/testing/after_teardown_test.rb index 68c368909c..961af49479 100644 --- a/activesupport/test/testing/after_teardown_test.rb +++ b/activesupport/test/testing/after_teardown_test.rb @@ -4,13 +4,14 @@ require "abstract_unit" module OtherAfterTeardown def after_teardown + super + @witness = true end end -class AfterTeardownTest < Minitest::Test +class AfterTeardownTest < ActiveSupport::TestCase include OtherAfterTeardown - include ActiveSupport::Testing::SetupAndTeardown attr_writer :witness @@ -21,11 +22,12 @@ class AfterTeardownTest < Minitest::Test end def after_teardown - assert_raises MyError do + assert_changes -> { failures.count }, from: 0, to: 1 do super end assert_equal true, @witness + failures.clear end def test_teardown_raise_but_all_after_teardown_method_are_called |