aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2016-08-06 19:55:02 +0200
committerXavier Noria <fxn@hashref.com>2016-08-06 20:16:27 +0200
commit80e66cc4d90bf8c15d1a5f6e3152e90147f00772 (patch)
treee7e75464af04f3cf1935b29238dbd7cb2337b0dd /activesupport
parent411ccbdab2608c62aabdb320d52cb02d446bb39c (diff)
downloadrails-80e66cc4d90bf8c15d1a5f6e3152e90147f00772.tar.gz
rails-80e66cc4d90bf8c15d1a5f6e3152e90147f00772.tar.bz2
rails-80e66cc4d90bf8c15d1a5f6e3152e90147f00772.zip
normalizes indentation and whitespace across the project
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/cache/mem_cache_store.rb28
-rw-r--r--activesupport/lib/active_support/callbacks.rb1120
-rw-r--r--activesupport/lib/active_support/concurrency/share_lock.rb34
-rw-r--r--activesupport/lib/active_support/core_ext/array/prepend_and_append.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/date_and_time/zones.rb13
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb12
-rw-r--r--activesupport/lib/active_support/core_ext/hash/slice.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/numeric/inquiry.rb42
-rw-r--r--activesupport/lib/active_support/core_ext/string/inflections.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/string/output_safety.rb6
-rw-r--r--activesupport/lib/active_support/dependencies.rb26
-rw-r--r--activesupport/lib/active_support/duration/iso8601_parser.rb56
-rw-r--r--activesupport/lib/active_support/evented_file_update_checker.rb100
-rw-r--r--activesupport/lib/active_support/file_update_checker.rb86
-rw-r--r--activesupport/lib/active_support/gzip.rb2
-rw-r--r--activesupport/lib/active_support/inflector/methods.rb30
-rw-r--r--activesupport/lib/active_support/inflector/transliterate.rb2
-rw-r--r--activesupport/lib/active_support/key_generator.rb24
-rw-r--r--activesupport/lib/active_support/log_subscriber/test_helper.rb10
-rw-r--r--activesupport/lib/active_support/message_encryptor.rb102
-rw-r--r--activesupport/lib/active_support/multibyte/unicode.rb34
-rw-r--r--activesupport/lib/active_support/notifications/instrumenter.rb6
-rw-r--r--activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb1
-rw-r--r--activesupport/lib/active_support/number_helper/number_to_phone_converter.rb1
-rw-r--r--activesupport/lib/active_support/testing/stream.rb56
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb10
-rw-r--r--activesupport/lib/active_support/xml_mini.rb38
-rw-r--r--activesupport/lib/active_support/xml_mini/jdom.rb134
-rw-r--r--activesupport/test/autoload_test.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/a/b.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/a/c/d.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/a/c/em/f.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/conflict.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/cross_site_dependency.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/d.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/em.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb1
-rw-r--r--activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb2
-rw-r--r--activesupport/test/autoloading_fixtures/requires_constant.rb1
-rw-r--r--activesupport/test/autoloading_fixtures/typo.rb1
-rw-r--r--activesupport/test/caching_test.rb14
-rw-r--r--activesupport/test/core_ext/date_ext_test.rb1
-rw-r--r--activesupport/test/core_ext/module/anonymous_test.rb2
-rw-r--r--activesupport/test/core_ext/module/attribute_accessor_per_thread_test.rb8
-rw-r--r--activesupport/test/core_ext/module/qualified_const_test.rb8
-rw-r--r--activesupport/test/core_ext/module/reachable_test.rb2
-rw-r--r--activesupport/test/core_ext/module_test.rb6
-rw-r--r--activesupport/test/core_ext/object/inclusion_test.rb4
-rw-r--r--activesupport/test/dependencies/conflict.rb2
-rw-r--r--activesupport/test/dependencies/cross_site_depender.rb2
-rw-r--r--activesupport/test/dependencies/service_one.rb2
-rw-r--r--activesupport/test/dependencies/service_two.rb2
-rw-r--r--activesupport/test/dependencies_test_helpers.rb2
-rw-r--r--activesupport/test/descendants_tracker_test_cases.rb34
-rw-r--r--activesupport/test/fixtures/autoload/another_class.rb2
-rw-r--r--activesupport/test/fixtures/autoload/some_class.rb2
-rw-r--r--activesupport/test/inflector_test_cases.rb36
-rw-r--r--activesupport/test/json/decoding_test.rb15
-rw-r--r--activesupport/test/key_generator_test.rb114
-rw-r--r--activesupport/test/lazy_load_hooks_test.rb2
-rw-r--r--activesupport/test/message_encryptor_test.rb26
-rw-r--r--activesupport/test/multibyte_chars_test.rb22
-rw-r--r--activesupport/test/share_lock_test.rb124
-rw-r--r--activesupport/test/subscriber_test.rb6
-rw-r--r--activesupport/test/xml_mini/jdom_engine_test.rb12
-rw-r--r--activesupport/test/xml_mini/libxml_engine_test.rb194
-rw-r--r--activesupport/test/xml_mini/libxmlsax_engine_test.rb160
-rw-r--r--activesupport/test/xml_mini/nokogiri_engine_test.rb182
-rw-r--r--activesupport/test/xml_mini/nokogirisax_engine_test.rb182
-rw-r--r--activesupport/test/xml_mini/rexml_engine_test.rb4
72 files changed, 1587 insertions, 1595 deletions
diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb
index e8b56676cb..e51c6b2f10 100644
--- a/activesupport/lib/active_support/cache/mem_cache_store.rb
+++ b/activesupport/lib/active_support/cache/mem_cache_store.rb
@@ -27,23 +27,23 @@ module ActiveSupport
# Provide support for raw values in the local cache strategy.
module LocalCacheWithRaw # :nodoc:
protected
- def read_entry(key, options)
- entry = super
- if options[:raw] && local_cache && entry
- entry = deserialize_entry(entry.value)
+ def read_entry(key, options)
+ entry = super
+ if options[:raw] && local_cache && entry
+ entry = deserialize_entry(entry.value)
+ end
+ entry
end
- entry
- end
- def write_entry(key, entry, options) # :nodoc:
- if options[:raw] && local_cache
- raw_entry = Entry.new(entry.value.to_s)
- raw_entry.expires_at = entry.expires_at
- super(key, raw_entry, options)
- else
- super
+ def write_entry(key, entry, options) # :nodoc:
+ if options[:raw] && local_cache
+ raw_entry = Entry.new(entry.value.to_s)
+ raw_entry.expires_at = entry.expires_at
+ super(key, raw_entry, options)
+ else
+ super
+ end
end
- end
end
prepend Strategy::LocalCache
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 985f432c7b..a450b0e6d4 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -92,705 +92,705 @@ module ActiveSupport
private
- def __run_callbacks__(callbacks, &block)
- if callbacks.empty?
- yield if block_given?
- else
- runner = callbacks.compile
- e = Filters::Environment.new(self, false, nil, block)
- runner.call(e).value
+ def __run_callbacks__(callbacks, &block)
+ if callbacks.empty?
+ yield if block_given?
+ else
+ runner = callbacks.compile
+ e = Filters::Environment.new(self, false, nil, block)
+ runner.call(e).value
+ end
end
- end
# A hook invoked every time a before callback is halted.
# This can be overridden in ActiveSupport::Callbacks implementors in order
# to provide better debugging/logging.
- def halted_callback_hook(filter)
- end
-
- module Conditionals # :nodoc:
- class Value
- def initialize(&block)
- @block = block
- end
- def call(target, value); @block.call(value); end
+ def halted_callback_hook(filter)
end
- end
-
- module Filters
- Environment = Struct.new(:target, :halted, :value, :run_block)
- class End
- def call(env)
- block = env.run_block
- env.value = !env.halted && (!block || block.call)
- env
+ module Conditionals # :nodoc:
+ class Value
+ def initialize(&block)
+ @block = block
+ end
+ def call(target, value); @block.call(value); end
end
end
- ENDING = End.new
- class Before
- def self.build(callback_sequence, user_callback, user_conditions, chain_config, filter)
- halted_lambda = chain_config[:terminator]
+ module Filters
+ Environment = Struct.new(:target, :halted, :value, :run_block)
- if user_conditions.any?
- halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter)
- else
- halting(callback_sequence, user_callback, halted_lambda, filter)
+ class End
+ def call(env)
+ block = env.run_block
+ env.value = !env.halted && (!block || block.call)
+ env
end
end
+ ENDING = End.new
- def self.halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter)
- callback_sequence.before do |env|
- target = env.target
- value = env.value
- halted = env.halted
+ class Before
+ def self.build(callback_sequence, user_callback, user_conditions, chain_config, filter)
+ halted_lambda = chain_config[:terminator]
- if !halted && user_conditions.all? { |c| c.call(target, value) }
- result_lambda = -> { user_callback.call target, value }
- env.halted = halted_lambda.call(target, result_lambda)
- if env.halted
- target.send :halted_callback_hook, filter
- end
+ if user_conditions.any?
+ halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter)
+ else
+ halting(callback_sequence, user_callback, halted_lambda, filter)
end
+ end
- env
+ def self.halting_and_conditional(callback_sequence, user_callback, user_conditions, halted_lambda, filter)
+ callback_sequence.before do |env|
+ target = env.target
+ value = env.value
+ halted = env.halted
+
+ if !halted && user_conditions.all? { |c| c.call(target, value) }
+ result_lambda = -> { user_callback.call target, value }
+ env.halted = halted_lambda.call(target, result_lambda)
+ if env.halted
+ target.send :halted_callback_hook, filter
+ end
+ end
+
+ env
+ end
end
- end
- private_class_method :halting_and_conditional
+ private_class_method :halting_and_conditional
- def self.halting(callback_sequence, user_callback, halted_lambda, filter)
- callback_sequence.before do |env|
- target = env.target
- value = env.value
- halted = env.halted
+ def self.halting(callback_sequence, user_callback, halted_lambda, filter)
+ callback_sequence.before do |env|
+ target = env.target
+ value = env.value
+ halted = env.halted
- unless halted
- result_lambda = -> { user_callback.call target, value }
- env.halted = halted_lambda.call(target, result_lambda)
+ unless halted
+ result_lambda = -> { user_callback.call target, value }
+ env.halted = halted_lambda.call(target, result_lambda)
- if env.halted
- target.send :halted_callback_hook, filter
+ if env.halted
+ target.send :halted_callback_hook, filter
+ end
end
- end
- env
+ env
+ end
end
+ private_class_method :halting
end
- private_class_method :halting
- end
- class After
- def self.build(callback_sequence, user_callback, user_conditions, chain_config)
- if chain_config[:skip_after_callbacks_if_terminated]
- if user_conditions.any?
- halting_and_conditional(callback_sequence, user_callback, user_conditions)
- else
- halting(callback_sequence, user_callback)
- end
- else
- if user_conditions.any?
- conditional callback_sequence, user_callback, user_conditions
+ class After
+ def self.build(callback_sequence, user_callback, user_conditions, chain_config)
+ if chain_config[:skip_after_callbacks_if_terminated]
+ if user_conditions.any?
+ halting_and_conditional(callback_sequence, user_callback, user_conditions)
+ else
+ halting(callback_sequence, user_callback)
+ end
else
- simple callback_sequence, user_callback
+ if user_conditions.any?
+ conditional callback_sequence, user_callback, user_conditions
+ else
+ simple callback_sequence, user_callback
+ end
end
end
- end
- def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
- callback_sequence.after do |env|
- target = env.target
- value = env.value
- halted = env.halted
+ def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
+ callback_sequence.after do |env|
+ target = env.target
+ value = env.value
+ halted = env.halted
- if !halted && user_conditions.all? { |c| c.call(target, value) }
- user_callback.call target, value
- end
+ if !halted && user_conditions.all? { |c| c.call(target, value) }
+ user_callback.call target, value
+ end
- env
+ env
+ end
end
- end
- private_class_method :halting_and_conditional
+ private_class_method :halting_and_conditional
- def self.halting(callback_sequence, user_callback)
- callback_sequence.after do |env|
- unless env.halted
- user_callback.call env.target, env.value
- end
+ def self.halting(callback_sequence, user_callback)
+ callback_sequence.after do |env|
+ unless env.halted
+ user_callback.call env.target, env.value
+ end
- env
+ env
+ end
end
- end
- private_class_method :halting
+ private_class_method :halting
- def self.conditional(callback_sequence, user_callback, user_conditions)
- callback_sequence.after do |env|
- target = env.target
- value = env.value
+ def self.conditional(callback_sequence, user_callback, user_conditions)
+ callback_sequence.after do |env|
+ target = env.target
+ value = env.value
- if user_conditions.all? { |c| c.call(target, value) }
- user_callback.call target, value
- end
+ if user_conditions.all? { |c| c.call(target, value) }
+ user_callback.call target, value
+ end
- env
+ env
+ end
end
- end
- private_class_method :conditional
+ private_class_method :conditional
- def self.simple(callback_sequence, user_callback)
- callback_sequence.after do |env|
- user_callback.call env.target, env.value
+ def self.simple(callback_sequence, user_callback)
+ callback_sequence.after do |env|
+ user_callback.call env.target, env.value
- env
+ env
+ end
end
+ private_class_method :simple
end
- private_class_method :simple
- end
- class Around
- def self.build(callback_sequence, user_callback, user_conditions, chain_config)
- if user_conditions.any?
- halting_and_conditional(callback_sequence, user_callback, user_conditions)
- else
- halting(callback_sequence, user_callback)
+ class Around
+ def self.build(callback_sequence, user_callback, user_conditions, chain_config)
+ if user_conditions.any?
+ halting_and_conditional(callback_sequence, user_callback, user_conditions)
+ else
+ halting(callback_sequence, user_callback)
+ end
end
- end
- def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
- callback_sequence.around do |env, &run|
- target = env.target
- value = env.value
- halted = env.halted
-
- if !halted && user_conditions.all? { |c| c.call(target, value) }
- user_callback.call(target, value) {
- run.call.value
- }
- env
- else
- run.call
+ def self.halting_and_conditional(callback_sequence, user_callback, user_conditions)
+ callback_sequence.around do |env, &run|
+ target = env.target
+ value = env.value
+ halted = env.halted
+
+ if !halted && user_conditions.all? { |c| c.call(target, value) }
+ user_callback.call(target, value) {
+ run.call.value
+ }
+ env
+ else
+ run.call
+ end
end
end
- end
- private_class_method :halting_and_conditional
+ private_class_method :halting_and_conditional
- def self.halting(callback_sequence, user_callback)
- callback_sequence.around do |env, &run|
- target = env.target
- value = env.value
+ def self.halting(callback_sequence, user_callback)
+ callback_sequence.around do |env, &run|
+ target = env.target
+ value = env.value
- if env.halted
- run.call
- else
- user_callback.call(target, value) {
- run.call.value
- }
- env
+ if env.halted
+ run.call
+ else
+ user_callback.call(target, value) {
+ run.call.value
+ }
+ env
+ end
end
end
+ private_class_method :halting
end
- private_class_method :halting
end
- end
- class Callback #:nodoc:#
- def self.build(chain, filter, kind, options)
- if filter.is_a?(String)
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ class Callback #:nodoc:#
+ def self.build(chain, filter, kind, options)
+ if filter.is_a?(String)
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
Passing string to define callback is deprecated and will be removed
in Rails 5.1 without replacement.
MSG
- end
-
- new chain.name, filter, kind, options, chain.config
- end
+ end
- attr_accessor :kind, :name
- attr_reader :chain_config
-
- def initialize(name, filter, kind, options, chain_config)
- @chain_config = chain_config
- @name = name
- @kind = kind
- @filter = filter
- @key = compute_identifier filter
- @if = Array(options[:if])
- @unless = Array(options[:unless])
- end
+ new chain.name, filter, kind, options, chain.config
+ end
- def filter; @key; end
- def raw_filter; @filter; end
+ attr_accessor :kind, :name
+ attr_reader :chain_config
+
+ def initialize(name, filter, kind, options, chain_config)
+ @chain_config = chain_config
+ @name = name
+ @kind = kind
+ @filter = filter
+ @key = compute_identifier filter
+ @if = Array(options[:if])
+ @unless = Array(options[:unless])
+ end
- def merge_conditional_options(chain, if_option:, unless_option:)
- options = {
- if: @if.dup,
- unless: @unless.dup
- }
+ def filter; @key; end
+ def raw_filter; @filter; end
- options[:if].concat Array(unless_option)
- options[:unless].concat Array(if_option)
+ def merge_conditional_options(chain, if_option:, unless_option:)
+ options = {
+ if: @if.dup,
+ unless: @unless.dup
+ }
- self.class.build chain, @filter, @kind, options
- end
+ options[:if].concat Array(unless_option)
+ options[:unless].concat Array(if_option)
- def matches?(_kind, _filter)
- @kind == _kind && filter == _filter
- end
+ self.class.build chain, @filter, @kind, options
+ end
- def duplicates?(other)
- case @filter
- when Symbol, String
- matches?(other.kind, other.filter)
- else
- false
+ def matches?(_kind, _filter)
+ @kind == _kind && filter == _filter
end
- end
- # Wraps code with filter
- def apply(callback_sequence)
- user_conditions = conditions_lambdas
- user_callback = make_lambda @filter
-
- case kind
- when :before
- Filters::Before.build(callback_sequence, user_callback, user_conditions, chain_config, @filter)
- when :after
- Filters::After.build(callback_sequence, user_callback, user_conditions, chain_config)
- when :around
- Filters::Around.build(callback_sequence, user_callback, user_conditions, chain_config)
+ def duplicates?(other)
+ case @filter
+ when Symbol, String
+ matches?(other.kind, other.filter)
+ else
+ false
+ end
end
- end
- private
+ # Wraps code with filter
+ def apply(callback_sequence)
+ user_conditions = conditions_lambdas
+ user_callback = make_lambda @filter
+
+ case kind
+ when :before
+ Filters::Before.build(callback_sequence, user_callback, user_conditions, chain_config, @filter)
+ when :after
+ Filters::After.build(callback_sequence, user_callback, user_conditions, chain_config)
+ when :around
+ Filters::Around.build(callback_sequence, user_callback, user_conditions, chain_config)
+ end
+ end
- def invert_lambda(l)
- lambda { |*args, &blk| !l.call(*args, &blk) }
- end
+ private
- # Filters support:
- #
- # Symbols:: A method to call.
- # Strings:: Some content to evaluate.
- # Procs:: A proc to call with the object.
- # Objects:: An object with a <tt>before_foo</tt> method on it to call.
- #
- # All of these objects are converted into a lambda and handled
- # the same after this point.
- def make_lambda(filter)
- case filter
- when Symbol
- lambda { |target, _, &blk| target.send filter, &blk }
- when String
- l = eval "lambda { |value| #{filter} }"
- lambda { |target, value| target.instance_exec(value, &l) }
- when Conditionals::Value then filter
- when ::Proc
- if filter.arity > 1
- return lambda { |target, _, &block|
- raise ArgumentError unless block
- target.instance_exec(target, block, &filter)
- }
+ def invert_lambda(l)
+ lambda { |*args, &blk| !l.call(*args, &blk) }
end
- if filter.arity <= 0
- lambda { |target, _| target.instance_exec(&filter) }
- else
- lambda { |target, _| target.instance_exec(target, &filter) }
- end
- else
- scopes = Array(chain_config[:scope])
- method_to_call = scopes.map{ |s| public_send(s) }.join("_")
+ # Filters support:
+ #
+ # Symbols:: A method to call.
+ # Strings:: Some content to evaluate.
+ # Procs:: A proc to call with the object.
+ # Objects:: An object with a <tt>before_foo</tt> method on it to call.
+ #
+ # All of these objects are converted into a lambda and handled
+ # the same after this point.
+ def make_lambda(filter)
+ case filter
+ when Symbol
+ lambda { |target, _, &blk| target.send filter, &blk }
+ when String
+ l = eval "lambda { |value| #{filter} }"
+ lambda { |target, value| target.instance_exec(value, &l) }
+ when Conditionals::Value then filter
+ when ::Proc
+ if filter.arity > 1
+ return lambda { |target, _, &block|
+ raise ArgumentError unless block
+ target.instance_exec(target, block, &filter)
+ }
+ end
- lambda { |target, _, &blk|
- filter.public_send method_to_call, target, &blk
- }
- end
- end
+ if filter.arity <= 0
+ lambda { |target, _| target.instance_exec(&filter) }
+ else
+ lambda { |target, _| target.instance_exec(target, &filter) }
+ end
+ else
+ scopes = Array(chain_config[:scope])
+ method_to_call = scopes.map{ |s| public_send(s) }.join("_")
- def compute_identifier(filter)
- case filter
- when String, ::Proc
- filter.object_id
- else
- filter
- end
- end
+ lambda { |target, _, &blk|
+ filter.public_send method_to_call, target, &blk
+ }
+ end
+ end
+
+ def compute_identifier(filter)
+ case filter
+ when String, ::Proc
+ filter.object_id
+ else
+ filter
+ end
+ end
- def conditions_lambdas
- @if.map { |c| make_lambda c } +
- @unless.map { |c| invert_lambda make_lambda c }
+ def conditions_lambdas
+ @if.map { |c| make_lambda c } +
+ @unless.map { |c| invert_lambda make_lambda c }
+ end
end
- end
# Execute before and after filters in a sequence instead of
# chaining them with nested lambda calls, see:
# https://github.com/rails/rails/issues/18011
- class CallbackSequence
- def initialize(&call)
- @call = call
- @before = []
- @after = []
- end
+ class CallbackSequence
+ def initialize(&call)
+ @call = call
+ @before = []
+ @after = []
+ end
- def before(&before)
- @before.unshift(before)
- self
- end
+ def before(&before)
+ @before.unshift(before)
+ self
+ end
- def after(&after)
- @after.push(after)
- self
- end
+ def after(&after)
+ @after.push(after)
+ self
+ end
- def around(&around)
- CallbackSequence.new do |arg|
- around.call(arg) {
- self.call(arg)
- }
+ def around(&around)
+ CallbackSequence.new do |arg|
+ around.call(arg) {
+ self.call(arg)
+ }
+ end
end
- end
- def call(arg)
- @before.each { |b| b.call(arg) }
- value = @call.call(arg)
- @after.each { |a| a.call(arg) }
- value
+ def call(arg)
+ @before.each { |b| b.call(arg) }
+ value = @call.call(arg)
+ @after.each { |a| a.call(arg) }
+ value
+ end
end
- end
# An Array with a compile method.
- class CallbackChain #:nodoc:#
- include Enumerable
-
- attr_reader :name, :config
-
- def initialize(name, config)
- @name = name
- @config = {
- scope: [:kind],
- terminator: default_terminator
- }.merge!(config)
- @chain = []
- @callbacks = nil
- @mutex = Mutex.new
- end
+ class CallbackChain #:nodoc:#
+ include Enumerable
+
+ attr_reader :name, :config
+
+ def initialize(name, config)
+ @name = name
+ @config = {
+ scope: [:kind],
+ terminator: default_terminator
+ }.merge!(config)
+ @chain = []
+ @callbacks = nil
+ @mutex = Mutex.new
+ end
- def each(&block); @chain.each(&block); end
- def index(o); @chain.index(o); end
- def empty?; @chain.empty?; end
+ def each(&block); @chain.each(&block); end
+ def index(o); @chain.index(o); end
+ def empty?; @chain.empty?; end
- def insert(index, o)
- @callbacks = nil
- @chain.insert(index, o)
- end
+ def insert(index, o)
+ @callbacks = nil
+ @chain.insert(index, o)
+ end
- def delete(o)
- @callbacks = nil
- @chain.delete(o)
- end
+ def delete(o)
+ @callbacks = nil
+ @chain.delete(o)
+ end
- def clear
- @callbacks = nil
- @chain.clear
- self
- end
+ def clear
+ @callbacks = nil
+ @chain.clear
+ self
+ end
- def initialize_copy(other)
- @callbacks = nil
- @chain = other.chain.dup
- @mutex = Mutex.new
- end
+ def initialize_copy(other)
+ @callbacks = nil
+ @chain = other.chain.dup
+ @mutex = Mutex.new
+ end
- def compile
- @callbacks || @mutex.synchronize do
- final_sequence = CallbackSequence.new { |env| Filters::ENDING.call(env) }
- @callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
- callback.apply callback_sequence
+ def compile
+ @callbacks || @mutex.synchronize do
+ final_sequence = CallbackSequence.new { |env| Filters::ENDING.call(env) }
+ @callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback|
+ callback.apply callback_sequence
+ end
end
end
- end
- def append(*callbacks)
- callbacks.each { |c| append_one(c) }
- end
-
- def prepend(*callbacks)
- callbacks.each { |c| prepend_one(c) }
- end
+ def append(*callbacks)
+ callbacks.each { |c| append_one(c) }
+ end
- protected
- def chain; @chain; end
+ def prepend(*callbacks)
+ callbacks.each { |c| prepend_one(c) }
+ end
- private
+ protected
+ def chain; @chain; end
- def append_one(callback)
- @callbacks = nil
- remove_duplicates(callback)
- @chain.push(callback)
- end
+ private
- def prepend_one(callback)
- @callbacks = nil
- remove_duplicates(callback)
- @chain.unshift(callback)
- end
+ def append_one(callback)
+ @callbacks = nil
+ remove_duplicates(callback)
+ @chain.push(callback)
+ end
- def remove_duplicates(callback)
- @callbacks = nil
- @chain.delete_if { |c| callback.duplicates?(c) }
- end
+ def prepend_one(callback)
+ @callbacks = nil
+ remove_duplicates(callback)
+ @chain.unshift(callback)
+ end
- def default_terminator
- Proc.new do |target, result_lambda|
- terminate = true
- catch(:abort) do
- result_lambda.call if result_lambda.is_a?(Proc)
- terminate = false
+ def remove_duplicates(callback)
+ @callbacks = nil
+ @chain.delete_if { |c| callback.duplicates?(c) }
end
- terminate
- end
- end
- end
- module ClassMethods
- def normalize_callback_params(filters, block) # :nodoc:
- type = CALLBACK_FILTER_TYPES.include?(filters.first) ? filters.shift : :before
- options = filters.extract_options!
- filters.unshift(block) if block
- [type, filters, options.dup]
+ def default_terminator
+ Proc.new do |target, result_lambda|
+ terminate = true
+ catch(:abort) do
+ result_lambda.call if result_lambda.is_a?(Proc)
+ terminate = false
+ end
+ terminate
+ end
+ end
end
- # This is used internally to append, prepend and skip callbacks to the
- # CallbackChain.
- def __update_callbacks(name) #:nodoc:
- ([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse_each do |target|
- chain = target.get_callbacks name
- yield target, chain.dup
+ module ClassMethods
+ def normalize_callback_params(filters, block) # :nodoc:
+ type = CALLBACK_FILTER_TYPES.include?(filters.first) ? filters.shift : :before
+ options = filters.extract_options!
+ filters.unshift(block) if block
+ [type, filters, options.dup]
end
- end
- # Install a callback for the given event.
- #
- # set_callback :save, :before, :before_method
- # set_callback :save, :after, :after_method, if: :condition
- # set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff }
- #
- # The second argument indicates whether the callback is to be run +:before+,
- # +:after+, or +:around+ the event. If omitted, +:before+ is assumed. This
- # means the first example above can also be written as:
- #
- # set_callback :save, :before_method
- #
- # The callback can be specified as a symbol naming an instance method; as a
- # proc, lambda, or block; as a string to be instance evaluated(deprecated); or as an
- # object that responds to a certain method determined by the <tt>:scope</tt>
- # argument to +define_callbacks+.
- #
- # If a proc, lambda, or block is given, its body is evaluated in the context
- # of the current object. It can also optionally accept the current object as
- # an argument.
- #
- # Before and around callbacks are called in the order that they are set;
- # after callbacks are called in the reverse order.
- #
- # Around callbacks can access the return value from the event, if it
- # wasn't halted, from the +yield+ call.
- #
- # ===== Options
- #
- # * <tt>:if</tt> - A symbol, a string or an array of symbols and strings,
- # each naming an instance method or a proc; the callback will be called
- # only when they all return a true value.
- # * <tt>:unless</tt> - A symbol, a string or an array of symbols and
- # strings, each naming an instance method or a proc; the callback will
- # be called only when they all return a false value.
- # * <tt>:prepend</tt> - If +true+, the callback will be prepended to the
- # existing chain rather than appended.
- def set_callback(name, *filter_list, &block)
- type, filters, options = normalize_callback_params(filter_list, block)
- self_chain = get_callbacks name
- mapped = filters.map do |filter|
- Callback.build(self_chain, filter, type, options)
+ # This is used internally to append, prepend and skip callbacks to the
+ # CallbackChain.
+ def __update_callbacks(name) #:nodoc:
+ ([self] + ActiveSupport::DescendantsTracker.descendants(self)).reverse_each do |target|
+ chain = target.get_callbacks name
+ yield target, chain.dup
+ end
end
- __update_callbacks(name) do |target, chain|
- options[:prepend] ? chain.prepend(*mapped) : chain.append(*mapped)
- target.set_callbacks name, chain
+ # Install a callback for the given event.
+ #
+ # set_callback :save, :before, :before_method
+ # set_callback :save, :after, :after_method, if: :condition
+ # set_callback :save, :around, ->(r, block) { stuff; result = block.call; stuff }
+ #
+ # The second argument indicates whether the callback is to be run +:before+,
+ # +:after+, or +:around+ the event. If omitted, +:before+ is assumed. This
+ # means the first example above can also be written as:
+ #
+ # set_callback :save, :before_method
+ #
+ # The callback can be specified as a symbol naming an instance method; as a
+ # proc, lambda, or block; as a string to be instance evaluated(deprecated); or as an
+ # object that responds to a certain method determined by the <tt>:scope</tt>
+ # argument to +define_callbacks+.
+ #
+ # If a proc, lambda, or block is given, its body is evaluated in the context
+ # of the current object. It can also optionally accept the current object as
+ # an argument.
+ #
+ # Before and around callbacks are called in the order that they are set;
+ # after callbacks are called in the reverse order.
+ #
+ # Around callbacks can access the return value from the event, if it
+ # wasn't halted, from the +yield+ call.
+ #
+ # ===== Options
+ #
+ # * <tt>:if</tt> - A symbol, a string or an array of symbols and strings,
+ # each naming an instance method or a proc; the callback will be called
+ # only when they all return a true value.
+ # * <tt>:unless</tt> - A symbol, a string or an array of symbols and
+ # strings, each naming an instance method or a proc; the callback will
+ # be called only when they all return a false value.
+ # * <tt>:prepend</tt> - If +true+, the callback will be prepended to the
+ # existing chain rather than appended.
+ def set_callback(name, *filter_list, &block)
+ type, filters, options = normalize_callback_params(filter_list, block)
+ self_chain = get_callbacks name
+ mapped = filters.map do |filter|
+ Callback.build(self_chain, filter, type, options)
+ end
+
+ __update_callbacks(name) do |target, chain|
+ options[:prepend] ? chain.prepend(*mapped) : chain.append(*mapped)
+ target.set_callbacks name, chain
+ end
end
- end
- # Skip a previously set callback. Like +set_callback+, <tt>:if</tt> or
- # <tt>:unless</tt> options may be passed in order to control when the
- # callback is skipped.
- #
- # class Writer < Person
- # skip_callback :validate, :before, :check_membership, if: -> { self.age > 18 }
- # end
- #
- # An <tt>ArgumentError</tt> will be raised if the callback has not
- # already been set (unless the <tt>:raise</tt> option is set to <tt>false</tt>).
- def skip_callback(name, *filter_list, &block)
- type, filters, options = normalize_callback_params(filter_list, block)
- options[:raise] = true unless options.key?(:raise)
-
- __update_callbacks(name) do |target, chain|
- filters.each do |filter|
- callback = chain.find {|c| c.matches?(type, filter) }
-
- if !callback && options[:raise]
- raise ArgumentError, "#{type.to_s.capitalize} #{name} callback #{filter.inspect} has not been defined"
- end
+ # Skip a previously set callback. Like +set_callback+, <tt>:if</tt> or
+ # <tt>:unless</tt> options may be passed in order to control when the
+ # callback is skipped.
+ #
+ # class Writer < Person
+ # skip_callback :validate, :before, :check_membership, if: -> { self.age > 18 }
+ # end
+ #
+ # An <tt>ArgumentError</tt> will be raised if the callback has not
+ # already been set (unless the <tt>:raise</tt> option is set to <tt>false</tt>).
+ def skip_callback(name, *filter_list, &block)
+ type, filters, options = normalize_callback_params(filter_list, block)
+ options[:raise] = true unless options.key?(:raise)
+
+ __update_callbacks(name) do |target, chain|
+ filters.each do |filter|
+ callback = chain.find {|c| c.matches?(type, filter) }
+
+ if !callback && options[:raise]
+ raise ArgumentError, "#{type.to_s.capitalize} #{name} callback #{filter.inspect} has not been defined"
+ end
- if callback && (options.key?(:if) || options.key?(:unless))
- new_callback = callback.merge_conditional_options(chain, if_option: options[:if], unless_option: options[:unless])
- chain.insert(chain.index(callback), new_callback)
- end
+ if callback && (options.key?(:if) || options.key?(:unless))
+ new_callback = callback.merge_conditional_options(chain, if_option: options[:if], unless_option: options[:unless])
+ chain.insert(chain.index(callback), new_callback)
+ end
- chain.delete(callback)
+ chain.delete(callback)
+ end
+ target.set_callbacks name, chain
end
- target.set_callbacks name, chain
end
- end
- # Remove all set callbacks for the given event.
- def reset_callbacks(name)
- callbacks = get_callbacks name
+ # Remove all set callbacks for the given event.
+ def reset_callbacks(name)
+ callbacks = get_callbacks name
- ActiveSupport::DescendantsTracker.descendants(self).each do |target|
- chain = target.get_callbacks(name).dup
- callbacks.each { |c| chain.delete(c) }
- target.set_callbacks name, chain
- end
+ ActiveSupport::DescendantsTracker.descendants(self).each do |target|
+ chain = target.get_callbacks(name).dup
+ callbacks.each { |c| chain.delete(c) }
+ target.set_callbacks name, chain
+ end
- self.set_callbacks name, callbacks.dup.clear
- end
+ self.set_callbacks name, callbacks.dup.clear
+ end
- # Define sets of events in the object life cycle that support callbacks.
- #
- # define_callbacks :validate
- # define_callbacks :initialize, :save, :destroy
- #
- # ===== Options
- #
- # * <tt>:terminator</tt> - Determines when a before filter will halt the
- # callback chain, preventing following before and around callbacks from
- # being called and the event from being triggered.
- # This should be a lambda to be executed.
- # The current object and the result lambda of the callback will be provided
- # to the terminator lambda.
- #
- # define_callbacks :validate, terminator: ->(target, result_lambda) { result_lambda.call == false }
- #
- # In this example, if any before validate callbacks returns +false+,
- # any successive before and around callback is not executed.
- #
- # The default terminator halts the chain when a callback throws +:abort+.
- #
- # * <tt>:skip_after_callbacks_if_terminated</tt> - Determines if after
- # callbacks should be terminated by the <tt>:terminator</tt> option. By
- # default after callbacks are executed no matter if callback chain was
- # terminated or not. This option makes sense only when <tt>:terminator</tt>
- # option is specified.
- #
- # * <tt>:scope</tt> - Indicates which methods should be executed when an
- # object is used as a callback.
- #
- # class Audit
- # def before(caller)
- # puts 'Audit: before is called'
- # end
- #
- # def before_save(caller)
- # puts 'Audit: before_save is called'
- # end
- # end
- #
- # class Account
- # include ActiveSupport::Callbacks
- #
- # define_callbacks :save
- # set_callback :save, :before, Audit.new
- #
- # def save
- # run_callbacks :save do
- # puts 'save in main'
- # end
- # end
- # end
- #
- # In the above case whenever you save an account the method
- # <tt>Audit#before</tt> will be called. On the other hand
- #
- # define_callbacks :save, scope: [:kind, :name]
- #
- # would trigger <tt>Audit#before_save</tt> instead. That's constructed
- # by calling <tt>#{kind}_#{name}</tt> on the given instance. In this
- # case "kind" is "before" and "name" is "save". In this context +:kind+
- # and +:name+ have special meanings: +:kind+ refers to the kind of
- # callback (before/after/around) and +:name+ refers to the method on
- # which callbacks are being defined.
- #
- # A declaration like
- #
- # define_callbacks :save, scope: [:name]
- #
- # would call <tt>Audit#save</tt>.
- #
- # ===== Notes
- #
- # +names+ passed to `define_callbacks` must not end with
- # `!`, `?` or `=`.
- #
- # Calling `define_callbacks` multiple times with the same +names+ will
- # overwrite previous callbacks registered with `set_callback`.
- def define_callbacks(*names)
- options = names.extract_options!
-
- names.each do |name|
- class_attribute "_#{name}_callbacks", instance_writer: false
- set_callbacks name, CallbackChain.new(name, options)
-
- module_eval <<-RUBY, __FILE__, __LINE__ + 1
+ # Define sets of events in the object life cycle that support callbacks.
+ #
+ # define_callbacks :validate
+ # define_callbacks :initialize, :save, :destroy
+ #
+ # ===== Options
+ #
+ # * <tt>:terminator</tt> - Determines when a before filter will halt the
+ # callback chain, preventing following before and around callbacks from
+ # being called and the event from being triggered.
+ # This should be a lambda to be executed.
+ # The current object and the result lambda of the callback will be provided
+ # to the terminator lambda.
+ #
+ # define_callbacks :validate, terminator: ->(target, result_lambda) { result_lambda.call == false }
+ #
+ # In this example, if any before validate callbacks returns +false+,
+ # any successive before and around callback is not executed.
+ #
+ # The default terminator halts the chain when a callback throws +:abort+.
+ #
+ # * <tt>:skip_after_callbacks_if_terminated</tt> - Determines if after
+ # callbacks should be terminated by the <tt>:terminator</tt> option. By
+ # default after callbacks are executed no matter if callback chain was
+ # terminated or not. This option makes sense only when <tt>:terminator</tt>
+ # option is specified.
+ #
+ # * <tt>:scope</tt> - Indicates which methods should be executed when an
+ # object is used as a callback.
+ #
+ # class Audit
+ # def before(caller)
+ # puts 'Audit: before is called'
+ # end
+ #
+ # def before_save(caller)
+ # puts 'Audit: before_save is called'
+ # end
+ # end
+ #
+ # class Account
+ # include ActiveSupport::Callbacks
+ #
+ # define_callbacks :save
+ # set_callback :save, :before, Audit.new
+ #
+ # def save
+ # run_callbacks :save do
+ # puts 'save in main'
+ # end
+ # end
+ # end
+ #
+ # In the above case whenever you save an account the method
+ # <tt>Audit#before</tt> will be called. On the other hand
+ #
+ # define_callbacks :save, scope: [:kind, :name]
+ #
+ # would trigger <tt>Audit#before_save</tt> instead. That's constructed
+ # by calling <tt>#{kind}_#{name}</tt> on the given instance. In this
+ # case "kind" is "before" and "name" is "save". In this context +:kind+
+ # and +:name+ have special meanings: +:kind+ refers to the kind of
+ # callback (before/after/around) and +:name+ refers to the method on
+ # which callbacks are being defined.
+ #
+ # A declaration like
+ #
+ # define_callbacks :save, scope: [:name]
+ #
+ # would call <tt>Audit#save</tt>.
+ #
+ # ===== Notes
+ #
+ # +names+ passed to `define_callbacks` must not end with
+ # `!`, `?` or `=`.
+ #
+ # Calling `define_callbacks` multiple times with the same +names+ will
+ # overwrite previous callbacks registered with `set_callback`.
+ def define_callbacks(*names)
+ options = names.extract_options!
+
+ names.each do |name|
+ class_attribute "_#{name}_callbacks", instance_writer: false
+ set_callbacks name, CallbackChain.new(name, options)
+
+ module_eval <<-RUBY, __FILE__, __LINE__ + 1
def _run_#{name}_callbacks(&block)
__run_callbacks__(_#{name}_callbacks, &block)
end
RUBY
+ end
end
- end
- protected
+ protected
- def get_callbacks(name) # :nodoc:
- send "_#{name}_callbacks"
- end
+ def get_callbacks(name) # :nodoc:
+ send "_#{name}_callbacks"
+ end
- def set_callbacks(name, callbacks) # :nodoc:
- send "_#{name}_callbacks=", callbacks
- end
+ def set_callbacks(name, callbacks) # :nodoc:
+ send "_#{name}_callbacks=", callbacks
+ end
- def deprecated_false_terminator # :nodoc:
- Proc.new do |target, result_lambda|
- terminate = true
- catch(:abort) do
- result = result_lambda.call if result_lambda.is_a?(Proc)
- if Callbacks.halt_and_display_warning_on_return_false && result == false
- display_deprecation_warning_for_false_terminator
- else
- terminate = false
+ def deprecated_false_terminator # :nodoc:
+ Proc.new do |target, result_lambda|
+ terminate = true
+ catch(:abort) do
+ result = result_lambda.call if result_lambda.is_a?(Proc)
+ if Callbacks.halt_and_display_warning_on_return_false && result == false
+ display_deprecation_warning_for_false_terminator
+ else
+ terminate = false
+ end
+ end
+ terminate
end
end
- terminate
- end
- end
- private
+ private
- def display_deprecation_warning_for_false_terminator
- ActiveSupport::Deprecation.warn(<<-MSG.squish)
+ def display_deprecation_warning_for_false_terminator
+ ActiveSupport::Deprecation.warn(<<-MSG.squish)
Returning `false` in Active Record and Active Model callbacks will not implicitly halt a callback chain in Rails 5.1.
To explicitly halt the callback chain, please use `throw :abort` instead.
MSG
+ end
end
- end
end
end
diff --git a/activesupport/lib/active_support/concurrency/share_lock.rb b/activesupport/lib/active_support/concurrency/share_lock.rb
index f57e81bad8..e61dadd0cc 100644
--- a/activesupport/lib/active_support/concurrency/share_lock.rb
+++ b/activesupport/lib/active_support/concurrency/share_lock.rb
@@ -201,26 +201,26 @@ module ActiveSupport
private
# Must be called within synchronize
- def busy_for_exclusive?(purpose)
- busy_for_sharing?(purpose) ||
- @sharing.size > (@sharing[Thread.current] > 0 ? 1 : 0)
- end
+ def busy_for_exclusive?(purpose)
+ busy_for_sharing?(purpose) ||
+ @sharing.size > (@sharing[Thread.current] > 0 ? 1 : 0)
+ end
- def busy_for_sharing?(purpose)
- (@exclusive_thread && @exclusive_thread != Thread.current) ||
- @waiting.any? { |t, (_, c)| t != Thread.current && !c.include?(purpose) }
- end
+ def busy_for_sharing?(purpose)
+ (@exclusive_thread && @exclusive_thread != Thread.current) ||
+ @waiting.any? { |t, (_, c)| t != Thread.current && !c.include?(purpose) }
+ end
- def eligible_waiters?(compatible)
- @waiting.any? { |t, (p, _)| compatible.include?(p) && @waiting.all? { |t2, (_, c2)| t == t2 || c2.include?(p) } }
- end
+ def eligible_waiters?(compatible)
+ @waiting.any? { |t, (p, _)| compatible.include?(p) && @waiting.all? { |t2, (_, c2)| t == t2 || c2.include?(p) } }
+ end
- def wait_for(method)
- @sleeping[Thread.current] = method
- @cv.wait_while { yield }
- ensure
- @sleeping.delete Thread.current
- end
+ def wait_for(method)
+ @sleeping[Thread.current] = method
+ @cv.wait_while { yield }
+ ensure
+ @sleeping.delete Thread.current
+ end
end
end
end
diff --git a/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb b/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb
index f8d48b69df..16a6789f8d 100644
--- a/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb
+++ b/activesupport/lib/active_support/core_ext/array/prepend_and_append.rb
@@ -4,4 +4,4 @@ class Array
# The human way of thinking about adding stuff to the beginning of a list is with prepend.
alias_method :prepend, :unshift
-end \ No newline at end of file
+end
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 5cc4e936cd..2e64097933 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -129,7 +129,7 @@ class Date
options.fetch(:day, day)
)
end
-
+
# Allow Date to be compared with Time by converting to DateTime and relying on the <=> from there.
def compare_with_coercion(other)
if other.is_a?(Time)
diff --git a/activesupport/lib/active_support/core_ext/date_and_time/zones.rb b/activesupport/lib/active_support/core_ext/date_and_time/zones.rb
index e2432c8f8a..c5b46c598c 100644
--- a/activesupport/lib/active_support/core_ext/date_and_time/zones.rb
+++ b/activesupport/lib/active_support/core_ext/date_and_time/zones.rb
@@ -28,13 +28,12 @@ module DateAndTime
private
- def time_with_zone(time, zone)
- if time
- ActiveSupport::TimeWithZone.new(time.utc? ? time : time.getutc, zone)
- else
- ActiveSupport::TimeWithZone.new(nil, zone, to_time(:utc))
+ def time_with_zone(time, zone)
+ if time
+ ActiveSupport::TimeWithZone.new(time.utc? ? time : time.getutc, zone)
+ else
+ ActiveSupport::TimeWithZone.new(nil, zone, to_time(:utc))
+ end
end
- end
end
end
-
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 9fa64bbcdb..44ae96dbe8 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -95,11 +95,11 @@ class DateTime
private
- def offset_in_seconds
- (offset * 86400).to_i
- end
+ def offset_in_seconds
+ (offset * 86400).to_i
+ end
- def seconds_since_unix_epoch
- (jd - 2440588) * 86400 - offset_in_seconds + seconds_since_midnight
- end
+ def seconds_since_unix_epoch
+ (jd - 2440588) * 86400 - offset_in_seconds + seconds_since_midnight
+ end
end
diff --git a/activesupport/lib/active_support/core_ext/hash/slice.rb b/activesupport/lib/active_support/core_ext/hash/slice.rb
index 1d5f38231a..161b00dfb3 100644
--- a/activesupport/lib/active_support/core_ext/hash/slice.rb
+++ b/activesupport/lib/active_support/core_ext/hash/slice.rb
@@ -1,11 +1,11 @@
class Hash
- # Slices a hash to include only the given keys. Returns a hash containing
+ # Slices a hash to include only the given keys. Returns a hash containing
# the given keys.
- #
+ #
# { a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)
# # => {:a=>1, :b=>2}
- #
- # This is useful for limiting an options hash to valid keys before
+ #
+ # This is useful for limiting an options hash to valid keys before
# passing to a method:
#
# def search(criteria = {})
diff --git a/activesupport/lib/active_support/core_ext/numeric/inquiry.rb b/activesupport/lib/active_support/core_ext/numeric/inquiry.rb
index 7e7ac1b0b2..ec79701189 100644
--- a/activesupport/lib/active_support/core_ext/numeric/inquiry.rb
+++ b/activesupport/lib/active_support/core_ext/numeric/inquiry.rb
@@ -1,26 +1,26 @@
unless 1.respond_to?(:positive?) # TODO: Remove this file when we drop support to ruby < 2.3
-class Numeric
- # Returns true if the number is positive.
- #
- # 1.positive? # => true
- # 0.positive? # => false
- # -1.positive? # => false
- def positive?
- self > 0
- end
+ class Numeric
+ # Returns true if the number is positive.
+ #
+ # 1.positive? # => true
+ # 0.positive? # => false
+ # -1.positive? # => false
+ def positive?
+ self > 0
+ end
- # Returns true if the number is negative.
- #
- # -1.negative? # => true
- # 0.negative? # => false
- # 1.negative? # => false
- def negative?
- self < 0
+ # Returns true if the number is negative.
+ #
+ # -1.negative? # => true
+ # 0.negative? # => false
+ # 1.negative? # => false
+ def negative?
+ self < 0
+ end
end
-end
-class Complex
- undef :positive?
- undef :negative?
-end
+ class Complex
+ undef :positive?
+ undef :negative?
+ end
end
diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb
index 26d5c43ae9..bf94b97ceb 100644
--- a/activesupport/lib/active_support/core_ext/string/inflections.rb
+++ b/activesupport/lib/active_support/core_ext/string/inflections.rb
@@ -164,7 +164,7 @@ class String
#
# <%= link_to(@person.name, person_path) %>
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
- #
+ #
# To preserve the case of the characters in a string, use the `preserve_case` argument.
#
# class Person
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb
index d01a837fc9..2b7e556ced 100644
--- a/activesupport/lib/active_support/core_ext/string/output_safety.rb
+++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -243,9 +243,9 @@ module ActiveSupport #:nodoc:
private
- def html_escape_interpolated_argument(arg)
- (!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
- end
+ def html_escape_interpolated_argument(arg)
+ (!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
+ end
end
end
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index 73ca737c82..9f1593a23a 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -170,9 +170,9 @@ module ActiveSupport #:nodoc:
end
private
- def pop_modules(modules)
- modules.each { |mod| @stack[mod].pop }
- end
+ def pop_modules(modules)
+ modules.each { |mod| @stack[mod].pop }
+ end
end
# An internal stack used to record which constants are loaded by any block.
@@ -282,17 +282,17 @@ module ActiveSupport #:nodoc:
private
- def load(file, wrap = false)
- result = false
- load_dependency(file) { result = super }
- result
- end
+ def load(file, wrap = false)
+ result = false
+ load_dependency(file) { result = super }
+ result
+ end
- def require(file)
- result = false
- load_dependency(file) { result = super }
- result
- end
+ def require(file)
+ result = false
+ load_dependency(file) { result = super }
+ result
+ end
end
# Exception file-blaming.
diff --git a/activesupport/lib/active_support/duration/iso8601_parser.rb b/activesupport/lib/active_support/duration/iso8601_parser.rb
index 3f113b1ef0..99a77c0bd3 100644
--- a/activesupport/lib/active_support/duration/iso8601_parser.rb
+++ b/activesupport/lib/active_support/duration/iso8601_parser.rb
@@ -80,44 +80,44 @@ module ActiveSupport
private
- def finished?
- scanner.eos?
- end
+ def finished?
+ scanner.eos?
+ end
# Parses number which can be a float with either comma or period.
- def number
- PERIOD_OR_COMMA.match?(scanner[1]) ? scanner[1].tr(COMMA, PERIOD).to_f : scanner[1].to_i
- end
+ def number
+ PERIOD_OR_COMMA.match?(scanner[1]) ? scanner[1].tr(COMMA, PERIOD).to_f : scanner[1].to_i
+ end
- def scan(pattern)
- scanner.scan(pattern)
- end
+ def scan(pattern)
+ scanner.scan(pattern)
+ end
- def raise_parsing_error(reason = nil)
- raise ParsingError, "Invalid ISO 8601 duration: #{scanner.string.inspect} #{reason}".strip
- end
+ def raise_parsing_error(reason = nil)
+ raise ParsingError, "Invalid ISO 8601 duration: #{scanner.string.inspect} #{reason}".strip
+ end
# Checks for various semantic errors as stated in ISO 8601 standard.
- def validate!
- raise_parsing_error("is empty duration") if parts.empty?
+ def validate!
+ raise_parsing_error("is empty duration") if parts.empty?
- # Mixing any of Y, M, D with W is invalid.
- if parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any?
- raise_parsing_error("mixing weeks with other date parts not allowed")
- end
+ # Mixing any of Y, M, D with W is invalid.
+ if parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any?
+ raise_parsing_error("mixing weeks with other date parts not allowed")
+ end
- # Specifying an empty T part is invalid.
- if mode == :time && (parts.keys & TIME_COMPONENTS).empty?
- raise_parsing_error("time part marker is present but time part is empty")
- end
+ # Specifying an empty T part is invalid.
+ if mode == :time && (parts.keys & TIME_COMPONENTS).empty?
+ raise_parsing_error("time part marker is present but time part is empty")
+ end
- fractions = parts.values.reject(&:zero?).select { |a| (a % 1) != 0 }
- unless fractions.empty? || (fractions.size == 1 && fractions.last == @parts.values.reject(&:zero?).last)
- raise_parsing_error "(only last part can be fractional)"
- end
+ fractions = parts.values.reject(&:zero?).select { |a| (a % 1) != 0 }
+ unless fractions.empty? || (fractions.size == 1 && fractions.last == @parts.values.reject(&:zero?).last)
+ raise_parsing_error "(only last part can be fractional)"
+ end
- return true
- end
+ return true
+ end
end
end
end
diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb
index 576cd869e5..f54f88eb0a 100644
--- a/activesupport/lib/active_support/evented_file_update_checker.rb
+++ b/activesupport/lib/active_support/evented_file_update_checker.rb
@@ -124,71 +124,71 @@ module ActiveSupport
@ph.filter_out_descendants(dtw)
end
- class PathHelper
- def xpath(path)
- Pathname.new(path).expand_path
- end
+ class PathHelper
+ def xpath(path)
+ Pathname.new(path).expand_path
+ end
- def normalize_extension(ext)
- ext.to_s.sub(/\A\./, "")
- end
+ def normalize_extension(ext)
+ ext.to_s.sub(/\A\./, "")
+ end
- # Given a collection of Pathname objects returns the longest subpath
- # common to all of them, or +nil+ if there is none.
- def longest_common_subpath(paths)
- return if paths.empty?
-
- lcsp = Pathname.new(paths[0])
-
- paths[1..-1].each do |path|
- until ascendant_of?(lcsp, path)
- if lcsp.root?
- # If we get here a root directory is not an ascendant of path.
- # This may happen if there are paths in different drives on
- # Windows.
- return
- else
- lcsp = lcsp.parent
+ # Given a collection of Pathname objects returns the longest subpath
+ # common to all of them, or +nil+ if there is none.
+ def longest_common_subpath(paths)
+ return if paths.empty?
+
+ lcsp = Pathname.new(paths[0])
+
+ paths[1..-1].each do |path|
+ until ascendant_of?(lcsp, path)
+ if lcsp.root?
+ # If we get here a root directory is not an ascendant of path.
+ # This may happen if there are paths in different drives on
+ # Windows.
+ return
+ else
+ lcsp = lcsp.parent
+ end
end
end
- end
- lcsp
- end
+ lcsp
+ end
- # Returns the deepest existing ascendant, which could be the argument itself.
- def existing_parent(dir)
- dir.ascend do |ascendant|
- break ascendant if ascendant.directory?
+ # Returns the deepest existing ascendant, which could be the argument itself.
+ def existing_parent(dir)
+ dir.ascend do |ascendant|
+ break ascendant if ascendant.directory?
+ end
end
- end
- # Filters out directories which are descendants of others in the collection (stable).
- def filter_out_descendants(dirs)
- return dirs if dirs.length < 2
+ # Filters out directories which are descendants of others in the collection (stable).
+ def filter_out_descendants(dirs)
+ return dirs if dirs.length < 2
- dirs_sorted_by_nparts = dirs.sort_by { |dir| dir.each_filename.to_a.length }
- descendants = []
+ dirs_sorted_by_nparts = dirs.sort_by { |dir| dir.each_filename.to_a.length }
+ descendants = []
- until dirs_sorted_by_nparts.empty?
- dir = dirs_sorted_by_nparts.shift
+ until dirs_sorted_by_nparts.empty?
+ dir = dirs_sorted_by_nparts.shift
- dirs_sorted_by_nparts.reject! do |possible_descendant|
- ascendant_of?(dir, possible_descendant) && descendants << possible_descendant
+ dirs_sorted_by_nparts.reject! do |possible_descendant|
+ ascendant_of?(dir, possible_descendant) && descendants << possible_descendant
+ end
end
- end
- # Array#- preserves order.
- dirs - descendants
- end
+ # Array#- preserves order.
+ dirs - descendants
+ end
- private
+ private
- def ascendant_of?(base, other)
- base != other && other.ascend do |ascendant|
- break true if base == ascendant
+ def ascendant_of?(base, other)
+ base != other && other.ascend do |ascendant|
+ break true if base == ascendant
+ end
end
- end
- end
+ end
end
end
diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb
index 6befd1de51..0b7d67e37a 100644
--- a/activesupport/lib/active_support/file_update_checker.rb
+++ b/activesupport/lib/active_support/file_update_checker.rb
@@ -93,17 +93,17 @@ module ActiveSupport
private
- def watched
- @watched || begin
- all = @files.select { |f| File.exist?(f) }
- all.concat(Dir[@glob]) if @glob
- all
+ def watched
+ @watched || begin
+ all = @files.select { |f| File.exist?(f) }
+ all.concat(Dir[@glob]) if @glob
+ all
+ end
end
- end
- def updated_at(paths)
- @updated_at || max_mtime(paths) || Time.at(0)
- end
+ def updated_at(paths)
+ @updated_at || max_mtime(paths) || Time.at(0)
+ end
# This method returns the maximum mtime of the files in +paths+, or +nil+
# if the array is empty.
@@ -112,46 +112,46 @@ module ActiveSupport
# can happen for example if the user changes the clock by hand. It is
# healthy to consider this edge case because with mtimes in the future
# reloading is not triggered.
- def max_mtime(paths)
- time_now = Time.now
- max_mtime = nil
-
- # Time comparisons are performed with #compare_without_coercion because
- # AS redefines these operators in a way that is much slower and does not
- # bring any benefit in this particular code.
- #
- # Read t1.compare_without_coercion(t2) < 0 as t1 < t2.
- paths.each do |path|
- mtime = File.mtime(path)
-
- next if time_now.compare_without_coercion(mtime) < 0
-
- if max_mtime.nil? || max_mtime.compare_without_coercion(mtime) < 0
- max_mtime = mtime
+ def max_mtime(paths)
+ time_now = Time.now
+ max_mtime = nil
+
+ # Time comparisons are performed with #compare_without_coercion because
+ # AS redefines these operators in a way that is much slower and does not
+ # bring any benefit in this particular code.
+ #
+ # Read t1.compare_without_coercion(t2) < 0 as t1 < t2.
+ paths.each do |path|
+ mtime = File.mtime(path)
+
+ next if time_now.compare_without_coercion(mtime) < 0
+
+ if max_mtime.nil? || max_mtime.compare_without_coercion(mtime) < 0
+ max_mtime = mtime
+ end
end
- end
- max_mtime
- end
+ max_mtime
+ end
- def compile_glob(hash)
- hash.freeze # Freeze so changes aren't accidentally pushed
- return if hash.empty?
+ def compile_glob(hash)
+ hash.freeze # Freeze so changes aren't accidentally pushed
+ return if hash.empty?
- globs = hash.map do |key, value|
- "#{escape(key)}/**/*#{compile_ext(value)}"
+ globs = hash.map do |key, value|
+ "#{escape(key)}/**/*#{compile_ext(value)}"
+ end
+ "{#{globs.join(",")}}"
end
- "{#{globs.join(",")}}"
- end
- def escape(key)
- key.gsub(",",'\,')
- end
+ def escape(key)
+ key.gsub(",",'\,')
+ end
- def compile_ext(array)
- array = Array(array)
- return if array.empty?
- ".{#{array.join(",")}}"
- end
+ def compile_ext(array)
+ array = Array(array)
+ return if array.empty?
+ ".{#{array.join(",")}}"
+ end
end
end
diff --git a/activesupport/lib/active_support/gzip.rb b/activesupport/lib/active_support/gzip.rb
index 38734a56b5..4aee8dddba 100644
--- a/activesupport/lib/active_support/gzip.rb
+++ b/activesupport/lib/active_support/gzip.rb
@@ -9,7 +9,7 @@ module ActiveSupport
# # => "\x1F\x8B\b\x00o\x8D\xCDO\x00\x03K\xCE\xCF-(J-.V\xC8MU\x04\x00R>n\x83\f\x00\x00\x00"
#
# ActiveSupport::Gzip.decompress(gzip)
- # # => "compress me!"
+ # # => "compress me!"
module Gzip
class Stream < StringIO
def initialize(*)
diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb
index ddbdac4eae..fcfe063290 100644
--- a/activesupport/lib/active_support/inflector/methods.rb
+++ b/activesupport/lib/active_support/inflector/methods.rb
@@ -361,31 +361,31 @@ module ActiveSupport
#
# const_regexp("Foo::Bar::Baz") # => "Foo(::Bar(::Baz)?)?"
# const_regexp("::") # => "::"
- def const_regexp(camel_cased_word) #:nodoc:
- parts = camel_cased_word.split("::".freeze)
+ def const_regexp(camel_cased_word) #:nodoc:
+ parts = camel_cased_word.split("::".freeze)
- return Regexp.escape(camel_cased_word) if parts.blank?
+ return Regexp.escape(camel_cased_word) if parts.blank?
- last = parts.pop
+ last = parts.pop
- parts.reverse.inject(last) do |acc, part|
- part.empty? ? acc : "#{part}(::#{acc})?"
+ parts.reverse.inject(last) do |acc, part|
+ part.empty? ? acc : "#{part}(::#{acc})?"
+ end
end
- end
# Applies inflection rules for +singularize+ and +pluralize+.
#
# apply_inflections('post', inflections.plurals) # => "posts"
# apply_inflections('posts', inflections.singulars) # => "post"
- def apply_inflections(word, rules)
- result = word.to_s.dup
+ def apply_inflections(word, rules)
+ result = word.to_s.dup
- if word.empty? || inflections.uncountables.uncountable?(result)
- result
- else
- rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
- result
+ if word.empty? || inflections.uncountables.uncountable?(result)
+ result
+ else
+ rules.each { |(rule, replacement)| break if result.sub!(rule, replacement) }
+ result
+ end
end
- end
end
end
diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb
index 8f7c6987bc..3f4eeff2dd 100644
--- a/activesupport/lib/active_support/inflector/transliterate.rb
+++ b/activesupport/lib/active_support/inflector/transliterate.rb
@@ -104,7 +104,7 @@ module ActiveSupport
# Remove leading/trailing separator.
parameterized_string.gsub!(re_leading_trailing_separator, "".freeze)
end
-
+
parameterized_string.downcase! unless preserve_case
parameterized_string
end
diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb
index 8b7c5f170b..156cfc32f8 100644
--- a/activesupport/lib/active_support/key_generator.rb
+++ b/activesupport/lib/active_support/key_generator.rb
@@ -53,19 +53,19 @@ module ActiveSupport
# To prevent users from using something insecure like "Password" we make sure that the
# secret they've provided is at least 30 characters in length.
- def ensure_secret_secure(secret)
- if secret.blank?
- raise ArgumentError, "A secret is required to generate an integrity hash " \
- "for cookie session data. Set a secret_key_base of at least " \
- "#{SECRET_MIN_LENGTH} characters in config/secrets.yml."
- end
+ def ensure_secret_secure(secret)
+ if secret.blank?
+ raise ArgumentError, "A secret is required to generate an integrity hash " \
+ "for cookie session data. Set a secret_key_base of at least " \
+ "#{SECRET_MIN_LENGTH} characters in config/secrets.yml."
+ end
- if secret.length < SECRET_MIN_LENGTH
- raise ArgumentError, "Secret should be something secure, " \
- "like \"#{SecureRandom.hex(16)}\". The value you " \
- "provided, \"#{secret}\", is shorter than the minimum length " \
- "of #{SECRET_MIN_LENGTH} characters."
+ if secret.length < SECRET_MIN_LENGTH
+ raise ArgumentError, "Secret should be something secure, " \
+ "like \"#{SecureRandom.hex(16)}\". The value you " \
+ "provided, \"#{secret}\", is shorter than the minimum length " \
+ "of #{SECRET_MIN_LENGTH} characters."
+ end
end
- end
end
end
diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb
index 7db156b057..a7e30632f6 100644
--- a/activesupport/lib/active_support/log_subscriber/test_helper.rb
+++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb
@@ -62,11 +62,11 @@ module ActiveSupport
end
def method_missing(level, message = nil)
- if block_given?
- @logged[level] << yield
- else
- @logged[level] << message
- end
+ if block_given?
+ @logged[level] << yield
+ else
+ @logged[level] << message
+ end
end
def logged(level)
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb
index 2fe1e42273..c198e4e6f1 100644
--- a/activesupport/lib/active_support/message_encryptor.rb
+++ b/activesupport/lib/active_support/message_encryptor.rb
@@ -79,66 +79,66 @@ module ActiveSupport
private
- def _encrypt(value)
- cipher = new_cipher
- cipher.encrypt
- cipher.key = @secret
+ def _encrypt(value)
+ cipher = new_cipher
+ cipher.encrypt
+ cipher.key = @secret
- # Rely on OpenSSL for the initialization vector
- iv = cipher.random_iv
- cipher.auth_data = "" if aead_mode?
+ # Rely on OpenSSL for the initialization vector
+ iv = cipher.random_iv
+ cipher.auth_data = "" if aead_mode?
- encrypted_data = cipher.update(@serializer.dump(value))
- encrypted_data << cipher.final
+ encrypted_data = cipher.update(@serializer.dump(value))
+ encrypted_data << cipher.final
- blob = "#{::Base64.strict_encode64 encrypted_data}--#{::Base64.strict_encode64 iv}"
- blob << "--#{::Base64.strict_encode64 cipher.auth_tag}" if aead_mode?
- blob
- end
-
- def _decrypt(encrypted_message)
- cipher = new_cipher
- encrypted_data, iv, auth_tag = encrypted_message.split("--".freeze).map {|v| ::Base64.strict_decode64(v)}
-
- # Currently the OpenSSL bindings do not raise an error if auth_tag is
- # truncated, which would allow an attacker to easily forge it. See
- # https://github.com/ruby/openssl/issues/63
- raise InvalidMessage if aead_mode? && auth_tag.bytes.length != 16
-
- cipher.decrypt
- cipher.key = @secret
- cipher.iv = iv
- if aead_mode?
- cipher.auth_tag = auth_tag
- cipher.auth_data = ""
+ blob = "#{::Base64.strict_encode64 encrypted_data}--#{::Base64.strict_encode64 iv}"
+ blob << "--#{::Base64.strict_encode64 cipher.auth_tag}" if aead_mode?
+ blob
end
- decrypted_data = cipher.update(encrypted_data)
- decrypted_data << cipher.final
-
- @serializer.load(decrypted_data)
- rescue OpenSSLCipherError, TypeError, ArgumentError
- raise InvalidMessage
- end
+ def _decrypt(encrypted_message)
+ cipher = new_cipher
+ encrypted_data, iv, auth_tag = encrypted_message.split("--".freeze).map {|v| ::Base64.strict_decode64(v)}
+
+ # Currently the OpenSSL bindings do not raise an error if auth_tag is
+ # truncated, which would allow an attacker to easily forge it. See
+ # https://github.com/ruby/openssl/issues/63
+ raise InvalidMessage if aead_mode? && auth_tag.bytes.length != 16
+
+ cipher.decrypt
+ cipher.key = @secret
+ cipher.iv = iv
+ if aead_mode?
+ cipher.auth_tag = auth_tag
+ cipher.auth_data = ""
+ end
+
+ decrypted_data = cipher.update(encrypted_data)
+ decrypted_data << cipher.final
+
+ @serializer.load(decrypted_data)
+ rescue OpenSSLCipherError, TypeError, ArgumentError
+ raise InvalidMessage
+ end
- def new_cipher
- OpenSSL::Cipher.new(@cipher)
- end
+ def new_cipher
+ OpenSSL::Cipher.new(@cipher)
+ end
- def verifier
- @verifier
- end
+ def verifier
+ @verifier
+ end
- def aead_mode?
- @aead_mode ||= new_cipher.authenticated?
- end
+ def aead_mode?
+ @aead_mode ||= new_cipher.authenticated?
+ end
- def resolve_verifier
- if aead_mode?
- NullVerifier
- else
- MessageVerifier.new(@sign_secret || @secret, digest: @digest, serializer: NullSerializer)
+ def resolve_verifier
+ if aead_mode?
+ NullVerifier
+ else
+ MessageVerifier.new(@sign_secret || @secret, digest: @digest, serializer: NullSerializer)
+ end
end
- end
end
end
diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb
index 86f80a97e5..dfd87c9397 100644
--- a/activesupport/lib/active_support/multibyte/unicode.rb
+++ b/activesupport/lib/active_support/multibyte/unicode.rb
@@ -389,25 +389,25 @@ module ActiveSupport
private
- def apply_mapping(string, mapping) #:nodoc:
- database.codepoints
- string.each_codepoint.map do |codepoint|
- cp = database.codepoints[codepoint]
- if cp and (ncp = cp.send(mapping)) and ncp > 0
- ncp
- else
- codepoint
- end
- end.pack("U*")
- end
+ def apply_mapping(string, mapping) #:nodoc:
+ database.codepoints
+ string.each_codepoint.map do |codepoint|
+ cp = database.codepoints[codepoint]
+ if cp and (ncp = cp.send(mapping)) and ncp > 0
+ ncp
+ else
+ codepoint
+ end
+ end.pack("U*")
+ end
- def recode_windows1252_chars(string)
- string.encode(Encoding::UTF_8, Encoding::Windows_1252, invalid: :replace, undef: :replace)
- end
+ def recode_windows1252_chars(string)
+ string.encode(Encoding::UTF_8, Encoding::Windows_1252, invalid: :replace, undef: :replace)
+ end
- def database
- @database ||= UnicodeDatabase.new
- end
+ def database
+ @database ||= UnicodeDatabase.new
+ end
end
end
end
diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb
index 16e6ec95fb..23262d5398 100644
--- a/activesupport/lib/active_support/notifications/instrumenter.rb
+++ b/activesupport/lib/active_support/notifications/instrumenter.rb
@@ -44,9 +44,9 @@ module ActiveSupport
private
- def unique_id
- SecureRandom.hex(10)
- end
+ def unique_id
+ SecureRandom.hex(10)
+ end
end
class Event
diff --git a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb
index 2b8ff77986..78cb33aa62 100644
--- a/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb
+++ b/activesupport/lib/active_support/number_helper/number_to_human_size_converter.rb
@@ -59,4 +59,3 @@ module ActiveSupport
end
end
end
-
diff --git a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
index dee74fa7a6..07b1f18695 100644
--- a/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
+++ b/activesupport/lib/active_support/number_helper/number_to_phone_converter.rb
@@ -55,4 +55,3 @@ module ActiveSupport
end
end
end
-
diff --git a/activesupport/lib/active_support/testing/stream.rb b/activesupport/lib/active_support/testing/stream.rb
index 895192ad05..1d06b94559 100644
--- a/activesupport/lib/active_support/testing/stream.rb
+++ b/activesupport/lib/active_support/testing/stream.rb
@@ -3,40 +3,40 @@ module ActiveSupport
module Stream #:nodoc:
private
- def silence_stream(stream)
- old_stream = stream.dup
- stream.reopen(IO::NULL)
- stream.sync = true
- yield
- ensure
- stream.reopen(old_stream)
- old_stream.close
- end
+ def silence_stream(stream)
+ old_stream = stream.dup
+ stream.reopen(IO::NULL)
+ stream.sync = true
+ yield
+ ensure
+ stream.reopen(old_stream)
+ old_stream.close
+ end
- def quietly
- silence_stream(STDOUT) do
- silence_stream(STDERR) do
- yield
+ def quietly
+ silence_stream(STDOUT) do
+ silence_stream(STDERR) do
+ yield
+ end
end
end
- end
- def capture(stream)
- stream = stream.to_s
- captured_stream = Tempfile.new(stream)
- stream_io = eval("$#{stream}")
- origin_stream = stream_io.dup
- stream_io.reopen(captured_stream)
+ def capture(stream)
+ stream = stream.to_s
+ captured_stream = Tempfile.new(stream)
+ stream_io = eval("$#{stream}")
+ origin_stream = stream_io.dup
+ stream_io.reopen(captured_stream)
- yield
+ yield
- stream_io.rewind
- return captured_stream.read
- ensure
- captured_stream.close
- captured_stream.unlink
- stream_io.reopen(origin_stream)
- end
+ stream_io.rewind
+ return captured_stream.read
+ ensure
+ captured_stream.close
+ captured_stream.unlink
+ stream_io.reopen(origin_stream)
+ end
end
end
end
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index d805381d1e..26906d2911 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -227,11 +227,11 @@ module ActiveSupport
def [](arg)
case arg
when String
- begin
- @lazy_zones_map[arg] ||= create(arg)
- rescue TZInfo::InvalidTimezoneIdentifier
- nil
- end
+ begin
+ @lazy_zones_map[arg] ||= create(arg)
+ rescue TZInfo::InvalidTimezoneIdentifier
+ nil
+ end
when Numeric, ActiveSupport::Duration
arg *= 3600 if arg.abs <= 13
all.find { |z| z.utc_offset == arg.to_i }
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index 5611b1b143..12a7c61240 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -151,29 +151,29 @@ module ActiveSupport
protected
- def _dasherize(key)
- # $2 must be a non-greedy regex for this to work
- left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
- "#{left}#{middle.tr('_ ', '--')}#{right}"
- end
+ def _dasherize(key)
+ # $2 must be a non-greedy regex for this to work
+ left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
+ "#{left}#{middle.tr('_ ', '--')}#{right}"
+ end
# TODO: Add support for other encodings
- def _parse_binary(bin, entity) #:nodoc:
- case entity["encoding"]
- when "base64"
- ::Base64.decode64(bin)
- else
- bin
+ def _parse_binary(bin, entity) #:nodoc:
+ case entity["encoding"]
+ when "base64"
+ ::Base64.decode64(bin)
+ else
+ bin
+ end
end
- end
- def _parse_file(file, entity)
- f = StringIO.new(::Base64.decode64(file))
- f.extend(FileLike)
- f.original_filename = entity["name"]
- f.content_type = entity["content_type"]
- f
- end
+ def _parse_file(file, entity)
+ f = StringIO.new(::Base64.decode64(file))
+ f.extend(FileLike)
+ f.original_filename = entity["name"]
+ f.content_type = entity["content_type"]
+ f
+ end
private
diff --git a/activesupport/lib/active_support/xml_mini/jdom.rb b/activesupport/lib/active_support/xml_mini/jdom.rb
index 44923f8da9..90f6cc464f 100644
--- a/activesupport/lib/active_support/xml_mini/jdom.rb
+++ b/activesupport/lib/active_support/xml_mini/jdom.rb
@@ -58,35 +58,35 @@ module ActiveSupport
# Hash to merge the converted element into.
# element::
# XML element to merge into hash
- def merge_element!(hash, element, depth)
- raise "Document too deep!" if depth == 0
- delete_empty(hash)
- merge!(hash, element.tag_name, collapse(element, depth))
- end
+ def merge_element!(hash, element, depth)
+ raise "Document too deep!" if depth == 0
+ delete_empty(hash)
+ merge!(hash, element.tag_name, collapse(element, depth))
+ end
- def delete_empty(hash)
- hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ""
- end
+ def delete_empty(hash)
+ hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ""
+ end
# Actually converts an XML document element into a data structure.
#
# element::
# The document element to be collapsed.
- def collapse(element, depth)
- hash = get_attributes(element)
-
- child_nodes = element.child_nodes
- if child_nodes.length > 0
- (0...child_nodes.length).each do |i|
- child = child_nodes.item(i)
- merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
+ def collapse(element, depth)
+ hash = get_attributes(element)
+
+ child_nodes = element.child_nodes
+ if child_nodes.length > 0
+ (0...child_nodes.length).each do |i|
+ child = child_nodes.item(i)
+ merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
+ end
+ merge_texts!(hash, element) unless empty_content?(element)
+ hash
+ else
+ merge_texts!(hash, element)
end
- merge_texts!(hash, element) unless empty_content?(element)
- hash
- else
- merge_texts!(hash, element)
end
- end
# Merge all the texts of an element into the hash
#
@@ -94,16 +94,16 @@ module ActiveSupport
# Hash to add the converted element to.
# element::
# XML element whose texts are to me merged into the hash
- def merge_texts!(hash, element)
- delete_empty(hash)
- text_children = texts(element)
- if text_children.join.empty?
- hash
- else
- # must use value to prevent double-escaping
- merge!(hash, CONTENT_KEY, text_children.join)
+ def merge_texts!(hash, element)
+ delete_empty(hash)
+ text_children = texts(element)
+ if text_children.join.empty?
+ hash
+ else
+ # must use value to prevent double-escaping
+ merge!(hash, CONTENT_KEY, text_children.join)
+ end
end
- end
# Adds a new key/value pair to an existing Hash. If the key to be added
# already exists and the existing value associated with key is not
@@ -116,66 +116,66 @@ module ActiveSupport
# Key to be added.
# value::
# Value to be associated with key.
- def merge!(hash, key, value)
- if hash.has_key?(key)
- if hash[key].instance_of?(Array)
- hash[key] << value
+ def merge!(hash, key, value)
+ if hash.has_key?(key)
+ if hash[key].instance_of?(Array)
+ hash[key] << value
+ else
+ hash[key] = [hash[key], value]
+ end
+ elsif value.instance_of?(Array)
+ hash[key] = [value]
else
- hash[key] = [hash[key], value]
+ hash[key] = value
end
- elsif value.instance_of?(Array)
- hash[key] = [value]
- else
- hash[key] = value
+ hash
end
- hash
- end
# Converts the attributes array of an XML element into a hash.
# Returns an empty Hash if node has no attributes.
#
# element::
# XML element to extract attributes from.
- def get_attributes(element)
- attribute_hash = {}
- attributes = element.attributes
- (0...attributes.length).each do |i|
- attribute_hash[CONTENT_KEY] ||= ""
- attribute_hash[attributes.item(i).name] = attributes.item(i).value
+ def get_attributes(element)
+ attribute_hash = {}
+ attributes = element.attributes
+ (0...attributes.length).each do |i|
+ attribute_hash[CONTENT_KEY] ||= ""
+ attribute_hash[attributes.item(i).name] = attributes.item(i).value
+ end
+ attribute_hash
end
- attribute_hash
- end
# Determines if a document element has text content
#
# element::
# XML element to be checked.
- def texts(element)
- texts = []
- child_nodes = element.child_nodes
- (0...child_nodes.length).each do |i|
- item = child_nodes.item(i)
- if item.node_type == Node.TEXT_NODE
- texts << item.get_data
+ def texts(element)
+ texts = []
+ child_nodes = element.child_nodes
+ (0...child_nodes.length).each do |i|
+ item = child_nodes.item(i)
+ if item.node_type == Node.TEXT_NODE
+ texts << item.get_data
+ end
end
+ texts
end
- texts
- end
# Determines if a document element has text content
#
# element::
# XML element to be checked.
- def empty_content?(element)
- text = ""
- child_nodes = element.child_nodes
- (0...child_nodes.length).each do |i|
- item = child_nodes.item(i)
- if item.node_type == Node.TEXT_NODE
- text << item.get_data.strip
+ def empty_content?(element)
+ text = ""
+ child_nodes = element.child_nodes
+ (0...child_nodes.length).each do |i|
+ item = child_nodes.item(i)
+ if item.node_type == Node.TEXT_NODE
+ text << item.get_data.strip
+ end
end
+ text.strip.length == 0
end
- text.strip.length == 0
- end
end
end
diff --git a/activesupport/test/autoload_test.rb b/activesupport/test/autoload_test.rb
index 6a0ce5f3dd..c4d6a69212 100644
--- a/activesupport/test/autoload_test.rb
+++ b/activesupport/test/autoload_test.rb
@@ -78,4 +78,4 @@ class TestAutoloadModule < ActiveSupport::TestCase
assert !$LOADED_FEATURES.include?(@another_class_path)
assert_nothing_raised { ::Fixtures::AnotherClass }
end
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/a/b.rb b/activesupport/test/autoloading_fixtures/a/b.rb
index 9c9e6454cf..0dbbbbd181 100644
--- a/activesupport/test/autoloading_fixtures/a/b.rb
+++ b/activesupport/test/autoloading_fixtures/a/b.rb
@@ -1,2 +1,2 @@
class A::B
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/a/c/d.rb b/activesupport/test/autoloading_fixtures/a/c/d.rb
index 0f40d6fbc4..2c0ec5f182 100644
--- a/activesupport/test/autoloading_fixtures/a/c/d.rb
+++ b/activesupport/test/autoloading_fixtures/a/c/d.rb
@@ -1,2 +1,2 @@
class A::C::D
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/a/c/em/f.rb b/activesupport/test/autoloading_fixtures/a/c/em/f.rb
index 8b28e19148..3ff1b7efa0 100644
--- a/activesupport/test/autoloading_fixtures/a/c/em/f.rb
+++ b/activesupport/test/autoloading_fixtures/a/c/em/f.rb
@@ -1,2 +1,2 @@
class A::C::EM::F
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/conflict.rb b/activesupport/test/autoloading_fixtures/conflict.rb
index 4ac6201902..d7f42b5d5f 100644
--- a/activesupport/test/autoloading_fixtures/conflict.rb
+++ b/activesupport/test/autoloading_fixtures/conflict.rb
@@ -1 +1 @@
-Conflict = 2 \ No newline at end of file
+Conflict = 2
diff --git a/activesupport/test/autoloading_fixtures/cross_site_dependency.rb b/activesupport/test/autoloading_fixtures/cross_site_dependency.rb
index 21ee554e92..de941bf271 100644
--- a/activesupport/test/autoloading_fixtures/cross_site_dependency.rb
+++ b/activesupport/test/autoloading_fixtures/cross_site_dependency.rb
@@ -1,2 +1,2 @@
class CrossSiteDependency
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/d.rb b/activesupport/test/autoloading_fixtures/d.rb
index 45c794d4ca..52850e1e1a 100644
--- a/activesupport/test/autoloading_fixtures/d.rb
+++ b/activesupport/test/autoloading_fixtures/d.rb
@@ -1,2 +1,2 @@
class D
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/em.rb b/activesupport/test/autoloading_fixtures/em.rb
index 16a1838667..e47024999e 100644
--- a/activesupport/test/autoloading_fixtures/em.rb
+++ b/activesupport/test/autoloading_fixtures/em.rb
@@ -1,2 +1,2 @@
class EM
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb
index e3d1218c96..d2c4f6b0c5 100644
--- a/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb
+++ b/activesupport/test/autoloading_fixtures/load_path/loaded_constant.rb
@@ -1,3 +1,2 @@
module LoadedConstant
end
-
diff --git a/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb b/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb
index 80244b8bab..04c426833e 100644
--- a/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb
+++ b/activesupport/test/autoloading_fixtures/module_folder/nested_sibling.rb
@@ -1,2 +1,2 @@
class ModuleFolder::NestedSibling
-end \ No newline at end of file
+end
diff --git a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb
index d12d02f3aa..4f2020c503 100644
--- a/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb
+++ b/activesupport/test/autoloading_fixtures/module_with_custom_const_missing/a/b.rb
@@ -1 +1 @@
-ModuleWithCustomConstMissing::A::B = "10" \ No newline at end of file
+ModuleWithCustomConstMissing::A::B = "10"
diff --git a/activesupport/test/autoloading_fixtures/requires_constant.rb b/activesupport/test/autoloading_fixtures/requires_constant.rb
index 14804a0de0..f04dcc4091 100644
--- a/activesupport/test/autoloading_fixtures/requires_constant.rb
+++ b/activesupport/test/autoloading_fixtures/requires_constant.rb
@@ -2,4 +2,3 @@ require "loaded_constant"
module RequiresConstant
end
-
diff --git a/activesupport/test/autoloading_fixtures/typo.rb b/activesupport/test/autoloading_fixtures/typo.rb
index 8e047f5fd4..0ffe07c2b3 100644
--- a/activesupport/test/autoloading_fixtures/typo.rb
+++ b/activesupport/test/autoloading_fixtures/typo.rb
@@ -1,2 +1 @@
TypO = 1
-
diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb
index 422b7f0834..072a2530ba 100644
--- a/activesupport/test/caching_test.rb
+++ b/activesupport/test/caching_test.rb
@@ -130,13 +130,13 @@ class CacheKeyTest < ActiveSupport::TestCase
private
- def with_env(kv)
- old_values = {}
- kv.each { |key, value| old_values[key], ENV[key] = ENV[key], value }
- yield
- ensure
- old_values.each { |key, value| ENV[key] = value}
- end
+ def with_env(kv)
+ old_values = {}
+ kv.each { |key, value| old_values[key], ENV[key] = ENV[key], value }
+ yield
+ ensure
+ old_values.each { |key, value| ENV[key] = value}
+ end
end
class CacheStoreSettingTest < ActiveSupport::TestCase
diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb
index 0c9b88d861..0655197335 100644
--- a/activesupport/test/core_ext/date_ext_test.rb
+++ b/activesupport/test/core_ext/date_ext_test.rb
@@ -407,4 +407,3 @@ class DateExtBehaviorTest < ActiveSupport::TestCase
end
end
end
-
diff --git a/activesupport/test/core_ext/module/anonymous_test.rb b/activesupport/test/core_ext/module/anonymous_test.rb
index 36aecfa4c8..f885444284 100644
--- a/activesupport/test/core_ext/module/anonymous_test.rb
+++ b/activesupport/test/core_ext/module/anonymous_test.rb
@@ -11,4 +11,4 @@ class AnonymousTest < ActiveSupport::TestCase
assert !Kernel.anonymous?
assert !Object.anonymous?
end
-end \ No newline at end of file
+end
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 903c7206cd..cda5a34442 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
@@ -65,15 +65,15 @@ class ModuleAttributeAccessorPerThreadTest < ActiveSupport::TestCase
threads << Thread.new do
@class.foo = "other things"
sleep 1
- assert_equal "other things", @class.foo
+ assert_equal "other things", @class.foo
end
-
+
threads << Thread.new do
@class.foo = "really other things"
sleep 1
- assert_equal "really other things", @class.foo
+ assert_equal "really other things", @class.foo
end
-
+
threads.each { |t| t.join }
end
diff --git a/activesupport/test/core_ext/module/qualified_const_test.rb b/activesupport/test/core_ext/module/qualified_const_test.rb
index 1362171b09..dcfac4ced1 100644
--- a/activesupport/test/core_ext/module/qualified_const_test.rb
+++ b/activesupport/test/core_ext/module/qualified_const_test.rb
@@ -111,8 +111,8 @@ class QualifiedConstTest < ActiveSupport::TestCase
private
- def assert_raise_with_message(expected_exception, expected_message, &block)
- exception = assert_raise(expected_exception, &block)
- assert_equal expected_message, exception.message
- end
+ def assert_raise_with_message(expected_exception, expected_message, &block)
+ exception = assert_raise(expected_exception, &block)
+ assert_equal expected_message, exception.message
+ end
end
diff --git a/activesupport/test/core_ext/module/reachable_test.rb b/activesupport/test/core_ext/module/reachable_test.rb
index 01b5f34845..487c7dee16 100644
--- a/activesupport/test/core_ext/module/reachable_test.rb
+++ b/activesupport/test/core_ext/module/reachable_test.rb
@@ -38,4 +38,4 @@ class AnonymousTest < ActiveSupport::TestCase
assert !c.reachable?
assert !m.reachable?
end
-end \ No newline at end of file
+end
diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb
index 9a2e52efa7..bfe60e0f5f 100644
--- a/activesupport/test/core_ext/module_test.rb
+++ b/activesupport/test/core_ext/module_test.rb
@@ -43,9 +43,9 @@ class Someone < Struct.new(:name, :place)
private
- def private_name
- "Private"
- end
+ def private_name
+ "Private"
+ end
end
Invoice = Struct.new(:client) do
diff --git a/activesupport/test/core_ext/object/inclusion_test.rb b/activesupport/test/core_ext/object/inclusion_test.rb
index 9258c46be5..be211ec7dc 100644
--- a/activesupport/test/core_ext/object/inclusion_test.rb
+++ b/activesupport/test/core_ext/object/inclusion_test.rb
@@ -46,11 +46,11 @@ class InTest < ActiveSupport::TestCase
assert !A.in?(A)
assert !A.in?(D)
end
-
+
def test_no_method_catching
assert_raise(ArgumentError) { 1.in?(1) }
end
-
+
def test_presence_in
assert_equal "stuff", "stuff".presence_in(%w( lots of stuff ))
assert_nil "stuff".presence_in(%w( lots of crap ))
diff --git a/activesupport/test/dependencies/conflict.rb b/activesupport/test/dependencies/conflict.rb
index e888b7b54c..7eff49bbfa 100644
--- a/activesupport/test/dependencies/conflict.rb
+++ b/activesupport/test/dependencies/conflict.rb
@@ -1 +1 @@
-Conflict = 1 \ No newline at end of file
+Conflict = 1
diff --git a/activesupport/test/dependencies/cross_site_depender.rb b/activesupport/test/dependencies/cross_site_depender.rb
index a31015fc5e..fbc3b64f56 100644
--- a/activesupport/test/dependencies/cross_site_depender.rb
+++ b/activesupport/test/dependencies/cross_site_depender.rb
@@ -1,3 +1,3 @@
class CrossSiteDepender
CrossSiteDependency
-end \ No newline at end of file
+end
diff --git a/activesupport/test/dependencies/service_one.rb b/activesupport/test/dependencies/service_one.rb
index f43bfea235..afc3042269 100644
--- a/activesupport/test/dependencies/service_one.rb
+++ b/activesupport/test/dependencies/service_one.rb
@@ -2,4 +2,4 @@ $loaded_service_one ||= 0
$loaded_service_one += 1
class ServiceOne
-end \ No newline at end of file
+end
diff --git a/activesupport/test/dependencies/service_two.rb b/activesupport/test/dependencies/service_two.rb
index 5205a78bb8..aabfc3c553 100644
--- a/activesupport/test/dependencies/service_two.rb
+++ b/activesupport/test/dependencies/service_two.rb
@@ -1,2 +1,2 @@
class ServiceTwo
-end \ No newline at end of file
+end
diff --git a/activesupport/test/dependencies_test_helpers.rb b/activesupport/test/dependencies_test_helpers.rb
index 4ee01fda39..9bc63ed89e 100644
--- a/activesupport/test/dependencies_test_helpers.rb
+++ b/activesupport/test/dependencies_test_helpers.rb
@@ -25,4 +25,4 @@ module DependenciesTestHelpers
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
-end \ No newline at end of file
+end
diff --git a/activesupport/test/descendants_tracker_test_cases.rb b/activesupport/test/descendants_tracker_test_cases.rb
index 4fba58bd47..09c5ce1f07 100644
--- a/activesupport/test/descendants_tracker_test_cases.rb
+++ b/activesupport/test/descendants_tracker_test_cases.rb
@@ -42,24 +42,24 @@ module DescendantsTrackerTestCases
protected
- def assert_equal_sets(expected, actual)
- assert_equal Set.new(expected), Set.new(actual)
- end
-
- def mark_as_autoloaded(*klasses)
- # If ActiveSupport::Dependencies is not loaded, forget about autoloading.
- # This allows using AS::DescendantsTracker without AS::Dependencies.
- if defined? ActiveSupport::Dependencies
- old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup
- ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name)
+ def assert_equal_sets(expected, actual)
+ assert_equal Set.new(expected), Set.new(actual)
end
- old_descendants = ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").dup
- old_descendants.each { |k, v| old_descendants[k] = v.dup }
+ def mark_as_autoloaded(*klasses)
+ # If ActiveSupport::Dependencies is not loaded, forget about autoloading.
+ # This allows using AS::DescendantsTracker without AS::Dependencies.
+ if defined? ActiveSupport::Dependencies
+ old_autoloaded = ActiveSupport::Dependencies.autoloaded_constants.dup
+ ActiveSupport::Dependencies.autoloaded_constants = klasses.map(&:name)
+ end
+
+ old_descendants = ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").dup
+ old_descendants.each { |k, v| old_descendants[k] = v.dup }
- yield
- ensure
- ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded if defined? ActiveSupport::Dependencies
- ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").replace(old_descendants)
- end
+ yield
+ ensure
+ ActiveSupport::Dependencies.autoloaded_constants = old_autoloaded if defined? ActiveSupport::Dependencies
+ ActiveSupport::DescendantsTracker.class_eval("@@direct_descendants").replace(old_descendants)
+ end
end
diff --git a/activesupport/test/fixtures/autoload/another_class.rb b/activesupport/test/fixtures/autoload/another_class.rb
index a240b3de41..ab6e075ab4 100644
--- a/activesupport/test/fixtures/autoload/another_class.rb
+++ b/activesupport/test/fixtures/autoload/another_class.rb
@@ -1,2 +1,2 @@
class Fixtures::AnotherClass
-end \ No newline at end of file
+end
diff --git a/activesupport/test/fixtures/autoload/some_class.rb b/activesupport/test/fixtures/autoload/some_class.rb
index 13b3c73ef5..30d41eb0bf 100644
--- a/activesupport/test/fixtures/autoload/some_class.rb
+++ b/activesupport/test/fixtures/autoload/some_class.rb
@@ -1,2 +1,2 @@
class Fixtures::Autoload::SomeClass
-end \ No newline at end of file
+end
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb
index 4ee723076e..a8283301b3 100644
--- a/activesupport/test/inflector_test_cases.rb
+++ b/activesupport/test/inflector_test_cases.rb
@@ -176,12 +176,12 @@ module InflectorTestCases
StringToParameterizedPreserveCase = {
"Donald E. Knuth" => "Donald-E-Knuth",
- "Random text with *(bad)* characters" => "Random-text-with-bad-characters",
- "Allow_Under_Scores" => "Allow_Under_Scores",
- "Trailing bad characters!@#" => "Trailing-bad-characters",
- "!@#Leading bad characters" => "Leading-bad-characters",
- "Squeeze separators" => "Squeeze-separators",
- "Test with + sign" => "Test-with-sign",
+ "Random text with *(bad)* characters" => "Random-text-with-bad-characters",
+ "Allow_Under_Scores" => "Allow_Under_Scores",
+ "Trailing bad characters!@#" => "Trailing-bad-characters",
+ "!@#Leading bad characters" => "Leading-bad-characters",
+ "Squeeze separators" => "Squeeze-separators",
+ "Test with + sign" => "Test-with-sign",
"Test with malformed utf8 \xA9" => "Test-with-malformed-utf8"
}
@@ -199,11 +199,11 @@ module InflectorTestCases
StringToParameterizePreserveCaseWithNoSeparator = {
"Donald E. Knuth" => "DonaldEKnuth",
"With-some-dashes" => "With-some-dashes",
- "Random text with *(bad)* characters" => "Randomtextwithbadcharacters",
- "Trailing bad characters!@#" => "Trailingbadcharacters",
- "!@#Leading bad characters" => "Leadingbadcharacters",
- "Squeeze separators" => "Squeezeseparators",
- "Test with + sign" => "Testwithsign",
+ "Random text with *(bad)* characters" => "Randomtextwithbadcharacters",
+ "Trailing bad characters!@#" => "Trailingbadcharacters",
+ "!@#Leading bad characters" => "Leadingbadcharacters",
+ "Squeeze separators" => "Squeezeseparators",
+ "Test with + sign" => "Testwithsign",
"Test with malformed utf8 \xA9" => "Testwithmalformedutf8"
}
@@ -220,14 +220,14 @@ module InflectorTestCases
}
StringToParameterizePreserceCaseWithUnderscore = {
- "Donald E. Knuth" => "Donald_E_Knuth",
+ "Donald E. Knuth" => "Donald_E_Knuth",
"Random text with *(bad)* characters" => "Random_text_with_bad_characters",
- "With-some-dashes" => "With-some-dashes",
- "Allow_Under_Scores" => "Allow_Under_Scores",
- "Trailing bad characters!@#" => "Trailing_bad_characters",
- "!@#Leading bad characters" => "Leading_bad_characters",
- "Squeeze separators" => "Squeeze_separators",
- "Test with + sign" => "Test_with_sign",
+ "With-some-dashes" => "With-some-dashes",
+ "Allow_Under_Scores" => "Allow_Under_Scores",
+ "Trailing bad characters!@#" => "Trailing_bad_characters",
+ "!@#Leading bad characters" => "Leading_bad_characters",
+ "Squeeze separators" => "Squeeze_separators",
+ "Test with + sign" => "Test_with_sign",
"Test with malformed utf8 \xA9" => "Test_with_malformed_utf8"
}
diff --git a/activesupport/test/json/decoding_test.rb b/activesupport/test/json/decoding_test.rb
index 04eb10aafe..97cc508268 100644
--- a/activesupport/test/json/decoding_test.rb
+++ b/activesupport/test/json/decoding_test.rb
@@ -107,12 +107,11 @@ class TestJSONDecoding < ActiveSupport::TestCase
private
- def with_parse_json_times(value)
- old_value = ActiveSupport.parse_json_times
- ActiveSupport.parse_json_times = value
- yield
- ensure
- ActiveSupport.parse_json_times = old_value
- end
+ def with_parse_json_times(value)
+ old_value = ActiveSupport.parse_json_times
+ ActiveSupport.parse_json_times = value
+ yield
+ ensure
+ ActiveSupport.parse_json_times = old_value
+ end
end
-
diff --git a/activesupport/test/key_generator_test.rb b/activesupport/test/key_generator_test.rb
index 705537007a..89db9563ac 100644
--- a/activesupport/test/key_generator_test.rb
+++ b/activesupport/test/key_generator_test.rb
@@ -7,71 +7,71 @@ rescue LoadError, NameError
$stderr.puts "Skipping KeyGenerator test: broken OpenSSL install"
else
-require "active_support/time"
-require "active_support/json"
-
-class KeyGeneratorTest < ActiveSupport::TestCase
- def setup
- @secret = SecureRandom.hex(64)
- @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2)
- end
-
- test "Generating a key of the default length" do
- derived_key = @generator.generate_key("some_salt")
- assert_kind_of String, derived_key
- assert_equal 64, derived_key.length, "Should have generated a key of the default size"
- end
-
- test "Generating a key of an alternative length" do
- derived_key = @generator.generate_key("some_salt", 32)
- assert_kind_of String, derived_key
- assert_equal 32, derived_key.length, "Should have generated a key of the right size"
+ require "active_support/time"
+ require "active_support/json"
+
+ class KeyGeneratorTest < ActiveSupport::TestCase
+ def setup
+ @secret = SecureRandom.hex(64)
+ @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2)
+ end
+
+ test "Generating a key of the default length" do
+ derived_key = @generator.generate_key("some_salt")
+ assert_kind_of String, derived_key
+ assert_equal 64, derived_key.length, "Should have generated a key of the default size"
+ end
+
+ test "Generating a key of an alternative length" do
+ derived_key = @generator.generate_key("some_salt", 32)
+ assert_kind_of String, derived_key
+ assert_equal 32, derived_key.length, "Should have generated a key of the right size"
+ end
+
+ test "Expected results" do
+ # For any given set of inputs, this method must continue to return
+ # the same output: if it changes, any existing values relying on a
+ # key would break.
+
+ expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055739be5cc6956345d5ae38e7e1daa66f1de587dc8da2bf9e8b965af4b3918a122"
+ assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt").unpack("H*").first
+
+ expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055"
+ assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt", 32).unpack("H*").first
+
+ expected = "cbea7f7f47df705967dc508f4e446fd99e7797b1d70011c6899cd39bbe62907b8508337d678505a7dc8184e037f1003ba3d19fc5d829454668e91d2518692eae"
+ assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64, iterations: 2).generate_key("some_salt").unpack("H*").first
+ end
end
- test "Expected results" do
- # For any given set of inputs, this method must continue to return
- # the same output: if it changes, any existing values relying on a
- # key would break.
+ class CachingKeyGeneratorTest < ActiveSupport::TestCase
+ def setup
+ @secret = SecureRandom.hex(64)
+ @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2)
+ @caching_generator = ActiveSupport::CachingKeyGenerator.new(@generator)
+ end
- expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055739be5cc6956345d5ae38e7e1daa66f1de587dc8da2bf9e8b965af4b3918a122"
- assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt").unpack("H*").first
+ test "Generating a cached key for same salt and key size" do
+ derived_key = @caching_generator.generate_key("some_salt", 32)
+ cached_key = @caching_generator.generate_key("some_salt", 32)
- expected = "b129376f68f1ecae788d7433310249d65ceec090ecacd4c872a3a9e9ec78e055"
- assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64).generate_key("some_salt", 32).unpack("H*").first
+ assert_equal derived_key, cached_key
+ assert_equal derived_key.object_id, cached_key.object_id
+ end
- expected = "cbea7f7f47df705967dc508f4e446fd99e7797b1d70011c6899cd39bbe62907b8508337d678505a7dc8184e037f1003ba3d19fc5d829454668e91d2518692eae"
- assert_equal expected, ActiveSupport::KeyGenerator.new("0" * 64, iterations: 2).generate_key("some_salt").unpack("H*").first
- end
-end
+ test "Does not cache key for different salt" do
+ derived_key = @caching_generator.generate_key("some_salt", 32)
+ different_salt_key = @caching_generator.generate_key("other_salt", 32)
-class CachingKeyGeneratorTest < ActiveSupport::TestCase
- def setup
- @secret = SecureRandom.hex(64)
- @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2)
- @caching_generator = ActiveSupport::CachingKeyGenerator.new(@generator)
- end
+ assert_not_equal derived_key, different_salt_key
+ end
- test "Generating a cached key for same salt and key size" do
- derived_key = @caching_generator.generate_key("some_salt", 32)
- cached_key = @caching_generator.generate_key("some_salt", 32)
+ test "Does not cache key for different length" do
+ derived_key = @caching_generator.generate_key("some_salt", 32)
+ different_length_key = @caching_generator.generate_key("some_salt", 64)
- assert_equal derived_key, cached_key
- assert_equal derived_key.object_id, cached_key.object_id
+ assert_not_equal derived_key, different_length_key
+ end
end
- test "Does not cache key for different salt" do
- derived_key = @caching_generator.generate_key("some_salt", 32)
- different_salt_key = @caching_generator.generate_key("other_salt", 32)
-
- assert_not_equal derived_key, different_salt_key
- end
-
- test "Does not cache key for different length" do
- derived_key = @caching_generator.generate_key("some_salt", 32)
- different_length_key = @caching_generator.generate_key("some_salt", 64)
-
- assert_not_equal derived_key, different_length_key
- end
-end
-
end
diff --git a/activesupport/test/lazy_load_hooks_test.rb b/activesupport/test/lazy_load_hooks_test.rb
index d08efa429a..3b1959a1c9 100644
--- a/activesupport/test/lazy_load_hooks_test.rb
+++ b/activesupport/test/lazy_load_hooks_test.rb
@@ -93,4 +93,4 @@ private
@incr = incr
end
end
-end \ No newline at end of file
+end
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
index a4976fa1ea..fb0b1e377d 100644
--- a/activesupport/test/message_encryptor_test.rb
+++ b/activesupport/test/message_encryptor_test.rb
@@ -90,21 +90,21 @@ class MessageEncryptorTest < ActiveSupport::TestCase
private
- def assert_not_decrypted(value)
- assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do
- @encryptor.decrypt_and_verify(@verifier.generate(value))
+ def assert_not_decrypted(value)
+ assert_raise(ActiveSupport::MessageEncryptor::InvalidMessage) do
+ @encryptor.decrypt_and_verify(@verifier.generate(value))
+ end
end
- end
- def assert_not_verified(value)
- assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do
- @encryptor.decrypt_and_verify(value)
+ def assert_not_verified(value)
+ assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do
+ @encryptor.decrypt_and_verify(value)
+ end
end
- end
- def munge(base64_string)
- bits = ::Base64.strict_decode64(base64_string)
- bits.reverse!
- ::Base64.strict_encode64(bits)
- end
+ def munge(base64_string)
+ bits = ::Base64.strict_decode64(base64_string)
+ bits.reverse!
+ ::Base64.strict_encode64(bits)
+ end
end
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 81f05dcd5b..9ca9c7c803 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -513,7 +513,7 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase
"аБвг АБВГ" => "Абвг абвг",
"АБВГ АБВГ" => "Абвг абвг",
"" => "" }.each do |f,t|
- assert_equal t, chars(f).capitalize
+ assert_equal t, chars(f).capitalize
end
end
@@ -720,16 +720,16 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase
private
- def string_from_classes(classes)
- # Characters from the character classes as described in UAX #29
- character_from_class = {
- l: 0x1100, v: 0x1160, t: 0x11A8, lv: 0xAC00, lvt: 0xAC01, cr: 0x000D, lf: 0x000A,
- extend: 0x094D, n: 0x64, spacingmark: 0x0903, r: 0x1F1E6, control: 0x0001
- }
- classes.collect do |k|
- character_from_class[k.intern]
- end.pack("U*")
- end
+ def string_from_classes(classes)
+ # Characters from the character classes as described in UAX #29
+ character_from_class = {
+ l: 0x1100, v: 0x1160, t: 0x11A8, lv: 0xAC00, lvt: 0xAC01, cr: 0x000D, lf: 0x000A,
+ extend: 0x094D, n: 0x64, spacingmark: 0x0903, r: 0x1F1E6, control: 0x0001
+ }
+ classes.collect do |k|
+ character_from_class[k.intern]
+ end.pack("U*")
+ end
end
class MultibyteInternalsTest < ActiveSupport::TestCase
diff --git a/activesupport/test/share_lock_test.rb b/activesupport/test/share_lock_test.rb
index 168ead2401..8155d46934 100644
--- a/activesupport/test/share_lock_test.rb
+++ b/activesupport/test/share_lock_test.rb
@@ -489,90 +489,90 @@ class ShareLockTest < ActiveSupport::TestCase
private
- module CustomAssertions
- SUFFICIENT_TIMEOUT = 0.2
+ module CustomAssertions
+ SUFFICIENT_TIMEOUT = 0.2
- private
+ private
- def assert_threads_stuck_but_releasable_by_latch(threads, latch)
- assert_threads_stuck threads
- latch.count_down
- assert_threads_not_stuck threads
- end
+ def assert_threads_stuck_but_releasable_by_latch(threads, latch)
+ assert_threads_stuck threads
+ latch.count_down
+ assert_threads_not_stuck threads
+ end
- def assert_threads_stuck(threads)
- sleep(SUFFICIENT_TIMEOUT) # give threads time to do their business
- assert(Array(threads).all? { |t| t.join(0.001).nil? })
- end
+ def assert_threads_stuck(threads)
+ sleep(SUFFICIENT_TIMEOUT) # give threads time to do their business
+ assert(Array(threads).all? { |t| t.join(0.001).nil? })
+ end
- def assert_threads_not_stuck(threads)
- assert(Array(threads).all? { |t| t.join(SUFFICIENT_TIMEOUT) })
+ def assert_threads_not_stuck(threads)
+ assert(Array(threads).all? { |t| t.join(SUFFICIENT_TIMEOUT) })
+ end
end
- end
- class CustomAssertionsTest < ActiveSupport::TestCase
- include CustomAssertions
+ class CustomAssertionsTest < ActiveSupport::TestCase
+ include CustomAssertions
- def setup
- @latch = Concurrent::CountDownLatch.new
- @thread = Thread.new { @latch.wait }
- end
+ def setup
+ @latch = Concurrent::CountDownLatch.new
+ @thread = Thread.new { @latch.wait }
+ end
- def teardown
- @latch.count_down
- @thread.join
- end
+ def teardown
+ @latch.count_down
+ @thread.join
+ end
- def test_happy_path
- assert_threads_stuck_but_releasable_by_latch @thread, @latch
- end
+ def test_happy_path
+ assert_threads_stuck_but_releasable_by_latch @thread, @latch
+ end
- def test_detects_stuck_thread
- assert_raises(Minitest::Assertion) do
- assert_threads_not_stuck @thread
+ def test_detects_stuck_thread
+ assert_raises(Minitest::Assertion) do
+ assert_threads_not_stuck @thread
+ end
end
- end
- def test_detects_free_thread
- @latch.count_down
- assert_raises(Minitest::Assertion) do
- assert_threads_stuck @thread
+ def test_detects_free_thread
+ @latch.count_down
+ assert_raises(Minitest::Assertion) do
+ assert_threads_stuck @thread
+ end
end
- end
- def test_detects_already_released
- @latch.count_down
- assert_raises(Minitest::Assertion) do
- assert_threads_stuck_but_releasable_by_latch @thread, @latch
+ def test_detects_already_released
+ @latch.count_down
+ assert_raises(Minitest::Assertion) do
+ assert_threads_stuck_but_releasable_by_latch @thread, @latch
+ end
end
- end
- def test_detects_remains_latched
- another_latch = Concurrent::CountDownLatch.new
- assert_raises(Minitest::Assertion) do
- assert_threads_stuck_but_releasable_by_latch @thread, another_latch
+ def test_detects_remains_latched
+ another_latch = Concurrent::CountDownLatch.new
+ assert_raises(Minitest::Assertion) do
+ assert_threads_stuck_but_releasable_by_latch @thread, another_latch
+ end
end
end
- end
- include CustomAssertions
+ include CustomAssertions
- def with_thread_waiting_in_lock_section(lock_section)
- in_section = Concurrent::CountDownLatch.new
- section_release = Concurrent::CountDownLatch.new
+ def with_thread_waiting_in_lock_section(lock_section)
+ in_section = Concurrent::CountDownLatch.new
+ section_release = Concurrent::CountDownLatch.new
- stuck_thread = Thread.new do
- @lock.send(lock_section) do
- in_section.count_down
- section_release.wait
+ stuck_thread = Thread.new do
+ @lock.send(lock_section) do
+ in_section.count_down
+ section_release.wait
+ end
end
- end
- in_section.wait
+ in_section.wait
- yield section_release
- ensure
- section_release.count_down
- stuck_thread.join # clean up
- end
+ yield section_release
+ ensure
+ section_release.count_down
+ stuck_thread.join # clean up
+ end
end
diff --git a/activesupport/test/subscriber_test.rb b/activesupport/test/subscriber_test.rb
index 5ec8affc9b..9127da35d4 100644
--- a/activesupport/test/subscriber_test.rb
+++ b/activesupport/test/subscriber_test.rb
@@ -16,9 +16,9 @@ class TestSubscriber < ActiveSupport::Subscriber
private
- def private_party(event)
- events << event
- end
+ def private_party(event)
+ events << event
+ end
end
# Monkey patch subscriber to test that only one subscriber per method is added.
diff --git a/activesupport/test/xml_mini/jdom_engine_test.rb b/activesupport/test/xml_mini/jdom_engine_test.rb
index fea3711c37..43edd49663 100644
--- a/activesupport/test/xml_mini/jdom_engine_test.rb
+++ b/activesupport/test/xml_mini/jdom_engine_test.rb
@@ -19,18 +19,18 @@ if RUBY_PLATFORM.include?("java")
end
def test_file_from_xml
- hash = Hash.from_xml(<<-eoxml)
+ hash = Hash.from_xml(<<-eoxml)
<blog>
<logo type="file" name="logo.png" content_type="image/png">
</logo>
</blog>
eoxml
- assert hash.has_key?("blog")
- assert hash["blog"].has_key?("logo")
+ assert hash.has_key?("blog")
+ assert hash["blog"].has_key?("logo")
- file = hash["blog"]["logo"]
- assert_equal "logo.png", file.original_filename
- assert_equal "image/png", file.content_type
+ file = hash["blog"]["logo"]
+ assert_equal "logo.png", file.original_filename
+ assert_equal "image/png", file.content_type
end
def test_not_allowed_to_expand_entities_to_files
diff --git a/activesupport/test/xml_mini/libxml_engine_test.rb b/activesupport/test/xml_mini/libxml_engine_test.rb
index c40145ae5f..d5fd17d06e 100644
--- a/activesupport/test/xml_mini/libxml_engine_test.rb
+++ b/activesupport/test/xml_mini/libxml_engine_test.rb
@@ -3,56 +3,56 @@ begin
rescue LoadError
# Skip libxml tests
else
-require "abstract_unit"
-require "active_support/xml_mini"
-require "active_support/core_ext/hash/conversions"
+ require "abstract_unit"
+ require "active_support/xml_mini"
+ require "active_support/core_ext/hash/conversions"
-class LibxmlEngineTest < ActiveSupport::TestCase
- include ActiveSupport
+ class LibxmlEngineTest < ActiveSupport::TestCase
+ include ActiveSupport
- def setup
- @default_backend = XmlMini.backend
- XmlMini.backend = "LibXML"
+ def setup
+ @default_backend = XmlMini.backend
+ XmlMini.backend = "LibXML"
- LibXML::XML::Error.set_handler(&lambda { |error| }) #silence libxml, exceptions will do
- end
+ LibXML::XML::Error.set_handler(&lambda { |error| }) #silence libxml, exceptions will do
+ end
- def teardown
- XmlMini.backend = @default_backend
- end
+ def teardown
+ XmlMini.backend = @default_backend
+ end
- def test_exception_thrown_on_expansion_attack
- assert_raise LibXML::XML::Error do
- attack_xml = %{<?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE member [
- <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
- <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
- <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
- <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
- <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
- <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
- <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
- ]>
- <member>
- &a;
- </member>
- }
- Hash.from_xml(attack_xml)
+ def test_exception_thrown_on_expansion_attack
+ assert_raise LibXML::XML::Error do
+ attack_xml = %{<?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE member [
+ <!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
+ <!ENTITY b "&c;&c;&c;&c;&c;&c;&c;&c;&c;&c;">
+ <!ENTITY c "&d;&d;&d;&d;&d;&d;&d;&d;&d;&d;">
+ <!ENTITY d "&e;&e;&e;&e;&e;&e;&e;&e;&e;&e;">
+ <!ENTITY e "&f;&f;&f;&f;&f;&f;&f;&f;&f;&f;">
+ <!ENTITY f "&g;&g;&g;&g;&g;&g;&g;&g;&g;&g;">
+ <!ENTITY g "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
+ ]>
+ <member>
+ &a;
+ </member>
+ }
+ Hash.from_xml(attack_xml)
+ end
end
- end
- def test_setting_libxml_as_backend
- XmlMini.backend = "LibXML"
- assert_equal XmlMini_LibXML, XmlMini.backend
- end
+ def test_setting_libxml_as_backend
+ XmlMini.backend = "LibXML"
+ assert_equal XmlMini_LibXML, XmlMini.backend
+ end
- def test_blank_returns_empty_hash
- assert_equal({}, XmlMini.parse(nil))
- assert_equal({}, XmlMini.parse(""))
- end
+ def test_blank_returns_empty_hash
+ assert_equal({}, XmlMini.parse(nil))
+ assert_equal({}, XmlMini.parse(""))
+ end
- def test_array_type_makes_an_array
- assert_equal_rexml(<<-eoxml)
+ def test_array_type_makes_an_array
+ assert_equal_rexml(<<-eoxml)
<blog>
<posts type="array">
<post>a post</post>
@@ -60,67 +60,67 @@ class LibxmlEngineTest < ActiveSupport::TestCase
</posts>
</blog>
eoxml
- end
+ end
- def test_one_node_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products/>
- eoxml
- end
+ def test_one_node_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products/>
+ eoxml
+ end
- def test_one_node_with_attributes_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products foo="bar"/>
- eoxml
- end
+ def test_one_node_with_attributes_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products foo="bar"/>
+ eoxml
+ end
- def test_products_node_with_book_node_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_book_node_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
</products>
eoxml
- end
+ end
- def test_products_node_with_two_book_nodes_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_two_book_nodes_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
eoxml
- end
+ end
- def test_single_node_with_content_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_single_node_with_content_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
hello world
</products>
eoxml
- end
+ end
- def test_children_with_children
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_children
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello everyone
</products>
</root>
eoxml
- end
+ end
- def test_children_with_non_adjacent_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_non_adjacent_text
+ assert_equal_rexml(<<-eoxml)
<root>
good
<products>
@@ -129,10 +129,10 @@ class LibxmlEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- end
+ end
- def test_parse_from_io
- io = StringIO.new(<<-eoxml)
+ def test_parse_from_io
+ io = StringIO.new(<<-eoxml)
<root>
good
<products>
@@ -141,31 +141,31 @@ class LibxmlEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- assert_equal_rexml(io)
- end
+ assert_equal_rexml(io)
+ end
- def test_children_with_simple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_simple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_multiple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_multiple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text_and_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text_and_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello <![CDATA[cdatablock]]>
@@ -173,32 +173,32 @@ class LibxmlEngineTest < ActiveSupport::TestCase
</products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products> </products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text_and_attribute
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text_and_attribute
+ assert_equal_rexml(<<-eoxml)
<root>
<products type="file"> </products>
</root>
eoxml
- end
+ end
- private
- def assert_equal_rexml(xml)
- parsed_xml = XmlMini.parse(xml)
- xml.rewind if xml.respond_to?(:rewind)
- hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) }
- assert_equal(hash, parsed_xml)
- end
-end
+ private
+ def assert_equal_rexml(xml)
+ parsed_xml = XmlMini.parse(xml)
+ xml.rewind if xml.respond_to?(:rewind)
+ hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) }
+ assert_equal(hash, parsed_xml)
+ end
+ end
end
diff --git a/activesupport/test/xml_mini/libxmlsax_engine_test.rb b/activesupport/test/xml_mini/libxmlsax_engine_test.rb
index a92cd9da8c..e25fa2813c 100644
--- a/activesupport/test/xml_mini/libxmlsax_engine_test.rb
+++ b/activesupport/test/xml_mini/libxmlsax_engine_test.rb
@@ -3,25 +3,25 @@ begin
rescue LoadError
# Skip libxml tests
else
-require "abstract_unit"
-require "active_support/xml_mini"
-require "active_support/core_ext/hash/conversions"
+ require "abstract_unit"
+ require "active_support/xml_mini"
+ require "active_support/core_ext/hash/conversions"
-class LibXMLSAXEngineTest < ActiveSupport::TestCase
- include ActiveSupport
+ class LibXMLSAXEngineTest < ActiveSupport::TestCase
+ include ActiveSupport
- def setup
- @default_backend = XmlMini.backend
- XmlMini.backend = "LibXMLSAX"
- end
+ def setup
+ @default_backend = XmlMini.backend
+ XmlMini.backend = "LibXMLSAX"
+ end
- def teardown
- XmlMini.backend = @default_backend
- end
+ def teardown
+ XmlMini.backend = @default_backend
+ end
- def test_exception_thrown_on_expansion_attack
- assert_raise LibXML::XML::Error do
- attack_xml = <<-EOT
+ def test_exception_thrown_on_expansion_attack
+ assert_raise LibXML::XML::Error do
+ attack_xml = <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@@ -37,22 +37,22 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase
</member>
EOT
- Hash.from_xml(attack_xml)
+ Hash.from_xml(attack_xml)
+ end
end
- end
- def test_setting_libxml_as_backend
- XmlMini.backend = "LibXMLSAX"
- assert_equal XmlMini_LibXMLSAX, XmlMini.backend
- end
+ def test_setting_libxml_as_backend
+ XmlMini.backend = "LibXMLSAX"
+ assert_equal XmlMini_LibXMLSAX, XmlMini.backend
+ end
- def test_blank_returns_empty_hash
- assert_equal({}, XmlMini.parse(nil))
- assert_equal({}, XmlMini.parse(""))
- end
+ def test_blank_returns_empty_hash
+ assert_equal({}, XmlMini.parse(nil))
+ assert_equal({}, XmlMini.parse(""))
+ end
- def test_array_type_makes_an_array
- assert_equal_rexml(<<-eoxml)
+ def test_array_type_makes_an_array
+ assert_equal_rexml(<<-eoxml)
<blog>
<posts type="array">
<post>a post</post>
@@ -60,67 +60,67 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase
</posts>
</blog>
eoxml
- end
+ end
- def test_one_node_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products/>
- eoxml
- end
+ def test_one_node_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products/>
+ eoxml
+ end
- def test_one_node_with_attributes_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products foo="bar"/>
- eoxml
- end
+ def test_one_node_with_attributes_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products foo="bar"/>
+ eoxml
+ end
- def test_products_node_with_book_node_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_book_node_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
</products>
eoxml
- end
+ end
- def test_products_node_with_two_book_nodes_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_two_book_nodes_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
eoxml
- end
+ end
- def test_single_node_with_content_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_single_node_with_content_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
hello world
</products>
eoxml
- end
+ end
- def test_children_with_children
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_children
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello everyone
</products>
</root>
eoxml
- end
+ end
- def test_children_with_non_adjacent_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_non_adjacent_text
+ assert_equal_rexml(<<-eoxml)
<root>
good
<products>
@@ -129,10 +129,10 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- end
+ end
- def test_parse_from_io
- io = StringIO.new(<<-eoxml)
+ def test_parse_from_io
+ io = StringIO.new(<<-eoxml)
<root>
good
<products>
@@ -141,31 +141,31 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- assert_equal_rexml(io)
- end
+ assert_equal_rexml(io)
+ end
- def test_children_with_simple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_simple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_multiple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_multiple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text_and_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text_and_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello <![CDATA[cdatablock]]>
@@ -173,23 +173,23 @@ class LibXMLSAXEngineTest < ActiveSupport::TestCase
</products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products> </products>
</root>
eoxml
- end
-
- private
- def assert_equal_rexml(xml)
- parsed_xml = XmlMini.parse(xml)
- xml.rewind if xml.respond_to?(:rewind)
- hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) }
- assert_equal(hash, parsed_xml)
end
-end
+
+ private
+ def assert_equal_rexml(xml)
+ parsed_xml = XmlMini.parse(xml)
+ xml.rewind if xml.respond_to?(:rewind)
+ hash = XmlMini.with_backend("REXML") { XmlMini.parse(xml) }
+ assert_equal(hash, parsed_xml)
+ end
+ end
end
diff --git a/activesupport/test/xml_mini/nokogiri_engine_test.rb b/activesupport/test/xml_mini/nokogiri_engine_test.rb
index dd169e7eb4..44b82da4e4 100644
--- a/activesupport/test/xml_mini/nokogiri_engine_test.rb
+++ b/activesupport/test/xml_mini/nokogiri_engine_test.rb
@@ -3,38 +3,38 @@ begin
rescue LoadError
# Skip nokogiri tests
else
-require "abstract_unit"
-require "active_support/xml_mini"
-require "active_support/core_ext/hash/conversions"
-
-class NokogiriEngineTest < ActiveSupport::TestCase
- def setup
- @default_backend = ActiveSupport::XmlMini.backend
- ActiveSupport::XmlMini.backend = "Nokogiri"
- end
+ require "abstract_unit"
+ require "active_support/xml_mini"
+ require "active_support/core_ext/hash/conversions"
+
+ class NokogiriEngineTest < ActiveSupport::TestCase
+ def setup
+ @default_backend = ActiveSupport::XmlMini.backend
+ ActiveSupport::XmlMini.backend = "Nokogiri"
+ end
- def teardown
- ActiveSupport::XmlMini.backend = @default_backend
- end
+ def teardown
+ ActiveSupport::XmlMini.backend = @default_backend
+ end
- def test_file_from_xml
- hash = Hash.from_xml(<<-eoxml)
+ def test_file_from_xml
+ hash = Hash.from_xml(<<-eoxml)
<blog>
<logo type="file" name="logo.png" content_type="image/png">
</logo>
</blog>
eoxml
- assert hash.has_key?("blog")
- assert hash["blog"].has_key?("logo")
+ assert hash.has_key?("blog")
+ assert hash["blog"].has_key?("logo")
- file = hash["blog"]["logo"]
- assert_equal "logo.png", file.original_filename
- assert_equal "image/png", file.content_type
- end
+ file = hash["blog"]["logo"]
+ assert_equal "logo.png", file.original_filename
+ assert_equal "image/png", file.content_type
+ end
- def test_exception_thrown_on_expansion_attack
- assert_raise Nokogiri::XML::SyntaxError do
- attack_xml = <<-EOT
+ def test_exception_thrown_on_expansion_attack
+ assert_raise Nokogiri::XML::SyntaxError do
+ attack_xml = <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@@ -49,22 +49,22 @@ class NokogiriEngineTest < ActiveSupport::TestCase
&a;
</member>
EOT
- Hash.from_xml(attack_xml)
+ Hash.from_xml(attack_xml)
+ end
end
- end
- def test_setting_nokogiri_as_backend
- ActiveSupport::XmlMini.backend = "Nokogiri"
- assert_equal ActiveSupport::XmlMini_Nokogiri, ActiveSupport::XmlMini.backend
- end
+ def test_setting_nokogiri_as_backend
+ ActiveSupport::XmlMini.backend = "Nokogiri"
+ assert_equal ActiveSupport::XmlMini_Nokogiri, ActiveSupport::XmlMini.backend
+ end
- def test_blank_returns_empty_hash
- assert_equal({}, ActiveSupport::XmlMini.parse(nil))
- assert_equal({}, ActiveSupport::XmlMini.parse(""))
- end
+ def test_blank_returns_empty_hash
+ assert_equal({}, ActiveSupport::XmlMini.parse(nil))
+ assert_equal({}, ActiveSupport::XmlMini.parse(""))
+ end
- def test_array_type_makes_an_array
- assert_equal_rexml(<<-eoxml)
+ def test_array_type_makes_an_array
+ assert_equal_rexml(<<-eoxml)
<blog>
<posts type="array">
<post>a post</post>
@@ -72,67 +72,67 @@ class NokogiriEngineTest < ActiveSupport::TestCase
</posts>
</blog>
eoxml
- end
+ end
- def test_one_node_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products/>
- eoxml
- end
+ def test_one_node_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products/>
+ eoxml
+ end
- def test_one_node_with_attributes_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products foo="bar"/>
- eoxml
- end
+ def test_one_node_with_attributes_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products foo="bar"/>
+ eoxml
+ end
- def test_products_node_with_book_node_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_book_node_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
</products>
eoxml
- end
+ end
- def test_products_node_with_two_book_nodes_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_two_book_nodes_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
eoxml
- end
+ end
- def test_single_node_with_content_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_single_node_with_content_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
hello world
</products>
eoxml
- end
+ end
- def test_children_with_children
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_children
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello everyone
</products>
</root>
eoxml
- end
+ end
- def test_children_with_non_adjacent_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_non_adjacent_text
+ assert_equal_rexml(<<-eoxml)
<root>
good
<products>
@@ -141,10 +141,10 @@ class NokogiriEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- end
+ end
- def test_parse_from_io
- io = StringIO.new(<<-eoxml)
+ def test_parse_from_io
+ io = StringIO.new(<<-eoxml)
<root>
good
<products>
@@ -153,31 +153,31 @@ class NokogiriEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- assert_equal_rexml(io)
- end
+ assert_equal_rexml(io)
+ end
- def test_children_with_simple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_simple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_multiple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_multiple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text_and_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text_and_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello <![CDATA[cdatablock]]>
@@ -185,31 +185,31 @@ class NokogiriEngineTest < ActiveSupport::TestCase
</products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products> </products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text_and_attribute
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text_and_attribute
+ assert_equal_rexml(<<-eoxml)
<root>
<products type="file"> </products>
</root>
eoxml
- end
-
- private
- def assert_equal_rexml(xml)
- parsed_xml = ActiveSupport::XmlMini.parse(xml)
- xml.rewind if xml.respond_to?(:rewind)
- hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) }
- assert_equal(hash, parsed_xml)
end
-end
+
+ private
+ def assert_equal_rexml(xml)
+ parsed_xml = ActiveSupport::XmlMini.parse(xml)
+ xml.rewind if xml.respond_to?(:rewind)
+ hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) }
+ assert_equal(hash, parsed_xml)
+ end
+ end
end
diff --git a/activesupport/test/xml_mini/nokogirisax_engine_test.rb b/activesupport/test/xml_mini/nokogirisax_engine_test.rb
index 9a2bcc3f7e..24b35cadf6 100644
--- a/activesupport/test/xml_mini/nokogirisax_engine_test.rb
+++ b/activesupport/test/xml_mini/nokogirisax_engine_test.rb
@@ -3,38 +3,38 @@ begin
rescue LoadError
# Skip nokogiri tests
else
-require "abstract_unit"
-require "active_support/xml_mini"
-require "active_support/core_ext/hash/conversions"
-
-class NokogiriSAXEngineTest < ActiveSupport::TestCase
- def setup
- @default_backend = ActiveSupport::XmlMini.backend
- ActiveSupport::XmlMini.backend = "NokogiriSAX"
- end
+ require "abstract_unit"
+ require "active_support/xml_mini"
+ require "active_support/core_ext/hash/conversions"
+
+ class NokogiriSAXEngineTest < ActiveSupport::TestCase
+ def setup
+ @default_backend = ActiveSupport::XmlMini.backend
+ ActiveSupport::XmlMini.backend = "NokogiriSAX"
+ end
- def teardown
- ActiveSupport::XmlMini.backend = @default_backend
- end
+ def teardown
+ ActiveSupport::XmlMini.backend = @default_backend
+ end
- def test_file_from_xml
- hash = Hash.from_xml(<<-eoxml)
+ def test_file_from_xml
+ hash = Hash.from_xml(<<-eoxml)
<blog>
<logo type="file" name="logo.png" content_type="image/png">
</logo>
</blog>
eoxml
- assert hash.has_key?("blog")
- assert hash["blog"].has_key?("logo")
+ assert hash.has_key?("blog")
+ assert hash["blog"].has_key?("logo")
- file = hash["blog"]["logo"]
- assert_equal "logo.png", file.original_filename
- assert_equal "image/png", file.content_type
- end
+ file = hash["blog"]["logo"]
+ assert_equal "logo.png", file.original_filename
+ assert_equal "image/png", file.content_type
+ end
- def test_exception_thrown_on_expansion_attack
- assert_raise RuntimeError do
- attack_xml = <<-EOT
+ def test_exception_thrown_on_expansion_attack
+ assert_raise RuntimeError do
+ attack_xml = <<-EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE member [
<!ENTITY a "&b;&b;&b;&b;&b;&b;&b;&b;&b;&b;">
@@ -50,22 +50,22 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase
</member>
EOT
- Hash.from_xml(attack_xml)
+ Hash.from_xml(attack_xml)
+ end
end
- end
- def test_setting_nokogirisax_as_backend
- ActiveSupport::XmlMini.backend = "NokogiriSAX"
- assert_equal ActiveSupport::XmlMini_NokogiriSAX, ActiveSupport::XmlMini.backend
- end
+ def test_setting_nokogirisax_as_backend
+ ActiveSupport::XmlMini.backend = "NokogiriSAX"
+ assert_equal ActiveSupport::XmlMini_NokogiriSAX, ActiveSupport::XmlMini.backend
+ end
- def test_blank_returns_empty_hash
- assert_equal({}, ActiveSupport::XmlMini.parse(nil))
- assert_equal({}, ActiveSupport::XmlMini.parse(""))
- end
+ def test_blank_returns_empty_hash
+ assert_equal({}, ActiveSupport::XmlMini.parse(nil))
+ assert_equal({}, ActiveSupport::XmlMini.parse(""))
+ end
- def test_array_type_makes_an_array
- assert_equal_rexml(<<-eoxml)
+ def test_array_type_makes_an_array
+ assert_equal_rexml(<<-eoxml)
<blog>
<posts type="array">
<post>a post</post>
@@ -73,67 +73,67 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase
</posts>
</blog>
eoxml
- end
+ end
- def test_one_node_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products/>
- eoxml
- end
+ def test_one_node_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products/>
+ eoxml
+ end
- def test_one_node_with_attributes_document_as_hash
- assert_equal_rexml(<<-eoxml)
- <products foo="bar"/>
- eoxml
- end
+ def test_one_node_with_attributes_document_as_hash
+ assert_equal_rexml(<<-eoxml)
+ <products foo="bar"/>
+ eoxml
+ end
- def test_products_node_with_book_node_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_book_node_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
</products>
eoxml
- end
+ end
- def test_products_node_with_two_book_nodes_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_products_node_with_two_book_nodes_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
<book name="awesome" id="12345" />
<book name="america" id="67890" />
</products>
eoxml
- end
+ end
- def test_single_node_with_content_as_hash
- assert_equal_rexml(<<-eoxml)
+ def test_single_node_with_content_as_hash
+ assert_equal_rexml(<<-eoxml)
<products>
hello world
</products>
eoxml
- end
+ end
- def test_children_with_children
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_children
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<book name="america" id="67890" />
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello everyone
</products>
</root>
eoxml
- end
+ end
- def test_children_with_non_adjacent_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_non_adjacent_text
+ assert_equal_rexml(<<-eoxml)
<root>
good
<products>
@@ -142,10 +142,10 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- end
+ end
- def test_parse_from_io
- io = StringIO.new(<<-eoxml)
+ def test_parse_from_io
+ io = StringIO.new(<<-eoxml)
<root>
good
<products>
@@ -154,31 +154,31 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase
morning
</root>
eoxml
- assert_equal_rexml(io)
- end
+ assert_equal_rexml(io)
+ end
- def test_children_with_simple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_simple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_multiple_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_multiple_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
<![CDATA[cdatablock1]]><![CDATA[cdatablock2]]>
</products>
</root>
eoxml
- end
+ end
- def test_children_with_text_and_cdata
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_text_and_cdata
+ assert_equal_rexml(<<-eoxml)
<root>
<products>
hello <![CDATA[cdatablock]]>
@@ -186,31 +186,31 @@ class NokogiriSAXEngineTest < ActiveSupport::TestCase
</products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text
+ assert_equal_rexml(<<-eoxml)
<root>
<products> </products>
</root>
eoxml
- end
+ end
- def test_children_with_blank_text_and_attribute
- assert_equal_rexml(<<-eoxml)
+ def test_children_with_blank_text_and_attribute
+ assert_equal_rexml(<<-eoxml)
<root>
<products type="file"> </products>
</root>
eoxml
- end
-
- private
- def assert_equal_rexml(xml)
- parsed_xml = ActiveSupport::XmlMini.parse(xml)
- xml.rewind if xml.respond_to?(:rewind)
- hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) }
- assert_equal(hash, parsed_xml)
end
-end
+
+ private
+ def assert_equal_rexml(xml)
+ parsed_xml = ActiveSupport::XmlMini.parse(xml)
+ xml.rewind if xml.respond_to?(:rewind)
+ hash = ActiveSupport::XmlMini.with_backend("REXML") { ActiveSupport::XmlMini.parse(xml) }
+ assert_equal(hash, parsed_xml)
+ end
+ end
end
diff --git a/activesupport/test/xml_mini/rexml_engine_test.rb b/activesupport/test/xml_mini/rexml_engine_test.rb
index 2af98f7fe2..a3bae7a89c 100644
--- a/activesupport/test/xml_mini/rexml_engine_test.rb
+++ b/activesupport/test/xml_mini/rexml_engine_test.rb
@@ -26,8 +26,8 @@ class REXMLEngineTest < ActiveSupport::TestCase
assert hash.has_key?("root")
assert hash["root"].has_key?("products")
assert_match "good", hash["root"]["__content__"]
- products = hash["root"]["products"]
- assert products.has_key?("__content__")
+ products = hash["root"]["products"]
+ assert products.has_key?("__content__")
assert_match "hello everyone", products["__content__"]
end