activesupport 1.2.4 → 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +505 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/lib/active_support/actionable_error.rb +50 -0
- data/lib/active_support/all.rb +5 -0
- data/lib/active_support/array_inquirer.rb +50 -0
- data/lib/active_support/backtrace_cleaner.rb +234 -0
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +53 -0
- data/lib/active_support/broadcast_logger.rb +238 -0
- data/lib/active_support/builder.rb +8 -0
- data/lib/active_support/cache/coder.rb +153 -0
- data/lib/active_support/cache/entry.rb +134 -0
- data/lib/active_support/cache/file_store.rb +244 -0
- data/lib/active_support/cache/mem_cache_store.rb +288 -0
- data/lib/active_support/cache/memory_store.rb +264 -0
- data/lib/active_support/cache/null_store.rb +62 -0
- data/lib/active_support/cache/redis_cache_store.rb +498 -0
- data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
- data/lib/active_support/cache/strategy/local_cache.rb +246 -0
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +1170 -0
- data/lib/active_support/callbacks.rb +960 -0
- data/lib/active_support/class_attribute.rb +33 -0
- data/lib/active_support/code_generator.rb +79 -0
- data/lib/active_support/concern.rb +217 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +18 -0
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/concurrency/share_lock.rb +225 -0
- data/lib/active_support/concurrency/thread_monitor.rb +55 -0
- data/lib/active_support/configurable.rb +193 -0
- data/lib/active_support/configuration_file.rb +60 -0
- data/lib/active_support/continuous_integration.rb +145 -0
- data/lib/active_support/core_ext/array/access.rb +100 -0
- data/lib/active_support/core_ext/array/conversions.rb +209 -26
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +31 -0
- data/lib/active_support/core_ext/array/grouping.rb +109 -0
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/wrap.rb +48 -0
- data/lib/active_support/core_ext/array.rb +8 -4
- data/lib/active_support/core_ext/benchmark.rb +6 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
- data/lib/active_support/core_ext/big_decimal.rb +3 -0
- data/lib/active_support/core_ext/class/attribute.rb +137 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
- data/lib/active_support/core_ext/class/subclasses.rb +24 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/date/acts_like.rb +10 -0
- data/lib/active_support/core_ext/date/blank.rb +18 -0
- data/lib/active_support/core_ext/date/calculations.rb +161 -0
- data/lib/active_support/core_ext/date/conversions.rb +95 -28
- data/lib/active_support/core_ext/date/zones.rb +8 -0
- data/lib/active_support/core_ext/date.rb +6 -5
- data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +23 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
- data/lib/active_support/core_ext/date_time/blank.rb +18 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +16 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +108 -0
- data/lib/active_support/core_ext/date_time.rb +7 -0
- data/lib/active_support/core_ext/digest/uuid.rb +76 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +277 -7
- data/lib/active_support/core_ext/erb/util.rb +201 -0
- data/lib/active_support/core_ext/file/atomic.rb +72 -0
- data/lib/active_support/core_ext/file.rb +3 -0
- data/lib/active_support/core_ext/hash/conversions.rb +262 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +43 -0
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +19 -55
- data/lib/active_support/core_ext/hash/keys.rb +134 -44
- data/lib/active_support/core_ext/hash/reverse_merge.rb +22 -22
- data/lib/active_support/core_ext/hash/slice.rb +27 -0
- data/lib/active_support/core_ext/hash.rb +9 -8
- data/lib/active_support/core_ext/integer/inflections.rb +29 -13
- data/lib/active_support/core_ext/integer/multiple.rb +12 -0
- data/lib/active_support/core_ext/integer/time.rb +22 -0
- data/lib/active_support/core_ext/integer.rb +4 -6
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
- data/lib/active_support/core_ext/kernel.rb +4 -78
- data/lib/active_support/core_ext/load_error.rb +6 -35
- data/lib/active_support/core_ext/module/aliasing.rb +31 -0
- data/lib/active_support/core_ext/module/anonymous.rb +30 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +48 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
- data/lib/active_support/core_ext/module/concerning.rb +140 -0
- data/lib/active_support/core_ext/module/delegation.rb +225 -0
- data/lib/active_support/core_ext/module/deprecation.rb +25 -0
- data/lib/active_support/core_ext/module/introspection.rb +65 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +17 -0
- data/lib/active_support/core_ext/module.rb +13 -0
- data/lib/active_support/core_ext/name_error.rb +59 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +73 -42
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/time.rb +64 -57
- data/lib/active_support/core_ext/numeric.rb +4 -6
- data/lib/active_support/core_ext/object/acts_like.rb +45 -0
- data/lib/active_support/core_ext/object/blank.rb +199 -0
- data/lib/active_support/core_ext/object/conversions.rb +6 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
- data/lib/active_support/core_ext/object/duplicable.rb +69 -0
- data/lib/active_support/core_ext/object/inclusion.rb +37 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
- data/lib/active_support/core_ext/object/json.rb +267 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -0
- data/lib/active_support/core_ext/object/to_query.rb +93 -0
- data/lib/active_support/core_ext/object/try.rb +158 -0
- data/lib/active_support/core_ext/object/with.rb +46 -0
- data/lib/active_support/core_ext/object/with_options.rb +101 -0
- data/lib/active_support/core_ext/object.rb +17 -0
- data/lib/active_support/core_ext/pathname/blank.rb +20 -0
- data/lib/active_support/core_ext/pathname/existence.rb +23 -0
- data/lib/active_support/core_ext/pathname.rb +4 -0
- data/lib/active_support/core_ext/range/compare_range.rb +57 -0
- data/lib/active_support/core_ext/range/conversions.rb +58 -17
- data/lib/active_support/core_ext/range/overlap.rb +40 -0
- data/lib/active_support/core_ext/range/sole.rb +17 -0
- data/lib/active_support/core_ext/range.rb +5 -4
- data/lib/active_support/core_ext/regexp.rb +14 -0
- data/lib/active_support/core_ext/securerandom.rb +57 -0
- data/lib/active_support/core_ext/string/access.rb +93 -56
- data/lib/active_support/core_ext/string/behavior.rb +8 -0
- data/lib/active_support/core_ext/string/conversions.rb +57 -16
- data/lib/active_support/core_ext/string/exclude.rb +13 -0
- data/lib/active_support/core_ext/string/filters.rb +151 -0
- data/lib/active_support/core_ext/string/indent.rb +45 -0
- data/lib/active_support/core_ext/string/inflections.rb +297 -54
- data/lib/active_support/core_ext/string/inquiry.rb +16 -0
- data/lib/active_support/core_ext/string/multibyte.rb +67 -0
- data/lib/active_support/core_ext/string/output_safety.rb +235 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -18
- data/lib/active_support/core_ext/string/strip.rb +27 -0
- data/lib/active_support/core_ext/string/zones.rb +16 -0
- data/lib/active_support/core_ext/string.rb +14 -10
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/thread/backtrace/location.rb +7 -0
- data/lib/active_support/core_ext/time/acts_like.rb +10 -0
- data/lib/active_support/core_ext/time/calculations.rb +358 -153
- data/lib/active_support/core_ext/time/compatibility.rb +15 -0
- data/lib/active_support/core_ext/time/conversions.rb +69 -30
- data/lib/active_support/core_ext/time/zones.rb +97 -0
- data/lib/active_support/core_ext/time.rb +6 -6
- data/lib/active_support/core_ext.rb +5 -1
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +243 -0
- data/lib/active_support/deep_mergeable.rb +53 -0
- data/lib/active_support/delegation.rb +183 -0
- data/lib/active_support/dependencies/autoload.rb +72 -0
- data/lib/active_support/dependencies/interlock.rb +55 -0
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +84 -222
- data/lib/active_support/deprecation/behaviors.rb +148 -0
- data/lib/active_support/deprecation/constant_accessor.rb +74 -0
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +54 -0
- data/lib/active_support/deprecation/method_wrappers.rb +68 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
- data/lib/active_support/deprecation/reporting.rb +162 -0
- data/lib/active_support/deprecation.rb +81 -0
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +112 -0
- data/lib/active_support/digest.rb +22 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +64 -0
- data/lib/active_support/duration.rb +524 -0
- data/lib/active_support/editor.rb +70 -0
- data/lib/active_support/encrypted_configuration.rb +126 -0
- data/lib/active_support/encrypted_file.rb +133 -0
- data/lib/active_support/environment_inquirer.rb +40 -0
- data/lib/active_support/error_reporter/test_helper.rb +15 -0
- data/lib/active_support/error_reporter.rb +318 -0
- data/lib/active_support/event_reporter/test_helper.rb +32 -0
- data/lib/active_support/event_reporter.rb +592 -0
- data/lib/active_support/evented_file_update_checker.rb +185 -0
- data/lib/active_support/execution_context/test_helper.rb +13 -0
- data/lib/active_support/execution_context.rb +110 -0
- data/lib/active_support/execution_wrapper.rb +150 -0
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +166 -0
- data/lib/active_support/fork_tracker.rb +43 -0
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +41 -0
- data/lib/active_support/hash_with_indifferent_access.rb +464 -0
- data/lib/active_support/html_safe_translation.rb +56 -0
- data/lib/active_support/i18n.rb +17 -0
- data/lib/active_support/i18n_railtie.rb +140 -0
- data/lib/active_support/inflections.rb +68 -49
- data/lib/active_support/inflector/inflections.rb +290 -0
- data/lib/active_support/inflector/methods.rb +387 -0
- data/lib/active_support/inflector/transliterate.rb +147 -0
- data/lib/active_support/inflector.rb +7 -164
- data/lib/active_support/isolated_execution_state.rb +76 -0
- data/lib/active_support/json/decoding.rb +78 -0
- data/lib/active_support/json/encoding.rb +256 -0
- data/lib/active_support/json.rb +4 -0
- data/lib/active_support/key_generator.rb +66 -0
- data/lib/active_support/lazy_load_hooks.rb +107 -0
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +141 -0
- data/lib/active_support/log_subscriber/test_helper.rb +106 -0
- data/lib/active_support/log_subscriber.rb +188 -0
- data/lib/active_support/logger.rb +55 -0
- data/lib/active_support/logger_silence.rb +21 -0
- data/lib/active_support/logger_thread_safe_level.rb +50 -0
- data/lib/active_support/message_encryptor.rb +374 -0
- data/lib/active_support/message_encryptors.rb +193 -0
- data/lib/active_support/message_pack/cache_serializer.rb +23 -0
- data/lib/active_support/message_pack/extensions.rb +310 -0
- data/lib/active_support/message_pack/serializer.rb +63 -0
- data/lib/active_support/message_pack.rb +50 -0
- data/lib/active_support/message_verifier.rb +377 -0
- data/lib/active_support/message_verifiers.rb +189 -0
- data/lib/active_support/messages/codec.rb +65 -0
- data/lib/active_support/messages/metadata.rb +146 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotation_coordinator.rb +102 -0
- data/lib/active_support/messages/rotator.rb +69 -0
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +188 -0
- data/lib/active_support/multibyte/unicode.rb +42 -0
- data/lib/active_support/multibyte.rb +27 -0
- data/lib/active_support/notifications/fanout.rb +467 -0
- data/lib/active_support/notifications/instrumenter.rb +240 -0
- data/lib/active_support/notifications.rb +281 -0
- data/lib/active_support/number_helper/number_converter.rb +190 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
- data/lib/active_support/number_helper/rounding_helper.rb +46 -0
- data/lib/active_support/number_helper.rb +479 -0
- data/lib/active_support/option_merger.rb +38 -0
- data/lib/active_support/ordered_hash.rb +50 -0
- data/lib/active_support/ordered_options.rb +141 -25
- data/lib/active_support/parameter_filter.rb +157 -0
- data/lib/active_support/rails.rb +26 -0
- data/lib/active_support/railtie.rb +180 -0
- data/lib/active_support/reloader.rb +138 -0
- data/lib/active_support/rescuable.rb +176 -0
- data/lib/active_support/secure_compare_rotator.rb +58 -0
- data/lib/active_support/security_utils.rb +38 -0
- data/lib/active_support/string_inquirer.rb +35 -0
- data/lib/active_support/structured_event_subscriber.rb +99 -0
- data/lib/active_support/subscriber.rb +141 -0
- data/lib/active_support/syntax_error_proxy.rb +67 -0
- data/lib/active_support/tagged_logging.rb +157 -0
- data/lib/active_support/test_case.rb +365 -0
- data/lib/active_support/testing/assertions.rb +369 -0
- data/lib/active_support/testing/autorun.rb +10 -0
- data/lib/active_support/testing/constant_lookup.rb +51 -0
- data/lib/active_support/testing/constant_stubbing.rb +54 -0
- data/lib/active_support/testing/declarative.rb +28 -0
- data/lib/active_support/testing/deprecation.rb +82 -0
- data/lib/active_support/testing/error_reporter_assertions.rb +124 -0
- data/lib/active_support/testing/event_reporter_assertions.rb +227 -0
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +121 -0
- data/lib/active_support/testing/method_call_assertions.rb +69 -0
- data/lib/active_support/testing/notification_assertions.rb +92 -0
- data/lib/active_support/testing/parallelization/server.rb +98 -0
- data/lib/active_support/testing/parallelization/worker.rb +107 -0
- data/lib/active_support/testing/parallelization.rb +79 -0
- data/lib/active_support/testing/parallelize_executor.rb +81 -0
- data/lib/active_support/testing/setup_and_teardown.rb +57 -0
- data/lib/active_support/testing/stream.rb +41 -0
- data/lib/active_support/testing/tagged_logging.rb +27 -0
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +273 -0
- data/lib/active_support/time.rb +20 -0
- data/lib/active_support/time_with_zone.rb +613 -0
- data/lib/active_support/values/time_zone.rb +599 -158
- data/lib/active_support/version.rb +7 -6
- data/lib/active_support/xml_mini/jdom.rb +175 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
- data/lib/active_support/xml_mini/nokogiri.rb +83 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
- data/lib/active_support/xml_mini/rexml.rb +137 -0
- data/lib/active_support/xml_mini.rb +212 -0
- data/lib/active_support.rb +122 -10
- metadata +524 -93
- data/CHANGELOG +0 -283
- data/lib/active_support/binding_of_caller.rb +0 -84
- data/lib/active_support/breakpoint.rb +0 -523
- data/lib/active_support/class_attribute_accessors.rb +0 -57
- data/lib/active_support/class_inheritable_attributes.rb +0 -117
- data/lib/active_support/clean_logger.rb +0 -36
- data/lib/active_support/core_ext/blank.rb +0 -38
- data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -14
- data/lib/active_support/core_ext/cgi.rb +0 -5
- data/lib/active_support/core_ext/exception.rb +0 -29
- data/lib/active_support/core_ext/integer/even_odd.rb +0 -24
- data/lib/active_support/core_ext/object_and_class.rb +0 -44
- data/lib/active_support/module_attribute_accessors.rb +0 -57
- data/lib/active_support/whiny_nil.rb +0 -38
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support/core_ext/module/delegation"
|
|
4
|
+
require "active_support/core_ext/object/blank"
|
|
5
|
+
require "active_support/logger"
|
|
6
|
+
|
|
7
|
+
module ActiveSupport
|
|
8
|
+
# = Active Support Tagged Logging
|
|
9
|
+
#
|
|
10
|
+
# Wraps any standard Logger object to provide tagging capabilities.
|
|
11
|
+
#
|
|
12
|
+
# May be called with a block:
|
|
13
|
+
#
|
|
14
|
+
# logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
|
|
15
|
+
# logger.tagged('BCX') { logger.info 'Stuff' } # Logs "[BCX] Stuff"
|
|
16
|
+
# logger.tagged('BCX', "Jason") { |tagged_logger| tagged_logger.info 'Stuff' } # Logs "[BCX] [Jason] Stuff"
|
|
17
|
+
# logger.tagged('BCX') { logger.tagged('Jason') { logger.info 'Stuff' } } # Logs "[BCX] [Jason] Stuff"
|
|
18
|
+
#
|
|
19
|
+
# If called without a block, a new logger will be returned with applied tags:
|
|
20
|
+
#
|
|
21
|
+
# logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
|
|
22
|
+
# logger.tagged("BCX").info "Stuff" # Logs "[BCX] Stuff"
|
|
23
|
+
# logger.tagged("BCX", "Jason").info "Stuff" # Logs "[BCX] [Jason] Stuff"
|
|
24
|
+
# logger.tagged("BCX").tagged("Jason").info "Stuff" # Logs "[BCX] [Jason] Stuff"
|
|
25
|
+
#
|
|
26
|
+
# This is used by the default Rails.logger as configured by Railties to make
|
|
27
|
+
# it easy to stamp log lines with subdomains, request ids, and anything else
|
|
28
|
+
# to aid debugging of multi-user production applications.
|
|
29
|
+
module TaggedLogging
|
|
30
|
+
module Formatter # :nodoc:
|
|
31
|
+
# This method is invoked when a log event occurs.
|
|
32
|
+
def call(severity, timestamp, progname, msg)
|
|
33
|
+
super(severity, timestamp, progname, tag_stack.format_message(msg))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def tagged(*tags)
|
|
37
|
+
pushed_count = tag_stack.push_tags(tags).size
|
|
38
|
+
yield self
|
|
39
|
+
ensure
|
|
40
|
+
pop_tags(pushed_count)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def push_tags(*tags)
|
|
44
|
+
tag_stack.push_tags(tags)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def pop_tags(count = 1)
|
|
48
|
+
tag_stack.pop_tags(count)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def clear_tags!
|
|
52
|
+
tag_stack.clear
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def tag_stack
|
|
56
|
+
# We use our object ID here to avoid conflicting with other instances
|
|
57
|
+
@thread_key ||= "activesupport_tagged_logging_tags:#{object_id}"
|
|
58
|
+
IsolatedExecutionState[@thread_key] ||= TagStack.new
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def current_tags
|
|
62
|
+
tag_stack.tags
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def tags_text
|
|
66
|
+
tag_stack.format_message("")
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class TagStack # :nodoc:
|
|
71
|
+
attr_reader :tags
|
|
72
|
+
|
|
73
|
+
def initialize
|
|
74
|
+
@tags = []
|
|
75
|
+
@tags_string = nil
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def push_tags(tags)
|
|
79
|
+
@tags_string = nil
|
|
80
|
+
tags.flatten!
|
|
81
|
+
tags.reject!(&:blank?)
|
|
82
|
+
@tags.concat(tags)
|
|
83
|
+
tags
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def pop_tags(count)
|
|
87
|
+
@tags_string = nil
|
|
88
|
+
@tags.pop(count)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def clear
|
|
92
|
+
@tags_string = nil
|
|
93
|
+
@tags.clear
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def format_message(message)
|
|
97
|
+
if @tags.empty?
|
|
98
|
+
message
|
|
99
|
+
elsif @tags.size == 1
|
|
100
|
+
"[#{@tags[0]}] #{message}"
|
|
101
|
+
else
|
|
102
|
+
@tags_string ||= "[#{@tags.join("] [")}] "
|
|
103
|
+
"#{@tags_string}#{message}"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
module LocalTagStorage # :nodoc:
|
|
109
|
+
attr_accessor :tag_stack
|
|
110
|
+
|
|
111
|
+
def self.extended(base)
|
|
112
|
+
base.tag_stack = TagStack.new
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Returns an `ActiveSupport::Logger` that has already been wrapped with tagged logging concern.
|
|
117
|
+
def self.logger(*args, **kwargs)
|
|
118
|
+
new ActiveSupport::Logger.new(*args, **kwargs)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def self.new(logger)
|
|
122
|
+
logger = logger.clone
|
|
123
|
+
|
|
124
|
+
if logger.formatter
|
|
125
|
+
logger.formatter = logger.formatter.clone
|
|
126
|
+
|
|
127
|
+
# Workaround for https://bugs.ruby-lang.org/issues/20250
|
|
128
|
+
# Can be removed when Ruby 3.4 is the least supported version.
|
|
129
|
+
logger.formatter.object_id if logger.formatter.is_a?(Proc)
|
|
130
|
+
else
|
|
131
|
+
# Ensure we set a default formatter so we aren't extending nil!
|
|
132
|
+
logger.formatter = ActiveSupport::Logger::SimpleFormatter.new
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
logger.formatter.extend Formatter
|
|
136
|
+
logger.extend(self)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter
|
|
140
|
+
|
|
141
|
+
def tagged(*tags)
|
|
142
|
+
if block_given?
|
|
143
|
+
formatter.tagged(*tags) { yield self }
|
|
144
|
+
else
|
|
145
|
+
logger = ActiveSupport::TaggedLogging.new(self)
|
|
146
|
+
logger.formatter.extend LocalTagStorage
|
|
147
|
+
logger.push_tags(*formatter.current_tags, *tags)
|
|
148
|
+
logger
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def flush
|
|
153
|
+
clear_tags!
|
|
154
|
+
super if defined?(super)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "minitest"
|
|
4
|
+
require "active_support/testing/tagged_logging"
|
|
5
|
+
require "active_support/testing/setup_and_teardown"
|
|
6
|
+
require "active_support/testing/tests_without_assertions"
|
|
7
|
+
require "active_support/testing/assertions"
|
|
8
|
+
require "active_support/testing/error_reporter_assertions"
|
|
9
|
+
require "active_support/testing/event_reporter_assertions"
|
|
10
|
+
require "active_support/testing/deprecation"
|
|
11
|
+
require "active_support/testing/declarative"
|
|
12
|
+
require "active_support/testing/isolation"
|
|
13
|
+
require "active_support/testing/constant_lookup"
|
|
14
|
+
require "active_support/testing/time_helpers"
|
|
15
|
+
require "active_support/testing/constant_stubbing"
|
|
16
|
+
require "active_support/testing/file_fixtures"
|
|
17
|
+
require "active_support/testing/parallelization"
|
|
18
|
+
require "active_support/testing/parallelize_executor"
|
|
19
|
+
require "active_support/testing/notification_assertions"
|
|
20
|
+
require "concurrent/utility/processor_counter"
|
|
21
|
+
|
|
22
|
+
module ActiveSupport
|
|
23
|
+
class TestCase < ::Minitest::Test
|
|
24
|
+
Assertion = Minitest::Assertion
|
|
25
|
+
|
|
26
|
+
# Class variable to store the parallel worker ID
|
|
27
|
+
@@parallel_worker_id = nil
|
|
28
|
+
|
|
29
|
+
class << self
|
|
30
|
+
# Returns the current parallel worker ID if tests are running in parallel,
|
|
31
|
+
# nil otherwise.
|
|
32
|
+
#
|
|
33
|
+
# ActiveSupport::TestCase.parallel_worker_id # => 2
|
|
34
|
+
def parallel_worker_id
|
|
35
|
+
@@parallel_worker_id
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def parallel_worker_id=(value) # :nodoc:
|
|
39
|
+
@@parallel_worker_id = value
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Sets the order in which test cases are run.
|
|
43
|
+
#
|
|
44
|
+
# ActiveSupport::TestCase.test_order = :random # => :random
|
|
45
|
+
#
|
|
46
|
+
# Valid values are:
|
|
47
|
+
# * +:random+ (to run tests in random order)
|
|
48
|
+
# * +:parallel+ (to run tests in parallel)
|
|
49
|
+
# * +:sorted+ (to run tests alphabetically by method name)
|
|
50
|
+
# * +:alpha+ (equivalent to +:sorted+)
|
|
51
|
+
def test_order=(new_order)
|
|
52
|
+
ActiveSupport.test_order = new_order
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Returns the order in which test cases are run.
|
|
56
|
+
#
|
|
57
|
+
# ActiveSupport::TestCase.test_order # => :random
|
|
58
|
+
#
|
|
59
|
+
# Possible values are +:random+, +:parallel+, +:alpha+, +:sorted+.
|
|
60
|
+
# Defaults to +:random+.
|
|
61
|
+
def test_order
|
|
62
|
+
ActiveSupport.test_order ||= :random
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
if Minitest.respond_to? :run_order # MT6 API change
|
|
66
|
+
def run_order # :nodoc:
|
|
67
|
+
test_order
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Parallelizes the test suite.
|
|
72
|
+
#
|
|
73
|
+
# Takes a +workers+ argument that controls how many times the process
|
|
74
|
+
# is forked. For each process a new database will be created suffixed
|
|
75
|
+
# with the worker number.
|
|
76
|
+
#
|
|
77
|
+
# test-database_0
|
|
78
|
+
# test-database_1
|
|
79
|
+
#
|
|
80
|
+
# If <tt>ENV["PARALLEL_WORKERS"]</tt> is set the workers argument will be ignored
|
|
81
|
+
# and the environment variable will be used instead. This is useful for CI
|
|
82
|
+
# environments, or other environments where you may need more workers than
|
|
83
|
+
# you do for local testing.
|
|
84
|
+
#
|
|
85
|
+
# If the number of workers is set to +1+ or fewer, the tests will not be
|
|
86
|
+
# parallelized.
|
|
87
|
+
#
|
|
88
|
+
# If +workers+ is set to +:number_of_processors+, the number of workers will be
|
|
89
|
+
# set to the actual core count on the machine you are on.
|
|
90
|
+
#
|
|
91
|
+
# The default parallelization method is to fork processes. If you'd like to
|
|
92
|
+
# use threads instead you can pass <tt>with: :threads</tt> to the +parallelize+
|
|
93
|
+
# method. Note the threaded parallelization does not create multiple
|
|
94
|
+
# databases and will not work with system tests.
|
|
95
|
+
#
|
|
96
|
+
# parallelize(workers: :number_of_processors, with: :threads)
|
|
97
|
+
#
|
|
98
|
+
# The threaded parallelization uses minitest's parallel executor directly.
|
|
99
|
+
# The processes parallelization uses a Ruby DRb server.
|
|
100
|
+
#
|
|
101
|
+
# Because parallelization presents an overhead, it is only enabled when the
|
|
102
|
+
# number of tests to run is above the +threshold+ param. The default value is
|
|
103
|
+
# 50, and it's configurable via +config.active_support.test_parallelization_threshold+.
|
|
104
|
+
#
|
|
105
|
+
# If you want to skip Rails default creation of one database per process in favor of
|
|
106
|
+
# writing your own implementation, you can set +parallelize_databases+, or configure it
|
|
107
|
+
# via +config.active_support.parallelize_test_databases+.
|
|
108
|
+
#
|
|
109
|
+
# parallelize(workers: :number_of_processors, parallelize_databases: false)
|
|
110
|
+
#
|
|
111
|
+
# Note that your test suite may deadlock if you attempt to use only one database
|
|
112
|
+
# with multiple processes.
|
|
113
|
+
def parallelize(workers: :number_of_processors, with: :processes, threshold: ActiveSupport.test_parallelization_threshold, parallelize_databases: ActiveSupport.parallelize_test_databases)
|
|
114
|
+
case
|
|
115
|
+
when ENV["PARALLEL_WORKERS"]
|
|
116
|
+
workers = ENV["PARALLEL_WORKERS"].to_i
|
|
117
|
+
when workers == :number_of_processors
|
|
118
|
+
workers = (Concurrent.available_processor_count || Concurrent.processor_count).floor
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
if with == :processes
|
|
122
|
+
ActiveSupport.parallelize_test_databases = parallelize_databases
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
Minitest.parallel_executor = ActiveSupport::Testing::ParallelizeExecutor.new(size: workers, with: with, threshold: threshold)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Before fork hook for parallel testing. This can be used to run anything
|
|
129
|
+
# before the processes are forked.
|
|
130
|
+
#
|
|
131
|
+
# In your +test_helper.rb+ add the following:
|
|
132
|
+
#
|
|
133
|
+
# class ActiveSupport::TestCase
|
|
134
|
+
# parallelize_before_fork do
|
|
135
|
+
# # run this before fork
|
|
136
|
+
# end
|
|
137
|
+
# end
|
|
138
|
+
def parallelize_before_fork(&block)
|
|
139
|
+
ActiveSupport::Testing::Parallelization.before_fork_hook(&block)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# Setup hook for parallel testing. This can be used if you have multiple
|
|
143
|
+
# databases or any behavior that needs to be run after the process is forked
|
|
144
|
+
# but before the tests run.
|
|
145
|
+
#
|
|
146
|
+
# Note: this feature is not available with the threaded parallelization.
|
|
147
|
+
#
|
|
148
|
+
# In your +test_helper.rb+ add the following:
|
|
149
|
+
#
|
|
150
|
+
# class ActiveSupport::TestCase
|
|
151
|
+
# parallelize_setup do
|
|
152
|
+
# # create databases
|
|
153
|
+
# end
|
|
154
|
+
# end
|
|
155
|
+
def parallelize_setup(&block)
|
|
156
|
+
ActiveSupport::Testing::Parallelization.after_fork_hook(&block)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Clean up hook for parallel testing. This can be used to drop databases
|
|
160
|
+
# if your app uses multiple write/read databases or other clean up before
|
|
161
|
+
# the tests finish. This runs before the forked process is closed.
|
|
162
|
+
#
|
|
163
|
+
# Note: this feature is not available with the threaded parallelization.
|
|
164
|
+
#
|
|
165
|
+
# In your +test_helper.rb+ add the following:
|
|
166
|
+
#
|
|
167
|
+
# class ActiveSupport::TestCase
|
|
168
|
+
# parallelize_teardown do
|
|
169
|
+
# # drop databases
|
|
170
|
+
# end
|
|
171
|
+
# end
|
|
172
|
+
def parallelize_teardown(&block)
|
|
173
|
+
ActiveSupport::Testing::Parallelization.run_cleanup_hook(&block)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# :singleton-method: fixture_paths
|
|
177
|
+
#
|
|
178
|
+
# Returns the ActiveRecord::FixtureSet collection.
|
|
179
|
+
#
|
|
180
|
+
# In your +test_helper.rb+ you must have <tt>require "rails/test_help"</tt>.
|
|
181
|
+
|
|
182
|
+
# :singleton-method: fixture_paths=
|
|
183
|
+
#
|
|
184
|
+
# :call-seq:
|
|
185
|
+
# fixture_paths=(fixture_paths)
|
|
186
|
+
#
|
|
187
|
+
# Sets the given path to the fixture set.
|
|
188
|
+
#
|
|
189
|
+
# Can also append multiple paths.
|
|
190
|
+
#
|
|
191
|
+
# ActiveSupport::TestCase.fixture_paths << "component1/test/fixtures"
|
|
192
|
+
#
|
|
193
|
+
# In your +test_helper.rb+ you must have <tt>require "rails/test_help"</tt>.
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
alias_method :method_name, :name
|
|
197
|
+
|
|
198
|
+
# Returns the current parallel worker ID if tests are running in parallel
|
|
199
|
+
def parallel_worker_id
|
|
200
|
+
self.class.parallel_worker_id
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
include ActiveSupport::Testing::TaggedLogging
|
|
204
|
+
prepend ActiveSupport::Testing::SetupAndTeardown
|
|
205
|
+
prepend ActiveSupport::Testing::TestsWithoutAssertions
|
|
206
|
+
include ActiveSupport::Testing::Assertions
|
|
207
|
+
include ActiveSupport::Testing::ErrorReporterAssertions
|
|
208
|
+
include ActiveSupport::Testing::EventReporterAssertions
|
|
209
|
+
include ActiveSupport::Testing::NotificationAssertions
|
|
210
|
+
include ActiveSupport::Testing::Deprecation
|
|
211
|
+
include ActiveSupport::Testing::ConstantStubbing
|
|
212
|
+
include ActiveSupport::Testing::TimeHelpers
|
|
213
|
+
include ActiveSupport::Testing::FileFixtures
|
|
214
|
+
extend ActiveSupport::Testing::Declarative
|
|
215
|
+
|
|
216
|
+
##
|
|
217
|
+
# :method: assert_not_empty
|
|
218
|
+
#
|
|
219
|
+
# :call-seq:
|
|
220
|
+
# assert_not_empty(obj, msg = nil)
|
|
221
|
+
#
|
|
222
|
+
# Alias for: refute_empty[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_empty]
|
|
223
|
+
|
|
224
|
+
#
|
|
225
|
+
alias :assert_not_empty :refute_empty
|
|
226
|
+
|
|
227
|
+
##
|
|
228
|
+
# :method: assert_not_equal
|
|
229
|
+
#
|
|
230
|
+
# :call-seq:
|
|
231
|
+
# assert_not_equal(exp, act, msg = nil)
|
|
232
|
+
#
|
|
233
|
+
# Alias for: refute_equal[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_equal]
|
|
234
|
+
|
|
235
|
+
#
|
|
236
|
+
alias :assert_not_equal :refute_equal
|
|
237
|
+
|
|
238
|
+
##
|
|
239
|
+
# :method: assert_not_in_delta
|
|
240
|
+
#
|
|
241
|
+
# :call-seq:
|
|
242
|
+
# assert_not_in_delta(exp, act, delta = 0.001, msg = nil)
|
|
243
|
+
#
|
|
244
|
+
# Alias for: refute_in_delta[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_in_delta]
|
|
245
|
+
|
|
246
|
+
#
|
|
247
|
+
alias :assert_not_in_delta :refute_in_delta
|
|
248
|
+
|
|
249
|
+
##
|
|
250
|
+
# :method: assert_not_in_epsilon
|
|
251
|
+
#
|
|
252
|
+
# :call-seq:
|
|
253
|
+
# assert_not_in_epsilon(a, b, epsilon = 0.001, msg = nil)
|
|
254
|
+
#
|
|
255
|
+
# Alias for: refute_in_epsilon[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_in_epsilon]
|
|
256
|
+
|
|
257
|
+
#
|
|
258
|
+
alias :assert_not_in_epsilon :refute_in_epsilon
|
|
259
|
+
|
|
260
|
+
##
|
|
261
|
+
# :method: assert_not_includes
|
|
262
|
+
#
|
|
263
|
+
# :call-seq:
|
|
264
|
+
# assert_not_includes(collection, obj, msg = nil)
|
|
265
|
+
#
|
|
266
|
+
# Alias for: refute_includes[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_includes]
|
|
267
|
+
|
|
268
|
+
#
|
|
269
|
+
alias :assert_not_includes :refute_includes
|
|
270
|
+
|
|
271
|
+
##
|
|
272
|
+
# :method: assert_not_instance_of
|
|
273
|
+
#
|
|
274
|
+
# :call-seq:
|
|
275
|
+
# assert_not_instance_of(cls, obj, msg = nil)
|
|
276
|
+
#
|
|
277
|
+
# Alias for: refute_instance_of[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_instance_of]
|
|
278
|
+
|
|
279
|
+
#
|
|
280
|
+
alias :assert_not_instance_of :refute_instance_of
|
|
281
|
+
|
|
282
|
+
##
|
|
283
|
+
# :method: assert_not_kind_of
|
|
284
|
+
#
|
|
285
|
+
# :call-seq:
|
|
286
|
+
# assert_not_kind_of(cls, obj, msg = nil)
|
|
287
|
+
#
|
|
288
|
+
# Alias for: refute_kind_of[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_kind_of]
|
|
289
|
+
|
|
290
|
+
#
|
|
291
|
+
alias :assert_not_kind_of :refute_kind_of
|
|
292
|
+
|
|
293
|
+
##
|
|
294
|
+
# :method: assert_no_match
|
|
295
|
+
#
|
|
296
|
+
# :call-seq:
|
|
297
|
+
# assert_no_match(matcher, obj, msg = nil)
|
|
298
|
+
#
|
|
299
|
+
# Alias for: refute_match[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_match]
|
|
300
|
+
|
|
301
|
+
#
|
|
302
|
+
alias :assert_no_match :refute_match
|
|
303
|
+
|
|
304
|
+
##
|
|
305
|
+
# :method: assert_not_nil
|
|
306
|
+
#
|
|
307
|
+
# :call-seq:
|
|
308
|
+
# assert_not_nil(obj, msg = nil)
|
|
309
|
+
#
|
|
310
|
+
# Alias for: refute_nil[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_nil]
|
|
311
|
+
|
|
312
|
+
#
|
|
313
|
+
alias :assert_not_nil :refute_nil
|
|
314
|
+
|
|
315
|
+
##
|
|
316
|
+
# :method: assert_not_operator
|
|
317
|
+
#
|
|
318
|
+
# :call-seq:
|
|
319
|
+
# assert_not_operator(o1, op, o2 = UNDEFINED, msg = nil)
|
|
320
|
+
#
|
|
321
|
+
# Alias for: refute_operator[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_operator]
|
|
322
|
+
|
|
323
|
+
#
|
|
324
|
+
alias :assert_not_operator :refute_operator
|
|
325
|
+
|
|
326
|
+
##
|
|
327
|
+
# :method: assert_not_predicate
|
|
328
|
+
#
|
|
329
|
+
# :call-seq:
|
|
330
|
+
# assert_not_predicate(o1, op, msg = nil)
|
|
331
|
+
#
|
|
332
|
+
# Alias for: refute_predicate[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_predicate]
|
|
333
|
+
|
|
334
|
+
#
|
|
335
|
+
alias :assert_not_predicate :refute_predicate
|
|
336
|
+
|
|
337
|
+
##
|
|
338
|
+
# :method: assert_not_respond_to
|
|
339
|
+
#
|
|
340
|
+
# :call-seq:
|
|
341
|
+
# assert_not_respond_to(obj, meth, msg = nil)
|
|
342
|
+
#
|
|
343
|
+
# Alias for: refute_respond_to[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_respond_to]
|
|
344
|
+
|
|
345
|
+
#
|
|
346
|
+
alias :assert_not_respond_to :refute_respond_to
|
|
347
|
+
|
|
348
|
+
##
|
|
349
|
+
# :method: assert_not_same
|
|
350
|
+
#
|
|
351
|
+
# :call-seq:
|
|
352
|
+
# assert_not_same(exp, act, msg = nil)
|
|
353
|
+
#
|
|
354
|
+
# Alias for: refute_same[https://docs.seattlerb.org/minitest/Minitest/Assertions.html#method-i-refute_same]
|
|
355
|
+
|
|
356
|
+
#
|
|
357
|
+
alias :assert_not_same :refute_same
|
|
358
|
+
|
|
359
|
+
ActiveSupport.run_load_hooks(:active_support_test_case, self)
|
|
360
|
+
|
|
361
|
+
def inspect # :nodoc:
|
|
362
|
+
Object.instance_method(:to_s).bind_call(self)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
end
|