diff options
Diffstat (limited to 'activesupport')
20 files changed, 270 insertions, 233 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index f20c7c92e6..dad7005eb1 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,11 @@ +* Allow initializing `thread_mattr_*` attributes via `:default` option + + class Scraper + thread_mattr_reader :client, default: Api::Client.new + end + + *Guilherme Mansur* + * Add `compact_blank` for those times when you want to remove #blank? values from an Enumerable (also `compact_blank!` on Hash, Array, ActionController::Parameters) diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index a5063d0784..a42553ae3a 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -7,6 +7,7 @@ require "active_support/core_ext/module/attribute_accessors" require "active_support/core_ext/numeric/bytes" require "active_support/core_ext/numeric/time" require "active_support/core_ext/object/to_param" +require "active_support/core_ext/object/try" require "active_support/core_ext/string/inflections" module ActiveSupport diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index c7a2378e41..27cb47eb6e 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "active_support/core_ext/object/try" +require "active_support/core_ext/date_time/conversions" module DateAndTime module Calculations diff --git a/activesupport/lib/active_support/core_ext/hash/conversions.rb b/activesupport/lib/active_support/core_ext/hash/conversions.rb index 5b48254646..cc42647879 100644 --- a/activesupport/lib/active_support/core_ext/hash/conversions.rb +++ b/activesupport/lib/active_support/core_ext/hash/conversions.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true require "active_support/xml_mini" -require "active_support/time" require "active_support/core_ext/object/blank" require "active_support/core_ext/object/to_param" require "active_support/core_ext/object/to_query" +require "active_support/core_ext/object/try" require "active_support/core_ext/array/wrap" require "active_support/core_ext/hash/reverse_merge" require "active_support/core_ext/string/inflections" diff --git a/activesupport/lib/active_support/core_ext/marshal.rb b/activesupport/lib/active_support/core_ext/marshal.rb index 0c72cd7b47..5ff0e34d82 100644 --- a/activesupport/lib/active_support/core_ext/marshal.rb +++ b/activesupport/lib/active_support/core_ext/marshal.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "active_support/core_ext/string/inflections" + module ActiveSupport module MarshalWithAutoloading # :nodoc: def load(source, proc = nil) diff --git a/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb b/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb index a6e87aeb68..ea4034303e 100644 --- a/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +++ b/activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb @@ -33,7 +33,7 @@ class Module # end # # Current.new.user # => NoMethodError - def thread_mattr_reader(*syms, instance_reader: true, instance_accessor: true) # :nodoc: + def thread_mattr_reader(*syms, instance_reader: true, instance_accessor: true, default: nil) # :nodoc: syms.each do |sym| raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym) @@ -52,6 +52,8 @@ class Module end EOS end + + Thread.current["attr_" + name + "_#{sym}"] = default unless default.nil? end end alias :thread_cattr_reader :thread_mattr_reader @@ -74,7 +76,7 @@ class Module # end # # Current.new.user = "DHH" # => NoMethodError - def thread_mattr_writer(*syms, instance_writer: true, instance_accessor: true) # :nodoc: + def thread_mattr_writer(*syms, instance_writer: true, instance_accessor: true, default: nil) # :nodoc: syms.each do |sym| raise NameError.new("invalid attribute name: #{sym}") unless /^[_A-Za-z]\w*$/.match?(sym) @@ -93,6 +95,8 @@ class Module end EOS end + + public_send("#{sym}=", default) unless default.nil? end end alias :thread_cattr_writer :thread_mattr_writer @@ -136,8 +140,8 @@ class Module # # Current.new.user = "DHH" # => NoMethodError # Current.new.user # => NoMethodError - def thread_mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true) - thread_mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor) + def thread_mattr_accessor(*syms, instance_reader: true, instance_writer: true, instance_accessor: true, default: nil) + thread_mattr_reader(*syms, instance_reader: instance_reader, instance_accessor: instance_accessor, default: default) thread_mattr_writer(*syms, instance_writer: instance_writer, instance_accessor: instance_accessor) end alias :thread_cattr_accessor :thread_mattr_accessor diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 94d1115ccf..33a17a7741 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "active_support/inflections" +require "active_support/core_ext/object/blank" module ActiveSupport # The Inflector transforms words from singular to plural, class names to table diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 3ba2d93ed8..1899a1212d 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -60,6 +60,7 @@ module ActiveSupport # Transliteration is restricted to UTF-8, US-ASCII and GB18030 strings # Other encodings will raise an ArgumentError. def transliterate(string, replacement = "?", locale: nil) + string = string.dup if string.frozen? raise ArgumentError, "Can only transliterate strings. Received #{string.class.name}" unless string.is_a?(String) allowed_encodings = [Encoding::UTF_8, Encoding::US_ASCII, Encoding::GB18030] diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index dda71b880e..b0f30d2995 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -3,6 +3,7 @@ require "mutex_m" require "concurrent/map" require "set" +require "active_support/core_ext/object/try" module ActiveSupport module Notifications diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 8572d56722..59d2d6f530 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -6,6 +6,7 @@ require "bigdecimal" require "active_support/core_ext/string/access" require "active_support/ordered_hash" require "active_support/core_ext/object/conversions" +require "active_support/core_ext/date/conversions" require "active_support/core_ext/object/deep_dup" require "active_support/inflections" diff --git a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb index e0e331fc91..a2b3239884 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb @@ -4,23 +4,32 @@ require "abstract_unit" require "active_support/core_ext/module/attribute_accessors_per_thread" class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase - def setup - @class = Class.new do - thread_mattr_accessor :foo - thread_mattr_accessor :bar, instance_writer: false - thread_mattr_reader :shaq, instance_reader: false - thread_mattr_accessor :camp, instance_accessor: false - - def self.name; "MyClass" end - end + class MyClass + thread_mattr_accessor :foo + thread_mattr_accessor :bar, instance_writer: false + thread_mattr_reader :shaq, instance_reader: false + thread_mattr_accessor :camp, instance_accessor: false + end - @subclass = Class.new(@class) do - def self.name; "SubMyClass" end - end + class SubMyClass < MyClass + end + setup do + @class = MyClass + @subclass = SubMyClass @object = @class.new end + def test_can_initialize_with_default_value + Thread.new do + @class.thread_mattr_accessor :baz, default: "default_value" + + assert_equal "default_value", @class.baz + end.join + + assert_nil @class.baz + end + def test_should_use_mattr_default Thread.new do assert_nil @class.foo @@ -66,23 +75,23 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase threads = [] threads << Thread.new do @class.foo = "things" - sleep 1 + Thread.pass assert_equal "things", @class.foo end threads << Thread.new do @class.foo = "other things" - sleep 1 + Thread.pass assert_equal "other things", @class.foo end threads << Thread.new do @class.foo = "really other things" - sleep 1 + Thread.pass assert_equal "really other things", @class.foo end - threads.each { |t| t.join } + threads.each(&:join) end def test_should_raise_name_error_if_attribute_name_is_invalid diff --git a/activesupport/test/core_ext/object/acts_like_test.rb b/activesupport/test/core_ext/object/acts_like_test.rb index 31241caf0a..8aa9eb036a 100644 --- a/activesupport/test/core_ext/object/acts_like_test.rb +++ b/activesupport/test/core_ext/object/acts_like_test.rb @@ -1,7 +1,10 @@ # frozen_string_literal: true require "abstract_unit" -require "active_support/core_ext/object" +require "active_support/core_ext/date/acts_like" +require "active_support/core_ext/time/acts_like" +require "active_support/core_ext/date_time/acts_like" +require "active_support/core_ext/object/acts_like" class ObjectTests < ActiveSupport::TestCase class DuckTime diff --git a/activesupport/test/core_ext/object/deep_dup_test.rb b/activesupport/test/core_ext/object/deep_dup_test.rb index 1fb26ebac7..8e5e28c513 100644 --- a/activesupport/test/core_ext/object/deep_dup_test.rb +++ b/activesupport/test/core_ext/object/deep_dup_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "abstract_unit" -require "active_support/core_ext/object" +require "active_support/core_ext/object/deep_dup" class DeepDupTest < ActiveSupport::TestCase def test_array_deep_dup diff --git a/activesupport/test/core_ext/object/instance_variables_test.rb b/activesupport/test/core_ext/object/instance_variables_test.rb index 9052d209a3..dd710e9349 100644 --- a/activesupport/test/core_ext/object/instance_variables_test.rb +++ b/activesupport/test/core_ext/object/instance_variables_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "abstract_unit" -require "active_support/core_ext/object" +require "active_support/core_ext/object/instance_variables" class ObjectInstanceVariableTest < ActiveSupport::TestCase def setup diff --git a/activesupport/test/core_ext/object/json_gem_encoding_test.rb b/activesupport/test/core_ext/object/json_gem_encoding_test.rb index 4cdb6ed09f..eef02f7458 100644 --- a/activesupport/test/core_ext/object/json_gem_encoding_test.rb +++ b/activesupport/test/core_ext/object/json_gem_encoding_test.rb @@ -22,7 +22,7 @@ class JsonGemEncodingTest < ActiveSupport::TestCase JSONTest::EncodingTestCases.constants.each_with_index do |name| JSONTest::EncodingTestCases.const_get(name).each_with_index do |(subject, _), i| - test("#{name[0..-6].underscore} #{i}") do + test("#{name[0..-6]} #{i}") do assert_same_with_or_without_active_support(subject) end end diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb index a838334034..d501b5edce 100644 --- a/activesupport/test/core_ext/object/try_test.rb +++ b/activesupport/test/core_ext/object/try_test.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "abstract_unit" -require "active_support/core_ext/object" +require "active_support/core_ext/object/try" class ObjectTryTest < ActiveSupport::TestCase def setup diff --git a/activesupport/test/current_attributes_test.rb b/activesupport/test/current_attributes_test.rb index adbdc646bc..4cbf462da0 100644 --- a/activesupport/test/current_attributes_test.rb +++ b/activesupport/test/current_attributes_test.rb @@ -9,7 +9,7 @@ class CurrentAttributesTest < ActiveSupport::TestCase attribute :world, :account, :person, :request delegate :time_zone, to: :person - before_reset { Session.previous = person.try(:id) } + before_reset { Session.previous = person&.id } resets do Time.zone = "UTC" @@ -18,13 +18,13 @@ class CurrentAttributesTest < ActiveSupport::TestCase def account=(account) super - self.person = "#{account}'s person" + self.person = Person.new(1, "#{account}'s person") end def person=(person) super - Time.zone = person.try(:time_zone) - Session.current = person.try(:id) + Time.zone = person&.time_zone + Session.current = person&.id end def request @@ -63,7 +63,7 @@ class CurrentAttributesTest < ActiveSupport::TestCase test "set attribute via overwritten method" do Current.account = "account/1" assert_equal "account/1", Current.account - assert_equal "account/1's person", Current.person + assert_equal "account/1's person", Current.person.name end test "set auxiliary class via overwritten method" do diff --git a/activesupport/test/file_update_checker_shared_tests.rb b/activesupport/test/file_update_checker_shared_tests.rb index 84d89fa0a7..bd056a1576 100644 --- a/activesupport/test/file_update_checker_shared_tests.rb +++ b/activesupport/test/file_update_checker_shared_tests.rb @@ -3,294 +3,298 @@ require "fileutils" module FileUpdateCheckerSharedTests - extend ActiveSupport::Testing::Declarative - include FileUtils + def self.included(kls) + kls.class_eval do + extend ActiveSupport::Testing::Declarative + include FileUtils - def tmpdir - @tmpdir - end + def tmpdir + @tmpdir + end - def tmpfile(name) - File.join(tmpdir, name) - end + def tmpfile(name) + File.join(tmpdir, name) + end - def tmpfiles - @tmpfiles ||= %w(foo.rb bar.rb baz.rb).map { |f| tmpfile(f) } - end + def tmpfiles + @tmpfiles ||= %w(foo.rb bar.rb baz.rb).map { |f| tmpfile(f) } + end - def run(*args) - capture_exceptions do - Dir.mktmpdir(nil, __dir__) { |dir| @tmpdir = dir; super } - end - end + def run(*args) + capture_exceptions do + Dir.mktmpdir(nil, __dir__) { |dir| @tmpdir = dir; super } + end + end - test "should not execute the block if no paths are given" do - silence_warnings { require "listen" } - i = 0 + test "should not execute the block if no paths are given" do + silence_warnings { require "listen" } + i = 0 - checker = new_checker { i += 1 } + checker = new_checker { i += 1 } - assert_not checker.execute_if_updated - assert_equal 0, i - end + assert_not checker.execute_if_updated + assert_equal 0, i + end - test "should not execute the block if no files change" do - i = 0 + test "should not execute the block if no files change" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - checker = new_checker(tmpfiles) { i += 1 } + checker = new_checker(tmpfiles) { i += 1 } - assert_not checker.execute_if_updated - assert_equal 0, i - end + assert_not checker.execute_if_updated + assert_equal 0, i + end - test "should execute the block once when files are created" do - i = 0 + test "should execute the block once when files are created" do + i = 0 - checker = new_checker(tmpfiles) { i += 1 } + checker = new_checker(tmpfiles) { i += 1 } - touch(tmpfiles) - wait + touch(tmpfiles) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "should execute the block once when files are modified" do - i = 0 + test "should execute the block once when files are modified" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - checker = new_checker(tmpfiles) { i += 1 } + checker = new_checker(tmpfiles) { i += 1 } - touch(tmpfiles) - wait + touch(tmpfiles) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "should execute the block once when files are deleted" do - i = 0 + test "should execute the block once when files are deleted" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - checker = new_checker(tmpfiles) { i += 1 } + checker = new_checker(tmpfiles) { i += 1 } - rm_f(tmpfiles) - wait + rm_f(tmpfiles) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "updated should become true when watched files are created" do - i = 0 + test "updated should become true when watched files are created" do + i = 0 - checker = new_checker(tmpfiles) { i += 1 } - assert_not_predicate checker, :updated? + checker = new_checker(tmpfiles) { i += 1 } + assert_not_predicate checker, :updated? - touch(tmpfiles) - wait + touch(tmpfiles) + wait - assert_predicate checker, :updated? - end + assert_predicate checker, :updated? + end - test "updated should become true when watched files are modified" do - i = 0 + test "updated should become true when watched files are modified" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - checker = new_checker(tmpfiles) { i += 1 } - assert_not_predicate checker, :updated? + checker = new_checker(tmpfiles) { i += 1 } + assert_not_predicate checker, :updated? - touch(tmpfiles) - wait + touch(tmpfiles) + wait - assert_predicate checker, :updated? - end + assert_predicate checker, :updated? + end - test "updated should become true when watched files are deleted" do - i = 0 + test "updated should become true when watched files are deleted" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - checker = new_checker(tmpfiles) { i += 1 } - assert_not_predicate checker, :updated? + checker = new_checker(tmpfiles) { i += 1 } + assert_not_predicate checker, :updated? - rm_f(tmpfiles) - wait + rm_f(tmpfiles) + wait - assert_predicate checker, :updated? - end + assert_predicate checker, :updated? + end - test "should be robust to handle files with wrong modified time" do - i = 0 + test "should be robust to handle files with wrong modified time" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - now = Time.now - time = Time.mktime(now.year + 1, now.month, now.day) # wrong mtime from the future - File.utime(time, time, tmpfiles[0]) + now = Time.now + time = Time.mktime(now.year + 1, now.month, now.day) # wrong mtime from the future + File.utime(time, time, tmpfiles[0]) - checker = new_checker(tmpfiles) { i += 1 } + checker = new_checker(tmpfiles) { i += 1 } - touch(tmpfiles[1..-1]) - wait + touch(tmpfiles[1..-1]) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "should return max_time for files with mtime = Time.at(0)" do - i = 0 + test "should return max_time for files with mtime = Time.at(0)" do + i = 0 - FileUtils.touch(tmpfiles) + FileUtils.touch(tmpfiles) - time = Time.at(0) # wrong mtime from the future - File.utime(time, time, tmpfiles[0]) + time = Time.at(0) # wrong mtime from the future + File.utime(time, time, tmpfiles[0]) - checker = new_checker(tmpfiles) { i += 1 } + checker = new_checker(tmpfiles) { i += 1 } - touch(tmpfiles[1..-1]) - wait + touch(tmpfiles[1..-1]) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "should cache updated result until execute" do - i = 0 + test "should cache updated result until execute" do + i = 0 - checker = new_checker(tmpfiles) { i += 1 } - assert_not_predicate checker, :updated? + checker = new_checker(tmpfiles) { i += 1 } + assert_not_predicate checker, :updated? - touch(tmpfiles) - wait + touch(tmpfiles) + wait - assert_predicate checker, :updated? - checker.execute - assert_not_predicate checker, :updated? - end + assert_predicate checker, :updated? + checker.execute + assert_not_predicate checker, :updated? + end - test "should execute the block if files change in a watched directory one extension" do - i = 0 + test "should execute the block if files change in a watched directory one extension" do + i = 0 - checker = new_checker([], tmpdir => :rb) { i += 1 } + checker = new_checker([], tmpdir => :rb) { i += 1 } - touch(tmpfile("foo.rb")) - wait + touch(tmpfile("foo.rb")) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "should execute the block if files change in a watched directory any extensions" do - i = 0 + test "should execute the block if files change in a watched directory any extensions" do + i = 0 - checker = new_checker([], tmpdir => []) { i += 1 } + checker = new_checker([], tmpdir => []) { i += 1 } - touch(tmpfile("foo.rb")) - wait + touch(tmpfile("foo.rb")) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "should execute the block if files change in a watched directory several extensions" do - i = 0 + test "should execute the block if files change in a watched directory several extensions" do + i = 0 - checker = new_checker([], tmpdir => [:rb, :txt]) { i += 1 } + checker = new_checker([], tmpdir => [:rb, :txt]) { i += 1 } - touch(tmpfile("foo.rb")) - wait + touch(tmpfile("foo.rb")) + wait - assert checker.execute_if_updated - assert_equal 1, i + assert checker.execute_if_updated + assert_equal 1, i - touch(tmpfile("foo.txt")) - wait + touch(tmpfile("foo.txt")) + wait - assert checker.execute_if_updated - assert_equal 2, i - end + assert checker.execute_if_updated + assert_equal 2, i + end - test "should not execute the block if the file extension is not watched" do - i = 0 + test "should not execute the block if the file extension is not watched" do + i = 0 - checker = new_checker([], tmpdir => :txt) { i += 1 } + checker = new_checker([], tmpdir => :txt) { i += 1 } - touch(tmpfile("foo.rb")) - wait + touch(tmpfile("foo.rb")) + wait - assert_not checker.execute_if_updated - assert_equal 0, i - end + assert_not checker.execute_if_updated + assert_equal 0, i + end - test "does not assume files exist on instantiation" do - i = 0 + test "does not assume files exist on instantiation" do + i = 0 - non_existing = tmpfile("non_existing.rb") - checker = new_checker([non_existing]) { i += 1 } + non_existing = tmpfile("non_existing.rb") + checker = new_checker([non_existing]) { i += 1 } - touch(non_existing) - wait + touch(non_existing) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "detects files in new subdirectories" do - i = 0 + test "detects files in new subdirectories" do + i = 0 - checker = new_checker([], tmpdir => :rb) { i += 1 } + checker = new_checker([], tmpdir => :rb) { i += 1 } - subdir = tmpfile("subdir") - mkdir(subdir) - wait + subdir = tmpfile("subdir") + mkdir(subdir) + wait - assert_not checker.execute_if_updated - assert_equal 0, i + assert_not checker.execute_if_updated + assert_equal 0, i - touch(File.join(subdir, "nested.rb")) - wait + touch(File.join(subdir, "nested.rb")) + wait - assert checker.execute_if_updated - assert_equal 1, i - end + assert checker.execute_if_updated + assert_equal 1, i + end - test "looked up extensions are inherited in subdirectories not listening to them" do - i = 0 + test "looked up extensions are inherited in subdirectories not listening to them" do + i = 0 - subdir = tmpfile("subdir") - mkdir(subdir) + subdir = tmpfile("subdir") + mkdir(subdir) - checker = new_checker([], tmpdir => :rb, subdir => :txt) { i += 1 } + checker = new_checker([], tmpdir => :rb, subdir => :txt) { i += 1 } - touch(tmpfile("new.txt")) - wait + touch(tmpfile("new.txt")) + wait - assert_not checker.execute_if_updated - assert_equal 0, i + assert_not checker.execute_if_updated + assert_equal 0, i - # subdir does not look for Ruby files, but its parent tmpdir does. - touch(File.join(subdir, "nested.rb")) - wait + # subdir does not look for Ruby files, but its parent tmpdir does. + touch(File.join(subdir, "nested.rb")) + wait - assert checker.execute_if_updated - assert_equal 1, i + assert checker.execute_if_updated + assert_equal 1, i - touch(File.join(subdir, "nested.txt")) - wait + touch(File.join(subdir, "nested.txt")) + wait - assert checker.execute_if_updated - assert_equal 2, i - end + assert checker.execute_if_updated + assert_equal 2, i + end - test "initialize raises an ArgumentError if no block given" do - assert_raise ArgumentError do - new_checker([]) + test "initialize raises an ArgumentError if no block given" do + assert_raise ArgumentError do + new_checker([]) + end + end end end end diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index 2e02b5e938..f13c5efa47 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -59,19 +59,19 @@ class TransliterateTest < ActiveSupport::TestCase end def test_transliterate_handles_strings_with_valid_utf8_encodings - string = String.new("A", encoding: Encoding::UTF_8) + string = String.new("A", encoding: Encoding::UTF_8).freeze assert_equal "A", ActiveSupport::Inflector.transliterate(string) end def test_transliterate_handles_strings_with_valid_us_ascii_encodings - string = String.new("A", encoding: Encoding::US_ASCII) + string = String.new("A", encoding: Encoding::US_ASCII).freeze transcoded = ActiveSupport::Inflector.transliterate(string) assert_equal "A", transcoded assert_equal Encoding::US_ASCII, transcoded.encoding end def test_transliterate_handles_strings_with_valid_gb18030_encodings - string = String.new("A", encoding: Encoding::GB18030) + string = String.new("A", encoding: Encoding::GB18030).freeze transcoded = ActiveSupport::Inflector.transliterate(string) assert_equal "A", transcoded assert_equal Encoding::GB18030, transcoded.encoding @@ -84,7 +84,7 @@ class TransliterateTest < ActiveSupport::TestCase Encoding::GB18030 ] incompatible_encodings.each do |encoding| - string = String.new("", encoding: encoding) + string = String.new("", encoding: encoding).freeze exception = assert_raises ArgumentError do ActiveSupport::Inflector.transliterate(string) end @@ -93,17 +93,17 @@ class TransliterateTest < ActiveSupport::TestCase end def test_transliterate_handles_strings_with_invalid_utf8_bytes - string = String.new("\255", encoding: Encoding::UTF_8) + string = String.new("\255", encoding: Encoding::UTF_8).freeze assert_equal "?", ActiveSupport::Inflector.transliterate(string) end def test_transliterate_handles_strings_with_invalid_us_ascii_bytes - string = String.new("\255", encoding: Encoding::US_ASCII) + string = String.new("\255", encoding: Encoding::US_ASCII).freeze assert_equal "?", ActiveSupport::Inflector.transliterate(string) end def test_transliterate_handles_strings_with_invalid_gb18030_bytes - string = String.new("\255", encoding: Encoding::GB18030) + string = String.new("\255", encoding: Encoding::GB18030).freeze assert_equal "?", ActiveSupport::Inflector.transliterate(string) end end diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index 18a3f2ca66..73e7f40b0d 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -5,6 +5,7 @@ require "active_support/xml_mini" require "active_support/builder" require "active_support/core_ext/hash" require "active_support/core_ext/big_decimal" +require "active_support/core_ext/date/conversions" require "yaml" module XmlMiniTest |