diff options
author | Xavier Noria <fxn@hashref.com> | 2016-08-06 19:38:33 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-08-06 19:38:33 +0200 |
commit | 5c315a8fa6296904f5e0ba8da919fc395548cf98 (patch) | |
tree | c20da9c73b5db9caa8c2aa711955ed17f01d396d /activesupport | |
parent | d22e522179c1c90e658c3ed0e9b972ec62306209 (diff) | |
download | rails-5c315a8fa6296904f5e0ba8da919fc395548cf98.tar.gz rails-5c315a8fa6296904f5e0ba8da919fc395548cf98.tar.bz2 rails-5c315a8fa6296904f5e0ba8da919fc395548cf98.zip |
modernizes hash syntax in activesupport
Diffstat (limited to 'activesupport')
57 files changed, 1040 insertions, 1040 deletions
diff --git a/activesupport/Rakefile b/activesupport/Rakefile index de3467529d..54d7a5c6f3 100644 --- a/activesupport/Rakefile +++ b/activesupport/Rakefile @@ -1,6 +1,6 @@ require "rake/testtask" -task :default => :test +task default: :test task :package diff --git a/activesupport/bin/generate_tables b/activesupport/bin/generate_tables index c5ed991d94..d4e63644d9 100755 --- a/activesupport/bin/generate_tables +++ b/activesupport/bin/generate_tables @@ -20,10 +20,10 @@ module ActiveSupport class DatabaseGenerator BASE_URI = "http://www.unicode.org/Public/#{UNICODE_VERSION}/ucd/" SOURCES = { - :codepoints => BASE_URI + "UnicodeData.txt", - :composition_exclusion => BASE_URI + "CompositionExclusions.txt", - :grapheme_break_property => BASE_URI + "auxiliary/GraphemeBreakProperty.txt", - :cp1252 => "http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT" + codepoints: BASE_URI + "UnicodeData.txt", + composition_exclusion: BASE_URI + "CompositionExclusions.txt", + grapheme_break_property: BASE_URI + "auxiliary/GraphemeBreakProperty.txt", + cp1252: "http://unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP1252.TXT" } def initialize diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 1920e9f7b4..a760915bfd 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -153,7 +153,7 @@ module ActiveSupport # or +write+. To specify the threshold at which to compress values, set the # <tt>:compress_threshold</tt> option. The default threshold is 16K. class Store - cattr_accessor :logger, :instance_writer => true + cattr_accessor :logger, instance_writer: true attr_reader :silence, :options alias :silence? :silence @@ -557,7 +557,7 @@ module ActiveSupport def instrument(operation, key, options = nil) log { "Cache #{operation}: #{normalize_key(key, options)}#{options.blank? ? "" : " (#{options.inspect})"}" } - payload = { :key => key } + payload = { key: key } payload.merge!(options) if options.is_a?(Hash) ActiveSupport::Notifications.instrument("cache_#{operation}.active_support", payload){ yield(payload) } end @@ -574,7 +574,7 @@ module ActiveSupport # When an entry has a positive :race_condition_ttl defined, put the stale entry back into the cache # for a brief period while the entry is being recalculated. entry.expires_at = Time.now + race_ttl - write_entry(key, entry, :expires_in => race_ttl * 2) + write_entry(key, entry, expires_in: race_ttl * 2) else delete_entry(key, options) end diff --git a/activesupport/lib/active_support/cache/mem_cache_store.rb b/activesupport/lib/active_support/cache/mem_cache_store.rb index 5db40b37b0..e8b56676cb 100644 --- a/activesupport/lib/active_support/cache/mem_cache_store.rb +++ b/activesupport/lib/active_support/cache/mem_cache_store.rb @@ -97,7 +97,7 @@ module ActiveSupport options = merged_options(options) keys_to_names = Hash[names.map{|name| [normalize_key(name, options), name]}] - raw_values = @data.get_multi(keys_to_names.keys, :raw => true) + raw_values = @data.get_multi(keys_to_names.keys, raw: true) values = {} raw_values.each do |key, value| entry = deserialize_entry(value) @@ -112,7 +112,7 @@ module ActiveSupport # to zero. def increment(name, amount = 1, options = nil) # :nodoc: options = merged_options(options) - instrument(:increment, name, :amount => amount) do + instrument(:increment, name, amount: amount) do rescue_error_with nil do @data.incr(normalize_key(name, options), amount) end @@ -125,7 +125,7 @@ module ActiveSupport # to zero. def decrement(name, amount = 1, options = nil) # :nodoc: options = merged_options(options) - instrument(:decrement, name, :amount => amount) do + instrument(:decrement, name, amount: amount) do rescue_error_with nil do @data.decr(normalize_key(name, options), amount) end diff --git a/activesupport/lib/active_support/cache/memory_store.rb b/activesupport/lib/active_support/cache/memory_store.rb index e61d9f3053..d7dc574f5b 100644 --- a/activesupport/lib/active_support/cache/memory_store.rb +++ b/activesupport/lib/active_support/cache/memory_store.rb @@ -39,7 +39,7 @@ module ActiveSupport # Preemptively iterates through all stored keys and removes the ones which have expired. def cleanup(options = nil) options = merged_options(options) - instrument(:cleanup, :size => @data.size) do + instrument(:cleanup, size: @data.size) do keys = synchronize{ @data.keys } keys.each do |key| entry = @data[key] @@ -56,7 +56,7 @@ module ActiveSupport begin start_time = Time.now cleanup - instrument(:prune, target_size, :from => @cache_size) do + instrument(:prune, target_size, from: @cache_size) do keys = synchronize{ @key_access.keys.sort{|a,b| @key_access[a].to_f <=> @key_access[b].to_f} } keys.each do |key| delete_entry(key, options) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 9604777134..985f432c7b 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -323,8 +323,8 @@ module ActiveSupport def merge_conditional_options(chain, if_option:, unless_option:) options = { - :if => @if.dup, - :unless => @unless.dup + if: @if.dup, + unless: @unless.dup } options[:if].concat Array(unless_option) diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 7d7e896170..1d4c83ae52 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -66,9 +66,9 @@ class Array options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale, :fallback_string) default_connectors = { - :words_connector => ", ", - :two_words_connector => " and ", - :last_word_connector => ", and " + words_connector: ", ", + two_words_connector: " and ", + last_word_connector: ", and " } if defined?(I18n) i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {}) diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 983dd829f6..d553406dff 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -5,16 +5,16 @@ require "active_support/core_ext/module/remove_method" class Date DATE_FORMATS = { - :short => "%d %b", - :long => "%B %d, %Y", - :db => "%Y-%m-%d", - :number => "%Y%m%d", - :long_ordinal => lambda { |date| + short: "%d %b", + long: "%B %d, %Y", + db: "%Y-%m-%d", + number: "%Y%m%d", + long_ordinal: lambda { |date| day_format = ActiveSupport::Inflector.ordinalize(date.day) date.strftime("%B #{day_format}, %Y") # => "April 25th, 2007" }, - :rfc822 => "%d %b %Y", - :iso8601 => lambda { |date| date.iso8601 } + rfc822: "%d %b %Y", + iso8601: lambda { |date| date.iso8601 } } # Ruby 1.9 has Date#to_time which converts to localtime only. diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index e848a909e9..792076a449 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -3,13 +3,13 @@ require "active_support/core_ext/object/try" module DateAndTime module Calculations DAYS_INTO_WEEK = { - :monday => 0, - :tuesday => 1, - :wednesday => 2, - :thursday => 3, - :friday => 4, - :saturday => 5, - :sunday => 6 + monday: 0, + tuesday: 1, + wednesday: 2, + thursday: 3, + friday: 4, + saturday: 5, + sunday: 6 } WEEKEND_DAYS = [ 6, 0 ] @@ -60,42 +60,42 @@ module DateAndTime # Returns a new date/time the specified number of days ago. def days_ago(days) - advance(:days => -days) + advance(days: -days) end # Returns a new date/time the specified number of days in the future. def days_since(days) - advance(:days => days) + advance(days: days) end # Returns a new date/time the specified number of weeks ago. def weeks_ago(weeks) - advance(:weeks => -weeks) + advance(weeks: -weeks) end # Returns a new date/time the specified number of weeks in the future. def weeks_since(weeks) - advance(:weeks => weeks) + advance(weeks: weeks) end # Returns a new date/time the specified number of months ago. def months_ago(months) - advance(:months => -months) + advance(months: -months) end # Returns a new date/time the specified number of months in the future. def months_since(months) - advance(:months => months) + advance(months: months) end # Returns a new date/time the specified number of years ago. def years_ago(years) - advance(:years => -years) + advance(years: -years) end # Returns a new date/time the specified number of years in the future. def years_since(years) - advance(:years => years) + advance(years: years) end # Returns a new date/time at the start of the month. @@ -108,7 +108,7 @@ module DateAndTime # now = DateTime.current # => Thu, 18 Jun 2015 15:23:13 +0000 # now.beginning_of_month # => Mon, 01 Jun 2015 00:00:00 +0000 def beginning_of_month - first_hour(change(:day => 1)) + first_hour(change(day: 1)) end alias :at_beginning_of_month :beginning_of_month @@ -123,7 +123,7 @@ module DateAndTime # now.beginning_of_quarter # => Wed, 01 Jul 2015 00:00:00 +0000 def beginning_of_quarter first_quarter_month = [10, 7, 4, 1].detect { |m| m <= month } - beginning_of_month.change(:month => first_quarter_month) + beginning_of_month.change(month: first_quarter_month) end alias :at_beginning_of_quarter :beginning_of_quarter @@ -138,7 +138,7 @@ module DateAndTime # now.end_of_quarter # => Wed, 30 Sep 2015 23:59:59 +0000 def end_of_quarter last_quarter_month = [3, 6, 9, 12].detect { |m| m >= month } - beginning_of_month.change(:month => last_quarter_month).end_of_month + beginning_of_month.change(month: last_quarter_month).end_of_month end alias :at_end_of_quarter :end_of_quarter @@ -152,7 +152,7 @@ module DateAndTime # now = DateTime.current # => Fri, 10 Jul 2015 18:41:29 +0000 # now.beginning_of_year # => Thu, 01 Jan 2015 00:00:00 +0000 def beginning_of_year - change(:month => 1).beginning_of_month + change(month: 1).beginning_of_month end alias :at_beginning_of_year :beginning_of_year @@ -290,7 +290,7 @@ module DateAndTime # Returns a new date/time representing the end of the year. # DateTime objects will have a time set to 23:59:59. def end_of_year - change(:month => 12).end_of_month + change(month: 12).end_of_month end alias :at_end_of_year :end_of_year diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 24297f954c..70d5c9af8e 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -75,7 +75,7 @@ class DateTime end d = to_date.advance(options) - datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day) + datetime_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + @@ -104,7 +104,7 @@ class DateTime # Returns a new DateTime representing the start of the day (0:00). def beginning_of_day - change(:hour => 0) + change(hour: 0) end alias :midnight :beginning_of_day alias :at_midnight :beginning_of_day @@ -112,7 +112,7 @@ class DateTime # Returns a new DateTime representing the middle of the day (12:00) def middle_of_day - change(:hour => 12) + change(hour: 12) end alias :midday :middle_of_day alias :noon :middle_of_day @@ -122,31 +122,31 @@ class DateTime # Returns a new DateTime representing the end of the day (23:59:59). def end_of_day - change(:hour => 23, :min => 59, :sec => 59) + change(hour: 23, min: 59, sec: 59) end alias :at_end_of_day :end_of_day # Returns a new DateTime representing the start of the hour (hh:00:00). def beginning_of_hour - change(:min => 0) + change(min: 0) end alias :at_beginning_of_hour :beginning_of_hour # Returns a new DateTime representing the end of the hour (hh:59:59). def end_of_hour - change(:min => 59, :sec => 59) + change(min: 59, sec: 59) end alias :at_end_of_hour :end_of_hour # Returns a new DateTime representing the start of the minute (hh:mm:00). def beginning_of_minute - change(:sec => 0) + change(sec: 0) end alias :at_beginning_of_minute :beginning_of_minute # Returns a new DateTime representing the end of the minute (hh:mm:59). def end_of_minute - change(:sec => 59) + change(sec: 59) end alias :at_end_of_minute :end_of_minute diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb index 3e4894ce19..1c4d181443 100644 --- a/activesupport/lib/active_support/core_ext/object/json.rb +++ b/activesupport/lib/active_support/core_ext/object/json.rb @@ -208,7 +208,7 @@ end class Process::Status #:nodoc: def as_json(options = nil) - { :exitstatus => exitstatus, :pid => pid } + { exitstatus: exitstatus, pid: pid } end end diff --git a/activesupport/lib/active_support/core_ext/range/conversions.rb b/activesupport/lib/active_support/core_ext/range/conversions.rb index 965436c23a..69ea046cb6 100644 --- a/activesupport/lib/active_support/core_ext/range/conversions.rb +++ b/activesupport/lib/active_support/core_ext/range/conversions.rb @@ -1,6 +1,6 @@ module ActiveSupport::RangeWithFormat RANGE_FORMATS = { - :db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } + db: Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" } } # Convert range to a formatted string. See RANGE_FORMATS for predefined formats. diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 756df53069..c87d0c0b63 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -61,7 +61,7 @@ class Time # Time.new(2012, 8, 29, 12, 34, 56).seconds_since_midnight # => 45296.0 # Time.new(2012, 8, 29, 23, 59, 59).seconds_since_midnight # => 86399.0 def seconds_since_midnight - to_i - change(:hour => 0).to_i + (usec / 1.0e+6) + to_i - change(hour: 0).to_i + (usec / 1.0e+6) end # Returns the number of seconds until 23:59:59. @@ -141,7 +141,7 @@ class Time d = to_date.advance(options) d = d.gregorian if d.julian? - time_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day) + time_advanced_by_date = change(year: d.year, month: d.month, day: d.day) seconds_to_advance = \ options.fetch(:seconds, 0) + options.fetch(:minutes, 0) * 60 + @@ -169,7 +169,7 @@ class Time # Returns a new Time representing the start of the day (0:00) def beginning_of_day - change(:hour => 0) + change(hour: 0) end alias :midnight :beginning_of_day alias :at_midnight :beginning_of_day @@ -177,7 +177,7 @@ class Time # Returns a new Time representing the middle of the day (12:00) def middle_of_day - change(:hour => 12) + change(hour: 12) end alias :midday :middle_of_day alias :noon :middle_of_day @@ -188,41 +188,41 @@ class Time # Returns a new Time representing the end of the day, 23:59:59.999999 def end_of_day change( - :hour => 23, - :min => 59, - :sec => 59, - :usec => Rational(999999999, 1000) + hour: 23, + min: 59, + sec: 59, + usec: Rational(999999999, 1000) ) end alias :at_end_of_day :end_of_day # Returns a new Time representing the start of the hour (x:00) def beginning_of_hour - change(:min => 0) + change(min: 0) end alias :at_beginning_of_hour :beginning_of_hour # Returns a new Time representing the end of the hour, x:59:59.999999 def end_of_hour change( - :min => 59, - :sec => 59, - :usec => Rational(999999999, 1000) + min: 59, + sec: 59, + usec: Rational(999999999, 1000) ) end alias :at_end_of_hour :end_of_hour # Returns a new Time representing the start of the minute (x:xx:00) def beginning_of_minute - change(:sec => 0) + change(sec: 0) end alias :at_beginning_of_minute :beginning_of_minute # Returns a new Time representing the end of the minute, x:xx:59.999999 def end_of_minute change( - :sec => 59, - :usec => Rational(999999999, 1000) + sec: 59, + usec: Rational(999999999, 1000) ) end alias :at_end_of_minute :end_of_minute diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index 32f17992ec..f2bbe55aa6 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -3,22 +3,22 @@ require "active_support/values/time_zone" class Time DATE_FORMATS = { - :db => "%Y-%m-%d %H:%M:%S", - :number => "%Y%m%d%H%M%S", - :nsec => "%Y%m%d%H%M%S%9N", - :usec => "%Y%m%d%H%M%S%6N", - :time => "%H:%M", - :short => "%d %b %H:%M", - :long => "%B %d, %Y %H:%M", - :long_ordinal => lambda { |time| + db: "%Y-%m-%d %H:%M:%S", + number: "%Y%m%d%H%M%S", + nsec: "%Y%m%d%H%M%S%9N", + usec: "%Y%m%d%H%M%S%6N", + time: "%H:%M", + short: "%d %b %H:%M", + long: "%B %d, %Y %H:%M", + long_ordinal: lambda { |time| day_format = ActiveSupport::Inflector.ordinalize(time.day) time.strftime("%B #{day_format}, %Y %H:%M") }, - :rfc822 => lambda { |time| + rfc822: lambda { |time| offset_format = time.formatted_offset(false) time.strftime("%a, %d %b %Y %H:%M:%S #{offset_format}") }, - :iso8601 => lambda { |time| time.iso8601 } + iso8601: lambda { |time| time.iso8601 } } # Converts to a formatted string. See DATE_FORMATS for built-in formats. diff --git a/activesupport/lib/active_support/deprecation/behaviors.rb b/activesupport/lib/active_support/deprecation/behaviors.rb index d2a15c3acb..1d1354c23e 100644 --- a/activesupport/lib/active_support/deprecation/behaviors.rb +++ b/activesupport/lib/active_support/deprecation/behaviors.rb @@ -34,7 +34,7 @@ module ActiveSupport notify: ->(message, callstack) { ActiveSupport::Notifications.instrument("deprecation.rails", - :message => message, :callstack => callstack) + message: message, callstack: callstack) }, silence: ->(message, callstack) {}, diff --git a/activesupport/lib/active_support/inflector/transliterate.rb b/activesupport/lib/active_support/inflector/transliterate.rb index 157342cb8a..8f7c6987bc 100644 --- a/activesupport/lib/active_support/inflector/transliterate.rb +++ b/activesupport/lib/active_support/inflector/transliterate.rb @@ -60,7 +60,7 @@ module ActiveSupport def transliterate(string, replacement = "?".freeze) I18n.transliterate(ActiveSupport::Multibyte::Unicode.normalize( ActiveSupport::Multibyte::Unicode.tidy_bytes(string), :c), - :replacement => replacement) + replacement: replacement) end # Replaces special characters in a string so that it may be used as part of diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 164f1fe497..cee731417f 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -7,7 +7,7 @@ module ActiveSupport :time_precision, :time_precision=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :json_encoder, :json_encoder=, - :to => :'ActiveSupport::JSON::Encoding' + to: :'ActiveSupport::JSON::Encoding' end module JSON diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb index d6b5f253b2..c690b1b50b 100644 --- a/activesupport/lib/active_support/multibyte/chars.rb +++ b/activesupport/lib/active_support/multibyte/chars.rb @@ -46,7 +46,7 @@ module ActiveSupport #:nodoc: alias to_s wrapped_string alias to_str wrapped_string - delegate :<=>, :=~, :acts_like_string?, :to => :wrapped_string + delegate :<=>, :=~, :acts_like_string?, to: :wrapped_string # Creates a new Chars instance by wrapping _string_. def initialize(string) diff --git a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb index bed1b2701b..695ee1dad3 100644 --- a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb +++ b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb @@ -40,7 +40,7 @@ module ActiveSupport when Hash units[exp] || "" when String, Symbol - I18n.translate("#{units}.#{exp}", :locale => options[:locale], :count => number.to_i) + I18n.translate("#{units}.#{exp}", locale: options[:locale], count: number.to_i) else translate_in_locale("human.decimal_units.units.#{exp}", count: number.to_i) end @@ -56,7 +56,7 @@ module ActiveSupport when Hash units when String, Symbol - I18n.translate(units.to_s, :locale => options[:locale], :raise => true) + I18n.translate(units.to_s, locale: options[:locale], raise: true) when nil translate_in_locale("human.decimal_units.units", raise: true) else 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 fbd107463a..2b8ff77986 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 @@ -30,11 +30,11 @@ module ActiveSupport private def conversion_format - translate_number_value_with_default("human.storage_units.format", :locale => options[:locale], :raise => true) + translate_number_value_with_default("human.storage_units.format", locale: options[:locale], raise: true) end def unit - translate_number_value_with_default(storage_unit_key, :locale => options[:locale], :count => number.to_i, :raise => true) + translate_number_value_with_default(storage_unit_key, locale: options[:locale], count: number.to_i, raise: true) end def storage_unit_key diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index c6459ab0ee..5611b1b143 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -86,7 +86,7 @@ module ActiveSupport attr_accessor :depth self.depth = 100 - delegate :parse, :to => :backend + delegate :parse, to: :backend def backend current_thread_backend || @backend @@ -108,7 +108,7 @@ module ActiveSupport def to_tag(key, value, options) type_name = options.delete(:type) - merged_options = options.merge(:root => key, :skip_instruct => true) + merged_options = options.merge(root: key, skip_instruct: true) if value.is_a?(::Method) || value.is_a?(::Proc) if value.arity == 1 @@ -126,7 +126,7 @@ module ActiveSupport key = rename_key(key.to_s, options) - attributes = options[:skip_types] || type_name.nil? ? { } : { :type => type_name } + attributes = options[:skip_types] || type_name.nil? ? { } : { type: type_name } attributes[:nil] = true if value.nil? encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name] diff --git a/activesupport/test/benchmarkable_test.rb b/activesupport/test/benchmarkable_test.rb index 02e0ed6a71..6b9eb5aa66 100644 --- a/activesupport/test/benchmarkable_test.rb +++ b/activesupport/test/benchmarkable_test.rb @@ -57,13 +57,13 @@ class BenchmarkableTest < ActiveSupport::TestCase def test_within_level logger.level = ActiveSupport::Logger::DEBUG - benchmark("included_debug_run", :level => :debug) { } + benchmark("included_debug_run", level: :debug) { } assert_last_logged "included_debug_run" end def test_outside_level logger.level = ActiveSupport::Logger::ERROR - benchmark("skipped_debug_run", :level => :debug) { } + benchmark("skipped_debug_run", level: :debug) { } assert_no_match(/skipped_debug_run/, buffer.last) ensure logger.level = ActiveSupport::Logger::DEBUG diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 9d1c9724d9..be1f93a0b2 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -188,8 +188,8 @@ class CacheStoreSettingTest < ActiveSupport::TestCase end def test_mem_cache_fragment_cache_store_with_options - assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { :timeout => 10 }]) do - store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1", :namespace => "foo", :timeout => 10 + assert_called_with(Dalli::Client, :new, [%w[localhost 192.168.1.1], { timeout: 10 }]) do + store = ActiveSupport::Cache.lookup_store :mem_cache_store, "localhost", "192.168.1.1", namespace: "foo", timeout: 10 assert_kind_of(ActiveSupport::Cache::MemCacheStore, store) assert_equal "foo", store.options[:namespace] end @@ -204,7 +204,7 @@ end class CacheStoreNamespaceTest < ActiveSupport::TestCase def test_static_namespace - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "tester") + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester") cache.write("foo", "bar") assert_equal "bar", cache.read("foo") assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value @@ -213,14 +213,14 @@ class CacheStoreNamespaceTest < ActiveSupport::TestCase def test_proc_namespace test_val = "tester" proc = lambda{test_val} - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => proc) + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: proc) cache.write("foo", "bar") assert_equal "bar", cache.read("foo") assert_equal "bar", cache.instance_variable_get(:@data)["tester:foo"].value end def test_delete_matched_key_start - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "tester") + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "tester") cache.write("foo", "bar") cache.write("fu", "baz") cache.delete_matched(/^fo/) @@ -229,7 +229,7 @@ class CacheStoreNamespaceTest < ActiveSupport::TestCase end def test_delete_matched_key - cache = ActiveSupport::Cache.lookup_store(:memory_store, :namespace => "foo") + cache = ActiveSupport::Cache.lookup_store(:memory_store, namespace: "foo") cache.write("foo", "bar") cache.write("fu", "baz") cache.delete_matched(/OO/i) @@ -277,8 +277,8 @@ module CacheStoreBehavior def test_fetch_with_forced_cache_miss @cache.write("foo", "bar") assert_not_called(@cache, :read) do - assert_called_with(@cache, :write, ["foo", "bar", @cache.options.merge(:force => true)]) do - @cache.fetch("foo", :force => true) { "bar" } + assert_called_with(@cache, :write, ["foo", "bar", @cache.options.merge(force: true)]) do + @cache.fetch("foo", force: true) { "bar" } end end end @@ -305,8 +305,8 @@ module CacheStoreBehavior end def test_should_read_and_write_hash - assert @cache.write("foo", {:a => "b"}) - assert_equal({:a => "b"}, @cache.read("foo")) + assert @cache.write("foo", {a: "b"}) + assert_equal({a: "b"}, @cache.read("foo")) end def test_should_read_and_write_integer @@ -333,7 +333,7 @@ module CacheStoreBehavior def test_read_multi_with_expires time = Time.now - @cache.write("foo", "bar", :expires_in => 10) + @cache.write("foo", "bar", expires_in: 10) @cache.write("fu", "baz") @cache.write("fud", "biz") Time.stub(:now, time + 11) do @@ -364,17 +364,17 @@ module CacheStoreBehavior end def test_read_and_write_compressed_small_data - @cache.write("foo", "bar", :compress => true) + @cache.write("foo", "bar", compress: true) assert_equal "bar", @cache.read("foo") end def test_read_and_write_compressed_large_data - @cache.write("foo", "bar", :compress => true, :compress_threshold => 2) + @cache.write("foo", "bar", compress: true, compress_threshold: 2) assert_equal "bar", @cache.read("foo") end def test_read_and_write_compressed_nil - @cache.write("foo", nil, :compress => true) + @cache.write("foo", nil, compress: true) assert_nil @cache.read("foo") end @@ -402,7 +402,7 @@ module CacheStoreBehavior end def test_hash_as_cache_key - @cache.write({:foo => 1, :fu => 2}, "bar") + @cache.write({foo: 1, fu: 2}, "bar") assert_equal "bar", @cache.read("foo=1/fu=2") end @@ -467,9 +467,9 @@ module CacheStoreBehavior def test_race_condition_protection_is_limited time = Time.now - @cache.write("foo", "bar", :expires_in => 60) + @cache.write("foo", "bar", expires_in: 60) Time.stub(:now, time + 71) do - result = @cache.fetch("foo", :race_condition_ttl => 10) do + result = @cache.fetch("foo", race_condition_ttl: 10) do assert_equal nil, @cache.read("foo") "baz" end @@ -479,10 +479,10 @@ module CacheStoreBehavior def test_race_condition_protection_is_safe time = Time.now - @cache.write("foo", "bar", :expires_in => 60) + @cache.write("foo", "bar", expires_in: 60) Time.stub(:now, time + 61) do begin - @cache.fetch("foo", :race_condition_ttl => 10) do + @cache.fetch("foo", race_condition_ttl: 10) do assert_equal "bar", @cache.read("foo") raise ArgumentError.new end @@ -497,9 +497,9 @@ module CacheStoreBehavior def test_race_condition_protection time = Time.now - @cache.write("foo", "bar", :expires_in => 60) + @cache.write("foo", "bar", expires_in: 60) Time.stub(:now, time + 61) do - result = @cache.fetch("foo", :race_condition_ttl => 10) do + result = @cache.fetch("foo", race_condition_ttl: 10) do assert_equal "bar", @cache.read("foo") "baz" end @@ -509,11 +509,11 @@ module CacheStoreBehavior def test_crazy_key_characters crazy_key = "#/:*(<+=> )&$%@?;'\"\'`~-" - assert @cache.write(crazy_key, "1", :raw => true) + assert @cache.write(crazy_key, "1", raw: true) assert_equal "1", @cache.read(crazy_key) assert_equal "1", @cache.fetch(crazy_key) assert @cache.delete(crazy_key) - assert_equal "2", @cache.fetch(crazy_key, :raw => true) { "2" } + assert_equal "2", @cache.fetch(crazy_key, raw: true) { "2" } assert_equal 3, @cache.increment(crazy_key) assert_equal 2, @cache.decrement(crazy_key) end @@ -535,7 +535,7 @@ module CacheStoreBehavior ActiveSupport::Notifications.subscribe "cache_read.active_support" do |*args| @events << ActiveSupport::Notifications::Event.new(*args) end - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert @cache.fetch(key) {} assert_equal 1, @events.length assert_equal "cache_read.active_support", @events[0].name @@ -575,11 +575,11 @@ module EncodedKeyCacheBehavior Encoding.list.each do |encoding| define_method "test_#{encoding.name.underscore}_encoded_values" do key = "foo".force_encoding(encoding) - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) assert @cache.delete(key) - assert_equal "2", @cache.fetch(key, :raw => true) { "2" } + assert_equal "2", @cache.fetch(key, raw: true) { "2" } assert_equal 3, @cache.increment(key) assert_equal 2, @cache.decrement(key) end @@ -587,18 +587,18 @@ module EncodedKeyCacheBehavior def test_common_utf8_values key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) assert @cache.delete(key) - assert_equal "2", @cache.fetch(key, :raw => true) { "2" } + assert_equal "2", @cache.fetch(key, raw: true) { "2" } assert_equal 3, @cache.increment(key) assert_equal 2, @cache.decrement(key) end def test_retains_encoding key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) - assert @cache.write(key, "1", :raw => true) + assert @cache.write(key, "1", raw: true) assert_equal Encoding::UTF_8, key.encoding end end @@ -619,7 +619,7 @@ end module CacheIncrementDecrementBehavior def test_increment - @cache.write("foo", 1, :raw => true) + @cache.write("foo", 1, raw: true) assert_equal 1, @cache.read("foo").to_i assert_equal 2, @cache.increment("foo") assert_equal 2, @cache.read("foo").to_i @@ -629,7 +629,7 @@ module CacheIncrementDecrementBehavior end def test_decrement - @cache.write("foo", 3, :raw => true) + @cache.write("foo", 3, raw: true) assert_equal 3, @cache.read("foo").to_i assert_equal 2, @cache.decrement("foo") assert_equal 2, @cache.read("foo").to_i @@ -715,8 +715,8 @@ module LocalCacheBehavior def test_local_cache_of_increment @cache.with_local_cache do - @cache.write("foo", 1, :raw => true) - @peek.write("foo", 2, :raw => true) + @cache.write("foo", 1, raw: true) + @peek.write("foo", 2, raw: true) @cache.increment("foo") assert_equal 3, @cache.read("foo") end @@ -724,8 +724,8 @@ module LocalCacheBehavior def test_local_cache_of_decrement @cache.with_local_cache do - @cache.write("foo", 1, :raw => true) - @peek.write("foo", 3, :raw => true) + @cache.write("foo", 1, raw: true) + @peek.write("foo", 3, raw: true) @cache.decrement("foo") assert_equal 2, @cache.read("foo") end @@ -794,9 +794,9 @@ end class FileStoreTest < ActiveSupport::TestCase def setup Dir.mkdir(cache_dir) unless File.exist?(cache_dir) - @cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60) - @peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, :expires_in => 60) - @cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), :expires_in => 60) + @cache = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, expires_in: 60) + @peek = ActiveSupport::Cache.lookup_store(:file_store, cache_dir, expires_in: 60) + @cache_with_pathname = ActiveSupport::Cache.lookup_store(:file_store, Pathname.new(cache_dir), expires_in: 60) @buffer = StringIO.new @cache.logger = ActiveSupport::Logger.new(@buffer) @@ -928,7 +928,7 @@ end class MemoryStoreTest < ActiveSupport::TestCase def setup @record_size = ActiveSupport::Cache.lookup_store(:memory_store).send(:cached_size, 1, ActiveSupport::Cache::Entry.new("aaaaaaaaaa")) - @cache = ActiveSupport::Cache.lookup_store(:memory_store, :expires_in => 60, :size => @record_size * 10 + 1) + @cache = ActiveSupport::Cache.lookup_store(:memory_store, expires_in: 60, size: @record_size * 10 + 1) end include CacheStoreBehavior @@ -1022,9 +1022,9 @@ class MemoryStoreTest < ActiveSupport::TestCase def test_write_with_unless_exist assert_equal true, @cache.write(1, "aaaaaaaaaa") - assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true) + assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true) @cache.write(1, nil) - assert_equal false, @cache.write(1, "aaaaaaaaaa", :unless_exist => true) + assert_equal false, @cache.write(1, "aaaaaaaaaa", unless_exist: true) end end @@ -1044,7 +1044,7 @@ class MemCacheStoreTest < ActiveSupport::TestCase def setup skip "memcache server is not up" unless MEMCACHE_UP - @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :expires_in => 60) + @cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, expires_in: 60) @peek = ActiveSupport::Cache.lookup_store(:mem_cache_store) @data = @cache.instance_variable_get(:@data) @cache.clear @@ -1059,21 +1059,21 @@ class MemCacheStoreTest < ActiveSupport::TestCase include AutoloadingCacheBehavior def test_raw_values - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.write("foo", 2) assert_equal "2", cache.read("foo") end def test_raw_values_with_marshal - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.write("foo", Marshal.dump([])) assert_equal [], cache.read("foo") end def test_local_cache_raw_values - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.with_local_cache do cache.write("foo", 2) @@ -1082,7 +1082,7 @@ class MemCacheStoreTest < ActiveSupport::TestCase end def test_local_cache_raw_values_with_marshal - cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, :raw => true) + cache = ActiveSupport::Cache.lookup_store(:mem_cache_store, raw: true) cache.clear cache.with_local_cache do cache.write("foo", Marshal.dump([])) @@ -1133,12 +1133,12 @@ class NullStoreTest < ActiveSupport::TestCase end def test_increment - @cache.write("name", 1, :raw => true) + @cache.write("name", 1, raw: true) assert_nil @cache.increment("name") end def test_decrement - @cache.write("name", 1, :raw => true) + @cache.write("name", 1, raw: true) assert_nil @cache.increment("name") end @@ -1181,7 +1181,7 @@ class CacheStoreLoggerTest < ActiveSupport::TestCase proc = Proc.new do "proc_namespace" end - @cache.fetch("foo", {:namespace => proc}) { "bar" } + @cache.fetch("foo", {namespace: proc}) { "bar" } assert_match %r{proc_namespace:foo}, @buffer.string end @@ -1195,7 +1195,7 @@ class CacheEntryTest < ActiveSupport::TestCase def test_expired entry = ActiveSupport::Cache::Entry.new("value") assert !entry.expired?, "entry not expired" - entry = ActiveSupport::Cache::Entry.new("value", :expires_in => 60) + entry = ActiveSupport::Cache::Entry.new("value", expires_in: 60) assert !entry.expired?, "entry not expired" Time.stub(:now, Time.now + 61) do assert entry.expired?, "entry is expired" @@ -1204,7 +1204,7 @@ class CacheEntryTest < ActiveSupport::TestCase def test_compress_values value = "value" * 100 - entry = ActiveSupport::Cache::Entry.new(value, :compress => true, :compress_threshold => 1) + entry = ActiveSupport::Cache::Entry.new(value, compress: true, compress_threshold: 1) assert_equal value, entry.value assert(value.bytesize > entry.size, "value is compressed") end diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb index ab9627dfba..d1c217177d 100644 --- a/activesupport/test/callback_inheritance_test.rb +++ b/activesupport/test/callback_inheritance_test.rb @@ -9,8 +9,8 @@ class GrandParent end define_callbacks :dispatch - set_callback :dispatch, :before, :before1, :before2, :if => proc {|c| c.action_name == "index" || c.action_name == "update" } - set_callback :dispatch, :after, :after1, :after2, :if => proc {|c| c.action_name == "update" || c.action_name == "delete" } + set_callback :dispatch, :before, :before1, :before2, if: proc {|c| c.action_name == "index" || c.action_name == "update" } + set_callback :dispatch, :after, :after1, :after2, if: proc {|c| c.action_name == "update" || c.action_name == "delete" } def before1 @log << "before1" @@ -37,12 +37,12 @@ class GrandParent end class Parent < GrandParent - skip_callback :dispatch, :before, :before2, :unless => proc {|c| c.action_name == "update" } - skip_callback :dispatch, :after, :after2, :unless => proc {|c| c.action_name == "delete" } + skip_callback :dispatch, :before, :before2, unless: proc {|c| c.action_name == "update" } + skip_callback :dispatch, :after, :after2, unless: proc {|c| c.action_name == "delete" } end class Child < GrandParent - skip_callback :dispatch, :before, :before2, :unless => proc {|c| c.action_name == "update" }, :if => :state_open? + skip_callback :dispatch, :before, :before2, unless: proc {|c| c.action_name == "update" }, if: :state_open? def state_open? @state == :open diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 9eef3135f6..ac2c539f66 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -72,11 +72,11 @@ module CallbacksTest end class PersonSkipper < Person - skip_callback :save, :before, :before_save_method, :if => :yes - skip_callback :save, :after, :after_save_method, :unless => :yes - skip_callback :save, :after, :after_save_method, :if => :no - skip_callback :save, :before, :before_save_method, :unless => :no - skip_callback :save, :before, CallbackClass , :if => :yes + skip_callback :save, :before, :before_save_method, if: :yes + skip_callback :save, :after, :after_save_method, unless: :yes + skip_callback :save, :after, :after_save_method, if: :no + skip_callback :save, :before, :before_save_method, unless: :no + skip_callback :save, :before, CallbackClass , if: :yes def yes; true; end def no; false; end end @@ -89,7 +89,7 @@ module CallbacksTest define_callbacks :dispatch - set_callback :dispatch, :before, :log, :unless => proc {|c| c.action_name == :index || c.action_name == :show } + set_callback :dispatch, :before, :log, unless: proc {|c| c.action_name == :index || c.action_name == :show } set_callback :dispatch, :after, :log2 attr_reader :action_name, :logger @@ -114,7 +114,7 @@ module CallbacksTest end class Child < ParentController - skip_callback :dispatch, :before, :log, :if => proc {|c| c.action_name == :update} + skip_callback :dispatch, :before, :log, if: proc {|c| c.action_name == :update} skip_callback :dispatch, :after, :log2 end @@ -125,10 +125,10 @@ module CallbacksTest super end - before_save Proc.new {|r| r.history << [:before_save, :starts_true, :if] }, :if => :starts_true - before_save Proc.new {|r| r.history << [:before_save, :starts_false, :if] }, :if => :starts_false - before_save Proc.new {|r| r.history << [:before_save, :starts_true, :unless] }, :unless => :starts_true - before_save Proc.new {|r| r.history << [:before_save, :starts_false, :unless] }, :unless => :starts_false + before_save Proc.new {|r| r.history << [:before_save, :starts_true, :if] }, if: :starts_true + before_save Proc.new {|r| r.history << [:before_save, :starts_false, :if] }, if: :starts_false + before_save Proc.new {|r| r.history << [:before_save, :starts_true, :unless] }, unless: :starts_true + before_save Proc.new {|r| r.history << [:before_save, :starts_false, :unless] }, unless: :starts_false def starts_true if @@starts_true @@ -185,23 +185,23 @@ module CallbacksTest class ConditionalPerson < Record # proc - before_save Proc.new { |r| r.history << [:before_save, :proc] }, :if => Proc.new { |r| true } - before_save Proc.new { |r| r.history << "b00m" }, :if => Proc.new { |r| false } - before_save Proc.new { |r| r.history << [:before_save, :proc] }, :unless => Proc.new { |r| false } - before_save Proc.new { |r| r.history << "b00m" }, :unless => Proc.new { |r| true } + before_save Proc.new { |r| r.history << [:before_save, :proc] }, if: Proc.new { |r| true } + before_save Proc.new { |r| r.history << "b00m" }, if: Proc.new { |r| false } + before_save Proc.new { |r| r.history << [:before_save, :proc] }, unless: Proc.new { |r| false } + before_save Proc.new { |r| r.history << "b00m" }, unless: Proc.new { |r| true } # symbol - before_save Proc.new { |r| r.history << [:before_save, :symbol] }, :if => :yes - before_save Proc.new { |r| r.history << "b00m" }, :if => :no - before_save Proc.new { |r| r.history << [:before_save, :symbol] }, :unless => :no - before_save Proc.new { |r| r.history << "b00m" }, :unless => :yes + before_save Proc.new { |r| r.history << [:before_save, :symbol] }, if: :yes + before_save Proc.new { |r| r.history << "b00m" }, if: :no + before_save Proc.new { |r| r.history << [:before_save, :symbol] }, unless: :no + before_save Proc.new { |r| r.history << "b00m" }, unless: :yes # string - before_save Proc.new { |r| r.history << [:before_save, :string] }, :if => "yes" - before_save Proc.new { |r| r.history << "b00m" }, :if => "no" - before_save Proc.new { |r| r.history << [:before_save, :string] }, :unless => "no" - before_save Proc.new { |r| r.history << "b00m" }, :unless => "yes" + before_save Proc.new { |r| r.history << [:before_save, :string] }, if: "yes" + before_save Proc.new { |r| r.history << "b00m" }, if: "no" + before_save Proc.new { |r| r.history << [:before_save, :string] }, unless: "no" + before_save Proc.new { |r| r.history << "b00m" }, unless: "yes" # Combined if and unless - before_save Proc.new { |r| r.history << [:before_save, :combined_symbol] }, :if => :yes, :unless => :no - before_save Proc.new { |r| r.history << "b00m" }, :if => :yes, :unless => :yes + before_save Proc.new { |r| r.history << [:before_save, :combined_symbol] }, if: :yes, unless: :no + before_save Proc.new { |r| r.history << "b00m" }, if: :yes, unless: :yes def yes; true; end def other_yes; true; end @@ -225,18 +225,18 @@ module CallbacksTest class AroundPerson < MySuper attr_reader :history - set_callback :save, :before, :nope, :if => :no - set_callback :save, :before, :nope, :unless => :yes + set_callback :save, :before, :nope, if: :no + set_callback :save, :before, :nope, unless: :yes set_callback :save, :after, :tweedle ActiveSupport::Deprecation.silence { set_callback :save, :before, "tweedle_dee" } set_callback :save, :before, proc {|m| m.history << "yup" } - set_callback :save, :before, :nope, :if => proc { false } - set_callback :save, :before, :nope, :unless => proc { true } - set_callback :save, :before, :yup, :if => proc { true } - set_callback :save, :before, :yup, :unless => proc { false } + set_callback :save, :before, :nope, if: proc { false } + set_callback :save, :before, :nope, unless: proc { true } + set_callback :save, :before, :yup, if: proc { true } + set_callback :save, :before, :yup, unless: proc { false } set_callback :save, :around, :tweedle_dum - set_callback :save, :around, :w0tyes, :if => :yes - set_callback :save, :around, :w0tno, :if => :no + set_callback :save, :around, :w0tyes, if: :yes + set_callback :save, :around, :w0tno, if: :no set_callback :save, :around, :tweedle_deedle def no; false; end @@ -323,7 +323,7 @@ module CallbacksTest define_callbacks :save attr_reader :stuff - set_callback :save, :before, :action, :if => :yes + set_callback :save, :before, :action, if: :yes def yes() true end @@ -637,7 +637,7 @@ module CallbacksTest class CustomScopeObject include ActiveSupport::Callbacks - define_callbacks :save, :scope => [:kind, :name] + define_callbacks :save, scope: [:kind, :name] set_callback :save, :before, CallbackObject.new attr_accessor :record @@ -810,7 +810,7 @@ module CallbacksTest class WriterSkipper < Person attr_accessor :age - skip_callback :save, :before, :before_save_method, :if => lambda {self.age > 21} + skip_callback :save, :before, :before_save_method, if: lambda {self.age > 21} end class WriterCallbacksTest < ActiveSupport::TestCase @@ -903,7 +903,7 @@ module CallbacksTest Class.new { include ActiveSupport::Callbacks define_callbacks :foo - set_callback :foo, :before, :foo, :if => callback + set_callback :foo, :before, :foo, if: callback def foo; end def run; run_callbacks :foo; end } @@ -918,8 +918,8 @@ module CallbacksTest } klass = Class.new { include ActiveSupport::Callbacks - define_callbacks :foo, :scope => [:name] - set_callback :foo, :before, :foo, :if => callback + define_callbacks :foo, scope: [:name] + set_callback :foo, :before, :foo, if: callback def run; run_callbacks :foo; end private def foo; end diff --git a/activesupport/test/core_ext/class/attribute_test.rb b/activesupport/test/core_ext/class/attribute_test.rb index b1a10a007e..5a9ec78cc1 100644 --- a/activesupport/test/core_ext/class/attribute_test.rb +++ b/activesupport/test/core_ext/class/attribute_test.rb @@ -56,18 +56,18 @@ class ClassAttributeTest < ActiveSupport::TestCase end test "disabling instance writer" do - object = Class.new { class_attribute :setting, :instance_writer => false }.new + object = Class.new { class_attribute :setting, instance_writer: false }.new assert_raise(NoMethodError) { object.setting = "boom" } end test "disabling instance reader" do - object = Class.new { class_attribute :setting, :instance_reader => false }.new + object = Class.new { class_attribute :setting, instance_reader: false }.new assert_raise(NoMethodError) { object.setting } assert_raise(NoMethodError) { object.setting? } end test "disabling both instance writer and reader" do - object = Class.new { class_attribute :setting, :instance_accessor => false }.new + object = Class.new { class_attribute :setting, instance_accessor: false }.new assert_raise(NoMethodError) { object.setting } assert_raise(NoMethodError) { object.setting? } assert_raise(NoMethodError) { object.setting = "boom" } diff --git a/activesupport/test/core_ext/date_ext_test.rb b/activesupport/test/core_ext/date_ext_test.rb index 9368820a8e..0c9b88d861 100644 --- a/activesupport/test/core_ext/date_ext_test.rb +++ b/activesupport/test/core_ext/date_ext_test.rb @@ -81,10 +81,10 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_change - assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 11).change(:day => 21) - assert_equal Date.new(2007, 5, 11), Date.new(2005, 2, 11).change(:year => 2007, :month => 5) - assert_equal Date.new(2006,2,22), Date.new(2005,2,22).change(:year => 2006) - assert_equal Date.new(2005,6,22), Date.new(2005,2,22).change(:month => 6) + assert_equal Date.new(2005, 2, 21), Date.new(2005, 2, 11).change(day: 21) + assert_equal Date.new(2007, 5, 11), Date.new(2005, 2, 11).change(year: 2007, month: 5) + assert_equal Date.new(2006,2,22), Date.new(2005,2,22).change(year: 2006) + assert_equal Date.new(2005,6,22), Date.new(2005,2,22).change(month: 6) end def test_sunday @@ -139,34 +139,34 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_advance - assert_equal Date.new(2006,2,28), Date.new(2005,2,28).advance(:years => 1) - assert_equal Date.new(2005,6,28), Date.new(2005,2,28).advance(:months => 4) - assert_equal Date.new(2005,3,21), Date.new(2005,2,28).advance(:weeks => 3) - assert_equal Date.new(2005,3,5), Date.new(2005,2,28).advance(:days => 5) - assert_equal Date.new(2012,9,28), Date.new(2005,2,28).advance(:years => 7, :months => 7) - assert_equal Date.new(2013,10,3), Date.new(2005,2,28).advance(:years => 7, :months => 19, :days => 5) - assert_equal Date.new(2013,10,17), Date.new(2005,2,28).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Date.new(2005,2,28), Date.new(2004,2,29).advance(:years => 1) #leap day plus one year + assert_equal Date.new(2006,2,28), Date.new(2005,2,28).advance(years: 1) + assert_equal Date.new(2005,6,28), Date.new(2005,2,28).advance(months: 4) + assert_equal Date.new(2005,3,21), Date.new(2005,2,28).advance(weeks: 3) + assert_equal Date.new(2005,3,5), Date.new(2005,2,28).advance(days: 5) + assert_equal Date.new(2012,9,28), Date.new(2005,2,28).advance(years: 7, months: 7) + assert_equal Date.new(2013,10,3), Date.new(2005,2,28).advance(years: 7, months: 19, days: 5) + assert_equal Date.new(2013,10,17), Date.new(2005,2,28).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Date.new(2005,2,28), Date.new(2004,2,29).advance(years: 1) #leap day plus one year end def test_advance_does_first_years_and_then_days - assert_equal Date.new(2012, 2, 29), Date.new(2011, 2, 28).advance(:years => 1, :days => 1) + assert_equal Date.new(2012, 2, 29), Date.new(2011, 2, 28).advance(years: 1, days: 1) # If day was done first we would jump to 2012-03-01 instead. end def test_advance_does_first_months_and_then_days - assert_equal Date.new(2010, 3, 29), Date.new(2010, 2, 28).advance(:months => 1, :days => 1) + assert_equal Date.new(2010, 3, 29), Date.new(2010, 2, 28).advance(months: 1, days: 1) # If day was done first we would jump to 2010-04-01 instead. end def test_advance_in_calendar_reform - assert_equal Date.new(1582,10,15), Date.new(1582,10,4).advance(:days => 1) - assert_equal Date.new(1582,10,4), Date.new(1582,10,15).advance(:days => -1) + assert_equal Date.new(1582,10,15), Date.new(1582,10,4).advance(days: 1) + assert_equal Date.new(1582,10,4), Date.new(1582,10,15).advance(days: -1) 5.upto(14) do |day| - assert_equal Date.new(1582,10,4), Date.new(1582,9,day).advance(:months => 1) - assert_equal Date.new(1582,10,4), Date.new(1582,11,day).advance(:months => -1) - assert_equal Date.new(1582,10,4), Date.new(1581,10,day).advance(:years => 1) - assert_equal Date.new(1582,10,4), Date.new(1583,10,day).advance(:years => -1) + assert_equal Date.new(1582,10,4), Date.new(1582,9,day).advance(months: 1) + assert_equal Date.new(1582,10,4), Date.new(1582,11,day).advance(months: -1) + assert_equal Date.new(1582,10,4), Date.new(1581,10,day).advance(years: 1) + assert_equal Date.new(1582,10,4), Date.new(1583,10,day).advance(years: -1) end end @@ -384,9 +384,9 @@ class DateExtCalculationsTest < ActiveSupport::TestCase end def test_date_advance_should_not_change_passed_options_hash - options = { :years => 3, :months => 11, :days => 2 } + options = { years: 3, months: 11, days: 2 } Date.new(2005,2,28).advance(options) - assert_equal({ :years => 3, :months => 11, :days => 2 }, options) + assert_equal({ years: 3, months: 11, days: 2 }, options) end end diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 222a43f1b2..f2a50f4693 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -159,47 +159,47 @@ class DateTimeExtCalculationsTest < ActiveSupport::TestCase end def test_change - assert_equal DateTime.civil(2006,2,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:year => 2006) - assert_equal DateTime.civil(2005,6,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:month => 6) - assert_equal DateTime.civil(2012,9,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(:year => 2012, :month => 9) - assert_equal DateTime.civil(2005,2,22,16), DateTime.civil(2005,2,22,15,15,10).change(:hour => 16) - assert_equal DateTime.civil(2005,2,22,16,45), DateTime.civil(2005,2,22,15,15,10).change(:hour => 16, :min => 45) - assert_equal DateTime.civil(2005,2,22,15,45), DateTime.civil(2005,2,22,15,15,10).change(:min => 45) + assert_equal DateTime.civil(2006,2,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(year: 2006) + assert_equal DateTime.civil(2005,6,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(month: 6) + assert_equal DateTime.civil(2012,9,22,15,15,10), DateTime.civil(2005,2,22,15,15,10).change(year: 2012, month: 9) + assert_equal DateTime.civil(2005,2,22,16), DateTime.civil(2005,2,22,15,15,10).change(hour: 16) + assert_equal DateTime.civil(2005,2,22,16,45), DateTime.civil(2005,2,22,15,15,10).change(hour: 16, min: 45) + assert_equal DateTime.civil(2005,2,22,15,45), DateTime.civil(2005,2,22,15,15,10).change(min: 45) # datetime with fractions of a second - assert_equal DateTime.civil(2005,2,1,15,15,10.7), DateTime.civil(2005,2,22,15,15,10.7).change(:day => 1) + assert_equal DateTime.civil(2005,2,1,15,15,10.7), DateTime.civil(2005,2,22,15,15,10.7).change(day: 1) end def test_advance - assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 1) - assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:months => 4) - assert_equal DateTime.civil(2005,3,21,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal DateTime.civil(2005,3,5,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:days => 5) - assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 7) - assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) - assert_equal DateTime.civil(2013,10,17,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal DateTime.civil(2001,12,27,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal DateTime.civil(2005,2,28,20,15,10), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal DateTime.civil(2005,2,28,15,22,10), DateTime.civil(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal DateTime.civil(2005,2,28,15,15,19), DateTime.civil(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal DateTime.civil(2005,2,28,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal DateTime.civil(2005,2,28,10,8,1), DateTime.civil(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal DateTime.civil(2013,10,17,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal DateTime.civil(2006,2,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 1) + assert_equal DateTime.civil(2005,6,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(months: 4) + assert_equal DateTime.civil(2005,3,21,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(weeks: 3) + assert_equal DateTime.civil(2005,3,5,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(days: 5) + assert_equal DateTime.civil(2012,9,28,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 7) + assert_equal DateTime.civil(2013,10,3,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 19, days: 5) + assert_equal DateTime.civil(2013,10,17,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal DateTime.civil(2001,12,27,15,15,10), DateTime.civil(2005,2,28,15,15,10).advance(years: -3, months: -2, days: -1) + assert_equal DateTime.civil(2005,2,28,15,15,10), DateTime.civil(2004,2,29,15,15,10).advance(years: 1) #leap day plus one year + assert_equal DateTime.civil(2005,2,28,20,15,10), DateTime.civil(2005,2,28,15,15,10).advance(hours: 5) + assert_equal DateTime.civil(2005,2,28,15,22,10), DateTime.civil(2005,2,28,15,15,10).advance(minutes: 7) + assert_equal DateTime.civil(2005,2,28,15,15,19), DateTime.civil(2005,2,28,15,15,10).advance(seconds: 9) + assert_equal DateTime.civil(2005,2,28,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(hours: 5, minutes: 7, seconds: 9) + assert_equal DateTime.civil(2005,2,28,10,8,1), DateTime.civil(2005,2,28,15,15,10).advance(hours: -5, minutes: -7, seconds: -9) + assert_equal DateTime.civil(2013,10,17,20,22,19), DateTime.civil(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_advance_partial_days - assert_equal DateTime.civil(2012,9,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 1.5) - assert_equal DateTime.civil(2012,9,28,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 0.5) - assert_equal DateTime.civil(2012,10,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(:days => 1.5, :months => 1) + assert_equal DateTime.civil(2012,9,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(days: 1.5) + assert_equal DateTime.civil(2012,9,28,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(days: 0.5) + assert_equal DateTime.civil(2012,10,29,13,15,10), DateTime.civil(2012,9,28,1,15,10).advance(days: 1.5, months: 1) end def test_advanced_processes_first_the_date_deltas_and_then_the_time_deltas # If the time deltas were processed first, the following datetimes would be advanced to 2010/04/01 instead. - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59, 59).advance(:months => 1, :seconds => 1) - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59).advance(:months => 1, :minutes => 1) - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23).advance(:months => 1, :hours => 1) - assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 22, 58, 59).advance(:months => 1, :hours => 1, :minutes => 1, :seconds => 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59, 59).advance(months: 1, seconds: 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23, 59).advance(months: 1, minutes: 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 23).advance(months: 1, hours: 1) + assert_equal DateTime.civil(2010, 3, 29), DateTime.civil(2010, 2, 28, 22, 58, 59).advance(months: 1, hours: 1, minutes: 1, seconds: 1) end def test_last_week diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 6c1a6b1ed4..1253c13c5a 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -36,10 +36,10 @@ class HashExtTest < ActiveSupport::TestCase def setup @strings = { "a" => 1, "b" => 2 } @nested_strings = { "a" => { "b" => { "c" => 3 } } } - @symbols = { :a => 1, :b => 2 } - @nested_symbols = { :a => { :b => { :c => 3 } } } + @symbols = { a: 1, b: 2 } + @nested_symbols = { a: { b: { c: 3 } } } @mixed = { :a => 1, "b" => 2 } - @nested_mixed = { "a" => { :b => { "c" => 3 } } } + @nested_mixed = { "a" => { b: { "c" => 3 } } } @integers = { 0 => 1, 1 => 2 } @nested_integers = { 0 => { 1 => { 2 => 3} } } @illegal_symbols = { [] => 3 } @@ -47,8 +47,8 @@ class HashExtTest < ActiveSupport::TestCase @upcase_strings = { "A" => 1, "B" => 2 } @nested_upcase_strings = { "A" => { "B" => { "C" => 3 } } } @string_array_of_hashes = { "a" => [ { "b" => 2 }, { "c" => 3 }, 4 ] } - @symbol_array_of_hashes = { :a => [ { :b => 2 }, { :c => 3 }, 4 ] } - @mixed_array_of_hashes = { :a => [ { :b => 2 }, { "c" => 3 }, 4 ] } + @symbol_array_of_hashes = { a: [ { b: 2 }, { c: 3 }, 4 ] } + @mixed_array_of_hashes = { a: [ { b: 2 }, { "c" => 3 }, 4 ] } @upcase_array_of_hashes = { "A" => [ { "B" => 2 }, { "C" => 3 }, 4 ] } end @@ -127,7 +127,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @nested_mixed.deep_dup transformed_hash.deep_transform_keys!{ |key| key.to_s.upcase } assert_equal @nested_upcase_strings, transformed_hash - assert_equal @nested_mixed, { "a" => { :b => { "c" => 3 } } } + assert_equal @nested_mixed, { "a" => { b: { "c" => 3 } } } end def test_symbolize_keys @@ -183,7 +183,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @nested_mixed.deep_dup transformed_hash.deep_symbolize_keys! assert_equal @nested_symbols, transformed_hash - assert_equal @nested_mixed, { "a" => { :b => { "c" => 3 } } } + assert_equal @nested_mixed, { "a" => { b: { "c" => 3 } } } end def test_symbolize_keys_preserves_keys_that_cant_be_symbolized @@ -259,7 +259,7 @@ class HashExtTest < ActiveSupport::TestCase transformed_hash = @nested_mixed.deep_dup transformed_hash.deep_stringify_keys! assert_equal @nested_strings, transformed_hash - assert_equal @nested_mixed, { "a" => { :b => { "c" => 3 } } } + assert_equal @nested_mixed, { "a" => { b: { "c" => 3 } } } end def test_symbolize_keys_for_hash_with_indifferent_access @@ -360,9 +360,9 @@ class HashExtTest < ActiveSupport::TestCase assert_equal 1, @strings.fetch(:a) hashes = { :@strings => @strings, :@symbols => @symbols, :@mixed => @mixed } - method_map = { :'[]' => 1, :fetch => 1, :values_at => [1], - :has_key? => true, :include? => true, :key? => true, - :member? => true } + method_map = { '[]': 1, fetch: 1, values_at: [1], + has_key?: true, include?: true, key?: true, + member?: true } hashes.each do |name, hash| method_map.sort_by(&:to_s).each do |meth, expected| @@ -447,7 +447,7 @@ class HashExtTest < ActiveSupport::TestCase def test_update_with_to_hash_conversion hash = HashWithIndifferentAccess.new - hash.update HashByConversion.new({ :a => 1 }) + hash.update HashByConversion.new({ a: 1 }) assert_equal hash["a"], 1 end @@ -472,7 +472,7 @@ class HashExtTest < ActiveSupport::TestCase def test_merge_with_to_hash_conversion hash = HashWithIndifferentAccess.new - merged = hash.merge HashByConversion.new({ :a => 1 }) + merged = hash.merge HashByConversion.new({ a: 1 }) assert_equal merged["a"], 1 end @@ -529,13 +529,13 @@ class HashExtTest < ActiveSupport::TestCase assert_equal :old_value, hash[:key] hash = HashWithIndifferentAccess.new("some" => "value", "other" => "value") - hash.reverse_merge!(:some => "noclobber", :another => "clobber") + hash.reverse_merge!(some: "noclobber", another: "clobber") assert_equal "value", hash[:some] assert_equal "clobber", hash[:another] end def test_indifferent_deleting - get_hash = proc{ { :a => "foo" }.with_indifferent_access } + get_hash = proc{ { a: "foo" }.with_indifferent_access } hash = get_hash.call assert_equal hash.delete(:a), "foo" assert_equal hash.delete(:a), nil @@ -687,7 +687,7 @@ class HashExtTest < ActiveSupport::TestCase h = {"user" => {"id" => 5}}.with_indifferent_access ["user", :user].each {|user| [:id, "id"].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}} - h = {:user => {:id => 5}}.with_indifferent_access + h = {user: {id: 5}}.with_indifferent_access ["user", :user].each {|user| [:id, "id"].each {|id| assert_equal 5, h[user][id], "h[#{user.inspect}][#{id.inspect}] should be 5"}} end @@ -710,32 +710,32 @@ class HashExtTest < ActiveSupport::TestCase def test_assert_valid_keys assert_nothing_raised do - { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) - { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) + { failure: "stuff", funny: "business" }.assert_valid_keys([ :failure, :funny ]) + { failure: "stuff", funny: "business" }.assert_valid_keys(:failure, :funny) end # not all valid keys are required to be present assert_nothing_raised do - { :failure => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny, :sunny ]) - { :failure => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny, :sunny) + { failure: "stuff", funny: "business" }.assert_valid_keys([ :failure, :funny, :sunny ]) + { failure: "stuff", funny: "business" }.assert_valid_keys(:failure, :funny, :sunny) end exception = assert_raise ArgumentError do - { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure, :funny ]) + { failore: "stuff", funny: "business" }.assert_valid_keys([ :failure, :funny ]) end assert_equal "Unknown key: :failore. Valid keys are: :failure, :funny", exception.message exception = assert_raise ArgumentError do - { :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure, :funny) + { failore: "stuff", funny: "business" }.assert_valid_keys(:failure, :funny) end assert_equal "Unknown key: :failore. Valid keys are: :failure, :funny", exception.message exception = assert_raise ArgumentError do - { :failore => "stuff", :funny => "business" }.assert_valid_keys([ :failure ]) + { failore: "stuff", funny: "business" }.assert_valid_keys([ :failure ]) end assert_equal "Unknown key: :failore. Valid keys are: :failure", exception.message exception = assert_raise ArgumentError do - { :failore => "stuff", :funny => "business" }.assert_valid_keys(:failure) + { failore: "stuff", funny: "business" }.assert_valid_keys(:failure) end assert_equal "Unknown key: :failore. Valid keys are: :failure", exception.message end @@ -747,9 +747,9 @@ class HashExtTest < ActiveSupport::TestCase end def test_deep_merge - hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } } - hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } - expected = { :a => 1, :b => "b", :c => { :c1 => 2, :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } } + hash_1 = { a: "a", b: "b", c: { c1: "c1", c2: "c2", c3: { d1: "d1" } } } + hash_2 = { a: 1, c: { c1: 2, c3: { d2: "d2" } } } + expected = { a: 1, b: "b", c: { c1: 2, c2: "c2", c3: { d1: "d1", d2: "d2" } } } assert_equal expected, hash_1.deep_merge(hash_2) hash_1.deep_merge!(hash_2) @@ -757,9 +757,9 @@ class HashExtTest < ActiveSupport::TestCase end def test_deep_merge_with_block - hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } } - hash_2 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } - expected = { :a => [:a, "a", 1], :b => "b", :c => { :c1 => [:c1, "c1", 2], :c2 => "c2", :c3 => { :d1 => "d1", :d2 => "d2" } } } + hash_1 = { a: "a", b: "b", c: { c1: "c1", c2: "c2", c3: { d1: "d1" } } } + hash_2 = { a: 1, c: { c1: 2, c3: { d2: "d2" } } } + expected = { a: [:a, "a", 1], b: "b", c: { c1: [:c1, "c1", 2], c2: "c2", c3: { d1: "d1", d2: "d2" } } } assert_equal(expected, hash_1.deep_merge(hash_2) { |k,o,n| [k, o, n] }) hash_1.deep_merge!(hash_2) { |k,o,n| [k, o, n] } @@ -777,9 +777,9 @@ class HashExtTest < ActiveSupport::TestCase end def test_deep_merge_on_indifferent_access - hash_1 = HashWithIndifferentAccess.new({ :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } }) - hash_2 = HashWithIndifferentAccess.new({ :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } }) - hash_3 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } + hash_1 = HashWithIndifferentAccess.new({ a: "a", b: "b", c: { c1: "c1", c2: "c2", c3: { d1: "d1" } } }) + hash_2 = HashWithIndifferentAccess.new({ a: 1, c: { c1: 2, c3: { d2: "d2" } } }) + hash_3 = { a: 1, c: { c1: 2, c3: { d2: "d2" } } } expected = { "a" => 1, "b" => "b", "c" => { "c1" => 2, "c2" => "c2", "c3" => { "d1" => "d1", "d2" => "d2" } } } assert_equal expected, hash_1.deep_merge(hash_2) assert_equal expected, hash_1.deep_merge(hash_3) @@ -808,9 +808,9 @@ class HashExtTest < ActiveSupport::TestCase end def test_reverse_merge - defaults = { :a => "x", :b => "y", :c => 10 }.freeze - options = { :a => 1, :b => 2 } - expected = { :a => 1, :b => 2, :c => 10 } + defaults = { a: "x", b: "y", c: 10 }.freeze + options = { a: 1, b: 2 } + expected = { a: 1, b: 2, c: 10 } # Should merge defaults into options, creating a new hash. assert_equal expected, options.reverse_merge(defaults) @@ -828,8 +828,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_slice - original = { :a => "x", :b => "y", :c => 10 } - expected = { :a => "x", :b => "y" } + original = { a: "x", b: "y", c: 10 } + expected = { a: "x", b: "y" } # Should return a new hash with only the given keys. assert_equal expected, original.slice(:a, :b) @@ -837,8 +837,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_slice_inplace - original = { :a => "x", :b => "y", :c => 10 } - expected = { :c => 10 } + original = { a: "x", b: "y", c: 10 } + expected = { c: 10 } # Should replace the hash with only the given keys. assert_equal expected, original.slice!(:a, :b) @@ -855,7 +855,7 @@ class HashExtTest < ActiveSupport::TestCase def test_slice_inplace_with_an_array_key original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" } - expected = { :a => "x", :b => "y" } + expected = { a: "x", b: "y" } # Should replace the hash with only the given keys when given an array key. assert_equal expected, original.slice!([:a, :b], :c) @@ -863,15 +863,15 @@ class HashExtTest < ActiveSupport::TestCase def test_slice_with_splatted_keys original = { :a => "x", :b => "y", :c => 10, [:a, :b] => "an array key" } - expected = { :a => "x", :b => "y" } + expected = { a: "x", b: "y" } # Should grab each of the splatted keys. assert_equal expected, original.slice(*[:a, :b]) end def test_indifferent_slice - original = { :a => "x", :b => "y", :c => 10 }.with_indifferent_access - expected = { :a => "x", :b => "y" }.with_indifferent_access + original = { a: "x", b: "y", c: 10 }.with_indifferent_access + expected = { a: "x", b: "y" }.with_indifferent_access [["a", "b"], [:a, :b]].each do |keys| # Should return a new hash with only the given keys. @@ -881,8 +881,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_indifferent_slice_inplace - original = { :a => "x", :b => "y", :c => 10 }.with_indifferent_access - expected = { :c => 10 }.with_indifferent_access + original = { a: "x", b: "y", c: 10 }.with_indifferent_access + expected = { c: 10 }.with_indifferent_access [["a", "b"], [:a, :b]].each do |keys| # Should replace the hash with only the given keys. @@ -920,17 +920,17 @@ class HashExtTest < ActiveSupport::TestCase end def test_extract - original = {:a => 1, :b => 2, :c => 3, :d => 4} - expected = {:a => 1, :b => 2} - remaining = {:c => 3, :d => 4} + original = {a: 1, b: 2, c: 3, d: 4} + expected = {a: 1, b: 2} + remaining = {c: 3, d: 4} assert_equal expected, original.extract!(:a, :b, :x) assert_equal remaining, original end def test_extract_nils - original = {:a => nil, :b => nil} - expected = {:a => nil} + original = {a: nil, b: nil} + expected = {a: nil} extracted = original.extract!(:a, :x) assert_equal expected, extracted @@ -940,8 +940,8 @@ class HashExtTest < ActiveSupport::TestCase def test_indifferent_extract original = {:a => 1, "b" => 2, :c => 3, "d" => 4}.with_indifferent_access - expected = {:a => 1, :b => 2}.with_indifferent_access - remaining = {:c => 3, :d => 4}.with_indifferent_access + expected = {a: 1, b: 2}.with_indifferent_access + remaining = {c: 3, d: 4}.with_indifferent_access [["a", "b"], [:a, :b]].each do |keys| copy = original.dup @@ -951,8 +951,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_except - original = { :a => "x", :b => "y", :c => 10 } - expected = { :a => "x", :b => "y" } + original = { a: "x", b: "y", c: 10 } + expected = { a: "x", b: "y" } # Should return a new hash without the given keys. assert_equal expected, original.except(:c) @@ -964,8 +964,8 @@ class HashExtTest < ActiveSupport::TestCase end def test_except_with_more_than_one_argument - original = { :a => "x", :b => "y", :c => 10 } - expected = { :a => "x" } + original = { a: "x", b: "y", c: 10 } + expected = { a: "x" } assert_equal expected, original.except(:b, :c) @@ -974,7 +974,7 @@ class HashExtTest < ActiveSupport::TestCase end def test_except_with_original_frozen - original = { :a => "x", :b => "y" } + original = { a: "x", b: "y" } original.freeze assert_nothing_raised { original.except(:a) } @@ -982,7 +982,7 @@ class HashExtTest < ActiveSupport::TestCase end def test_except_does_not_delete_values_in_original - original = { :a => "x", :b => "y" } + original = { a: "x", b: "y" } assert_not_called(original, :delete) do original.except(:a) end @@ -1081,7 +1081,7 @@ end class IWriteMyOwnXML def to_xml(options = {}) options[:indent] ||= 2 - xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) + xml = options[:builder] ||= Builder::XmlMarkup.new(indent: options[:indent]) xml.instruct! unless options[:skip_instruct] xml.level_one do xml.tag!(:second_level, "content") @@ -1098,7 +1098,7 @@ class HashExtToParamTests < ActiveSupport::TestCase def test_string_hash assert_equal "", {}.to_param - assert_equal "hello=world", { :hello => "world" }.to_param + assert_equal "hello=world", { hello: "world" }.to_param assert_equal "hello=10", { "hello" => 10 }.to_param assert_equal "hello=world&say_bye=true", {:hello => "world", "say_bye" => true}.to_param end @@ -1122,46 +1122,46 @@ end class HashToXmlTest < ActiveSupport::TestCase def setup - @xml_options = { :root => :person, :skip_instruct => true, :indent => 0 } + @xml_options = { root: :person, skip_instruct: true, indent: 0 } end def test_one_level - xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) + xml = { name: "David", street: "Paulina" }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_dasherize_false - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:dasherize => false)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(dasherize: false)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street_name>Paulina</street_name>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_dasherize_true - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:dasherize => true)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(dasherize: true)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street-name>Paulina</street-name>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_camelize_true - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:camelize => true)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(camelize: true)) assert_equal "<Person>", xml.first(8) assert xml.include?(%(<StreetName>Paulina</StreetName>)) assert xml.include?(%(<Name>David</Name>)) end def test_one_level_camelize_lower - xml = { :name => "David", :street_name => "Paulina" }.to_xml(@xml_options.merge(:camelize => :lower)) + xml = { name: "David", street_name: "Paulina" }.to_xml(@xml_options.merge(camelize: :lower)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<streetName>Paulina</streetName>)) assert xml.include?(%(<name>David</name>)) end def test_one_level_with_types - xml = { :name => "David", :street => "Paulina", :age => 26, :age_in_millis => 820497600000, :moved_on => Date.new(2005, 11, 15), :resident => :yes }.to_xml(@xml_options) + xml = { name: "David", street: "Paulina", age: 26, age_in_millis: 820497600000, moved_on: Date.new(2005, 11, 15), resident: :yes }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) @@ -1172,7 +1172,7 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_one_level_with_nils - xml = { :name => "David", :street => "Paulina", :age => nil }.to_xml(@xml_options) + xml = { name: "David", street: "Paulina", age: nil }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) @@ -1180,7 +1180,7 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_one_level_with_skipping_types - xml = { :name => "David", :street => "Paulina", :age => nil }.to_xml(@xml_options.merge(:skip_types => true)) + xml = { name: "David", street: "Paulina", age: nil }.to_xml(@xml_options.merge(skip_types: true)) assert_equal "<person>", xml.first(8) assert xml.include?(%(<street>Paulina</street>)) assert xml.include?(%(<name>David</name>)) @@ -1188,7 +1188,7 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_one_level_with_yielding - xml = { :name => "David", :street => "Paulina" }.to_xml(@xml_options) do |x| + xml = { name: "David", street: "Paulina" }.to_xml(@xml_options) do |x| x.creator("Rails") end @@ -1199,21 +1199,21 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_two_levels - xml = { :name => "David", :address => { :street => "Paulina" } }.to_xml(@xml_options) + xml = { name: "David", address: { street: "Paulina" } }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<address><street>Paulina</street></address>)) assert xml.include?(%(<name>David</name>)) end def test_two_levels_with_second_level_overriding_to_xml - xml = { :name => "David", :address => { :street => "Paulina" }, :child => IWriteMyOwnXML.new }.to_xml(@xml_options) + xml = { name: "David", address: { street: "Paulina" }, child: IWriteMyOwnXML.new }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<address><street>Paulina</street></address>)) assert xml.include?(%(<level_one><second_level>content</second_level></level_one>)) end def test_two_levels_with_array - xml = { :name => "David", :addresses => [{ :street => "Paulina" }, { :street => "Evergreen" }] }.to_xml(@xml_options) + xml = { name: "David", addresses: [{ street: "Paulina" }, { street: "Evergreen" }] }.to_xml(@xml_options) assert_equal "<person>", xml.first(8) assert xml.include?(%(<addresses type="array"><address>)) assert xml.include?(%(<address><street>Paulina</street></address>)) @@ -1222,14 +1222,14 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_three_levels_with_array - xml = { :name => "David", :addresses => [{ :streets => [ { :name => "Paulina" }, { :name => "Paulina" } ] } ] }.to_xml(@xml_options) + xml = { name: "David", addresses: [{ streets: [ { name: "Paulina" }, { name: "Paulina" } ] } ] }.to_xml(@xml_options) assert xml.include?(%(<addresses type="array"><address><streets type="array"><street><name>)) end def test_timezoned_attributes xml = { - :created_at => Time.utc(1999,2,2), - :local_created_at => Time.utc(1999,2,2).in_time_zone("Eastern Time (US & Canada)") + created_at: Time.utc(1999,2,2), + local_created_at: Time.utc(1999,2,2).in_time_zone("Eastern Time (US & Canada)") }.to_xml(@xml_options) assert_match %r{<created-at type=\"dateTime\">1999-02-02T00:00:00Z</created-at>}, xml assert_match %r{<local-created-at type=\"dateTime\">1999-02-01T19:00:00-05:00</local-created-at>}, xml @@ -1268,17 +1268,17 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => "The First Topic", - :author_name => "David", - :id => 1, - :approved => false, - :replies_count => 0, - :replies_close_in => 2592000000, - :written_on => Date.new(2003, 7, 16), - :viewed_at => Time.utc(2003, 7, 16, 9, 28), - :content => "Have a nice day", - :author_email_address => "david@loudthinking.com", - :parent_id => nil + title: "The First Topic", + author_name: "David", + id: 1, + approved: false, + replies_count: 0, + replies_close_in: 2592000000, + written_on: Date.new(2003, 7, 16), + viewed_at: Time.utc(2003, 7, 16, 9, 28), + content: "Have a nice day", + author_email_address: "david@loudthinking.com", + parent_id: nil }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topics_xml)["topics"].first @@ -1303,18 +1303,18 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => "The First Topic", - :author_name => "David", - :id => 1, - :approved => true, - :replies_count => 0, - :replies_close_in => 2592000000, - :written_on => Date.new(2003, 7, 16), - :viewed_at => Time.utc(2003, 7, 16, 9, 28), - :author_email_address => "david@loudthinking.com", - :parent_id => nil, - :ad_revenue => BigDecimal("1.50"), - :optimum_viewing_angle => 135.0, + title: "The First Topic", + author_name: "David", + id: 1, + approved: true, + replies_count: 0, + replies_close_in: 2592000000, + written_on: Date.new(2003, 7, 16), + viewed_at: Time.utc(2003, 7, 16, 9, 28), + author_email_address: "david@loudthinking.com", + parent_id: nil, + ad_revenue: BigDecimal("1.50"), + optimum_viewing_angle: 135.0, }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] @@ -1333,12 +1333,12 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => nil, - :id => nil, - :approved => nil, - :written_on => nil, - :viewed_at => nil, - :parent_id => nil + title: nil, + id: nil, + approved: nil, + written_on: nil, + viewed_at: nil, + parent_id: nil }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["topic"] @@ -1377,17 +1377,17 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :title => "The First Topic", - :author_name => "David", - :id => 1, - :approved => false, - :replies_count => 0, - :replies_close_in => 2592000000, - :written_on => Date.new(2003, 7, 16), - :viewed_at => Time.utc(2003, 7, 16, 9, 28), - :content => "Have a nice day", - :author_email_address => "david@loudthinking.com", - :parent_id => nil + title: "The First Topic", + author_name: "David", + id: 1, + approved: false, + replies_count: 0, + replies_close_in: 2592000000, + written_on: Date.new(2003, 7, 16), + viewed_at: Time.utc(2003, 7, 16, 9, 28), + content: "Have a nice day", + author_email_address: "david@loudthinking.com", + parent_id: nil }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topics_xml)["topics"].first @@ -1403,14 +1403,14 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_topic_hash = { - :id => "175756086", - :owner => "55569174@N00", - :secret => "0279bf37a1", - :server => "76", - :title => "Colored Pencil PhotoBooth Fun", - :ispublic => "1", - :isfriend => "0", - :isfamily => "0", + id: "175756086", + owner: "55569174@N00", + secret: "0279bf37a1", + server: "76", + title: "Colored Pencil PhotoBooth Fun", + ispublic: "1", + isfriend: "0", + isfamily: "0", }.stringify_keys assert_equal expected_topic_hash, Hash.from_xml(topic_xml)["rsp"]["photos"]["photo"] @@ -1535,13 +1535,13 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_bacon_hash = { - :weight => 0.5, - :chunky => true, - :price => BigDecimal("12.50"), - :expires_at => Time.utc(2007,12,25,12,34,56), - :notes => "", - :illustration => "babe.png", - :caption => "That'll do, pig." + weight: 0.5, + chunky: true, + price: BigDecimal("12.50"), + expires_at: Time.utc(2007,12,25,12,34,56), + notes: "", + illustration: "babe.png", + caption: "That'll do, pig." }.stringify_keys assert_equal expected_bacon_hash, Hash.from_xml(bacon_xml)["bacon"] @@ -1557,8 +1557,8 @@ class HashToXmlTest < ActiveSupport::TestCase EOT expected_product_hash = { - :weight => 0.5, - :image => {"type" => "ProductImage", "filename" => "image.gif" }, + weight: 0.5, + image: {"type" => "ProductImage", "filename" => "image.gif" }, }.stringify_keys assert_equal expected_product_hash, Hash.from_xml(product_xml)["product"] @@ -1654,7 +1654,7 @@ class HashToXmlTest < ActiveSupport::TestCase # The XML builder seems to fail miserably when trying to tag something # with the same name as a Kernel method (throw, test, loop, select ...) def test_kernel_method_names_to_xml - hash = { :throw => { :ball => "red" } } + hash = { throw: { ball: "red" } } expected = "<person><throw><ball>red</ball></throw></person>" assert_nothing_raised do @@ -1670,8 +1670,8 @@ class HashToXmlTest < ActiveSupport::TestCase def test_escaping_to_xml hash = { - :bare_string => "First & Last Name", - :pre_escaped_string => "First & Last Name" + bare_string: "First & Last Name", + pre_escaped_string: "First & Last Name" }.stringify_keys expected_xml = "<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>" @@ -1681,16 +1681,16 @@ class HashToXmlTest < ActiveSupport::TestCase def test_unescaping_from_xml xml_string = "<person><bare-string>First & Last Name</bare-string><pre-escaped-string>First &amp; Last Name</pre-escaped-string></person>" expected_hash = { - :bare_string => "First & Last Name", - :pre_escaped_string => "First & Last Name" + bare_string: "First & Last Name", + pre_escaped_string: "First & Last Name" }.stringify_keys assert_equal expected_hash, Hash.from_xml(xml_string)["person"] end def test_roundtrip_to_xml_from_xml hash = { - :bare_string => "First & Last Name", - :pre_escaped_string => "First & Last Name" + bare_string: "First & Last Name", + pre_escaped_string: "First & Last Name" }.stringify_keys assert_equal hash, Hash.from_xml(hash.to_xml(@xml_options))["person"] @@ -1735,10 +1735,10 @@ class HashToXmlTest < ActiveSupport::TestCase end def test_to_xml_dups_options - options = {:skip_instruct => true} + options = {skip_instruct: true} {}.to_xml(options) # :builder, etc, shouldn't be added to options - assert_equal({:skip_instruct => true}, options) + assert_equal({skip_instruct: true}, options) end def test_expansion_count_is_limited diff --git a/activesupport/test/core_ext/module/attribute_accessor_test.rb b/activesupport/test/core_ext/module/attribute_accessor_test.rb index 0c66e2c33c..fea6806b9b 100644 --- a/activesupport/test/core_ext/module/attribute_accessor_test.rb +++ b/activesupport/test/core_ext/module/attribute_accessor_test.rb @@ -5,9 +5,9 @@ class ModuleAttributeAccessorTest < ActiveSupport::TestCase def setup m = @module = Module.new do mattr_accessor :foo - mattr_accessor :bar, :instance_writer => false - mattr_reader :shaq, :instance_reader => false - mattr_accessor :camp, :instance_accessor => false + mattr_accessor :bar, instance_writer: false + mattr_reader :shaq, instance_reader: false + mattr_accessor :camp, instance_accessor: false cattr_accessor(:defa) { "default_accessor_value" } cattr_reader(:defr) { "default_reader_value" } diff --git a/activesupport/test/core_ext/module_test.rb b/activesupport/test/core_ext/module_test.rb index 3d7ec0ef91..9a2e52efa7 100644 --- a/activesupport/test/core_ext/module_test.rb +++ b/activesupport/test/core_ext/module_test.rb @@ -25,21 +25,21 @@ Somewhere = Struct.new(:street, :city) do end class Someone < Struct.new(:name, :place) - delegate :street, :city, :to_f, :to => :place - delegate :name=, :to => :place, :prefix => true - delegate :upcase, :to => "place.city" - delegate :table_name, :to => :class - delegate :table_name, :to => :class, :prefix => true + delegate :street, :city, :to_f, to: :place + delegate :name=, to: :place, prefix: true + delegate :upcase, to: "place.city" + delegate :table_name, to: :class + delegate :table_name, to: :class, prefix: true def self.table_name "some_table" end FAILED_DELEGATE_LINE = __LINE__ + 1 - delegate :foo, :to => :place + delegate :foo, to: :place FAILED_DELEGATE_LINE_2 = __LINE__ + 1 - delegate :bar, :to => :place, :allow_nil => true + delegate :bar, to: :place, allow_nil: true private @@ -49,32 +49,32 @@ class Someone < Struct.new(:name, :place) end Invoice = Struct.new(:client) do - delegate :street, :city, :name, :to => :client, :prefix => true - delegate :street, :city, :name, :to => :client, :prefix => :customer + delegate :street, :city, :name, to: :client, prefix: true + delegate :street, :city, :name, to: :client, prefix: :customer end Project = Struct.new(:description, :person) do - delegate :name, :to => :person, :allow_nil => true - delegate :to_f, :to => :description, :allow_nil => true + delegate :name, to: :person, allow_nil: true + delegate :to_f, to: :description, allow_nil: true end Developer = Struct.new(:client) do - delegate :name, :to => :client, :prefix => nil + delegate :name, to: :client, prefix: nil end Event = Struct.new(:case) do - delegate :foo, :to => :case + delegate :foo, to: :case end Tester = Struct.new(:client) do - delegate :name, :to => :client, :prefix => false + delegate :name, to: :client, prefix: false def foo; 1; end end Product = Struct.new(:name) do - delegate :name, :to => :manufacturer, :prefix => true - delegate :name, :to => :type, :prefix => true + delegate :name, to: :manufacturer, prefix: true + delegate :name, to: :type, prefix: true def manufacturer @manufacturer ||= begin @@ -114,15 +114,15 @@ HasBlock = Struct.new(:block) do end class ParameterSet - delegate :[], :[]=, :to => :@params + delegate :[], :[]=, to: :@params def initialize - @params = {:foo => "bar"} + @params = {foo: "bar"} end end class Name - delegate :upcase, :to => :@full_name + delegate :upcase, to: :@full_name def initialize(first, last) @full_name = "#{first} #{last}" @@ -132,8 +132,8 @@ end class SideEffect attr_reader :ints - delegate :to_i, :to => :shift, :allow_nil => true - delegate :to_s, :to => :shift + delegate :to_i, to: :shift, allow_nil: true + delegate :to_s, to: :shift def initialize @ints = [1, 2, 3] @@ -189,7 +189,7 @@ class ModuleTest < ActiveSupport::TestCase Name.send :delegate, :nowhere end assert_raise(ArgumentError) do - Name.send :delegate, :noplace, :tos => :hollywood + Name.send :delegate, :noplace, tos: :hollywood end end @@ -233,7 +233,7 @@ class ModuleTest < ActiveSupport::TestCase def initialize(client) @client = client end - delegate :name, :address, :to => :@client, :prefix => true + delegate :name, :address, to: :@client, prefix: true end end end @@ -261,7 +261,7 @@ class ModuleTest < ActiveSupport::TestCase def test_delegation_with_allow_nil_and_nil_value_and_prefix Project.class_eval do - delegate :name, :to => :person, :allow_nil => true, :prefix => true + delegate :name, to: :person, allow_nil: true, prefix: true end rails = Project.new("Rails") assert_nil rails.person_name @@ -290,7 +290,7 @@ class ModuleTest < ActiveSupport::TestCase assert_nothing_raised do Class.new(parent) do class << self - delegate :parent_method, :to => :superclass + delegate :parent_method, to: :superclass end end end diff --git a/activesupport/test/core_ext/numeric_ext_test.rb b/activesupport/test/core_ext/numeric_ext_test.rb index 793f34897c..fc93a18ab1 100644 --- a/activesupport/test/core_ext/numeric_ext_test.rb +++ b/activesupport/test/core_ext/numeric_ext_test.rb @@ -23,41 +23,41 @@ class NumericExtTimeAndDateTimeTest < ActiveSupport::TestCase end def test_irregular_durations - assert_equal @now.advance(:days => 3000), 3000.days.since(@now) - assert_equal @now.advance(:months => 1), 1.month.since(@now) - assert_equal @now.advance(:months => -1), 1.month.until(@now) - assert_equal @now.advance(:years => 20), 20.years.since(@now) - assert_equal @dtnow.advance(:days => 3000), 3000.days.since(@dtnow) - assert_equal @dtnow.advance(:months => 1), 1.month.since(@dtnow) - assert_equal @dtnow.advance(:months => -1), 1.month.until(@dtnow) - assert_equal @dtnow.advance(:years => 20), 20.years.since(@dtnow) + assert_equal @now.advance(days: 3000), 3000.days.since(@now) + assert_equal @now.advance(months: 1), 1.month.since(@now) + assert_equal @now.advance(months: -1), 1.month.until(@now) + assert_equal @now.advance(years: 20), 20.years.since(@now) + assert_equal @dtnow.advance(days: 3000), 3000.days.since(@dtnow) + assert_equal @dtnow.advance(months: 1), 1.month.since(@dtnow) + assert_equal @dtnow.advance(months: -1), 1.month.until(@dtnow) + assert_equal @dtnow.advance(years: 20), 20.years.since(@dtnow) end def test_duration_addition - assert_equal @now.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@now) - assert_equal @now.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@now) - assert_equal @now.advance(:years => 2), (4.years - 2.years).since(@now) - assert_equal @dtnow.advance(:days => 1).advance(:months => 1), (1.day + 1.month).since(@dtnow) - assert_equal @dtnow.advance(:days => 7), (1.week + 5.seconds - 5.seconds).since(@dtnow) - assert_equal @dtnow.advance(:years => 2), (4.years - 2.years).since(@dtnow) + assert_equal @now.advance(days: 1).advance(months: 1), (1.day + 1.month).since(@now) + assert_equal @now.advance(days: 7), (1.week + 5.seconds - 5.seconds).since(@now) + assert_equal @now.advance(years: 2), (4.years - 2.years).since(@now) + assert_equal @dtnow.advance(days: 1).advance(months: 1), (1.day + 1.month).since(@dtnow) + assert_equal @dtnow.advance(days: 7), (1.week + 5.seconds - 5.seconds).since(@dtnow) + assert_equal @dtnow.advance(years: 2), (4.years - 2.years).since(@dtnow) end def test_time_plus_duration assert_equal @now + 8, @now + 8.seconds assert_equal @now + 22.9, @now + 22.9.seconds - assert_equal @now.advance(:days => 15), @now + 15.days - assert_equal @now.advance(:months => 1), @now + 1.month + assert_equal @now.advance(days: 15), @now + 15.days + assert_equal @now.advance(months: 1), @now + 1.month assert_equal @dtnow.since(8), @dtnow + 8.seconds assert_equal @dtnow.since(22.9), @dtnow + 22.9.seconds - assert_equal @dtnow.advance(:days => 15), @dtnow + 15.days - assert_equal @dtnow.advance(:months => 1), @dtnow + 1.month + assert_equal @dtnow.advance(days: 15), @dtnow + 15.days + assert_equal @dtnow.advance(months: 1), @dtnow + 1.month end def test_chaining_duration_operations - assert_equal @now.advance(:days => 2).advance(:months => -3), @now + 2.days - 3.months - assert_equal @now.advance(:days => 1).advance(:months => 2), @now + 1.day + 2.months - assert_equal @dtnow.advance(:days => 2).advance(:months => -3), @dtnow + 2.days - 3.months - assert_equal @dtnow.advance(:days => 1).advance(:months => 2), @dtnow + 1.day + 2.months + assert_equal @now.advance(days: 2).advance(months: -3), @now + 2.days - 3.months + assert_equal @now.advance(days: 1).advance(months: 2), @now + 1.day + 2.months + assert_equal @dtnow.advance(days: 2).advance(months: -3), @dtnow + 2.days - 3.months + assert_equal @dtnow.advance(days: 1).advance(months: 2), @dtnow + 1.day + 2.months end def test_duration_after_conversion_is_no_longer_accurate @@ -87,8 +87,8 @@ class NumericExtDateTest < ActiveSupport::TestCase end def test_chaining_duration_operations - assert_equal @today.advance(:days => 2).advance(:months => -3), @today + 2.days - 3.months - assert_equal @today.advance(:days => 1).advance(:months => 2), @today + 1.day + 2.months + assert_equal @today.advance(days: 2).advance(months: -3), @today + 2.days - 3.months + assert_equal @today.advance(days: 1).advance(months: 2), @today + 1.day + 2.months end def test_add_one_year_to_leap_day @@ -154,53 +154,53 @@ class NumericExtFormattingTest < ActiveSupport::TestCase def test_to_s__phone assert_equal("555-1234", 5551234.to_s(:phone)) assert_equal("800-555-1212", 8005551212.to_s(:phone)) - assert_equal("(800) 555-1212", 8005551212.to_s(:phone, :area_code => true)) - assert_equal("800 555 1212", 8005551212.to_s(:phone, :delimiter => " ")) - assert_equal("(800) 555-1212 x 123", 8005551212.to_s(:phone, :area_code => true, :extension => 123)) - assert_equal("800-555-1212", 8005551212.to_s(:phone, :extension => " ")) - assert_equal("555.1212", 5551212.to_s(:phone, :delimiter => ".")) - assert_equal("+1-800-555-1212", 8005551212.to_s(:phone, :country_code => 1)) - assert_equal("+18005551212", 8005551212.to_s(:phone, :country_code => 1, :delimiter => "")) + assert_equal("(800) 555-1212", 8005551212.to_s(:phone, area_code: true)) + assert_equal("800 555 1212", 8005551212.to_s(:phone, delimiter: " ")) + assert_equal("(800) 555-1212 x 123", 8005551212.to_s(:phone, area_code: true, extension: 123)) + assert_equal("800-555-1212", 8005551212.to_s(:phone, extension: " ")) + assert_equal("555.1212", 5551212.to_s(:phone, delimiter: ".")) + assert_equal("+1-800-555-1212", 8005551212.to_s(:phone, country_code: 1)) + assert_equal("+18005551212", 8005551212.to_s(:phone, country_code: 1, delimiter: "")) assert_equal("22-555-1212", 225551212.to_s(:phone)) - assert_equal("+45-22-555-1212", 225551212.to_s(:phone, :country_code => 45)) + assert_equal("+45-22-555-1212", 225551212.to_s(:phone, country_code: 45)) end def test_to_s__currency assert_equal("$1,234,567,890.50", 1234567890.50.to_s(:currency)) assert_equal("$1,234,567,890.51", 1234567890.506.to_s(:currency)) assert_equal("-$1,234,567,890.50", -1234567890.50.to_s(:currency)) - assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_s(:currency, :format => "%u %n")) - assert_equal("($1,234,567,890.50)", -1234567890.50.to_s(:currency, :negative_format => "(%u%n)")) - assert_equal("$1,234,567,892", 1234567891.50.to_s(:currency, :precision => 0)) - assert_equal("$1,234,567,890.5", 1234567890.50.to_s(:currency, :precision => 1)) - assert_equal("£1234567890,50", 1234567890.50.to_s(:currency, :unit => "£", :separator => ",", :delimiter => "")) + assert_equal("-$ 1,234,567,890.50", -1234567890.50.to_s(:currency, format: "%u %n")) + assert_equal("($1,234,567,890.50)", -1234567890.50.to_s(:currency, negative_format: "(%u%n)")) + assert_equal("$1,234,567,892", 1234567891.50.to_s(:currency, precision: 0)) + assert_equal("$1,234,567,890.5", 1234567890.50.to_s(:currency, precision: 1)) + assert_equal("£1234567890,50", 1234567890.50.to_s(:currency, unit: "£", separator: ",", delimiter: "")) end def test_to_s__rounded assert_equal("-111.235", -111.2346.to_s(:rounded)) assert_equal("111.235", 111.2346.to_s(:rounded)) - assert_equal("31.83", 31.825.to_s(:rounded, :precision => 2)) - assert_equal("111.23", 111.2346.to_s(:rounded, :precision => 2)) - assert_equal("111.00", 111.to_s(:rounded, :precision => 2)) - assert_equal("3268", (32.6751 * 100.00).to_s(:rounded, :precision => 0)) - assert_equal("112", 111.50.to_s(:rounded, :precision => 0)) - assert_equal("1234567892", 1234567891.50.to_s(:rounded, :precision => 0)) - assert_equal("0", 0.to_s(:rounded, :precision => 0)) - assert_equal("0.00100", 0.001.to_s(:rounded, :precision => 5)) - assert_equal("0.001", 0.00111.to_s(:rounded, :precision => 3)) - assert_equal("10.00", 9.995.to_s(:rounded, :precision => 2)) - assert_equal("11.00", 10.995.to_s(:rounded, :precision => 2)) - assert_equal("0.00", -0.001.to_s(:rounded, :precision => 2)) + assert_equal("31.83", 31.825.to_s(:rounded, precision: 2)) + assert_equal("111.23", 111.2346.to_s(:rounded, precision: 2)) + assert_equal("111.00", 111.to_s(:rounded, precision: 2)) + assert_equal("3268", (32.6751 * 100.00).to_s(:rounded, precision: 0)) + assert_equal("112", 111.50.to_s(:rounded, precision: 0)) + assert_equal("1234567892", 1234567891.50.to_s(:rounded, precision: 0)) + assert_equal("0", 0.to_s(:rounded, precision: 0)) + assert_equal("0.00100", 0.001.to_s(:rounded, precision: 5)) + assert_equal("0.001", 0.00111.to_s(:rounded, precision: 3)) + assert_equal("10.00", 9.995.to_s(:rounded, precision: 2)) + assert_equal("11.00", 10.995.to_s(:rounded, precision: 2)) + assert_equal("0.00", -0.001.to_s(:rounded, precision: 2)) end def test_to_s__percentage assert_equal("100.000%", 100.to_s(:percentage)) - assert_equal("100%", 100.to_s(:percentage, :precision => 0)) - assert_equal("302.06%", 302.0574.to_s(:percentage, :precision => 2)) - assert_equal("123.4%", 123.400.to_s(:percentage, :precision => 3, :strip_insignificant_zeros => true)) - assert_equal("1.000,000%", 1000.to_s(:percentage, :delimiter => ".", :separator => ",")) - assert_equal("1000.000 %", 1000.to_s(:percentage, :format => "%n %")) + assert_equal("100%", 100.to_s(:percentage, precision: 0)) + assert_equal("302.06%", 302.0574.to_s(:percentage, precision: 2)) + assert_equal("123.4%", 123.400.to_s(:percentage, precision: 3, strip_insignificant_zeros: true)) + assert_equal("1.000,000%", 1000.to_s(:percentage, delimiter: ".", separator: ",")) + assert_equal("1000.000 %", 1000.to_s(:percentage, format: "%n %")) end def test_to_s__delimited @@ -216,51 +216,51 @@ class NumericExtFormattingTest < ActiveSupport::TestCase end def test_to_s__delimited__with_options_hash - assert_equal "12 345 678", 12345678.to_s(:delimited, :delimiter => " ") - assert_equal "12,345,678-05", 12345678.05.to_s(:delimited, :separator => "-") - assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, :separator => ",", :delimiter => ".") - assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, :delimiter => ".", :separator => ",") + assert_equal "12 345 678", 12345678.to_s(:delimited, delimiter: " ") + assert_equal "12,345,678-05", 12345678.05.to_s(:delimited, separator: "-") + assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, separator: ",", delimiter: ".") + assert_equal "12.345.678,05", 12345678.05.to_s(:delimited, delimiter: ".", separator: ",") end def test_to_s__rounded_with_custom_delimiter_and_separator - assert_equal "31,83", 31.825.to_s(:rounded, :precision => 2, :separator => ",") - assert_equal "1.231,83", 1231.825.to_s(:rounded, :precision => 2, :separator => ",", :delimiter => ".") + assert_equal "31,83", 31.825.to_s(:rounded, precision: 2, separator: ",") + assert_equal "1.231,83", 1231.825.to_s(:rounded, precision: 2, separator: ",", delimiter: ".") end def test_to_s__rounded__with_significant_digits - assert_equal "124000", 123987.to_s(:rounded, :precision => 3, :significant => true) - assert_equal "120000000", 123987876.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "9775", 9775.to_s(:rounded, :precision => 4, :significant => true ) - assert_equal "5.4", 5.3923.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "5", 5.3923.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "1", 1.232.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "7", 7.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "1", 1.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "53", 52.7923.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "9775.00", 9775.to_s(:rounded, :precision => 6, :significant => true ) - assert_equal "5.392900", 5.3929.to_s(:rounded, :precision => 7, :significant => true ) - assert_equal "0.0", 0.to_s(:rounded, :precision => 2, :significant => true ) - assert_equal "0", 0.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "0.0001", 0.0001.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "0.000100", 0.0001.to_s(:rounded, :precision => 3, :significant => true ) - assert_equal "0.0001", 0.0001111.to_s(:rounded, :precision => 1, :significant => true ) - assert_equal "10.0", 9.995.to_s(:rounded, :precision => 3, :significant => true) - assert_equal "9.99", 9.994.to_s(:rounded, :precision => 3, :significant => true) - assert_equal "11.0", 10.995.to_s(:rounded, :precision => 3, :significant => true) + assert_equal "124000", 123987.to_s(:rounded, precision: 3, significant: true) + assert_equal "120000000", 123987876.to_s(:rounded, precision: 2, significant: true ) + assert_equal "9775", 9775.to_s(:rounded, precision: 4, significant: true ) + assert_equal "5.4", 5.3923.to_s(:rounded, precision: 2, significant: true ) + assert_equal "5", 5.3923.to_s(:rounded, precision: 1, significant: true ) + assert_equal "1", 1.232.to_s(:rounded, precision: 1, significant: true ) + assert_equal "7", 7.to_s(:rounded, precision: 1, significant: true ) + assert_equal "1", 1.to_s(:rounded, precision: 1, significant: true ) + assert_equal "53", 52.7923.to_s(:rounded, precision: 2, significant: true ) + assert_equal "9775.00", 9775.to_s(:rounded, precision: 6, significant: true ) + assert_equal "5.392900", 5.3929.to_s(:rounded, precision: 7, significant: true ) + assert_equal "0.0", 0.to_s(:rounded, precision: 2, significant: true ) + assert_equal "0", 0.to_s(:rounded, precision: 1, significant: true ) + assert_equal "0.0001", 0.0001.to_s(:rounded, precision: 1, significant: true ) + assert_equal "0.000100", 0.0001.to_s(:rounded, precision: 3, significant: true ) + assert_equal "0.0001", 0.0001111.to_s(:rounded, precision: 1, significant: true ) + assert_equal "10.0", 9.995.to_s(:rounded, precision: 3, significant: true) + assert_equal "9.99", 9.994.to_s(:rounded, precision: 3, significant: true) + assert_equal "11.0", 10.995.to_s(:rounded, precision: 3, significant: true) end def test_to_s__rounded__with_strip_insignificant_zeros - assert_equal "9775.43", 9775.43.to_s(:rounded, :precision => 4, :strip_insignificant_zeros => true ) - assert_equal "9775.2", 9775.2.to_s(:rounded, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) - assert_equal "0", 0.to_s(:rounded, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) + assert_equal "9775.43", 9775.43.to_s(:rounded, precision: 4, strip_insignificant_zeros: true ) + assert_equal "9775.2", 9775.2.to_s(:rounded, precision: 6, significant: true, strip_insignificant_zeros: true ) + assert_equal "0", 0.to_s(:rounded, precision: 6, significant: true, strip_insignificant_zeros: true ) end def test_to_s__rounded__with_significant_true_and_zero_precision # Zero precision with significant is a mistake (would always return zero), # so we treat it as if significant was false (increases backwards compatibility for number_to_human_size) - assert_equal "124", 123.987.to_s(:rounded, :precision => 0, :significant => true) - assert_equal "12", 12.to_s(:rounded, :precision => 0, :significant => true ) + assert_equal "124", 123.987.to_s(:rounded, precision: 0, significant: true) + assert_equal "12", 12.to_s(:rounded, precision: 0, significant: true ) end def test_to_s__human_size @@ -280,50 +280,50 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal "444 KB", kilobytes(444).to_s(:human_size) assert_equal "1020 MB", megabytes(1023).to_s(:human_size) assert_equal "3 TB", terabytes(3).to_s(:human_size) - assert_equal "1.2 MB", 1234567.to_s(:human_size, :precision => 2) - assert_equal "3 Bytes", 3.14159265.to_s(:human_size, :precision => 4) - assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, :precision => 2) - assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, :precision => 4) - assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, :precision => 4) + assert_equal "1.2 MB", 1234567.to_s(:human_size, precision: 2) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size, precision: 4) + assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 2) + assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, precision: 4) + assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, precision: 4) assert_equal "1 Byte", 1.1.to_s(:human_size) assert_equal "10 Bytes", 10.to_s(:human_size) end def test_to_s__human_size_with_si_prefix assert_deprecated do - assert_equal "3 Bytes", 3.14159265.to_s(:human_size, :prefix => :si) - assert_equal "123 Bytes", 123.0.to_s(:human_size, :prefix => :si) - assert_equal "123 Bytes", 123.to_s(:human_size, :prefix => :si) - assert_equal "1.23 KB", 1234.to_s(:human_size, :prefix => :si) - assert_equal "12.3 KB", 12345.to_s(:human_size, :prefix => :si) - assert_equal "1.23 MB", 1234567.to_s(:human_size, :prefix => :si) - assert_equal "1.23 GB", 1234567890.to_s(:human_size, :prefix => :si) - assert_equal "1.23 TB", 1234567890123.to_s(:human_size, :prefix => :si) - assert_equal "1.23 PB", 1234567890123456.to_s(:human_size, :prefix => :si) - assert_equal "1.23 EB", 1234567890123456789.to_s(:human_size, :prefix => :si) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size, prefix: :si) + assert_equal "123 Bytes", 123.0.to_s(:human_size, prefix: :si) + assert_equal "123 Bytes", 123.to_s(:human_size, prefix: :si) + assert_equal "1.23 KB", 1234.to_s(:human_size, prefix: :si) + assert_equal "12.3 KB", 12345.to_s(:human_size, prefix: :si) + assert_equal "1.23 MB", 1234567.to_s(:human_size, prefix: :si) + assert_equal "1.23 GB", 1234567890.to_s(:human_size, prefix: :si) + assert_equal "1.23 TB", 1234567890123.to_s(:human_size, prefix: :si) + assert_equal "1.23 PB", 1234567890123456.to_s(:human_size, prefix: :si) + assert_equal "1.23 EB", 1234567890123456789.to_s(:human_size, prefix: :si) end end def test_to_s__human_size_with_options_hash - assert_equal "1.2 MB", 1234567.to_s(:human_size, :precision => 2) - assert_equal "3 Bytes", 3.14159265.to_s(:human_size, :precision => 4) - assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, :precision => 2) - assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, :precision => 4) - assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, :precision => 4) - assert_equal "1 TB", 1234567890123.to_s(:human_size, :precision => 1) - assert_equal "500 MB", 524288000.to_s(:human_size, :precision=>3) - assert_equal "10 MB", 9961472.to_s(:human_size, :precision=>0) - assert_equal "40 KB", 41010.to_s(:human_size, :precision => 1) - assert_equal "40 KB", 41100.to_s(:human_size, :precision => 2) - assert_equal "1.0 KB", kilobytes(1.0123).to_s(:human_size, :precision => 2, :strip_insignificant_zeros => false) - assert_equal "1.012 KB", kilobytes(1.0123).to_s(:human_size, :precision => 3, :significant => false) - assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, :precision => 0, :significant => true) #ignores significant it precision is 0 + assert_equal "1.2 MB", 1234567.to_s(:human_size, precision: 2) + assert_equal "3 Bytes", 3.14159265.to_s(:human_size, precision: 4) + assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 2) + assert_equal "1.01 KB", kilobytes(1.0100).to_s(:human_size, precision: 4) + assert_equal "10 KB", kilobytes(10.000).to_s(:human_size, precision: 4) + assert_equal "1 TB", 1234567890123.to_s(:human_size, precision: 1) + assert_equal "500 MB", 524288000.to_s(:human_size, precision: 3) + assert_equal "10 MB", 9961472.to_s(:human_size, precision: 0) + assert_equal "40 KB", 41010.to_s(:human_size, precision: 1) + assert_equal "40 KB", 41100.to_s(:human_size, precision: 2) + assert_equal "1.0 KB", kilobytes(1.0123).to_s(:human_size, precision: 2, strip_insignificant_zeros: false) + assert_equal "1.012 KB", kilobytes(1.0123).to_s(:human_size, precision: 3, significant: false) + assert_equal "1 KB", kilobytes(1.0123).to_s(:human_size, precision: 0, significant: true) #ignores significant it precision is 0 end def test_to_s__human_size_with_custom_delimiter_and_separator - assert_equal "1,01 KB", kilobytes(1.0123).to_s(:human_size, :precision => 3, :separator => ",") - assert_equal "1,01 KB", kilobytes(1.0100).to_s(:human_size, :precision => 4, :separator => ",") - assert_equal "1.000,1 TB", terabytes(1000.1).to_s(:human_size, :precision => 5, :delimiter => ".", :separator => ",") + assert_equal "1,01 KB", kilobytes(1.0123).to_s(:human_size, precision: 3, separator: ",") + assert_equal "1,01 KB", kilobytes(1.0100).to_s(:human_size, precision: 4, separator: ",") + assert_equal "1.000,1 TB", terabytes(1000.1).to_s(:human_size, precision: 5, delimiter: ".", separator: ",") end def test_number_to_human @@ -339,51 +339,51 @@ class NumericExtFormattingTest < ActiveSupport::TestCase assert_equal "1.23 Trillion", 1234567890123.to_s(:human) assert_equal "1.23 Quadrillion", 1234567890123456.to_s(:human) assert_equal "1230 Quadrillion", 1234567890123456789.to_s(:human) - assert_equal "490 Thousand", 489939.to_s(:human, :precision => 2) - assert_equal "489.9 Thousand", 489939.to_s(:human, :precision => 4) - assert_equal "489 Thousand", 489000.to_s(:human, :precision => 4) - assert_equal "489.0 Thousand", 489000.to_s(:human, :precision => 4, :strip_insignificant_zeros => false) - assert_equal "1.2346 Million", 1234567.to_s(:human, :precision => 4, :significant => false) - assert_equal "1,2 Million", 1234567.to_s(:human, :precision => 1, :significant => false, :separator => ",") - assert_equal "1 Million", 1234567.to_s(:human, :precision => 0, :significant => true, :separator => ",") #significant forced to false + assert_equal "490 Thousand", 489939.to_s(:human, precision: 2) + assert_equal "489.9 Thousand", 489939.to_s(:human, precision: 4) + assert_equal "489 Thousand", 489000.to_s(:human, precision: 4) + assert_equal "489.0 Thousand", 489000.to_s(:human, precision: 4, strip_insignificant_zeros: false) + assert_equal "1.2346 Million", 1234567.to_s(:human, precision: 4, significant: false) + assert_equal "1,2 Million", 1234567.to_s(:human, precision: 1, significant: false, separator: ",") + assert_equal "1 Million", 1234567.to_s(:human, precision: 0, significant: true, separator: ",") #significant forced to false end def test_number_to_human_with_custom_units #Only integers - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal "123 lt", 123456.to_s(:human, :units => volume) - assert_equal "12 ml", 12.to_s(:human, :units => volume) - assert_equal "1.23 m3", 1234567.to_s(:human, :units => volume) + volume = {unit: "ml", thousand: "lt", million: "m3"} + assert_equal "123 lt", 123456.to_s(:human, units: volume) + assert_equal "12 ml", 12.to_s(:human, units: volume) + assert_equal "1.23 m3", 1234567.to_s(:human, units: volume) #Including fractionals - distance = {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} - assert_equal "1.23 mm", 0.00123.to_s(:human, :units => distance) - assert_equal "1.23 cm", 0.0123.to_s(:human, :units => distance) - assert_equal "1.23 dm", 0.123.to_s(:human, :units => distance) - assert_equal "1.23 m", 1.23.to_s(:human, :units => distance) - assert_equal "1.23 dam", 12.3.to_s(:human, :units => distance) - assert_equal "1.23 hm", 123.to_s(:human, :units => distance) - assert_equal "1.23 km", 1230.to_s(:human, :units => distance) - assert_equal "1.23 km", 1230.to_s(:human, :units => distance) - assert_equal "1.23 km", 1230.to_s(:human, :units => distance) - assert_equal "12.3 km", 12300.to_s(:human, :units => distance) + distance = {mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km"} + assert_equal "1.23 mm", 0.00123.to_s(:human, units: distance) + assert_equal "1.23 cm", 0.0123.to_s(:human, units: distance) + assert_equal "1.23 dm", 0.123.to_s(:human, units: distance) + assert_equal "1.23 m", 1.23.to_s(:human, units: distance) + assert_equal "1.23 dam", 12.3.to_s(:human, units: distance) + assert_equal "1.23 hm", 123.to_s(:human, units: distance) + assert_equal "1.23 km", 1230.to_s(:human, units: distance) + assert_equal "1.23 km", 1230.to_s(:human, units: distance) + assert_equal "1.23 km", 1230.to_s(:human, units: distance) + assert_equal "12.3 km", 12300.to_s(:human, units: distance) #The quantifiers don't need to be a continuous sequence - gangster = {:hundred => "hundred bucks", :million => "thousand quids"} - assert_equal "1 hundred bucks", 100.to_s(:human, :units => gangster) - assert_equal "25 hundred bucks", 2500.to_s(:human, :units => gangster) - assert_equal "25 thousand quids", 25000000.to_s(:human, :units => gangster) - assert_equal "12300 thousand quids", 12345000000.to_s(:human, :units => gangster) + gangster = {hundred: "hundred bucks", million: "thousand quids"} + assert_equal "1 hundred bucks", 100.to_s(:human, units: gangster) + assert_equal "25 hundred bucks", 2500.to_s(:human, units: gangster) + assert_equal "25 thousand quids", 25000000.to_s(:human, units: gangster) + assert_equal "12300 thousand quids", 12345000000.to_s(:human, units: gangster) #Spaces are stripped from the resulting string - assert_equal "4", 4.to_s(:human, :units => {:unit => "", :ten => "tens "}) - assert_equal "4.5 tens", 45.to_s(:human, :units => {:unit => "", :ten => " tens "}) + assert_equal "4", 4.to_s(:human, units: {unit: "", ten: "tens "}) + assert_equal "4.5 tens", 45.to_s(:human, units: {unit: "", ten: " tens "}) end def test_number_to_human_with_custom_format - assert_equal "123 times Thousand", 123456.to_s(:human, :format => "%n times %u") - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal "123.lt", 123456.to_s(:human, :units => volume, :format => "%n.%u") + assert_equal "123 times Thousand", 123456.to_s(:human, format: "%n times %u") + volume = {unit: "ml", thousand: "lt", million: "m3"} + assert_equal "123.lt", 123456.to_s(:human, units: volume, format: "%n.%u") end def test_to_s__injected_on_proper_types diff --git a/activesupport/test/core_ext/object/deep_dup_test.rb b/activesupport/test/core_ext/object/deep_dup_test.rb index 38981f0497..2c0526eebf 100644 --- a/activesupport/test/core_ext/object/deep_dup_test.rb +++ b/activesupport/test/core_ext/object/deep_dup_test.rb @@ -12,7 +12,7 @@ class DeepDupTest < ActiveSupport::TestCase end def test_hash_deep_dup - hash = { :a => { :b => "b" } } + hash = { a: { b: "b" } } dup = hash.deep_dup dup[:a][:c] = "c" assert_equal nil, hash[:a][:c] @@ -20,7 +20,7 @@ class DeepDupTest < ActiveSupport::TestCase end def test_array_deep_dup_with_hash_inside - array = [1, { :a => 2, :b => 3 } ] + array = [1, { a: 2, b: 3 } ] dup = array.deep_dup dup[1][:c] = 4 assert_equal nil, array[1][:c] @@ -28,7 +28,7 @@ class DeepDupTest < ActiveSupport::TestCase end def test_hash_deep_dup_with_array_inside - hash = { :a => [1, 2] } + hash = { a: [1, 2] } dup = hash.deep_dup dup[:a][2] = "c" assert_equal nil, hash[:a][2] @@ -37,7 +37,7 @@ class DeepDupTest < ActiveSupport::TestCase def test_deep_dup_initialize zero_hash = Hash.new 0 - hash = { :a => zero_hash } + hash = { a: zero_hash } dup = hash.deep_dup assert_equal 0, dup[:a][44] end diff --git a/activesupport/test/core_ext/object/to_query_test.rb b/activesupport/test/core_ext/object/to_query_test.rb index 42566d5374..aaa7e69acb 100644 --- a/activesupport/test/core_ext/object/to_query_test.rb +++ b/activesupport/test/core_ext/object/to_query_test.rb @@ -5,7 +5,7 @@ require "active_support/core_ext/string/output_safety" class ToQueryTest < ActiveSupport::TestCase def test_simple_conversion - assert_query_equal "a=10", :a => 10 + assert_query_equal "a=10", a: 10 end def test_cgi_escaping @@ -28,22 +28,22 @@ class ToQueryTest < ActiveSupport::TestCase def test_nested_conversion assert_query_equal "person%5Blogin%5D=seckar&person%5Bname%5D=Nicholas", - :person => Hash[:login, "seckar", :name, "Nicholas"] + person: Hash[:login, "seckar", :name, "Nicholas"] end def test_multiple_nested assert_query_equal "account%5Bperson%5D%5Bid%5D=20&person%5Bid%5D=10", - Hash[:account, {:person => {:id => 20}}, :person, {:id => 10}] + Hash[:account, {person: {id: 20}}, :person, {id: 10}] end def test_array_values assert_query_equal "person%5Bid%5D%5B%5D=10&person%5Bid%5D%5B%5D=20", - :person => {:id => [10, 20]} + person: {id: [10, 20]} end def test_array_values_are_not_sorted assert_query_equal "person%5Bid%5D%5B%5D=20&person%5Bid%5D%5B%5D=10", - :person => {:id => [20, 10]} + person: {id: [20, 10]} end def test_empty_array diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index fceee698fc..4b40503d22 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -263,16 +263,16 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_truncate_with_omission_and_separator - assert_equal "Hello[...]", "Hello World!".truncate(10, :omission => "[...]") - assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => " ") - assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => " ") - assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => " ") + assert_equal "Hello[...]", "Hello World!".truncate(10, omission: "[...]") + assert_equal "Hello[...]", "Hello Big World!".truncate(13, omission: "[...]", separator: " ") + assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, omission: "[...]", separator: " ") + assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, omission: "[...]", separator: " ") end def test_truncate_with_omission_and_regexp_separator - assert_equal "Hello[...]", "Hello Big World!".truncate(13, :omission => "[...]", :separator => /\s/) - assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, :omission => "[...]", :separator => /\s/) - assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => /\s/) + assert_equal "Hello[...]", "Hello Big World!".truncate(13, omission: "[...]", separator: /\s/) + assert_equal "Hello Big[...]", "Hello Big World!".truncate(14, omission: "[...]", separator: /\s/) + assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, omission: "[...]", separator: /\s/) end def test_truncate_words @@ -281,19 +281,19 @@ class StringInflectionsTest < ActiveSupport::TestCase end def test_truncate_words_with_omission - assert_equal "Hello Big World!", "Hello Big World!".truncate_words(3, :omission => "[...]") - assert_equal "Hello Big[...]", "Hello Big World!".truncate_words(2, :omission => "[...]") + assert_equal "Hello Big World!", "Hello Big World!".truncate_words(3, omission: "[...]") + assert_equal "Hello Big[...]", "Hello Big World!".truncate_words(2, omission: "[...]") end def test_truncate_words_with_separator - assert_equal "Hello<br>Big<br>World!...", "Hello<br>Big<br>World!<br>".truncate_words(3, :separator => "<br>") - assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :separator => "<br>") - assert_equal "Hello\n<br>Big...", "Hello\n<br>Big<br>Wide<br>World!".truncate_words(2, :separator => "<br>") + assert_equal "Hello<br>Big<br>World!...", "Hello<br>Big<br>World!<br>".truncate_words(3, separator: "<br>") + assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, separator: "<br>") + assert_equal "Hello\n<br>Big...", "Hello\n<br>Big<br>Wide<br>World!".truncate_words(2, separator: "<br>") end def test_truncate_words_with_separator_and_omission - assert_equal "Hello<br>Big<br>World![...]", "Hello<br>Big<br>World!<br>".truncate_words(3, :omission => "[...]", :separator => "<br>") - assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :omission => "[...]", :separator => "<br>") + assert_equal "Hello<br>Big<br>World![...]", "Hello<br>Big<br>World!<br>".truncate_words(3, omission: "[...]", separator: "<br>") + assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, omission: "[...]", separator: "<br>") end def test_truncate_words_with_complex_string @@ -821,7 +821,7 @@ class OutputSafetyTest < ActiveSupport::TestCase end test "emits normal string yaml" do - assert_equal "foo".to_yaml, "foo".html_safe.to_yaml(:foo => 1) + assert_equal "foo".to_yaml, "foo".html_safe.to_yaml(foo: 1) end test "call to_param returns a normal string" do diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 8fb85e3494..a6c9a7d5a8 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -393,122 +393,122 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase end def test_change - assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2006) - assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:month => 6) - assert_equal Time.local(2012,9,22,15,15,10), Time.local(2005,2,22,15,15,10).change(:year => 2012, :month => 9) - assert_equal Time.local(2005,2,22,16), Time.local(2005,2,22,15,15,10).change(:hour => 16) - assert_equal Time.local(2005,2,22,16,45), Time.local(2005,2,22,15,15,10).change(:hour => 16, :min => 45) - assert_equal Time.local(2005,2,22,15,45), Time.local(2005,2,22,15,15,10).change(:min => 45) - - assert_equal Time.local(2005,1,2, 5, 0, 0, 0), Time.local(2005,1,2,11,22,33,44).change(:hour => 5) - assert_equal Time.local(2005,1,2,11, 6, 0, 0), Time.local(2005,1,2,11,22,33,44).change(:min => 6) - assert_equal Time.local(2005,1,2,11,22, 7, 0), Time.local(2005,1,2,11,22,33,44).change(:sec => 7) - assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(:usec => 8) - assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,2).change(:nsec => 8000) - assert_raise(ArgumentError) { Time.local(2005,1,2,11,22,33, 8).change(:usec => 1, :nsec => 1) } + assert_equal Time.local(2006,2,22,15,15,10), Time.local(2005,2,22,15,15,10).change(year: 2006) + assert_equal Time.local(2005,6,22,15,15,10), Time.local(2005,2,22,15,15,10).change(month: 6) + assert_equal Time.local(2012,9,22,15,15,10), Time.local(2005,2,22,15,15,10).change(year: 2012, month: 9) + assert_equal Time.local(2005,2,22,16), Time.local(2005,2,22,15,15,10).change(hour: 16) + assert_equal Time.local(2005,2,22,16,45), Time.local(2005,2,22,15,15,10).change(hour: 16, min: 45) + assert_equal Time.local(2005,2,22,15,45), Time.local(2005,2,22,15,15,10).change(min: 45) + + assert_equal Time.local(2005,1,2, 5, 0, 0, 0), Time.local(2005,1,2,11,22,33,44).change(hour: 5) + assert_equal Time.local(2005,1,2,11, 6, 0, 0), Time.local(2005,1,2,11,22,33,44).change(min: 6) + assert_equal Time.local(2005,1,2,11,22, 7, 0), Time.local(2005,1,2,11,22,33,44).change(sec: 7) + assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,44).change(usec: 8) + assert_equal Time.local(2005,1,2,11,22,33, 8), Time.local(2005,1,2,11,22,33,2).change(nsec: 8000) + assert_raise(ArgumentError) { Time.local(2005,1,2,11,22,33, 8).change(usec: 1, nsec: 1) } assert_nothing_raised { Time.new(2015, 5, 9, 10, 00, 00, "+03:00").change(nsec: 999999999) } end def test_utc_change - assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:year => 2006) - assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:month => 6) - assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(:year => 2012, :month => 9) - assert_equal Time.utc(2005,2,22,16), Time.utc(2005,2,22,15,15,10).change(:hour => 16) - assert_equal Time.utc(2005,2,22,16,45), Time.utc(2005,2,22,15,15,10).change(:hour => 16, :min => 45) - assert_equal Time.utc(2005,2,22,15,45), Time.utc(2005,2,22,15,15,10).change(:min => 45) - assert_equal Time.utc(2005,1,2,11,22,33,8), Time.utc(2005,1,2,11,22,33,2).change(:nsec => 8000) + assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(year: 2006) + assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(month: 6) + assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).change(year: 2012, month: 9) + assert_equal Time.utc(2005,2,22,16), Time.utc(2005,2,22,15,15,10).change(hour: 16) + assert_equal Time.utc(2005,2,22,16,45), Time.utc(2005,2,22,15,15,10).change(hour: 16, min: 45) + assert_equal Time.utc(2005,2,22,15,45), Time.utc(2005,2,22,15,15,10).change(min: 45) + assert_equal Time.utc(2005,1,2,11,22,33,8), Time.utc(2005,1,2,11,22,33,2).change(nsec: 8000) end def test_offset_change - assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:year => 2006) - assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:month => 6) - assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:year => 2012, :month => 9) - assert_equal Time.new(2005,2,22,16,0,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:hour => 16) - assert_equal Time.new(2005,2,22,16,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:hour => 16, :min => 45) - assert_equal Time.new(2005,2,22,15,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(:min => 45) - assert_equal Time.new(2005,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,0,"-08:00").change(:sec => 10) - assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(:usec => 10).usec - assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(:nsec => 10).nsec - assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(:usec => 1000000) } - assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(:nsec => 1000000000) } + assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(year: 2006) + assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(month: 6) + assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(year: 2012, month: 9) + assert_equal Time.new(2005,2,22,16,0,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(hour: 16) + assert_equal Time.new(2005,2,22,16,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(hour: 16, min: 45) + assert_equal Time.new(2005,2,22,15,45,0,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").change(min: 45) + assert_equal Time.new(2005,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,0,"-08:00").change(sec: 10) + assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(usec: 10).usec + assert_equal 10, Time.new(2005,2,22,15,15,0,"-08:00").change(nsec: 10).nsec + assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(usec: 1000000) } + assert_raise(ArgumentError) { Time.new(2005, 2, 22, 15, 15, 45, "-08:00").change(nsec: 1000000000) } end def test_advance - assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 1) - assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:months => 4) - assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.5) - assert_in_delta Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(:weeks => 3.7), 1 - assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5) - assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.5) - assert_in_delta Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(:days => 5.7), 1 - assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 7) - assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :days => 5) - assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Time.local(2001,12,27,15,15,10), Time.local(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal Time.local(2005,2,28,15,15,10), Time.local(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal Time.local(2005,2,28,20,15,10), Time.local(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal Time.local(2005,2,28,15,22,10), Time.local(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal Time.local(2005,2,28,15,15,19), Time.local(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal Time.local(2005,2,28,20,22,19), Time.local(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal Time.local(2005,2,28,10,8,1), Time.local(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal Time.local(2013,10,17,20,22,19), Time.local(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal Time.local(2006,2,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 1) + assert_equal Time.local(2005,6,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(months: 4) + assert_equal Time.local(2005,3,21,15,15,10), Time.local(2005,2,28,15,15,10).advance(weeks: 3) + assert_equal Time.local(2005,3,25,3,15,10), Time.local(2005,2,28,15,15,10).advance(weeks: 3.5) + assert_in_delta Time.local(2005,3,26,12,51,10), Time.local(2005,2,28,15,15,10).advance(weeks: 3.7), 1 + assert_equal Time.local(2005,3,5,15,15,10), Time.local(2005,2,28,15,15,10).advance(days: 5) + assert_equal Time.local(2005,3,6,3,15,10), Time.local(2005,2,28,15,15,10).advance(days: 5.5) + assert_in_delta Time.local(2005,3,6,8,3,10), Time.local(2005,2,28,15,15,10).advance(days: 5.7), 1 + assert_equal Time.local(2012,9,28,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 7) + assert_equal Time.local(2013,10,3,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 19, days: 5) + assert_equal Time.local(2013,10,17,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Time.local(2001,12,27,15,15,10), Time.local(2005,2,28,15,15,10).advance(years: -3, months: -2, days: -1) + assert_equal Time.local(2005,2,28,15,15,10), Time.local(2004,2,29,15,15,10).advance(years: 1) #leap day plus one year + assert_equal Time.local(2005,2,28,20,15,10), Time.local(2005,2,28,15,15,10).advance(hours: 5) + assert_equal Time.local(2005,2,28,15,22,10), Time.local(2005,2,28,15,15,10).advance(minutes: 7) + assert_equal Time.local(2005,2,28,15,15,19), Time.local(2005,2,28,15,15,10).advance(seconds: 9) + assert_equal Time.local(2005,2,28,20,22,19), Time.local(2005,2,28,15,15,10).advance(hours: 5, minutes: 7, seconds: 9) + assert_equal Time.local(2005,2,28,10,8,1), Time.local(2005,2,28,15,15,10).advance(hours: -5, minutes: -7, seconds: -9) + assert_equal Time.local(2013,10,17,20,22,19), Time.local(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_utc_advance - assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 1) - assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:months => 4) - assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3) - assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.5) - assert_in_delta Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(:weeks => 3.7), 1 - assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5) - assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.5) - assert_in_delta Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(:days => 5.7), 1 - assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 7) - assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(:years => 7, :months => 19, :days => 11) - assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Time.utc(2001,12,27,15,15,10), Time.utc(2005,2,28,15,15,10).advance(:years => -3, :months => -2, :days => -1) - assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10).advance(:years => 1) #leap day plus one year - assert_equal Time.utc(2005,2,28,20,15,10), Time.utc(2005,2,28,15,15,10).advance(:hours => 5) - assert_equal Time.utc(2005,2,28,15,22,10), Time.utc(2005,2,28,15,15,10).advance(:minutes => 7) - assert_equal Time.utc(2005,2,28,15,15,19), Time.utc(2005,2,28,15,15,10).advance(:seconds => 9) - assert_equal Time.utc(2005,2,28,20,22,19), Time.utc(2005,2,28,15,15,10).advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal Time.utc(2005,2,28,10,8,1), Time.utc(2005,2,28,15,15,10).advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal Time.utc(2013,10,17,20,22,19), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal Time.utc(2006,2,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(years: 1) + assert_equal Time.utc(2005,6,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(months: 4) + assert_equal Time.utc(2005,3,21,15,15,10), Time.utc(2005,2,28,15,15,10).advance(weeks: 3) + assert_equal Time.utc(2005,3,25,3,15,10), Time.utc(2005,2,28,15,15,10).advance(weeks: 3.5) + assert_in_delta Time.utc(2005,3,26,12,51,10), Time.utc(2005,2,28,15,15,10).advance(weeks: 3.7), 1 + assert_equal Time.utc(2005,3,5,15,15,10), Time.utc(2005,2,28,15,15,10).advance(days: 5) + assert_equal Time.utc(2005,3,6,3,15,10), Time.utc(2005,2,28,15,15,10).advance(days: 5.5) + assert_in_delta Time.utc(2005,3,6,8,3,10), Time.utc(2005,2,28,15,15,10).advance(days: 5.7), 1 + assert_equal Time.utc(2012,9,22,15,15,10), Time.utc(2005,2,22,15,15,10).advance(years: 7, months: 7) + assert_equal Time.utc(2013,10,3,15,15,10), Time.utc(2005,2,22,15,15,10).advance(years: 7, months: 19, days: 11) + assert_equal Time.utc(2013,10,17,15,15,10), Time.utc(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Time.utc(2001,12,27,15,15,10), Time.utc(2005,2,28,15,15,10).advance(years: -3, months: -2, days: -1) + assert_equal Time.utc(2005,2,28,15,15,10), Time.utc(2004,2,29,15,15,10).advance(years: 1) #leap day plus one year + assert_equal Time.utc(2005,2,28,20,15,10), Time.utc(2005,2,28,15,15,10).advance(hours: 5) + assert_equal Time.utc(2005,2,28,15,22,10), Time.utc(2005,2,28,15,15,10).advance(minutes: 7) + assert_equal Time.utc(2005,2,28,15,15,19), Time.utc(2005,2,28,15,15,10).advance(seconds: 9) + assert_equal Time.utc(2005,2,28,20,22,19), Time.utc(2005,2,28,15,15,10).advance(hours: 5, minutes: 7, seconds: 9) + assert_equal Time.utc(2005,2,28,10,8,1), Time.utc(2005,2,28,15,15,10).advance(hours: -5, minutes: -7, seconds: -9) + assert_equal Time.utc(2013,10,17,20,22,19), Time.utc(2005,2,28,15,15,10).advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_offset_advance - assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(:years => 1) - assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(:months => 4) - assert_equal Time.new(2005,3,21,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:weeks => 3) - assert_equal Time.new(2005,3,25,3,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:weeks => 3.5) - assert_in_delta Time.new(2005,3,26,12,51,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:weeks => 3.7), 1 - assert_equal Time.new(2005,3,5,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:days => 5) - assert_equal Time.new(2005,3,6,3,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:days => 5.5) - assert_in_delta Time.new(2005,3,6,8,3,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:days => 5.7), 1 - assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(:years => 7, :months => 7) - assert_equal Time.new(2013,10,3,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(:years => 7, :months => 19, :days => 11) - assert_equal Time.new(2013,10,17,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:years => 7, :months => 19, :weeks => 2, :days => 5) - assert_equal Time.new(2001,12,27,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:years => -3, :months => -2, :days => -1) - assert_equal Time.new(2005,2,28,15,15,10,"-08:00"), Time.new(2004,2,29,15,15,10,"-08:00").advance(:years => 1) #leap day plus one year - assert_equal Time.new(2005,2,28,20,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:hours => 5) - assert_equal Time.new(2005,2,28,15,22,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:minutes => 7) - assert_equal Time.new(2005,2,28,15,15,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:seconds => 9) - assert_equal Time.new(2005,2,28,20,22,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:hours => 5, :minutes => 7, :seconds => 9) - assert_equal Time.new(2005,2,28,10,8,1,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:hours => -5, :minutes => -7, :seconds => -9) - assert_equal Time.new(2013,10,17,20,22,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9) + assert_equal Time.new(2006,2,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(years: 1) + assert_equal Time.new(2005,6,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(months: 4) + assert_equal Time.new(2005,3,21,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(weeks: 3) + assert_equal Time.new(2005,3,25,3,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(weeks: 3.5) + assert_in_delta Time.new(2005,3,26,12,51,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(weeks: 3.7), 1 + assert_equal Time.new(2005,3,5,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(days: 5) + assert_equal Time.new(2005,3,6,3,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(days: 5.5) + assert_in_delta Time.new(2005,3,6,8,3,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(days: 5.7), 1 + assert_equal Time.new(2012,9,22,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(years: 7, months: 7) + assert_equal Time.new(2013,10,3,15,15,10,"-08:00"), Time.new(2005,2,22,15,15,10,"-08:00").advance(years: 7, months: 19, days: 11) + assert_equal Time.new(2013,10,17,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(years: 7, months: 19, weeks: 2, days: 5) + assert_equal Time.new(2001,12,27,15,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(years: -3, months: -2, days: -1) + assert_equal Time.new(2005,2,28,15,15,10,"-08:00"), Time.new(2004,2,29,15,15,10,"-08:00").advance(years: 1) #leap day plus one year + assert_equal Time.new(2005,2,28,20,15,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(hours: 5) + assert_equal Time.new(2005,2,28,15,22,10,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(minutes: 7) + assert_equal Time.new(2005,2,28,15,15,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(seconds: 9) + assert_equal Time.new(2005,2,28,20,22,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(hours: 5, minutes: 7, seconds: 9) + assert_equal Time.new(2005,2,28,10,8,1,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(hours: -5, minutes: -7, seconds: -9) + assert_equal Time.new(2013,10,17,20,22,19,"-08:00"), Time.new(2005,2,28,15,15,10,"-08:00").advance(years: 7, months: 19, weeks: 2, days: 5, hours: 5, minutes: 7, seconds: 9) end def test_advance_with_nsec t = Time.at(0, Rational(108635108, 1000)) - assert_equal t, t.advance(:months => 0) + assert_equal t, t.advance(months: 0) end def test_advance_gregorian_proleptic - assert_equal Time.local(1582,10,14,15,15,10), Time.local(1582,10,15,15,15,10).advance(:days => -1) - assert_equal Time.local(1582,10,15,15,15,10), Time.local(1582,10,14,15,15,10).advance(:days => 1) - assert_equal Time.local(1582,10,5,15,15,10), Time.local(1582,10,4,15,15,10).advance(:days => 1) - assert_equal Time.local(1582,10,4,15,15,10), Time.local(1582,10,5,15,15,10).advance(:days => -1) + assert_equal Time.local(1582,10,14,15,15,10), Time.local(1582,10,15,15,15,10).advance(days: -1) + assert_equal Time.local(1582,10,15,15,15,10), Time.local(1582,10,14,15,15,10).advance(days: 1) + assert_equal Time.local(1582,10,5,15,15,10), Time.local(1582,10,4,15,15,10).advance(days: 1) + assert_equal Time.local(1582,10,4,15,15,10), Time.local(1582,10,5,15,15,10).advance(days: -1) end def test_last_week diff --git a/activesupport/test/core_ext/time_with_zone_test.rb b/activesupport/test/core_ext/time_with_zone_test.rb index 62235449bc..773d2c0fb7 100644 --- a/activesupport/test/core_ext/time_with_zone_test.rb +++ b/activesupport/test/core_ext/time_with_zone_test.rb @@ -584,18 +584,18 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_change assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect - assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.change(:year => 2001).inspect - assert_equal "Wed, 31 Mar 1999 19:00:00 EST -05:00", @twz.change(:month => 3).inspect - assert_equal "Wed, 03 Mar 1999 19:00:00 EST -05:00", @twz.change(:month => 2).inspect - assert_equal "Wed, 15 Dec 1999 19:00:00 EST -05:00", @twz.change(:day => 15).inspect - assert_equal "Fri, 31 Dec 1999 06:00:00 EST -05:00", @twz.change(:hour => 6).inspect - assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.change(:min => 15).inspect - assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.change(:sec => 30).inspect + assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.change(year: 2001).inspect + assert_equal "Wed, 31 Mar 1999 19:00:00 EST -05:00", @twz.change(month: 3).inspect + assert_equal "Wed, 03 Mar 1999 19:00:00 EST -05:00", @twz.change(month: 2).inspect + assert_equal "Wed, 15 Dec 1999 19:00:00 EST -05:00", @twz.change(day: 15).inspect + assert_equal "Fri, 31 Dec 1999 06:00:00 EST -05:00", @twz.change(hour: 6).inspect + assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.change(min: 15).inspect + assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.change(sec: 30).inspect end def test_change_at_dst_boundary twz = ActiveSupport::TimeWithZone.new(Time.at(1319936400).getutc, ActiveSupport::TimeZone["Madrid"]) - assert_equal twz, twz.change(:min => 0) + assert_equal twz, twz.change(min: 0) end def test_round_at_dst_boundary @@ -605,12 +605,12 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance assert_equal "Fri, 31 Dec 1999 19:00:00 EST -05:00", @twz.inspect - assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.advance(:years => 2).inspect - assert_equal "Fri, 31 Mar 2000 19:00:00 EST -05:00", @twz.advance(:months => 3).inspect - assert_equal "Tue, 04 Jan 2000 19:00:00 EST -05:00", @twz.advance(:days => 4).inspect - assert_equal "Sat, 01 Jan 2000 01:00:00 EST -05:00", @twz.advance(:hours => 6).inspect - assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.advance(:minutes => 15).inspect - assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.advance(:seconds => 30).inspect + assert_equal "Mon, 31 Dec 2001 19:00:00 EST -05:00", @twz.advance(years: 2).inspect + assert_equal "Fri, 31 Mar 2000 19:00:00 EST -05:00", @twz.advance(months: 3).inspect + assert_equal "Tue, 04 Jan 2000 19:00:00 EST -05:00", @twz.advance(days: 4).inspect + assert_equal "Sat, 01 Jan 2000 01:00:00 EST -05:00", @twz.advance(hours: 6).inspect + assert_equal "Fri, 31 Dec 1999 19:15:00 EST -05:00", @twz.advance(minutes: 15).inspect + assert_equal "Fri, 31 Dec 1999 19:00:30 EST -05:00", @twz.advance(seconds: 30).inspect end def test_beginning_of_year @@ -685,7 +685,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_year_from_leap_day twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2004,2,29)) - assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:years => 1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(years: 1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.years_since(1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.since(1.year).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.year).inspect @@ -693,7 +693,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_from_last_day_of_january twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2005,1,31)) - assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.advance(months: 1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.months_since(1).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", twz.since(1.month).inspect assert_equal "Mon, 28 Feb 2005 00:00:00 EST -05:00", (twz + 1.month).inspect @@ -701,7 +701,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_from_last_day_of_january_during_leap_year twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2000,1,31)) - assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.advance(months: 1).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.months_since(1).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", twz.since(1.month).inspect assert_equal "Tue, 29 Feb 2000 00:00:00 EST -05:00", (twz + 1.month).inspect @@ -709,7 +709,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_into_spring_dst_gap twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,3,2,2)) - assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:months => 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(months: 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.months_since(1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.since(1.month).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1.month).inspect @@ -717,7 +717,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_second_into_spring_dst_gap twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,1,59,59)) - assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(:seconds => 1).inspect + assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.advance(seconds: 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", (twz + 1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.since(1).inspect assert_equal "Sun, 02 Apr 2006 03:00:00 EDT -04:00", twz.since(1.second).inspect @@ -728,7 +728,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30)) # In 2006, spring DST transition occurred Apr 2 at 2AM; this day was only 23 hours long # When we advance 1 day, we want to end up at the same time on the next day - assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", twz.advance(:days => 1).inspect + assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", twz.advance(days: 1).inspect assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", twz.since(1.days).inspect assert_equal "Sun, 02 Apr 2006 10:30:00 EDT -04:00", (twz + 1.days).inspect assert_equal "Sun, 02 Apr 2006 10:30:01 EDT -04:00", twz.since(1.days + 1.second).inspect @@ -739,7 +739,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,2,10,30)) # In 2006, spring DST transition occurred Apr 2 at 2AM; this day was only 23 hours long # When we advance back 1 day, we want to end up at the same time on the previous day - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:days => -1).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(days: -1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.days).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.days).inspect assert_equal "Sat, 01 Apr 2006 10:30:01 EST -05:00", twz.ago(1.days - 1.second).inspect @@ -753,13 +753,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", (twz + 86400.seconds).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(86400).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(86400.seconds).inspect - assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(:seconds => 86400).inspect + assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(seconds: 86400).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", (twz + 1440.minutes).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(1440.minutes).inspect - assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(:minutes => 1440).inspect + assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(minutes: 1440).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", (twz + 24.hours).inspect assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.since(24.hours).inspect - assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(:hours => 24).inspect + assert_equal "Sun, 02 Apr 2006 11:30:00 EDT -04:00", twz.advance(hours: 24).inspect end def test_advance_1_day_expressed_as_number_of_seconds_minutes_or_hours_across_spring_dst_transition_backwards @@ -770,20 +770,20 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 86400.seconds).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(86400).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(86400.seconds).inspect - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:seconds => -86400).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(seconds: -86400).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1440.minutes).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1440.minutes).inspect - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:minutes => -1440).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(minutes: -1440).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 24.hours).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(24.hours).inspect - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:hours => -24).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(hours: -24).inspect end def test_advance_1_day_across_fall_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30)) # In 2006, fall DST transition occurred Oct 29 at 2AM; this day was 25 hours long # When we advance 1 day, we want to end up at the same time on the next day - assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", twz.advance(:days => 1).inspect + assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", twz.advance(days: 1).inspect assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", twz.since(1.days).inspect assert_equal "Sun, 29 Oct 2006 10:30:00 EST -05:00", (twz + 1.days).inspect assert_equal "Sun, 29 Oct 2006 10:30:01 EST -05:00", twz.since(1.days + 1.second).inspect @@ -794,7 +794,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,29,10,30)) # In 2006, fall DST transition occurred Oct 29 at 2AM; this day was 25 hours long # When we advance backwards 1 day, we want to end up at the same time on the previous day - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:days => -1).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(days: -1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.days).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.days).inspect assert_equal "Sat, 28 Oct 2006 10:30:01 EDT -04:00", twz.ago(1.days - 1.second).inspect @@ -808,13 +808,13 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", (twz + 86400.seconds).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(86400).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(86400.seconds).inspect - assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(:seconds => 86400).inspect + assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(seconds: 86400).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", (twz + 1440.minutes).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(1440.minutes).inspect - assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(:minutes => 1440).inspect + assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(minutes: 1440).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", (twz + 24.hours).inspect assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.since(24.hours).inspect - assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(:hours => 24).inspect + assert_equal "Sun, 29 Oct 2006 09:30:00 EST -05:00", twz.advance(hours: 24).inspect end def test_advance_1_day_expressed_as_number_of_seconds_minutes_or_hours_across_fall_dst_transition_backwards @@ -825,18 +825,18 @@ class TimeWithZoneTest < ActiveSupport::TestCase assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 86400.seconds).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(86400).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(86400.seconds).inspect - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:seconds => -86400).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(seconds: -86400).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1440.minutes).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1440.minutes).inspect - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:minutes => -1440).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(minutes: -1440).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 24.hours).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(24.hours).inspect - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:hours => -24).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(hours: -24).inspect end def test_advance_1_week_across_spring_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30)) - assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.advance(:weeks => 1).inspect + assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.advance(weeks: 1).inspect assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.weeks_since(1).inspect assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", twz.since(1.week).inspect assert_equal "Sat, 08 Apr 2006 10:30:00 EDT -04:00", (twz + 1.week).inspect @@ -844,7 +844,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_week_across_spring_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,8,10,30)) - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:weeks => -1).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(weeks: -1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.weeks_ago(1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.week).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.week).inspect @@ -852,7 +852,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_week_across_fall_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30)) - assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.advance(:weeks => 1).inspect + assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.advance(weeks: 1).inspect assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.weeks_since(1).inspect assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", twz.since(1.week).inspect assert_equal "Sat, 04 Nov 2006 10:30:00 EST -05:00", (twz + 1.week).inspect @@ -860,7 +860,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_week_across_fall_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,11,4,10,30)) - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:weeks => -1).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(weeks: -1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.weeks_ago(1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.week).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.week).inspect @@ -868,7 +868,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_spring_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,4,1,10,30)) - assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.advance(:months => 1).inspect + assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.advance(months: 1).inspect assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.months_since(1).inspect assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", twz.since(1.month).inspect assert_equal "Mon, 01 May 2006 10:30:00 EDT -04:00", (twz + 1.month).inspect @@ -876,7 +876,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_spring_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,5,1,10,30)) - assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(:months => -1).inspect + assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.advance(months: -1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.months_ago(1).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", twz.ago(1.month).inspect assert_equal "Sat, 01 Apr 2006 10:30:00 EST -05:00", (twz - 1.month).inspect @@ -884,7 +884,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_fall_dst_transition twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,10,28,10,30)) - assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.advance(:months => 1).inspect + assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.advance(months: 1).inspect assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.months_since(1).inspect assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", twz.since(1.month).inspect assert_equal "Tue, 28 Nov 2006 10:30:00 EST -05:00", (twz + 1.month).inspect @@ -892,7 +892,7 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_month_across_fall_dst_transition_backwards twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2006,11,28,10,30)) - assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(:months => -1).inspect + assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.advance(months: -1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.months_ago(1).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", twz.ago(1.month).inspect assert_equal "Sat, 28 Oct 2006 10:30:00 EDT -04:00", (twz - 1.month).inspect @@ -900,20 +900,20 @@ class TimeWithZoneTest < ActiveSupport::TestCase def test_advance_1_year twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2008,2,15,10,30)) - assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", twz.advance(:years => 1).inspect + assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", twz.advance(years: 1).inspect assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", twz.years_since(1).inspect assert_equal "Sun, 15 Feb 2009 10:30:00 EST -05:00", (twz + 1.year).inspect - assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", twz.advance(:years => -1).inspect + assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", twz.advance(years: -1).inspect assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", twz.years_ago(1).inspect assert_equal "Thu, 15 Feb 2007 10:30:00 EST -05:00", (twz - 1.year).inspect end def test_advance_1_year_during_dst twz = ActiveSupport::TimeWithZone.new(nil, @time_zone, Time.utc(2008,7,15,10,30)) - assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", twz.advance(:years => 1).inspect + assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", twz.advance(years: 1).inspect assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", twz.years_since(1).inspect assert_equal "Wed, 15 Jul 2009 10:30:00 EDT -04:00", (twz + 1.year).inspect - assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", twz.advance(:years => -1).inspect + assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", twz.advance(years: -1).inspect assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", twz.years_ago(1).inspect assert_equal "Sun, 15 Jul 2007 10:30:00 EDT -04:00", (twz - 1.year).inspect end diff --git a/activesupport/test/deprecation/method_wrappers_test.rb b/activesupport/test/deprecation/method_wrappers_test.rb index ec477f929e..85d057bb02 100644 --- a/activesupport/test/deprecation/method_wrappers_test.rb +++ b/activesupport/test/deprecation/method_wrappers_test.rb @@ -11,7 +11,7 @@ class MethodWrappersTest < ActiveSupport::TestCase def test_deprecate_methods_warning_default warning = /old_method is deprecated and will be removed from Rails \d.\d \(use new_method instead\)/ - ActiveSupport::Deprecation.deprecate_methods(@klass, :old_method => :new_method) + ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method) assert_deprecated(warning) { assert_equal "abc", @klass.new.old_method } end @@ -19,7 +19,7 @@ class MethodWrappersTest < ActiveSupport::TestCase def test_deprecate_methods_warning_with_optional_deprecator warning = /old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/ deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem") - ActiveSupport::Deprecation.deprecate_methods(@klass, :old_method => :new_method, :deprecator => deprecator) + ActiveSupport::Deprecation.deprecate_methods(@klass, old_method: :new_method, deprecator: deprecator) assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method } end @@ -27,7 +27,7 @@ class MethodWrappersTest < ActiveSupport::TestCase def test_deprecate_methods_warning_when_deprecated_with_custom_deprecator warning = /old_method is deprecated and will be removed from MyGem next-release \(use new_method instead\)/ deprecator = ActiveSupport::Deprecation.new("next-release", "MyGem") - deprecator.deprecate_methods(@klass, :old_method => :new_method) + deprecator.deprecate_methods(@klass, old_method: :new_method) assert_deprecated(warning, deprecator) { assert_equal "abc", @klass.new.old_method } end diff --git a/activesupport/test/deprecation_test.rb b/activesupport/test/deprecation_test.rb index 2971c384ed..b9447d74b4 100644 --- a/activesupport/test/deprecation_test.rb +++ b/activesupport/test/deprecation_test.rb @@ -24,7 +24,7 @@ class Deprecatee def c; end def d; end def e; end - deprecate :a, :b, :c => :e, :d => "you now need to do something extra for this one" + deprecate :a, :b, c: :e, d: "you now need to do something extra for this one" def f=(v); end deprecate :f= diff --git a/activesupport/test/i18n_test.rb b/activesupport/test/i18n_test.rb index 419482c527..7d88d2dc6b 100644 --- a/activesupport/test/i18n_test.rb +++ b/activesupport/test/i18n_test.rb @@ -18,15 +18,15 @@ class I18nTest < ActiveSupport::TestCase end def test_date_localization_with_default_format - assert_equal @date.strftime("%Y-%m-%d"), I18n.localize(@date, :format => :default) + assert_equal @date.strftime("%Y-%m-%d"), I18n.localize(@date, format: :default) end def test_date_localization_with_short_format - assert_equal @date.strftime("%b %d"), I18n.localize(@date, :format => :short) + assert_equal @date.strftime("%b %d"), I18n.localize(@date, format: :short) end def test_date_localization_with_long_format - assert_equal @date.strftime("%B %d, %Y"), I18n.localize(@date, :format => :long) + assert_equal @date.strftime("%B %d, %Y"), I18n.localize(@date, format: :long) end def test_time_localization_should_use_default_format @@ -34,15 +34,15 @@ class I18nTest < ActiveSupport::TestCase end def test_time_localization_with_default_format - assert_equal @time.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(@time, :format => :default) + assert_equal @time.strftime("%a, %d %b %Y %H:%M:%S %z"), I18n.localize(@time, format: :default) end def test_time_localization_with_short_format - assert_equal @time.strftime("%d %b %H:%M"), I18n.localize(@time, :format => :short) + assert_equal @time.strftime("%d %b %H:%M"), I18n.localize(@time, format: :short) end def test_time_localization_with_long_format - assert_equal @time.strftime("%B %d, %Y %H:%M"), I18n.localize(@time, :format => :long) + assert_equal @time.strftime("%B %d, %Y %H:%M"), I18n.localize(@time, format: :long) end def test_day_names @@ -89,13 +89,13 @@ class I18nTest < ActiveSupport::TestCase default_two_words_connector = I18n.translate(:'support.array.two_words_connector') default_last_word_connector = I18n.translate(:'support.array.last_word_connector') assert_equal "a, b, and c", %w[a b c].to_sentence - I18n.backend.store_translations "en", :support => { :array => { :two_words_connector => " & " } } + I18n.backend.store_translations "en", support: { array: { two_words_connector: " & " } } assert_equal "a & b", %w[a b].to_sentence - I18n.backend.store_translations "en", :support => { :array => { :last_word_connector => " and " } } + I18n.backend.store_translations "en", support: { array: { last_word_connector: " and " } } assert_equal "a, b and c", %w[a b c].to_sentence ensure - I18n.backend.store_translations "en", :support => { :array => { :two_words_connector => default_two_words_connector } } - I18n.backend.store_translations "en", :support => { :array => { :last_word_connector => default_last_word_connector } } + I18n.backend.store_translations "en", support: { array: { two_words_connector: default_two_words_connector } } + I18n.backend.store_translations "en", support: { array: { last_word_connector: default_last_word_connector } } end def test_to_sentence_with_empty_i18n_store diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 02bf9f0f35..4ee723076e 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -128,10 +128,10 @@ module InflectorTestCases } SymbolToLowerCamel = { - :product => "product", - :special_guest => "specialGuest", - :application_controller => "applicationController", - :area51_controller => "area51Controller" + product: "product", + special_guest: "specialGuest", + application_controller: "applicationController", + area51_controller: "area51Controller" } CamelToUnderscoreWithoutReverse = { diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index 308b29784e..4a9ed22951 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -47,12 +47,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_hash_encoding - assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(:a => :b) + assert_equal %({\"a\":\"b\"}), ActiveSupport::JSON.encode(a: :b) assert_equal %({\"a\":1}), ActiveSupport::JSON.encode("a" => 1) assert_equal %({\"a\":[1,2]}), ActiveSupport::JSON.encode("a" => [1,2]) assert_equal %({"1":2}), ActiveSupport::JSON.encode(1 => 2) - assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(:a => :b, :c => :d)) + assert_equal %({\"a\":\"b\",\"c\":\"d\"}), sorted_json(ActiveSupport::JSON.encode(a: :b, c: :d)) end def test_hash_keys_encoding @@ -98,11 +98,11 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_hash_should_allow_key_filtering_with_only - assert_equal %({"a":1}), ActiveSupport::JSON.encode({"a" => 1, :b => 2, :c => 3}, :only => "a") + assert_equal %({"a":1}), ActiveSupport::JSON.encode({"a" => 1, :b => 2, :c => 3}, only: "a") end def test_hash_should_allow_key_filtering_with_except - assert_equal %({"b":2}), ActiveSupport::JSON.encode({"foo" => "bar", :b => 2, :c => 3}, :except => ["foo", :c]) + assert_equal %({"b":2}), ActiveSupport::JSON.encode({"foo" => "bar", :b => 2, :c => 3}, except: ["foo", :c]) end def test_time_to_json_includes_local_offset @@ -115,7 +115,7 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_with_time_to_json with_standard_json_time_format(false) do - assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { :time => Time.utc(2009) }.to_json + assert_equal '{"time":"2009/01/01 00:00:00 +0000"}', { time: Time.utc(2009) }.to_json end end @@ -123,8 +123,8 @@ class TestJSONEncoding < ActiveSupport::TestCase assert_nothing_raised do hash = { "CHI" => { - :display_name => "chicago", - :latitude => 123.234 + display_name: "chicago", + latitude: 123.234 } } ActiveSupport::JSON.encode(hash) @@ -133,7 +133,7 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_hash_like_with_options h = JSONTest::Hashlike.new - json = h.to_json :only => [:foo] + json = h.to_json only: [:foo] assert_equal({"foo"=>"hello"}, JSON.parse(json)) end @@ -142,7 +142,7 @@ class TestJSONEncoding < ActiveSupport::TestCase obj = Object.new obj.instance_variable_set :@foo, "hello" obj.instance_variable_set :@bar, "world" - json = obj.to_json :only => ["foo"] + json = obj.to_json only: ["foo"] assert_equal({"foo"=>"hello"}, JSON.parse(json)) end @@ -151,43 +151,43 @@ class TestJSONEncoding < ActiveSupport::TestCase struct = Struct.new(:foo, :bar).new struct.foo = "hello" struct.bar = "world" - json = struct.to_json :only => [:foo] + json = struct.to_json only: [:foo] assert_equal({"foo"=>"hello"}, JSON.parse(json)) end def test_hash_should_pass_encoding_options_to_children_in_as_json person = { - :name => "John", - :address => { - :city => "London", - :country => "UK" + name: "John", + address: { + city: "London", + country: "UK" } } - json = person.as_json :only => [:address, :city] + json = person.as_json only: [:address, :city] assert_equal({ "address" => { "city" => "London" }}, json) end def test_hash_should_pass_encoding_options_to_children_in_to_json person = { - :name => "John", - :address => { - :city => "London", - :country => "UK" + name: "John", + address: { + city: "London", + country: "UK" } } - json = person.to_json :only => [:address, :city] + json = person.to_json only: [:address, :city] assert_equal(%({"address":{"city":"London"}}), json) end def test_array_should_pass_encoding_options_to_children_in_as_json people = [ - { :name => "John", :address => { :city => "London", :country => "UK" }}, - { :name => "Jean", :address => { :city => "Paris" , :country => "France" }} + { name: "John", address: { city: "London", country: "UK" }}, + { name: "Jean", address: { city: "Paris" , country: "France" }} ] - json = people.as_json :only => [:address, :city] + json = people.as_json only: [:address, :city] expected = [ { "address" => { "city" => "London" }}, { "address" => { "city" => "Paris" }} @@ -198,10 +198,10 @@ class TestJSONEncoding < ActiveSupport::TestCase def test_array_should_pass_encoding_options_to_children_in_to_json people = [ - { :name => "John", :address => { :city => "London", :country => "UK" }}, - { :name => "Jean", :address => { :city => "Paris" , :country => "France" }} + { name: "John", address: { city: "London", country: "UK" }}, + { name: "Jean", address: { city: "Paris" , country: "France" }} ] - json = people.to_json :only => [:address, :city] + json = people.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end @@ -210,8 +210,8 @@ class TestJSONEncoding < ActiveSupport::TestCase include Enumerable def initialize() @people = [ - { :name => "John", :address => { :city => "London", :country => "UK" }}, - { :name => "Jean", :address => { :city => "Paris" , :country => "France" }} + { name: "John", address: { city: "London", country: "UK" }}, + { name: "Jean", address: { city: "Paris" , country: "France" }} ] end def each(*, &blk) @@ -223,7 +223,7 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_enumerable_should_generate_json_with_as_json - json = People.new.as_json :only => [:address, :city] + json = People.new.as_json only: [:address, :city] expected = [ { "address" => { "city" => "London" }}, { "address" => { "city" => "Paris" }} @@ -233,12 +233,12 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_enumerable_should_generate_json_with_to_json - json = People.new.to_json :only => [:address, :city] + json = People.new.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end def test_enumerable_should_pass_encoding_options_to_children_in_as_json - json = People.new.each.as_json :only => [:address, :city] + json = People.new.each.as_json only: [:address, :city] expected = [ { "address" => { "city" => "London" }}, { "address" => { "city" => "Paris" }} @@ -248,7 +248,7 @@ class TestJSONEncoding < ActiveSupport::TestCase end def test_enumerable_should_pass_encoding_options_to_children_in_to_json - json = People.new.each.to_json :only => [:address, :city] + json = People.new.each.to_json only: [:address, :city] assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb index e7c0abda3e..ac0e2b2b05 100644 --- a/activesupport/test/json/encoding_test_cases.rb +++ b/activesupport/test/json/encoding_test_cases.rb @@ -9,7 +9,7 @@ module JSONTest class Hashlike def to_hash - { :foo => "hello", :bar => "world" } + { foo: "hello", bar: "world" } end end @@ -70,7 +70,7 @@ module JSONTest [ Custom.new(nil), "null" ], [ Custom.new(:a), '"a"' ], [ Custom.new([ :foo, "bar" ]), '["foo","bar"]' ], - [ Custom.new({ :foo => "hello", :bar => "world" }), '{"bar":"world","foo":"hello"}' ], + [ Custom.new({ foo: "hello", bar: "world" }), '{"bar":"world","foo":"hello"}' ], [ Custom.new(Hashlike.new), '{"bar":"world","foo":"hello"}' ], [ Custom.new(Custom.new(Custom.new(:a))), '"a"' ]] diff --git a/activesupport/test/key_generator_test.rb b/activesupport/test/key_generator_test.rb index 87e9ca7782..705537007a 100644 --- a/activesupport/test/key_generator_test.rb +++ b/activesupport/test/key_generator_test.rb @@ -13,7 +13,7 @@ require "active_support/json" class KeyGeneratorTest < ActiveSupport::TestCase def setup @secret = SecureRandom.hex(64) - @generator = ActiveSupport::KeyGenerator.new(@secret, :iterations=>2) + @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2) end test "Generating a key of the default length" do @@ -47,7 +47,7 @@ end class CachingKeyGeneratorTest < ActiveSupport::TestCase def setup @secret = SecureRandom.hex(64) - @generator = ActiveSupport::KeyGenerator.new(@secret, :iterations=>2) + @generator = ActiveSupport::KeyGenerator.new(@secret, iterations: 2) @caching_generator = ActiveSupport::CachingKeyGenerator.new(@generator) end diff --git a/activesupport/test/lazy_load_hooks_test.rb b/activesupport/test/lazy_load_hooks_test.rb index 1664ee8c92..d08efa429a 100644 --- a/activesupport/test/lazy_load_hooks_test.rb +++ b/activesupport/test/lazy_load_hooks_test.rb @@ -63,7 +63,7 @@ class LazyLoadHooksTest < ActiveSupport::TestCase def test_hook_with_yield_true i = 0 - ActiveSupport.on_load(:contextual_yield, :yield => true) do |obj| + ActiveSupport.on_load(:contextual_yield, yield: true) do |obj| i += obj.incr + incr_amt end assert_equal 0, i @@ -75,7 +75,7 @@ class LazyLoadHooksTest < ActiveSupport::TestCase i = 0 ActiveSupport.run_load_hooks(:contextual_yield_after, FakeContext.new(2)) assert_equal 0, i - ActiveSupport.on_load(:contextual_yield_after, :yield => true) do |obj| + ActiveSupport.on_load(:contextual_yield_after, yield: true) do |obj| i += obj.incr + incr_amt end assert_equal 7, i diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 14cfaac083..3d9f90f1cc 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -16,9 +16,9 @@ class MessageEncryptorTest < ActiveSupport::TestCase def setup @secret = SecureRandom.random_bytes(32) - @verifier = ActiveSupport::MessageVerifier.new(@secret, :serializer => ActiveSupport::MessageEncryptor::NullSerializer) + @verifier = ActiveSupport::MessageVerifier.new(@secret, serializer: ActiveSupport::MessageEncryptor::NullSerializer) @encryptor = ActiveSupport::MessageEncryptor.new(@secret) - @data = { :some => "data", :now => Time.local(2010) } + @data = { some: "data", now: Time.local(2010) } end def test_encrypting_twice_yields_differing_cipher_text @@ -51,7 +51,7 @@ class MessageEncryptorTest < ActiveSupport::TestCase def test_alternative_serialization_method prev = ActiveSupport.use_standard_json_time_format ActiveSupport.use_standard_json_time_format = true - encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32), SecureRandom.random_bytes(128), :serializer => JSONSerializer.new) + encryptor = ActiveSupport::MessageEncryptor.new(SecureRandom.random_bytes(32), SecureRandom.random_bytes(128), serializer: JSONSerializer.new) message = encryptor.encrypt_and_sign({ :foo => 123, "bar" => Time.utc(2010) }) exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00.000Z" } assert_equal exp, encryptor.decrypt_and_verify(message) diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index 29fa8d9b00..3cea0c71cc 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -17,7 +17,7 @@ class MessageVerifierTest < ActiveSupport::TestCase def setup @verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!") - @data = { :some => "data", :now => Time.local(2010) } + @data = { some: "data", now: Time.local(2010) } end def test_valid_message @@ -49,7 +49,7 @@ class MessageVerifierTest < ActiveSupport::TestCase def test_alternative_serialization_method prev = ActiveSupport.use_standard_json_time_format ActiveSupport.use_standard_json_time_format = true - verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", :serializer => JSONSerializer.new) + verifier = ActiveSupport::MessageVerifier.new("Hey, I'm a secret!", serializer: JSONSerializer.new) message = verifier.generate({ :foo => 123, "bar" => Time.utc(2010) }) exp = { "foo" => 123, "bar" => "2010-01-01T00:00:00.000Z" } assert_equal exp, verifier.verified(message) diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb index da3c2f1c6d..81f05dcd5b 100644 --- a/activesupport/test/multibyte_chars_test.rb +++ b/activesupport/test/multibyte_chars_test.rb @@ -723,8 +723,8 @@ class MultibyteCharsExtrasTest < ActiveSupport::TestCase 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 + 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] diff --git a/activesupport/test/notifications/instrumenter_test.rb b/activesupport/test/notifications/instrumenter_test.rb index fbbd320667..e454e6897b 100644 --- a/activesupport/test/notifications/instrumenter_test.rb +++ b/activesupport/test/notifications/instrumenter_test.rb @@ -22,7 +22,7 @@ module ActiveSupport super @notifier = TestNotifier.new @instrumenter = Instrumenter.new @notifier - @payload = { :foo => Object.new } + @payload = { foo: Object.new } end def test_instrument @@ -39,7 +39,7 @@ module ActiveSupport assert_equal 1, notifier.finishes.size name, _, payload = notifier.finishes.first assert_equal "awesome", name - assert_equal Hash[:result => 2], payload + assert_equal Hash[result: 2], payload end def test_start diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/notifications_test.rb index 7e0fe20291..106aa9c892 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/notifications_test.rb @@ -188,7 +188,7 @@ module Notifications end class InstrumentationTest < TestCase - delegate :instrument, :to => ActiveSupport::Notifications + delegate :instrument, to: ActiveSupport::Notifications def test_instrument_returns_block_result assert_equal 2, instrument(:awesome) { 1 + 1 } @@ -198,7 +198,7 @@ module Notifications assert_equal 2, instrument(:awesome) { |p| p[:result] = 1 + 1 } assert_equal 1, @events.size assert_equal :awesome, @events.first.name - assert_equal Hash[:result => 2], @events.first.payload + assert_equal Hash[result: 2], @events.first.payload end def test_instrumenter_exposes_its_id @@ -206,24 +206,24 @@ module Notifications end def test_nested_events_can_be_instrumented - instrument(:awesome, :payload => "notifications") do - instrument(:wot, :payload => "child") do + instrument(:awesome, payload: "notifications") do + instrument(:wot, payload: "child") do 1 + 1 end assert_equal 1, @events.size assert_equal :wot, @events.first.name - assert_equal Hash[:payload => "child"], @events.first.payload + assert_equal Hash[payload: "child"], @events.first.payload end assert_equal 2, @events.size assert_equal :awesome, @events.last.name - assert_equal Hash[:payload => "notifications"], @events.last.payload + assert_equal Hash[payload: "notifications"], @events.last.payload end def test_instrument_publishes_when_exception_is_raised begin - instrument(:awesome, :payload => "notifications") do + instrument(:awesome, payload: "notifications") do raise "FAIL" end rescue RuntimeError => e @@ -231,15 +231,15 @@ module Notifications end assert_equal 1, @events.size - assert_equal Hash[:payload => "notifications", - :exception => ["RuntimeError", "FAIL"], :exception_object => e], @events.last.payload + assert_equal Hash[payload: "notifications", + exception: ["RuntimeError", "FAIL"], exception_object: e], @events.last.payload end def test_event_is_pushed_even_without_block - instrument(:awesome, :payload => "notifications") + instrument(:awesome, payload: "notifications") assert_equal 1, @events.size assert_equal :awesome, @events.last.name - assert_equal Hash[:payload => "notifications"], @events.last.payload + assert_equal Hash[payload: "notifications"], @events.last.payload end end @@ -254,8 +254,8 @@ module Notifications end def test_events_consumes_information_given_as_payload - event = event(:foo, Time.now, Time.now + 1, random_id, :payload => :bar) - assert_equal Hash[:payload => :bar], event.payload + event = event(:foo, Time.now, Time.now + 1, random_id, payload: :bar) + assert_equal Hash[payload: :bar], event.payload end def test_event_is_parent_based_on_children diff --git a/activesupport/test/number_helper_i18n_test.rb b/activesupport/test/number_helper_i18n_test.rb index 82e036a020..f9d6dcf7b2 100644 --- a/activesupport/test/number_helper_i18n_test.rb +++ b/activesupport/test/number_helper_i18n_test.rb @@ -7,40 +7,40 @@ module ActiveSupport def setup I18n.backend.store_translations "ts", - :number => { - :format => { :precision => 3, :delimiter => ",", :separator => ".", :significant => false, :strip_insignificant_zeros => false }, - :currency => { :format => { :unit => "&$", :format => "%u - %n", :negative_format => "(%u - %n)", :precision => 2 } }, - :human => { - :format => { - :precision => 2, - :significant => true, - :strip_insignificant_zeros => true + number: { + format: { precision: 3, delimiter: ",", separator: ".", significant: false, strip_insignificant_zeros: false }, + currency: { format: { unit: "&$", format: "%u - %n", negative_format: "(%u - %n)", precision: 2 } }, + human: { + format: { + precision: 2, + significant: true, + strip_insignificant_zeros: true }, - :storage_units => { - :format => "%n %u", - :units => { - :byte => "b", - :kb => "k" + storage_units: { + format: "%n %u", + units: { + byte: "b", + kb: "k" } }, - :decimal_units => { - :format => "%n %u", - :units => { - :deci => {:one => "Tenth", :other => "Tenths"}, - :unit => "u", - :ten => {:one => "Ten", :other => "Tens"}, - :thousand => "t", - :million => "m", - :billion =>"b", - :trillion =>"t" , - :quadrillion =>"q" + decimal_units: { + format: "%n %u", + units: { + deci: {one: "Tenth", other: "Tenths"}, + unit: "u", + ten: {one: "Ten", other: "Tens"}, + thousand: "t", + million: "m", + billion: "b", + trillion: "t" , + quadrillion: "q" } } }, - :percentage => { :format => {:delimiter => "", :precision => 2, :strip_insignificant_zeros => true} }, - :precision => { :format => {:delimiter => "", :significant => true} } + percentage: { format: {delimiter: "", precision: 2, strip_insignificant_zeros: true} }, + precision: { format: {delimiter: "", significant: true} } }, - :custom_units_for_number_to_human => {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} + custom_units_for_number_to_human: {mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km"} end def teardown @@ -48,101 +48,101 @@ module ActiveSupport end def test_number_to_i18n_currency - assert_equal("&$ - 10.00", number_to_currency(10, :locale => "ts")) - assert_equal("(&$ - 10.00)", number_to_currency(-10, :locale => "ts")) - assert_equal("-10.00 - &$", number_to_currency(-10, :locale => "ts", :format => "%n - %u")) + assert_equal("&$ - 10.00", number_to_currency(10, locale: "ts")) + assert_equal("(&$ - 10.00)", number_to_currency(-10, locale: "ts")) + assert_equal("-10.00 - &$", number_to_currency(-10, locale: "ts", format: "%n - %u")) end def test_number_to_currency_with_empty_i18n_store - assert_equal("$10.00", number_to_currency(10, :locale => "empty")) - assert_equal("-$10.00", number_to_currency(-10, :locale => "empty")) + assert_equal("$10.00", number_to_currency(10, locale: "empty")) + assert_equal("-$10.00", number_to_currency(-10, locale: "empty")) end def test_locale_default_format_has_precedence_over_helper_defaults I18n.backend.store_translations "ts", - { :number => { :format => { :separator => ";" } } } + { number: { format: { separator: ";" } } } - assert_equal("&$ - 10;00", number_to_currency(10, :locale => "ts")) + assert_equal("&$ - 10;00", number_to_currency(10, locale: "ts")) end def test_number_to_currency_without_currency_negative_format - I18n.backend.store_translations "no_negative_format", :number => { - :currency => { :format => { :unit => "@", :format => "%n %u" } } + I18n.backend.store_translations "no_negative_format", number: { + currency: { format: { unit: "@", format: "%n %u" } } } - assert_equal("-10.00 @", number_to_currency(-10, :locale => "no_negative_format")) + assert_equal("-10.00 @", number_to_currency(-10, locale: "no_negative_format")) end def test_number_with_i18n_precision #Delimiter was set to "" - assert_equal("10000", number_to_rounded(10000, :locale => "ts")) + assert_equal("10000", number_to_rounded(10000, locale: "ts")) #Precision inherited and significant was set - assert_equal("1.00", number_to_rounded(1.0, :locale => "ts")) + assert_equal("1.00", number_to_rounded(1.0, locale: "ts")) end def test_number_with_i18n_precision_and_empty_i18n_store - assert_equal("123456789.123", number_to_rounded(123456789.123456789, :locale => "empty")) - assert_equal("1.000", number_to_rounded(1.0000, :locale => "empty")) + assert_equal("123456789.123", number_to_rounded(123456789.123456789, locale: "empty")) + assert_equal("1.000", number_to_rounded(1.0000, locale: "empty")) end def test_number_with_i18n_delimiter #Delimiter "," and separator "." - assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => "ts")) + assert_equal("1,000,000.234", number_to_delimited(1000000.234, locale: "ts")) end def test_number_with_i18n_delimiter_and_empty_i18n_store - assert_equal("1,000,000.234", number_to_delimited(1000000.234, :locale => "empty")) + assert_equal("1,000,000.234", number_to_delimited(1000000.234, locale: "empty")) end def test_number_to_i18n_percentage # to see if strip_insignificant_zeros is true - assert_equal("1%", number_to_percentage(1, :locale => "ts")) + assert_equal("1%", number_to_percentage(1, locale: "ts")) # precision is 2, significant should be inherited - assert_equal("1.24%", number_to_percentage(1.2434, :locale => "ts")) + assert_equal("1.24%", number_to_percentage(1.2434, locale: "ts")) # no delimiter - assert_equal("12434%", number_to_percentage(12434, :locale => "ts")) + assert_equal("12434%", number_to_percentage(12434, locale: "ts")) end def test_number_to_i18n_percentage_and_empty_i18n_store - assert_equal("1.000%", number_to_percentage(1, :locale => "empty")) - assert_equal("1.243%", number_to_percentage(1.2434, :locale => "empty")) - assert_equal("12434.000%", number_to_percentage(12434, :locale => "empty")) + assert_equal("1.000%", number_to_percentage(1, locale: "empty")) + assert_equal("1.243%", number_to_percentage(1.2434, locale: "empty")) + assert_equal("12434.000%", number_to_percentage(12434, locale: "empty")) end def test_number_to_i18n_human_size #b for bytes and k for kbytes - assert_equal("2 k", number_to_human_size(2048, :locale => "ts")) - assert_equal("42 b", number_to_human_size(42, :locale => "ts")) + assert_equal("2 k", number_to_human_size(2048, locale: "ts")) + assert_equal("42 b", number_to_human_size(42, locale: "ts")) end def test_number_to_i18n_human_size_with_empty_i18n_store - assert_equal("2 KB", number_to_human_size(2048, :locale => "empty")) - assert_equal("42 Bytes", number_to_human_size(42, :locale => "empty")) + assert_equal("2 KB", number_to_human_size(2048, locale: "empty")) + assert_equal("42 Bytes", number_to_human_size(42, locale: "empty")) end def test_number_to_human_with_default_translation_scope #Using t for thousand - assert_equal "2 t", number_to_human(2000, :locale => "ts") + assert_equal "2 t", number_to_human(2000, locale: "ts") #Significant was set to true with precision 2, using b for billion - assert_equal "1.2 b", number_to_human(1234567890, :locale => "ts") + assert_equal "1.2 b", number_to_human(1234567890, locale: "ts") #Using pluralization (Ten/Tens and Tenth/Tenths) - assert_equal "1 Tenth", number_to_human(0.1, :locale => "ts") - assert_equal "1.3 Tenth", number_to_human(0.134, :locale => "ts") - assert_equal "2 Tenths", number_to_human(0.2, :locale => "ts") - assert_equal "1 Ten", number_to_human(10, :locale => "ts") - assert_equal "1.2 Ten", number_to_human(12, :locale => "ts") - assert_equal "2 Tens", number_to_human(20, :locale => "ts") + assert_equal "1 Tenth", number_to_human(0.1, locale: "ts") + assert_equal "1.3 Tenth", number_to_human(0.134, locale: "ts") + assert_equal "2 Tenths", number_to_human(0.2, locale: "ts") + assert_equal "1 Ten", number_to_human(10, locale: "ts") + assert_equal "1.2 Ten", number_to_human(12, locale: "ts") + assert_equal "2 Tens", number_to_human(20, locale: "ts") end def test_number_to_human_with_empty_i18n_store - assert_equal "2 Thousand", number_to_human(2000, :locale => "empty") - assert_equal "1.23 Billion", number_to_human(1234567890, :locale => "empty") + assert_equal "2 Thousand", number_to_human(2000, locale: "empty") + assert_equal "1.23 Billion", number_to_human(1234567890, locale: "empty") end def test_number_to_human_with_custom_translation_scope #Significant was set to true with precision 2, with custom translated units - assert_equal "4.3 cm", number_to_human(0.0432, :locale => "ts", :units => :custom_units_for_number_to_human) + assert_equal "4.3 cm", number_to_human(0.0432, locale: "ts", units: :custom_units_for_number_to_human) end end end diff --git a/activesupport/test/number_helper_test.rb b/activesupport/test/number_helper_test.rb index 5f75436c87..fd566f8d21 100644 --- a/activesupport/test/number_helper_test.rb +++ b/activesupport/test/number_helper_test.rb @@ -46,17 +46,17 @@ module ActiveSupport [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| assert_equal("555-1234", number_helper.number_to_phone(5551234)) assert_equal("800-555-1212", number_helper.number_to_phone(8005551212)) - assert_equal("(800) 555-1212", number_helper.number_to_phone(8005551212, {:area_code => true})) - assert_equal("", number_helper.number_to_phone("", {:area_code => true})) - assert_equal("800 555 1212", number_helper.number_to_phone(8005551212, {:delimiter => " "})) - assert_equal("(800) 555-1212 x 123", number_helper.number_to_phone(8005551212, {:area_code => true, :extension => 123})) - assert_equal("800-555-1212", number_helper.number_to_phone(8005551212, :extension => " ")) - assert_equal("555.1212", number_helper.number_to_phone(5551212, :delimiter => ".")) + assert_equal("(800) 555-1212", number_helper.number_to_phone(8005551212, {area_code: true})) + assert_equal("", number_helper.number_to_phone("", {area_code: true})) + assert_equal("800 555 1212", number_helper.number_to_phone(8005551212, {delimiter: " "})) + assert_equal("(800) 555-1212 x 123", number_helper.number_to_phone(8005551212, {area_code: true, extension: 123})) + assert_equal("800-555-1212", number_helper.number_to_phone(8005551212, extension: " ")) + assert_equal("555.1212", number_helper.number_to_phone(5551212, delimiter: ".")) assert_equal("800-555-1212", number_helper.number_to_phone("8005551212")) - assert_equal("+1-800-555-1212", number_helper.number_to_phone(8005551212, :country_code => 1)) - assert_equal("+18005551212", number_helper.number_to_phone(8005551212, :country_code => 1, :delimiter => "")) + assert_equal("+1-800-555-1212", number_helper.number_to_phone(8005551212, country_code: 1)) + assert_equal("+18005551212", number_helper.number_to_phone(8005551212, country_code: 1, delimiter: "")) assert_equal("22-555-1212", number_helper.number_to_phone(225551212)) - assert_equal("+45-22-555-1212", number_helper.number_to_phone(225551212, :country_code => 45)) + assert_equal("+45-22-555-1212", number_helper.number_to_phone(225551212, country_code: 45)) assert_equal("(755) 6123-4567", number_helper.number_to_phone(75561234567, pattern: /(\d{3,4})(\d{4})(\d{4})/, area_code: true)) assert_equal("133-1234-5678", number_helper.number_to_phone(13312345678, pattern: /(\d{3})(\d{4})(\d{4})/)) end @@ -67,28 +67,28 @@ module ActiveSupport assert_equal("$1,234,567,890.50", number_helper.number_to_currency(1234567890.50)) assert_equal("$1,234,567,890.51", number_helper.number_to_currency(1234567890.506)) assert_equal("-$1,234,567,890.50", number_helper.number_to_currency(-1234567890.50)) - assert_equal("-$ 1,234,567,890.50", number_helper.number_to_currency(-1234567890.50, {:format => "%u %n"})) - assert_equal("($1,234,567,890.50)", number_helper.number_to_currency(-1234567890.50, {:negative_format => "(%u%n)"})) - assert_equal("$1,234,567,892", number_helper.number_to_currency(1234567891.50, {:precision => 0})) - assert_equal("$1,234,567,890.5", number_helper.number_to_currency(1234567890.50, {:precision => 1})) - assert_equal("£1234567890,50", number_helper.number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""})) + assert_equal("-$ 1,234,567,890.50", number_helper.number_to_currency(-1234567890.50, {format: "%u %n"})) + assert_equal("($1,234,567,890.50)", number_helper.number_to_currency(-1234567890.50, {negative_format: "(%u%n)"})) + assert_equal("$1,234,567,892", number_helper.number_to_currency(1234567891.50, {precision: 0})) + assert_equal("$1,234,567,890.5", number_helper.number_to_currency(1234567890.50, {precision: 1})) + assert_equal("£1234567890,50", number_helper.number_to_currency(1234567890.50, {unit: "£", separator: ",", delimiter: ""})) assert_equal("$1,234,567,890.50", number_helper.number_to_currency("1234567890.50")) - assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", {:unit => "Kč", :format => "%n %u"})) - assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", {:unit => "Kč", :format => "%n %u", :negative_format => "%n - %u"})) - assert_equal("0.00", number_helper.number_to_currency(+0.0, {:unit => "", :negative_format => "(%n)"})) + assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", {unit: "Kč", format: "%n %u"})) + assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", {unit: "Kč", format: "%n %u", negative_format: "%n - %u"})) + assert_equal("0.00", number_helper.number_to_currency(+0.0, {unit: "", negative_format: "(%n)"})) end end def test_number_to_percentage [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| assert_equal("100.000%", number_helper.number_to_percentage(100)) - assert_equal("100%", number_helper.number_to_percentage(100, {:precision => 0})) - assert_equal("302.06%", number_helper.number_to_percentage(302.0574, {:precision => 2})) + assert_equal("100%", number_helper.number_to_percentage(100, {precision: 0})) + assert_equal("302.06%", number_helper.number_to_percentage(302.0574, {precision: 2})) assert_equal("100.000%", number_helper.number_to_percentage("100")) assert_equal("1000.000%", number_helper.number_to_percentage("1000")) - assert_equal("123.4%", number_helper.number_to_percentage(123.400, :precision => 3, :strip_insignificant_zeros => true)) - assert_equal("1.000,000%", number_helper.number_to_percentage(1000, :delimiter => ".", :separator => ",")) - assert_equal("1000.000 %", number_helper.number_to_percentage(1000, :format => "%n %")) + assert_equal("123.4%", number_helper.number_to_percentage(123.400, precision: 3, strip_insignificant_zeros: true)) + assert_equal("1.000,000%", number_helper.number_to_percentage(1000, delimiter: ".", separator: ",")) + assert_equal("1000.000 %", number_helper.number_to_percentage(1000, format: "%n %")) assert_equal("98a%", number_helper.number_to_percentage("98a")) assert_equal("NaN%", number_helper.number_to_percentage(Float::NAN)) assert_equal("Inf%", number_helper.number_to_percentage(Float::INFINITY)) @@ -122,9 +122,9 @@ module ActiveSupport def test_to_delimited_with_options_hash [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "12 345 678", number_helper.number_to_delimited(12345678, :delimiter => " ") - assert_equal "12,345,678-05", number_helper.number_to_delimited(12345678.05, :separator => "-") - assert_equal "12.345.678,05", number_helper.number_to_delimited(12345678.05, :separator => ",", :delimiter => ".") + assert_equal "12 345 678", number_helper.number_to_delimited(12345678, delimiter: " ") + assert_equal "12,345,678-05", number_helper.number_to_delimited(12345678.05, separator: "-") + assert_equal "12.345.678,05", number_helper.number_to_delimited(12345678.05, separator: ",", delimiter: ".") end end @@ -132,77 +132,77 @@ module ActiveSupport [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| assert_equal("-111.235", number_helper.number_to_rounded(-111.2346)) assert_equal("111.235", number_helper.number_to_rounded(111.2346)) - assert_equal("31.83", number_helper.number_to_rounded(31.825, :precision => 2)) - assert_equal("111.23", number_helper.number_to_rounded(111.2346, :precision => 2)) - assert_equal("111.00", number_helper.number_to_rounded(111, :precision => 2)) + assert_equal("31.83", number_helper.number_to_rounded(31.825, precision: 2)) + assert_equal("111.23", number_helper.number_to_rounded(111.2346, precision: 2)) + assert_equal("111.00", number_helper.number_to_rounded(111, precision: 2)) assert_equal("111.235", number_helper.number_to_rounded("111.2346")) - assert_equal("31.83", number_helper.number_to_rounded("31.825", :precision => 2)) - assert_equal("3268", number_helper.number_to_rounded((32.6751 * 100.00), :precision => 0)) - assert_equal("112", number_helper.number_to_rounded(111.50, :precision => 0)) - assert_equal("1234567892", number_helper.number_to_rounded(1234567891.50, :precision => 0)) - assert_equal("0", number_helper.number_to_rounded(0, :precision => 0)) - assert_equal("0.00100", number_helper.number_to_rounded(0.001, :precision => 5)) - assert_equal("0.001", number_helper.number_to_rounded(0.00111, :precision => 3)) - assert_equal("10.00", number_helper.number_to_rounded(9.995, :precision => 2)) - assert_equal("11.00", number_helper.number_to_rounded(10.995, :precision => 2)) - assert_equal("0.00", number_helper.number_to_rounded(-0.001, :precision => 2)) - - assert_equal("111.23460000000000000000", number_helper.number_to_rounded(111.2346, :precision => 20)) - assert_equal("111.23460000000000000000", number_helper.number_to_rounded(Rational(1112346, 10000), :precision => 20)) - assert_equal("111.23460000000000000000", number_helper.number_to_rounded("111.2346", :precision => 20)) - assert_equal("111.23460000000000000000", number_helper.number_to_rounded(BigDecimal(111.2346, Float::DIG), :precision => 20)) - assert_equal("111.2346" + "0"*96, number_helper.number_to_rounded("111.2346", :precision => 100)) - assert_equal("111.2346", number_helper.number_to_rounded(Rational(1112346, 10000), :precision => 4)) - assert_equal("0.00", number_helper.number_to_rounded(Rational(0, 1), :precision => 2)) + assert_equal("31.83", number_helper.number_to_rounded("31.825", precision: 2)) + assert_equal("3268", number_helper.number_to_rounded((32.6751 * 100.00), precision: 0)) + assert_equal("112", number_helper.number_to_rounded(111.50, precision: 0)) + assert_equal("1234567892", number_helper.number_to_rounded(1234567891.50, precision: 0)) + assert_equal("0", number_helper.number_to_rounded(0, precision: 0)) + assert_equal("0.00100", number_helper.number_to_rounded(0.001, precision: 5)) + assert_equal("0.001", number_helper.number_to_rounded(0.00111, precision: 3)) + assert_equal("10.00", number_helper.number_to_rounded(9.995, precision: 2)) + assert_equal("11.00", number_helper.number_to_rounded(10.995, precision: 2)) + assert_equal("0.00", number_helper.number_to_rounded(-0.001, precision: 2)) + + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(111.2346, precision: 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(Rational(1112346, 10000), precision: 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded("111.2346", precision: 20)) + assert_equal("111.23460000000000000000", number_helper.number_to_rounded(BigDecimal(111.2346, Float::DIG), precision: 20)) + assert_equal("111.2346" + "0"*96, number_helper.number_to_rounded("111.2346", precision: 100)) + assert_equal("111.2346", number_helper.number_to_rounded(Rational(1112346, 10000), precision: 4)) + assert_equal("0.00", number_helper.number_to_rounded(Rational(0, 1), precision: 2)) end end def test_to_rounded_with_custom_delimiter_and_separator [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "31,83", number_helper.number_to_rounded(31.825, :precision => 2, :separator => ",") - assert_equal "1.231,83", number_helper.number_to_rounded(1231.825, :precision => 2, :separator => ",", :delimiter => ".") + assert_equal "31,83", number_helper.number_to_rounded(31.825, precision: 2, separator: ",") + assert_equal "1.231,83", number_helper.number_to_rounded(1231.825, precision: 2, separator: ",", delimiter: ".") end end def test_to_rounded_with_significant_digits [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "124000", number_helper.number_to_rounded(123987, :precision => 3, :significant => true) - assert_equal "120000000", number_helper.number_to_rounded(123987876, :precision => 2, :significant => true ) - assert_equal "40000", number_helper.number_to_rounded("43523", :precision => 1, :significant => true ) - assert_equal "9775", number_helper.number_to_rounded(9775, :precision => 4, :significant => true ) - assert_equal "5.4", number_helper.number_to_rounded(5.3923, :precision => 2, :significant => true ) - assert_equal "5", number_helper.number_to_rounded(5.3923, :precision => 1, :significant => true ) - assert_equal "1", number_helper.number_to_rounded(1.232, :precision => 1, :significant => true ) - assert_equal "7", number_helper.number_to_rounded(7, :precision => 1, :significant => true ) - assert_equal "1", number_helper.number_to_rounded(1, :precision => 1, :significant => true ) - assert_equal "53", number_helper.number_to_rounded(52.7923, :precision => 2, :significant => true ) - assert_equal "9775.00", number_helper.number_to_rounded(9775, :precision => 6, :significant => true ) - assert_equal "5.392900", number_helper.number_to_rounded(5.3929, :precision => 7, :significant => true ) - assert_equal "0.0", number_helper.number_to_rounded(0, :precision => 2, :significant => true ) - assert_equal "0", number_helper.number_to_rounded(0, :precision => 1, :significant => true ) - assert_equal "0.0001", number_helper.number_to_rounded(0.0001, :precision => 1, :significant => true ) - assert_equal "0.000100", number_helper.number_to_rounded(0.0001, :precision => 3, :significant => true ) - assert_equal "0.0001", number_helper.number_to_rounded(0.0001111, :precision => 1, :significant => true ) - assert_equal "10.0", number_helper.number_to_rounded(9.995, :precision => 3, :significant => true) - assert_equal "9.99", number_helper.number_to_rounded(9.994, :precision => 3, :significant => true) - assert_equal "11.0", number_helper.number_to_rounded(10.995, :precision => 3, :significant => true) - - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775, :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775.0, :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(Rational(9775, 1), :precision => 20, :significant => true ) - assert_equal "97.750000000000000000", number_helper.number_to_rounded(Rational(9775, 100), :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded(BigDecimal(9775), :precision => 20, :significant => true ) - assert_equal "9775.0000000000000000", number_helper.number_to_rounded("9775", :precision => 20, :significant => true ) - assert_equal "9775." + "0"*96, number_helper.number_to_rounded("9775", :precision => 100, :significant => true ) - assert_equal("97.7", number_helper.number_to_rounded(Rational(9772, 100), :precision => 3, :significant => true)) + assert_equal "124000", number_helper.number_to_rounded(123987, precision: 3, significant: true) + assert_equal "120000000", number_helper.number_to_rounded(123987876, precision: 2, significant: true ) + assert_equal "40000", number_helper.number_to_rounded("43523", precision: 1, significant: true ) + assert_equal "9775", number_helper.number_to_rounded(9775, precision: 4, significant: true ) + assert_equal "5.4", number_helper.number_to_rounded(5.3923, precision: 2, significant: true ) + assert_equal "5", number_helper.number_to_rounded(5.3923, precision: 1, significant: true ) + assert_equal "1", number_helper.number_to_rounded(1.232, precision: 1, significant: true ) + assert_equal "7", number_helper.number_to_rounded(7, precision: 1, significant: true ) + assert_equal "1", number_helper.number_to_rounded(1, precision: 1, significant: true ) + assert_equal "53", number_helper.number_to_rounded(52.7923, precision: 2, significant: true ) + assert_equal "9775.00", number_helper.number_to_rounded(9775, precision: 6, significant: true ) + assert_equal "5.392900", number_helper.number_to_rounded(5.3929, precision: 7, significant: true ) + assert_equal "0.0", number_helper.number_to_rounded(0, precision: 2, significant: true ) + assert_equal "0", number_helper.number_to_rounded(0, precision: 1, significant: true ) + assert_equal "0.0001", number_helper.number_to_rounded(0.0001, precision: 1, significant: true ) + assert_equal "0.000100", number_helper.number_to_rounded(0.0001, precision: 3, significant: true ) + assert_equal "0.0001", number_helper.number_to_rounded(0.0001111, precision: 1, significant: true ) + assert_equal "10.0", number_helper.number_to_rounded(9.995, precision: 3, significant: true) + assert_equal "9.99", number_helper.number_to_rounded(9.994, precision: 3, significant: true) + assert_equal "11.0", number_helper.number_to_rounded(10.995, precision: 3, significant: true) + + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775, precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(9775.0, precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(Rational(9775, 1), precision: 20, significant: true ) + assert_equal "97.750000000000000000", number_helper.number_to_rounded(Rational(9775, 100), precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded(BigDecimal(9775), precision: 20, significant: true ) + assert_equal "9775.0000000000000000", number_helper.number_to_rounded("9775", precision: 20, significant: true ) + assert_equal "9775." + "0"*96, number_helper.number_to_rounded("9775", precision: 100, significant: true ) + assert_equal("97.7", number_helper.number_to_rounded(Rational(9772, 100), precision: 3, significant: true)) end end def test_to_rounded_with_strip_insignificant_zeros [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "9775.43", number_helper.number_to_rounded(9775.43, :precision => 4, :strip_insignificant_zeros => true ) - assert_equal "9775.2", number_helper.number_to_rounded(9775.2, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) - assert_equal "0", number_helper.number_to_rounded(0, :precision => 6, :significant => true, :strip_insignificant_zeros => true ) + assert_equal "9775.43", number_helper.number_to_rounded(9775.43, precision: 4, strip_insignificant_zeros: true ) + assert_equal "9775.2", number_helper.number_to_rounded(9775.2, precision: 6, significant: true, strip_insignificant_zeros: true ) + assert_equal "0", number_helper.number_to_rounded(0, precision: 6, significant: true, strip_insignificant_zeros: true ) end end @@ -210,9 +210,9 @@ module ActiveSupport [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| # Zero precision with significant is a mistake (would always return zero), # so we treat it as if significant was false (increases backwards compatibility for number_to_human_size) - assert_equal "124", number_helper.number_to_rounded(123.987, :precision => 0, :significant => true) - assert_equal "12", number_helper.number_to_rounded(12, :precision => 0, :significant => true ) - assert_equal "12", number_helper.number_to_rounded("12.3", :precision => 0, :significant => true ) + assert_equal "124", number_helper.number_to_rounded(123.987, precision: 0, significant: true) + assert_equal "12", number_helper.number_to_rounded(12, precision: 0, significant: true ) + assert_equal "12", number_helper.number_to_rounded("12.3", precision: 0, significant: true ) end end @@ -234,12 +234,12 @@ module ActiveSupport assert_equal "444 KB", number_helper.number_to_human_size(kilobytes(444)) assert_equal "1020 MB", number_helper.number_to_human_size(megabytes(1023)) assert_equal "3 TB", number_helper.number_to_human_size(terabytes(3)) - assert_equal "1.2 MB", number_helper.number_to_human_size(1234567, :precision => 2) - assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, :precision => 4) + assert_equal "1.2 MB", number_helper.number_to_human_size(1234567, precision: 2) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, precision: 4) assert_equal "123 Bytes", number_helper.number_to_human_size("123") - assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), :precision => 2) - assert_equal "1.01 KB", number_helper.number_to_human_size(kilobytes(1.0100), :precision => 4) - assert_equal "10 KB", number_helper.number_to_human_size(kilobytes(10.000), :precision => 4) + assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2) + assert_equal "1.01 KB", number_helper.number_to_human_size(kilobytes(1.0100), precision: 4) + assert_equal "10 KB", number_helper.number_to_human_size(kilobytes(10.000), precision: 4) assert_equal "1 Byte", number_helper.number_to_human_size(1.1) assert_equal "10 Bytes", number_helper.number_to_human_size(10) end @@ -248,43 +248,43 @@ module ActiveSupport def test_number_to_human_size_with_si_prefix assert_deprecated do [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, :prefix => :si) - assert_equal "123 Bytes", number_helper.number_to_human_size(123.0, :prefix => :si) - assert_equal "123 Bytes", number_helper.number_to_human_size(123, :prefix => :si) - assert_equal "1.23 KB", number_helper.number_to_human_size(1234, :prefix => :si) - assert_equal "12.3 KB", number_helper.number_to_human_size(12345, :prefix => :si) - assert_equal "1.23 MB", number_helper.number_to_human_size(1234567, :prefix => :si) - assert_equal "1.23 GB", number_helper.number_to_human_size(1234567890, :prefix => :si) - assert_equal "1.23 TB", number_helper.number_to_human_size(1234567890123, :prefix => :si) - assert_equal "1.23 PB", number_helper.number_to_human_size(1234567890123456, :prefix => :si) - assert_equal "1.23 EB", number_helper.number_to_human_size(1234567890123456789, :prefix => :si) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, prefix: :si) + assert_equal "123 Bytes", number_helper.number_to_human_size(123.0, prefix: :si) + assert_equal "123 Bytes", number_helper.number_to_human_size(123, prefix: :si) + assert_equal "1.23 KB", number_helper.number_to_human_size(1234, prefix: :si) + assert_equal "12.3 KB", number_helper.number_to_human_size(12345, prefix: :si) + assert_equal "1.23 MB", number_helper.number_to_human_size(1234567, prefix: :si) + assert_equal "1.23 GB", number_helper.number_to_human_size(1234567890, prefix: :si) + assert_equal "1.23 TB", number_helper.number_to_human_size(1234567890123, prefix: :si) + assert_equal "1.23 PB", number_helper.number_to_human_size(1234567890123456, prefix: :si) + assert_equal "1.23 EB", number_helper.number_to_human_size(1234567890123456789, prefix: :si) end end end def test_number_to_human_size_with_options_hash [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "1.2 MB", number_helper.number_to_human_size(1234567, :precision => 2) - assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, :precision => 4) - assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), :precision => 2) - assert_equal "1.01 KB", number_helper.number_to_human_size(kilobytes(1.0100), :precision => 4) - assert_equal "10 KB", number_helper.number_to_human_size(kilobytes(10.000), :precision => 4) - assert_equal "1 TB", number_helper.number_to_human_size(1234567890123, :precision => 1) - assert_equal "500 MB", number_helper.number_to_human_size(524288000, :precision=>3) - assert_equal "10 MB", number_helper.number_to_human_size(9961472, :precision=>0) - assert_equal "40 KB", number_helper.number_to_human_size(41010, :precision => 1) - assert_equal "40 KB", number_helper.number_to_human_size(41100, :precision => 2) - assert_equal "1.0 KB", number_helper.number_to_human_size(kilobytes(1.0123), :precision => 2, :strip_insignificant_zeros => false) - assert_equal "1.012 KB", number_helper.number_to_human_size(kilobytes(1.0123), :precision => 3, :significant => false) - assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), :precision => 0, :significant => true) #ignores significant it precision is 0 + assert_equal "1.2 MB", number_helper.number_to_human_size(1234567, precision: 2) + assert_equal "3 Bytes", number_helper.number_to_human_size(3.14159265, precision: 4) + assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2) + assert_equal "1.01 KB", number_helper.number_to_human_size(kilobytes(1.0100), precision: 4) + assert_equal "10 KB", number_helper.number_to_human_size(kilobytes(10.000), precision: 4) + assert_equal "1 TB", number_helper.number_to_human_size(1234567890123, precision: 1) + assert_equal "500 MB", number_helper.number_to_human_size(524288000, precision: 3) + assert_equal "10 MB", number_helper.number_to_human_size(9961472, precision: 0) + assert_equal "40 KB", number_helper.number_to_human_size(41010, precision: 1) + assert_equal "40 KB", number_helper.number_to_human_size(41100, precision: 2) + assert_equal "1.0 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 2, strip_insignificant_zeros: false) + assert_equal "1.012 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 3, significant: false) + assert_equal "1 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 0, significant: true) #ignores significant it precision is 0 end end def test_number_to_human_size_with_custom_delimiter_and_separator [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "1,01 KB", number_helper.number_to_human_size(kilobytes(1.0123), :precision => 3, :separator => ",") - assert_equal "1,01 KB", number_helper.number_to_human_size(kilobytes(1.0100), :precision => 4, :separator => ",") - assert_equal "1.000,1 TB", number_helper.number_to_human_size(terabytes(1000.1), :precision => 5, :delimiter => ".", :separator => ",") + assert_equal "1,01 KB", number_helper.number_to_human_size(kilobytes(1.0123), precision: 3, separator: ",") + assert_equal "1,01 KB", number_helper.number_to_human_size(kilobytes(1.0100), precision: 4, separator: ",") + assert_equal "1.000,1 TB", number_helper.number_to_human_size(terabytes(1000.1), precision: 5, delimiter: ".", separator: ",") end end @@ -302,13 +302,13 @@ module ActiveSupport assert_equal "1.23 Trillion", number_helper.number_to_human(1234567890123) assert_equal "1.23 Quadrillion", number_helper.number_to_human(1234567890123456) assert_equal "1230 Quadrillion", number_helper.number_to_human(1234567890123456789) - assert_equal "490 Thousand", number_helper.number_to_human(489939, :precision => 2) - assert_equal "489.9 Thousand", number_helper.number_to_human(489939, :precision => 4) - assert_equal "489 Thousand", number_helper.number_to_human(489000, :precision => 4) - assert_equal "489.0 Thousand", number_helper.number_to_human(489000, :precision => 4, :strip_insignificant_zeros => false) - assert_equal "1.2346 Million", number_helper.number_to_human(1234567, :precision => 4, :significant => false) - assert_equal "1,2 Million", number_helper.number_to_human(1234567, :precision => 1, :significant => false, :separator => ",") - assert_equal "1 Million", number_helper.number_to_human(1234567, :precision => 0, :significant => true, :separator => ",") #significant forced to false + assert_equal "490 Thousand", number_helper.number_to_human(489939, precision: 2) + assert_equal "489.9 Thousand", number_helper.number_to_human(489939, precision: 4) + assert_equal "489 Thousand", number_helper.number_to_human(489000, precision: 4) + assert_equal "489.0 Thousand", number_helper.number_to_human(489000, precision: 4, strip_insignificant_zeros: false) + assert_equal "1.2346 Million", number_helper.number_to_human(1234567, precision: 4, significant: false) + assert_equal "1,2 Million", number_helper.number_to_human(1234567, precision: 1, significant: false, separator: ",") + assert_equal "1 Million", number_helper.number_to_human(1234567, precision: 0, significant: true, separator: ",") #significant forced to false assert_equal "1 Million", number_helper.number_to_human(999999) assert_equal "1 Billion", number_helper.number_to_human(999999999) end @@ -317,34 +317,34 @@ module ActiveSupport def test_number_to_human_with_custom_units [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| #Only integers - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal "123 lt", number_helper.number_to_human(123456, :units => volume) - assert_equal "12 ml", number_helper.number_to_human(12, :units => volume) - assert_equal "1.23 m3", number_helper.number_to_human(1234567, :units => volume) + volume = {unit: "ml", thousand: "lt", million: "m3"} + assert_equal "123 lt", number_helper.number_to_human(123456, units: volume) + assert_equal "12 ml", number_helper.number_to_human(12, units: volume) + assert_equal "1.23 m3", number_helper.number_to_human(1234567, units: volume) #Including fractionals - distance = {:mili => "mm", :centi => "cm", :deci => "dm", :unit => "m", :ten => "dam", :hundred => "hm", :thousand => "km"} - assert_equal "1.23 mm", number_helper.number_to_human(0.00123, :units => distance) - assert_equal "1.23 cm", number_helper.number_to_human(0.0123, :units => distance) - assert_equal "1.23 dm", number_helper.number_to_human(0.123, :units => distance) - assert_equal "1.23 m", number_helper.number_to_human(1.23, :units => distance) - assert_equal "1.23 dam", number_helper.number_to_human(12.3, :units => distance) - assert_equal "1.23 hm", number_helper.number_to_human(123, :units => distance) - assert_equal "1.23 km", number_helper.number_to_human(1230, :units => distance) - assert_equal "1.23 km", number_helper.number_to_human(1230, :units => distance) - assert_equal "1.23 km", number_helper.number_to_human(1230, :units => distance) - assert_equal "12.3 km", number_helper.number_to_human(12300, :units => distance) + distance = {mili: "mm", centi: "cm", deci: "dm", unit: "m", ten: "dam", hundred: "hm", thousand: "km"} + assert_equal "1.23 mm", number_helper.number_to_human(0.00123, units: distance) + assert_equal "1.23 cm", number_helper.number_to_human(0.0123, units: distance) + assert_equal "1.23 dm", number_helper.number_to_human(0.123, units: distance) + assert_equal "1.23 m", number_helper.number_to_human(1.23, units: distance) + assert_equal "1.23 dam", number_helper.number_to_human(12.3, units: distance) + assert_equal "1.23 hm", number_helper.number_to_human(123, units: distance) + assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance) + assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance) + assert_equal "1.23 km", number_helper.number_to_human(1230, units: distance) + assert_equal "12.3 km", number_helper.number_to_human(12300, units: distance) #The quantifiers don't need to be a continuous sequence - gangster = {:hundred => "hundred bucks", :million => "thousand quids"} - assert_equal "1 hundred bucks", number_helper.number_to_human(100, :units => gangster) - assert_equal "25 hundred bucks", number_helper.number_to_human(2500, :units => gangster) - assert_equal "25 thousand quids", number_helper.number_to_human(25000000, :units => gangster) - assert_equal "12300 thousand quids", number_helper.number_to_human(12345000000, :units => gangster) + gangster = {hundred: "hundred bucks", million: "thousand quids"} + assert_equal "1 hundred bucks", number_helper.number_to_human(100, units: gangster) + assert_equal "25 hundred bucks", number_helper.number_to_human(2500, units: gangster) + assert_equal "25 thousand quids", number_helper.number_to_human(25000000, units: gangster) + assert_equal "12300 thousand quids", number_helper.number_to_human(12345000000, units: gangster) #Spaces are stripped from the resulting string - assert_equal "4", number_helper.number_to_human(4, :units => {:unit => "", :ten => "tens "}) - assert_equal "4.5 tens", number_helper.number_to_human(45, :units => {:unit => "", :ten => " tens "}) + assert_equal "4", number_helper.number_to_human(4, units: {unit: "", ten: "tens "}) + assert_equal "4.5 tens", number_helper.number_to_human(45, units: {unit: "", ten: " tens "}) end end @@ -357,9 +357,9 @@ module ActiveSupport def test_number_to_human_with_custom_format [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal "123 times Thousand", number_helper.number_to_human(123456, :format => "%n times %u") - volume = {:unit => "ml", :thousand => "lt", :million => "m3"} - assert_equal "123.lt", number_helper.number_to_human(123456, :units => volume, :format => "%n.%u") + assert_equal "123 times Thousand", number_helper.number_to_human(123456, format: "%n times %u") + volume = {unit: "ml", thousand: "lt", million: "m3"} + assert_equal "123.lt", number_helper.number_to_human(123456, units: volume, format: "%n.%u") end end @@ -404,7 +404,7 @@ module ActiveSupport def test_number_helpers_should_return_non_numeric_param_unchanged [@instance_with_helpers, TestClassWithClassNumberHelpers, ActiveSupport::NumberHelper].each do |number_helper| - assert_equal("+1-x x 123", number_helper.number_to_phone("x", :country_code => 1, :extension => 123)) + assert_equal("+1-x x 123", number_helper.number_to_phone("x", country_code: 1, extension: 123)) assert_equal("x", number_helper.number_to_phone("x")) assert_equal("$x.", number_helper.number_to_currency("x.")) assert_equal("$x", number_helper.number_to_currency("x")) diff --git a/activesupport/test/option_merger_test.rb b/activesupport/test/option_merger_test.rb index 94870cebed..2bac550452 100644 --- a/activesupport/test/option_merger_test.rb +++ b/activesupport/test/option_merger_test.rb @@ -3,11 +3,11 @@ require "active_support/core_ext/object/with_options" class OptionMergerTest < ActiveSupport::TestCase def setup - @options = {:hello => "world"} + @options = {hello: "world"} end def test_method_with_options_merges_options_when_options_are_present - local_options = {:cool => true} + local_options = {cool: true} with_options(@options) do |o| assert_equal local_options, method_with_options(local_options) @@ -24,7 +24,7 @@ class OptionMergerTest < ActiveSupport::TestCase end def test_method_with_options_allows_to_overwrite_options - local_options = {:hello => "moon"} + local_options = {hello: "moon"} assert_equal @options.keys, local_options.keys with_options(@options) do |o| @@ -40,34 +40,34 @@ class OptionMergerTest < ActiveSupport::TestCase end def test_nested_method_with_options_containing_hashes_merge - with_options :conditions => { :method => :get } do |outer| - outer.with_options :conditions => { :domain => "www" } do |inner| - expected = { :conditions => { :method => :get, :domain => "www" } } + with_options conditions: { method: :get } do |outer| + outer.with_options conditions: { domain: "www" } do |inner| + expected = { conditions: { method: :get, domain: "www" } } assert_equal expected, inner.method_with_options end end end def test_nested_method_with_options_containing_hashes_overwrite - with_options :conditions => { :method => :get, :domain => "www" } do |outer| - outer.with_options :conditions => { :method => :post } do |inner| - expected = { :conditions => { :method => :post, :domain => "www" } } + with_options conditions: { method: :get, domain: "www" } do |outer| + outer.with_options conditions: { method: :post } do |inner| + expected = { conditions: { method: :post, domain: "www" } } assert_equal expected, inner.method_with_options end end end def test_nested_method_with_options_containing_hashes_going_deep - with_options :html => { :class => "foo", :style => { :margin => 0, :display => "block" } } do |outer| - outer.with_options :html => { :title => "bar", :style => { :margin => "1em", :color => "#fff" } } do |inner| - expected = { :html => { :class => "foo", :title => "bar", :style => { :margin => "1em", :display => "block", :color => "#fff" } } } + with_options html: { class: "foo", style: { margin: 0, display: "block" } } do |outer| + outer.with_options html: { title: "bar", style: { margin: "1em", color: "#fff" } } do |inner| + expected = { html: { class: "foo", title: "bar", style: { margin: "1em", display: "block", color: "#fff" } } } assert_equal expected, inner.method_with_options end end end def test_nested_method_with_options_using_lambda - local_lambda = lambda { { :lambda => true } } + local_lambda = lambda { { lambda: true } } with_options(@options) do |o| assert_equal @options.merge(local_lambda.call), o.method_with_options(local_lambda).call diff --git a/activesupport/test/ordered_hash_test.rb b/activesupport/test/ordered_hash_test.rb index 85abfa5002..f7977b276b 100644 --- a/activesupport/test/ordered_hash_test.rb +++ b/activesupport/test/ordered_hash_test.rb @@ -166,7 +166,7 @@ class OrderedHashTest < ActiveSupport::TestCase hash = ActiveSupport::OrderedHash.new hash[:a] = 0 hash[:b] = 0 - merged = hash.merge(:b => 2, :c => 7) do |key, old_value, new_value| + merged = hash.merge(b: 2, c: 7) do |key, old_value, new_value| new_value + 1 end @@ -179,7 +179,7 @@ class OrderedHashTest < ActiveSupport::TestCase hash = ActiveSupport::OrderedHash.new hash[:a] = 0 hash[:b] = 0 - hash.merge!(:a => 1, :c => 7) do |key, old_value, new_value| + hash.merge!(a: 1, c: 7) do |key, old_value, new_value| new_value + 3 end @@ -242,7 +242,7 @@ class OrderedHashTest < ActiveSupport::TestCase end def test_nested_under_indifferent_access - flash = {:a => ActiveSupport::OrderedHash[:b, 1, :c, 2]}.with_indifferent_access + flash = {a: ActiveSupport::OrderedHash[:b, 1, :c, 2]}.with_indifferent_access assert_kind_of ActiveSupport::OrderedHash, flash[:a] end @@ -305,7 +305,7 @@ class OrderedHashTest < ActiveSupport::TestCase def test_update_sets_keys @updated_ordered_hash = ActiveSupport::OrderedHash.new - @updated_ordered_hash.update(:name => "Bob") + @updated_ordered_hash.update(name: "Bob") assert_equal [:name], @updated_ordered_hash.keys end diff --git a/activesupport/test/rescuable_test.rb b/activesupport/test/rescuable_test.rb index 18e1b261e9..283afca642 100644 --- a/activesupport/test/rescuable_test.rb +++ b/activesupport/test/rescuable_test.rb @@ -24,9 +24,9 @@ class Stargate include ActiveSupport::Rescuable - rescue_from WraithAttack, :with => :sos_first + rescue_from WraithAttack, with: :sos_first - rescue_from WraithAttack, :with => :sos + rescue_from WraithAttack, with: :sos rescue_from "NuclearExplosion" do @result = "alldead" @@ -90,7 +90,7 @@ class CoolStargate < Stargate include ActiveSupport::Rescuable - rescue_from CoolError, :with => :sos_cool_error + rescue_from CoolError, with: :sos_cool_error def sos_cool_error @result = "sos_cool_error" diff --git a/activesupport/test/transliterate_test.rb b/activesupport/test/transliterate_test.rb index 8678932eae..fd417d4250 100644 --- a/activesupport/test/transliterate_test.rb +++ b/activesupport/test/transliterate_test.rb @@ -21,7 +21,7 @@ class TransliterateTest < ActiveSupport::TestCase def test_transliterate_should_work_with_custom_i18n_rules_and_uncomposed_utf8 char = [117, 776].pack("U*") # "ü" as ASCII "u" plus COMBINING DIAERESIS - I18n.backend.store_translations(:de, :i18n => {:transliterate => {:rule => {"ü" => "ue"}}}) + I18n.backend.store_translations(:de, i18n: {transliterate: {rule: {"ü" => "ue"}}}) default_locale, I18n.locale = I18n.locale, :de assert_equal "ue", ActiveSupport::Inflector.transliterate(char) ensure diff --git a/activesupport/test/xml_mini_test.rb b/activesupport/test/xml_mini_test.rb index 3179661dd1..77b6d6df8f 100644 --- a/activesupport/test/xml_mini_test.rb +++ b/activesupport/test/xml_mini_test.rb @@ -12,23 +12,23 @@ module XmlMiniTest end def test_rename_key_dasherizes_with_dasherize_true - assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => true) + assert_equal "my-key", ActiveSupport::XmlMini.rename_key("my_key", dasherize: true) end def test_rename_key_does_nothing_with_dasherize_false - assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", :dasherize => false) + assert_equal "my_key", ActiveSupport::XmlMini.rename_key("my_key", dasherize: false) end def test_rename_key_camelizes_with_camelize_true - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => true) + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", camelize: true) end def test_rename_key_lower_camelizes_with_camelize_lower - assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :lower) + assert_equal "myKey", ActiveSupport::XmlMini.rename_key("my_key", camelize: :lower) end def test_rename_key_lower_camelizes_with_camelize_upper - assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", :camelize => :upper) + assert_equal "MyKey", ActiveSupport::XmlMini.rename_key("my_key", camelize: :upper) end def test_rename_key_does_not_dasherize_leading_underscores @@ -63,7 +63,7 @@ module XmlMiniTest def setup @xml = ActiveSupport::XmlMini - @options = {:skip_instruct => true, :builder => Builder::XmlMarkup.new} + @options = {skip_instruct: true, builder: Builder::XmlMarkup.new} end test "#to_tag accepts a callable object and passes options with the builder" do |