From 8dd4aca4850c678f96d0a72098b3a080b51dea44 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Wed, 13 Nov 2013 12:31:02 +0900 Subject: Fix breakage in XmlMini - Boolean parsing breaks on non strings (i.e. integer 1|0) - Symbol parsing breaks on non strings. - BigDecimal parsing breaks due to missing require. - Update changelog. --- activesupport/lib/active_support/xml_mini.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb index d082a0a499..009ee4db90 100644 --- a/activesupport/lib/active_support/xml_mini.rb +++ b/activesupport/lib/active_support/xml_mini.rb @@ -1,7 +1,9 @@ require 'time' require 'base64' +require 'bigdecimal' require 'active_support/core_ext/module/delegation' require 'active_support/core_ext/string/inflections' +require 'active_support/core_ext/date_time/calculations' module ActiveSupport # = XmlMini @@ -56,13 +58,13 @@ module ActiveSupport # TODO use regexp instead of Date.parse unless defined?(PARSING) PARSING = { - "symbol" => Proc.new { |symbol| symbol.to_sym }, + "symbol" => Proc.new { |symbol| symbol.to_s.to_sym }, "date" => Proc.new { |date| ::Date.parse(date) }, "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc }, "integer" => Proc.new { |integer| integer.to_i }, "float" => Proc.new { |float| float.to_f }, "decimal" => Proc.new { |number| BigDecimal(number) }, - "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) }, + "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) }, "string" => Proc.new { |string| string.to_s }, "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml }, "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) }, -- cgit v1.2.3 From 0e9144dcecb1a21627ec66ca3578308c43368ee9 Mon Sep 17 00:00:00 2001 From: Anna Carey Date: Fri, 17 Jan 2014 16:49:10 -0500 Subject: set encoding to binmode for pipe --- activesupport/lib/active_support/testing/isolation.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb index 75ead48376..908af176be 100644 --- a/activesupport/lib/active_support/testing/isolation.rb +++ b/activesupport/lib/active_support/testing/isolation.rb @@ -37,6 +37,8 @@ module ActiveSupport module Forking def run_in_isolation(&blk) read, write = IO.pipe + read.binmode + write.binmode pid = fork do read.close -- cgit v1.2.3 From 90228a168b3234c257ae4b1768bf615488f556d6 Mon Sep 17 00:00:00 2001 From: robertomiranda Date: Sun, 19 Jan 2014 20:59:54 -0500 Subject: Update Error Message when secrets.secret_key_base isn't given --- activesupport/lib/active_support/key_generator.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb index 598c46bce5..58a2289b08 100644 --- a/activesupport/lib/active_support/key_generator.rb +++ b/activesupport/lib/active_support/key_generator.rb @@ -58,10 +58,10 @@ module ActiveSupport def ensure_secret_secure(secret) if secret.blank? raise ArgumentError, "A secret is required to generate an " + - "integrity hash for cookie session data. Use " + - "config.secret_key_base = \"some secret phrase of at " + - "least #{SECRET_MIN_LENGTH} characters\"" + - "in config/initializers/secret_token.rb" + "integrity hash for cookie session data. Set a " + + "secret_key_base of at least " + + "#{SECRET_MIN_LENGTH} characters " + + "in config/initializers/secrets.yml" end if secret.length < SECRET_MIN_LENGTH -- cgit v1.2.3 From f63c6e57ee7b777ffe8d9e8ba907cd4b36f4040d Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 20 Jan 2014 08:56:08 -0200 Subject: Fix secrets.yml path in exception message The file is config/secrets.yml, not config/initializers/secrets.yml. --- activesupport/lib/active_support/key_generator.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb index 58a2289b08..51d2da3a79 100644 --- a/activesupport/lib/active_support/key_generator.rb +++ b/activesupport/lib/active_support/key_generator.rb @@ -57,18 +57,16 @@ module ActiveSupport # secret they've provided is at least 30 characters in length. def ensure_secret_secure(secret) if secret.blank? - raise ArgumentError, "A secret is required to generate an " + - "integrity hash for cookie session data. Set a " + - "secret_key_base of at least " + - "#{SECRET_MIN_LENGTH} characters " + - "in config/initializers/secrets.yml" + raise ArgumentError, "A secret is required to generate an integrity hash " \ + "for cookie session data. Set a secret_key_base of at least " \ + "#{SECRET_MIN_LENGTH} characters in config/secrets.yml." end if secret.length < SECRET_MIN_LENGTH - raise ArgumentError, "Secret should be something secure, " + - "like \"#{SecureRandom.hex(16)}\". The value you " + - "provided, \"#{secret}\", is shorter than the minimum length " + - "of #{SECRET_MIN_LENGTH} characters" + raise ArgumentError, "Secret should be something secure, " \ + "like \"#{SecureRandom.hex(16)}\". The value you " \ + "provided, \"#{secret}\", is shorter than the minimum length " \ + "of #{SECRET_MIN_LENGTH} characters." end end end -- cgit v1.2.3 From b5944928700cfc13ed8f615acb54116a3039f345 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 16:56:33 +0000 Subject: Maintain current timezone when changing time during DST overlap Currently if a time is changed during DST overlap in the autumn then the method `period_for_local` will return the DST period. However if the original time is not DST then this can be surprising and is not what is generally wanted. This commit changes that behavior to maintain the current period if it's in the list of periods returned by `periods_for_local`. It is possible to alter the behavior of `period_for_local` by specifying a second argument but since we may be change from another time that could be either DST or not then this would give inconsistent results. Fixes #12163. --- activesupport/lib/active_support/time_with_zone.rb | 12 +++++++++--- activesupport/lib/active_support/values/time_zone.rb | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 50db7da9d9..d47aee00f4 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -45,7 +45,7 @@ module ActiveSupport def initialize(utc_time, time_zone, local_time = nil, period = nil) @utc, @time_zone, @time = utc_time, time_zone, local_time - @period = @utc ? period : get_period_and_ensure_valid_local_time + @period = @utc ? period : get_period_and_ensure_valid_local_time(period) end # Returns a Time or DateTime instance that represents the time in +time_zone+. @@ -292,6 +292,12 @@ module ActiveSupport end end + def change(options) + new_time = time.change(options) + periods = time_zone.periods_for_local(new_time) + self.class.new(nil, time_zone, new_time, periods.include?(period) ? period : nil) + end + %w(year mon month day mday wday yday hour min sec usec nsec to_date).each do |method_name| class_eval <<-EOV, __FILE__, __LINE__ + 1 def #{method_name} # def month @@ -367,12 +373,12 @@ module ActiveSupport end private - def get_period_and_ensure_valid_local_time + def get_period_and_ensure_valid_local_time(period) # we don't want a Time.local instance enforcing its own DST rules as well, # so transfer time values to a utc constructor if necessary @time = transfer_time_values_to_utc_constructor(@time) unless @time.utc? begin - @time_zone.period_for_local(@time) + period || @time_zone.period_for_local(@time) rescue ::TZInfo::PeriodNotFound # time is in the "spring forward" hour gap, so we're moving the time forward one hour and trying again @time += 1.hour diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index beaac42fa1..eb785d46ce 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -352,6 +352,10 @@ module ActiveSupport tzinfo.period_for_local(time, dst) end + def periods_for_local(time) #:nodoc: + tzinfo.periods_for_local(time) + end + def self.find_tzinfo(name) TZInfo::TimezoneProxy.new(MAPPING[name] || name) end -- cgit v1.2.3 From 4cfc467594da86090efa63f1852fb82df9458c2b Mon Sep 17 00:00:00 2001 From: Parker Selbert Date: Tue, 16 Jul 2013 16:16:33 -0400 Subject: Customize subsecond digits when encoding DateWithTime The subsecond fraction digits had been hardcoded to 3. This forced all timestamps to include the subsecond digits with no way to customize the value. While the subsecond format is part of the ISO8601 spec, it is not adhered to by all parsers (notably mobile clients). This adds the ability to customize the number of digits used, optionally setting them to 0 in order to eliminate the subsecond fraction entirely: ActiveSupport::JSON::Encoding.subsecond_fraction_digits = 0 --- activesupport/lib/active_support/json/encoding.rb | 7 ++++++- activesupport/lib/active_support/time_with_zone.rb | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 2859075e10..23896316e2 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -4,6 +4,7 @@ require 'active_support/core_ext/module/delegation' module ActiveSupport class << self delegate :use_standard_json_time_format, :use_standard_json_time_format=, + :subsecond_fraction_digits, :subsecond_fraction_digits=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :encode_big_decimal_as_string, :encode_big_decimal_as_string=, :json_encoder, :json_encoder=, @@ -60,7 +61,7 @@ module ActiveSupport end # Mark these as private so we don't leak encoding-specific constructs - private_constant :ESCAPED_CHARS, :ESCAPE_REGEX_WITH_HTML_ENTITIES, + private_constant :ESCAPED_CHARS, :ESCAPE_REGEX_WITH_HTML_ENTITIES, :ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString # Convert an object into a "JSON-ready" representation composed of @@ -105,6 +106,10 @@ module ActiveSupport # as a safety measure. attr_accessor :escape_html_entities_in_json + # Configures the inclusion of subsecond resolution when serializing instances + # of ActiveSupport::TimeWithZone. + attr_accessor :subsecond_fraction_digits + # Sets the encoder used by Rails to encode Ruby objects into JSON strings # in +Object#to_json+ and +ActiveSupport::JSON.encode+. attr_accessor :json_encoder diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index d47aee00f4..26d4e686fd 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -154,7 +154,8 @@ module ActiveSupport # # => "2005/02/01 05:15:10 -1000" def as_json(options = nil) if ActiveSupport::JSON::Encoding.use_standard_json_time_format - xmlschema(3) + digits = ActiveSupport::JSON::Encoding.subsecond_fraction_digits || 3 + xmlschema(digits) else %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) end -- cgit v1.2.3 From e3c382e3d69e7f25593cf45a4acc1b74bb93d057 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 20:39:16 +0000 Subject: Rename subsecond_fraction_digits option to time_precision --- activesupport/lib/active_support/json/encoding.rb | 8 ++++---- activesupport/lib/active_support/time_with_zone.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 23896316e2..bafd629848 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -4,7 +4,7 @@ require 'active_support/core_ext/module/delegation' module ActiveSupport class << self delegate :use_standard_json_time_format, :use_standard_json_time_format=, - :subsecond_fraction_digits, :subsecond_fraction_digits=, + :time_precision, :time_precision=, :escape_html_entities_in_json, :escape_html_entities_in_json=, :encode_big_decimal_as_string, :encode_big_decimal_as_string=, :json_encoder, :json_encoder=, @@ -106,9 +106,9 @@ module ActiveSupport # as a safety measure. attr_accessor :escape_html_entities_in_json - # Configures the inclusion of subsecond resolution when serializing instances - # of ActiveSupport::TimeWithZone. - attr_accessor :subsecond_fraction_digits + # Sets the precision of encoded time values. + # Defaults to 3 (equivalent to millisecond precision) + attr_accessor :time_precision # Sets the encoder used by Rails to encode Ruby objects into JSON strings # in +Object#to_json+ and +ActiveSupport::JSON.encode+. diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 26d4e686fd..1ed18fa473 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -154,7 +154,7 @@ module ActiveSupport # # => "2005/02/01 05:15:10 -1000" def as_json(options = nil) if ActiveSupport::JSON::Encoding.use_standard_json_time_format - digits = ActiveSupport::JSON::Encoding.subsecond_fraction_digits || 3 + digits = ActiveSupport::JSON::Encoding.time_precision || 3 xmlschema(digits) else %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) -- cgit v1.2.3 From c0965004486f2ea5a9656ba718a3377c9614f97d Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 21:09:06 +0000 Subject: Add support for JSON time_precision to Time and DateTime --- activesupport/lib/active_support/core_ext/object/json.rb | 8 ++++---- activesupport/lib/active_support/json/encoding.rb | 1 + activesupport/lib/active_support/time_with_zone.rb | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb index 1675145ffe..8e08cfbf26 100644 --- a/activesupport/lib/active_support/core_ext/object/json.rb +++ b/activesupport/lib/active_support/core_ext/object/json.rb @@ -16,12 +16,12 @@ require 'active_support/core_ext/module/aliasing' # otherwise they will always use to_json gem implementation, which is backwards incompatible in # several cases (for instance, the JSON implementation for Hash does not work) with inheritance # and consequently classes as ActiveSupport::OrderedHash cannot be serialized to json. -# +# # On the other hand, we should avoid conflict with ::JSON.{generate,dump}(obj). Unfortunately, the # JSON gem's encoder relies on its own to_json implementation to encode objects. Since it always # passes a ::JSON::State object as the only argument to to_json, we can detect that and forward the # calls to the original to_json method. -# +# # It should be noted that when using ::JSON.{generate,dump} directly, ActiveSupport's encoder is # bypassed completely. This means that as_json won't be invoked and the JSON gem will simply # ignore any options it does not natively understand. This also means that ::JSON.{generate,dump} @@ -163,7 +163,7 @@ end class Time def as_json(options = nil) #:nodoc: if ActiveSupport.use_standard_json_time_format - xmlschema(3) + xmlschema(ActiveSupport::JSON::Encoding.time_precision) else %(#{strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) end @@ -183,7 +183,7 @@ end class DateTime def as_json(options = nil) #:nodoc: if ActiveSupport.use_standard_json_time_format - xmlschema(3) + xmlschema(ActiveSupport::JSON::Encoding.time_precision) else strftime('%Y/%m/%d %H:%M:%S %z') end diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index bafd629848..f29d42276d 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -166,6 +166,7 @@ module ActiveSupport self.use_standard_json_time_format = true self.escape_html_entities_in_json = true self.json_encoder = JSONGemEncoder + self.time_precision = 3 end end end diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 1ed18fa473..626438c9e4 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -154,8 +154,7 @@ module ActiveSupport # # => "2005/02/01 05:15:10 -1000" def as_json(options = nil) if ActiveSupport::JSON::Encoding.use_standard_json_time_format - digits = ActiveSupport::JSON::Encoding.time_precision || 3 - xmlschema(digits) + xmlschema(ActiveSupport::JSON::Encoding.time_precision) else %(#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}) end -- cgit v1.2.3 From dd339bb0adc3bb1f0c376c4352f769ae2ab02b62 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 26 Jan 2014 21:22:23 +0000 Subject: Make ActiveSupport::TimeWithZone#xmlschema consistent Both Time#xmlschema and DateTime#xmlschema can accept nil values for the fraction_digits parameter. This commit makes this so for TimeWithZone values as well. --- activesupport/lib/active_support/time_with_zone.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 626438c9e4..d459af1778 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -132,8 +132,8 @@ module ActiveSupport end def xmlschema(fraction_digits = 0) - fraction = if fraction_digits > 0 - (".%06i" % time.usec)[0, fraction_digits + 1] + fraction = if fraction_digits.to_i > 0 + (".%06i" % time.usec)[0, fraction_digits.to_i + 1] end "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{fraction}#{formatted_offset(true, 'Z')}" -- cgit v1.2.3 From b23ffd0dac895aa3fd3afd8d9be36794941731b2 Mon Sep 17 00:00:00 2001 From: Lukasz Sarnacki Date: Fri, 10 Jan 2014 12:57:50 +0100 Subject: Allow session serializer key in config.session_store MessageEncryptor has :serializer option, where any serializer object can be passed. This commit make it possible to set this serializer from configuration level. There are predefined serializers (:marshal_serializer, :json_serialzier) and custom serializer can be passed as String, Symbol (camelized and constantized in ActionDispatch::Session namepspace) or serializer object. Default :json_serializer was also added to generators to provide secure defalt. --- activesupport/lib/active_support/message_encryptor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 7773611e11..b019ad0dec 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -12,7 +12,7 @@ module ActiveSupport # This can be used in situations similar to the MessageVerifier, but # where you don't want users to be able to determine the value of the payload. # - # salt = SecureRandom.random_bytes(64) + # salt = SecureRandom.random_bytes(64) # key = ActiveSupport::KeyGenerator.new('password').generate_key(salt) # => "\x89\xE0\x156\xAC..." # crypt = ActiveSupport::MessageEncryptor.new(key) # => # # encrypted_data = crypt.encrypt_and_sign('my secret data') # => "NlFBTTMwOUV5UlA1QlNEN2xkY2d6eThYWWh..." -- cgit v1.2.3 From b2bb1aaf66673a4d5bcb63ed0f5c15023c99d3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 21 Jan 2014 23:49:02 -0200 Subject: Implement a simple stub feature to use in the Time travel helpers --- .../lib/active_support/testing/time_helpers.rb | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 94230e56ba..0e48456715 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -1,7 +1,48 @@ module ActiveSupport module Testing + class SimpleStubs + Stub = Struct.new(:object, :method_name, :original_method) + + def initialize + @stubs = {} + end + + def stub_object(object, method_name, return_value) + key = [object.object_id, method_name] + + if (stub = @stubs[key]) + unstub_object(stub) + end + + @stubs[key] = Stub.new(object, method_name, object.method(method_name)) + + object.define_singleton_method(method_name) { return_value } + end + + def unstub_all! + @stubs.each do |_, stub| + unstub_object(stub) + end + @stubs = {} + end + + def unstub_object(stub) + stub.object.define_singleton_method(stub.method_name, stub.original_method) + end + end + # Containing helpers that helps you test passage of time. module TimeHelpers + def before_setup + super + @simple_stubs = SimpleStubs.new + end + + def after_teardown #:nodoc: + @simple_stubs.unstub_all! + super + end + # Change current time to the time in the future or in the past by a given time difference by # stubbing +Time.now+ and +Date.today+. Note that the stubs are automatically removed # at the end of each test. @@ -41,13 +82,12 @@ module ActiveSupport # end # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 def travel_to(date_or_time, &block) - Time.stubs now: date_or_time.to_time - Date.stubs today: date_or_time.to_date + @simple_stubs.stub_object(Time, :now, date_or_time.to_time) + @simple_stubs.stub_object(Date, :today, date_or_time.to_date) if block_given? block.call - Time.unstub :now - Date.unstub :today + @simple_stubs.unstub_all! end end end -- cgit v1.2.3 From 049a10d4051a48136199fcdfd77bf35df9e9ad11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 21:07:46 -0200 Subject: Alias the original method first to avoid warnings --- activesupport/lib/active_support/testing/time_helpers.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 0e48456715..cd56ae1883 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -14,8 +14,11 @@ module ActiveSupport unstub_object(stub) end - @stubs[key] = Stub.new(object, method_name, object.method(method_name)) + new_name = "__simple_stub__#{method_name}" + @stubs[key] = Stub.new(object, method_name, new_name) + + object.singleton_class.send :alias_method, new_name, method_name object.define_singleton_method(method_name) { return_value } end @@ -27,7 +30,9 @@ module ActiveSupport end def unstub_object(stub) - stub.object.define_singleton_method(stub.method_name, stub.original_method) + stub.object.singleton_class.send :undef_method, stub.method_name + stub.object.singleton_class.send :alias_method, stub.method_name, stub.original_method + stub.object.singleton_class.send :undef_method, stub.original_method end end -- cgit v1.2.3 From 6dce4367c2bba894bb94e27cdfe4c56fdcc2c3df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 21:10:10 -0200 Subject: Use instance method instead of before hook --- .../lib/active_support/testing/time_helpers.rb | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index cd56ae1883..77b8ba261e 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -38,13 +38,8 @@ module ActiveSupport # Containing helpers that helps you test passage of time. module TimeHelpers - def before_setup - super - @simple_stubs = SimpleStubs.new - end - def after_teardown #:nodoc: - @simple_stubs.unstub_all! + simple_stubs.unstub_all! super end @@ -87,14 +82,18 @@ module ActiveSupport # end # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 def travel_to(date_or_time, &block) - @simple_stubs.stub_object(Time, :now, date_or_time.to_time) - @simple_stubs.stub_object(Date, :today, date_or_time.to_date) + simple_stubs.stub_object(Time, :now, date_or_time.to_time) + simple_stubs.stub_object(Date, :today, date_or_time.to_date) if block_given? block.call - @simple_stubs.unstub_all! + simple_stubs.unstub_all! end end + + def simple_stubs + @simple_stubs ||= SimpleStubs.new + end end end end -- cgit v1.2.3 From 7cf9a1c6a6cba5565817aa11edc227b6369685e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 21:16:52 -0200 Subject: Change the class and method visibility --- .../lib/active_support/testing/time_helpers.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 77b8ba261e..af19c5a9f5 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -1,6 +1,6 @@ module ActiveSupport module Testing - class SimpleStubs + class SimpleStubs # :nodoc: Stub = Struct.new(:object, :method_name, :original_method) def initialize @@ -29,11 +29,13 @@ module ActiveSupport @stubs = {} end - def unstub_object(stub) - stub.object.singleton_class.send :undef_method, stub.method_name - stub.object.singleton_class.send :alias_method, stub.method_name, stub.original_method - stub.object.singleton_class.send :undef_method, stub.original_method - end + private + + def unstub_object(stub) + stub.object.singleton_class.send :undef_method, stub.method_name + stub.object.singleton_class.send :alias_method, stub.method_name, stub.original_method + stub.object.singleton_class.send :undef_method, stub.original_method + end end # Containing helpers that helps you test passage of time. @@ -91,9 +93,11 @@ module ActiveSupport end end - def simple_stubs - @simple_stubs ||= SimpleStubs.new - end + private + + def simple_stubs + @simple_stubs ||= SimpleStubs.new + end end end end -- cgit v1.2.3 From 17cb1266c7b91c934dcef2afe38ea4dab677ef91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 21:17:05 -0200 Subject: Store the singleton_class in a local variable --- activesupport/lib/active_support/testing/time_helpers.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index af19c5a9f5..84cbdf9608 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -32,9 +32,10 @@ module ActiveSupport private def unstub_object(stub) - stub.object.singleton_class.send :undef_method, stub.method_name - stub.object.singleton_class.send :alias_method, stub.method_name, stub.original_method - stub.object.singleton_class.send :undef_method, stub.original_method + singleton_class = stub.object.singleton_class + singleton_class.send :undef_method, stub.method_name + singleton_class.send :alias_method, stub.method_name, stub.original_method + singleton_class.send :undef_method, stub.original_method end end -- cgit v1.2.3 From 06e06cd454f3699d970c7dc8404170ac236c7743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 21:22:15 -0200 Subject: Use each_value --- activesupport/lib/active_support/testing/time_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 84cbdf9608..0ee6332d6f 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -23,7 +23,7 @@ module ActiveSupport end def unstub_all! - @stubs.each do |_, stub| + @stubs.each_value do |stub| unstub_object(stub) end @stubs = {} -- cgit v1.2.3 From 6b16c2788186d45c70bd1d9fc476407e3e265439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 22:24:48 -0200 Subject: Add `travel_back` to remove stubs from `travel` and `travel_to` --- .../lib/active_support/testing/time_helpers.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 0ee6332d6f..b183b8d8ef 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -42,7 +42,7 @@ module ActiveSupport # Containing helpers that helps you test passage of time. module TimeHelpers def after_teardown #:nodoc: - simple_stubs.unstub_all! + travel_back super end @@ -81,7 +81,7 @@ module ActiveSupport # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel_to Time.new(2004, 11, 24, 01, 04, 44) do - # User.create.created_at # => Wed, 24 Nov 2004 01:04:44 EST -05:00 + # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00 # end # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 def travel_to(date_or_time, &block) @@ -90,10 +90,21 @@ module ActiveSupport if block_given? block.call - simple_stubs.unstub_all! + travel_back end end + # Return the current time back to its original state. + # + # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 + # travel_to Time.new(2004, 11, 24, 01, 04, 44) + # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00 + # travel_back + # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 + def travel_back + simple_stubs.unstub_all! + end + private def simple_stubs -- cgit v1.2.3 From 7abb6e00c0f1d6cc98b10b0e7620dfb9786449a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 29 Jan 2014 22:41:30 -0200 Subject: Remove automatic removal of Date/Time stubs after each test case This behavior is only work out-of-box with minitest and also add a downside to run after each test case, even if we don't used the travel or travel_to methods --- activesupport/lib/active_support/testing/time_helpers.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index b183b8d8ef..4c6bca5ada 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -41,14 +41,8 @@ module ActiveSupport # Containing helpers that helps you test passage of time. module TimeHelpers - def after_teardown #:nodoc: - travel_back - super - end - # Change current time to the time in the future or in the past by a given time difference by - # stubbing +Time.now+ and +Date.today+. Note that the stubs are automatically removed - # at the end of each test. + # stubbing +Time.now+ and +Date.today+. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel 1.day @@ -68,8 +62,7 @@ module ActiveSupport end # Change current time to the given time by stubbing +Time.now+ and +Date.today+ to return the - # time or date passed into this method. Note that the stubs are automatically removed - # at the end of each test. + # time or date passed into this method. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel_to Time.new(2004, 11, 24, 01, 04, 44) -- cgit v1.2.3 From fa1f20e6549f962112948f5b3c27d09ab5e5faaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 30 Jan 2014 10:13:58 -0200 Subject: Improve documentation [ci skip] --- activesupport/lib/active_support/testing/time_helpers.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/time_helpers.rb b/activesupport/lib/active_support/testing/time_helpers.rb index 4c6bca5ada..9e0a3d6345 100644 --- a/activesupport/lib/active_support/testing/time_helpers.rb +++ b/activesupport/lib/active_support/testing/time_helpers.rb @@ -41,7 +41,7 @@ module ActiveSupport # Containing helpers that helps you test passage of time. module TimeHelpers - # Change current time to the time in the future or in the past by a given time difference by + # Changes current time to the time in the future or in the past by a given time difference by # stubbing +Time.now+ and +Date.today+. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 @@ -61,7 +61,7 @@ module ActiveSupport travel_to Time.now + duration, &block end - # Change current time to the given time by stubbing +Time.now+ and +Date.today+ to return the + # Changes current time to the given time by stubbing +Time.now+ and +Date.today+ to return the # time or date passed into this method. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 @@ -87,7 +87,8 @@ module ActiveSupport end end - # Return the current time back to its original state. + # Returns the current time back to its original state, by removing the stubs added by + # `travel` and `travel_to`. # # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00 # travel_to Time.new(2004, 11, 24, 01, 04, 44) -- cgit v1.2.3 From d4d041c1fe55c10a786a4a1a7ff0c34867944b2f Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Thu, 30 Jan 2014 12:05:02 +0100 Subject: fix typo and indent. [ci skip] --- activesupport/lib/active_support/core_ext/module/concerning.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/module/concerning.rb b/activesupport/lib/active_support/core_ext/module/concerning.rb index b22dc5ff1e..07a392404e 100644 --- a/activesupport/lib/active_support/core_ext/module/concerning.rb +++ b/activesupport/lib/active_support/core_ext/module/concerning.rb @@ -63,7 +63,7 @@ class Module # # == Mix-in noise exiled to its own file: # - # Once our chunk of behavior starts pushing the scroll-to-understand it + # Once our chunk of behavior starts pushing the scroll-to-understand it's # boundary, we give in and move it to a separate file. At this size, the # overhead feels in good proportion to the size of our extraction, despite # diluting our at-a-glance sense of how things really work. -- cgit v1.2.3 From 63f8fabe4939ad59d597dfea441002ef5b16d2f4 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Fri, 31 Jan 2014 17:13:12 +0000 Subject: Maintain the current timezone in wrap_with_time_zone Extend the solution from the fix for #12163 to the general case where `Time` methods are wrapped with a time zone. Fixes #12596. --- activesupport/lib/active_support/time_with_zone.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index d459af1778..c25c97cfa8 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -292,12 +292,6 @@ module ActiveSupport end end - def change(options) - new_time = time.change(options) - periods = time_zone.periods_for_local(new_time) - self.class.new(nil, time_zone, new_time, periods.include?(period) ? period : nil) - end - %w(year mon month day mday wday yday hour min sec usec nsec to_date).each do |method_name| class_eval <<-EOV, __FILE__, __LINE__ + 1 def #{method_name} # def month @@ -396,7 +390,8 @@ module ActiveSupport def wrap_with_time_zone(time) if time.acts_like?(:time) - self.class.new(nil, time_zone, time) + periods = time_zone.periods_for_local(time) + self.class.new(nil, time_zone, time, periods.include?(period) ? period : nil) elsif time.is_a?(Range) wrap_with_time_zone(time.begin)..wrap_with_time_zone(time.end) else -- cgit v1.2.3 From 85d820b1693a52faddf1f838512e132906272e41 Mon Sep 17 00:00:00 2001 From: David Celis Date: Fri, 31 Jan 2014 17:42:21 -0800 Subject: Don't require BigDecimal serialization extension Rails currently provides an extension to BigDecimal that redefines how it is serialized to YAML. However, as noted in #12467, this does not work as expected. When ActiveSupport is required, BigDecimal YAML serialization does not maintain the object type. It instead ends up serializing the number represented by the BigDecimal itself which, when loaded by YAML later, becomes a Float: ```ruby require 'yaml' require 'bigdecimal' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class require 'active_support/all' yaml = BigDecimal('13.37').to_yaml YAML.load(yaml).class ``` @tenderlove posits that we should deprecate the custom BigDecimal serialization and let Ruby handle it. For the time being, users who require this serialization for backwards compatibility can manually `require 'active_support/core_ext/big_decimal/yaml_conversions'`. This will close #12467 and deprecate the custom BigDecimal#to_yaml. Signed-off-by: David Celis --- .../lib/active_support/core_ext/big_decimal/conversions.rb | 8 -------- .../active_support/core_ext/big_decimal/yaml_conversions.rb | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index 39b8cea807..54b49e6d04 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -1,15 +1,7 @@ require 'bigdecimal' require 'bigdecimal/util' -require 'yaml' class BigDecimal - YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' } - - def encode_with(coder) - string = to_s - coder.represent_scalar(nil, YAML_MAPPING[string] || string) - end - # Backport this method if it doesn't exist unless method_defined?(:to_d) def to_d diff --git a/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb new file mode 100644 index 0000000000..aa2ed4d6fb --- /dev/null +++ b/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb @@ -0,0 +1,13 @@ +ActiveSupport::Deprecation.warn 'core_ext/big_decimal/yaml_conversions is deprecated and will be removed in the future.' + +require 'bigdecimal' +require 'yaml' + +class BigDecimal + YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' } + + def encode_with(coder) + string = to_s + coder.represent_scalar(nil, YAML_MAPPING[string] || string) + end +end -- cgit v1.2.3 From c87b27ebde4c5a0bc172ffce59faaadb20301dec Mon Sep 17 00:00:00 2001 From: David Celis Date: Sat, 1 Feb 2014 10:26:50 -0800 Subject: Remove BigDecimal#to_d This was backported for Ruby 1.8 support and is no longer needed. Signed-off-by: David Celis --- .../lib/active_support/core_ext/big_decimal/conversions.rb | 7 ------- 1 file changed, 7 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb index 54b49e6d04..843c592669 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/conversions.rb @@ -2,13 +2,6 @@ require 'bigdecimal' require 'bigdecimal/util' class BigDecimal - # Backport this method if it doesn't exist - unless method_defined?(:to_d) - def to_d - self - end - end - DEFAULT_STRING_FORMAT = 'F' def to_formatted_s(*args) if args[0].is_a?(Symbol) -- cgit v1.2.3 From 8c679fe0ca77e8cc6de6ae408a556995f3801ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 1 Feb 2014 18:29:41 -0200 Subject: Fix isolated tests --- .../lib/active_support/core_ext/big_decimal/yaml_conversions.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb b/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb index aa2ed4d6fb..46ba93ead4 100644 --- a/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +++ b/activesupport/lib/active_support/core_ext/big_decimal/yaml_conversions.rb @@ -2,6 +2,7 @@ ActiveSupport::Deprecation.warn 'core_ext/big_decimal/yaml_conversions is deprec require 'bigdecimal' require 'yaml' +require 'active_support/core_ext/big_decimal/conversions' class BigDecimal YAML_MAPPING = { 'Infinity' => '.Inf', '-Infinity' => '-.Inf', 'NaN' => '.NaN' } -- cgit v1.2.3 From dd493d3b6f25147227db4c5d119d6b48c31f42e6 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 3 Feb 2014 16:42:02 +0100 Subject: docs, be clear that `options` is a hash. Closes #11904. [ci skip]. --- activesupport/lib/active_support/cache.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 53154aef27..2b7f5943b5 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -452,7 +452,7 @@ module ActiveSupport # Clear the entire cache. Be careful with this method since it could # affect other processes if shared cache is being used. # - # Options are passed to the underlying cache implementation. + # The options hash is passed to the underlying cache implementation. # # All implementations may not support this method. def clear(options = nil) -- cgit v1.2.3 From 13d2696c10726afecd393753fcac88c5a9907d8c Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Wed, 29 Jan 2014 15:42:07 -0500 Subject: Return sized enumerator from Batches#find_each --- activesupport/lib/active_support/core_ext/enumerable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 4501b7ff58..a2dec41c87 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -35,7 +35,7 @@ module Enumerable if block_given? Hash[map { |elem| [yield(elem), elem] }] else - to_enum :index_by + to_enum(:index_by) { size } end end -- cgit v1.2.3 From a476020567a47f5fbec3629707d5bf31b400a284 Mon Sep 17 00:00:00 2001 From: Marc-Andre Lafortune Date: Tue, 4 Feb 2014 02:18:03 -0500 Subject: Return sized enumerator from Enumerable#index_by --- activesupport/lib/active_support/core_ext/enumerable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index a2dec41c87..1343beb87a 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -35,7 +35,7 @@ module Enumerable if block_given? Hash[map { |elem| [yield(elem), elem] }] else - to_enum(:index_by) { size } + to_enum(:index_by) { size if respond_to?(:size) } end end -- cgit v1.2.3 From 26698fb91d88dca0f860adcb80528d8d3f0f6285 Mon Sep 17 00:00:00 2001 From: Sean Walbran Date: Wed, 5 Feb 2014 17:19:51 -0600 Subject: fix interplay of humanize and html_escape --- activesupport/lib/active_support/inflector/methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index cdee4c2ca5..b642d87d76 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -117,7 +117,7 @@ module ActiveSupport result.gsub!(/([a-z\d]*)/i) { |match| "#{inflections.acronyms[match] || match.downcase}" } - result.gsub!(/^\w/) { $&.upcase } if options.fetch(:capitalize, true) + result.gsub!(/^\w/) { |match| match.upcase } if options.fetch(:capitalize, true) result end -- cgit v1.2.3 From 326e6527497126b2ea3627e377b6a4b5c9191bef Mon Sep 17 00:00:00 2001 From: Hincu Petru Date: Mon, 3 Feb 2014 09:51:05 +0000 Subject: Fixed "Hash#to_param confused by empty hash values #13892" --- activesupport/lib/active_support/core_ext/object/to_param.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb index 3b137ce6ae..e40846e7d6 100644 --- a/activesupport/lib/active_support/core_ext/object/to_param.rb +++ b/activesupport/lib/active_support/core_ext/object/to_param.rb @@ -51,6 +51,7 @@ class Hash # # This method is also aliased as +to_query+. def to_param(namespace = nil) + return (namespace ? nil.to_query(namespace) : '') if empty? collect do |key, value| value.to_query(namespace ? "#{namespace}[#{key}]" : key) end.sort! * '&' -- cgit v1.2.3 From ab51b285e2cccdc0cbdcd2daa04a7fd2fbb661ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 5 Feb 2014 23:55:17 -0200 Subject: Refatoring the method to avoid shot-circuit return --- activesupport/lib/active_support/core_ext/object/to_param.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/to_param.rb b/activesupport/lib/active_support/core_ext/object/to_param.rb index e40846e7d6..13be0038c2 100644 --- a/activesupport/lib/active_support/core_ext/object/to_param.rb +++ b/activesupport/lib/active_support/core_ext/object/to_param.rb @@ -51,9 +51,12 @@ class Hash # # This method is also aliased as +to_query+. def to_param(namespace = nil) - return (namespace ? nil.to_query(namespace) : '') if empty? - collect do |key, value| - value.to_query(namespace ? "#{namespace}[#{key}]" : key) - end.sort! * '&' + if empty? + namespace ? nil.to_query(namespace) : '' + else + collect do |key, value| + value.to_query(namespace ? "#{namespace}[#{key}]" : key) + end.sort! * '&' + end end end -- cgit v1.2.3 From c82dbc6a1c1a269fb21de8fd2722fc680ab7ea54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Thu, 6 Feb 2014 01:03:41 -0200 Subject: Fix to_query with empty arrays too --- activesupport/lib/active_support/core_ext/object/to_query.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/to_query.rb b/activesupport/lib/active_support/core_ext/object/to_query.rb index 5d5fcf00e0..37352fa608 100644 --- a/activesupport/lib/active_support/core_ext/object/to_query.rb +++ b/activesupport/lib/active_support/core_ext/object/to_query.rb @@ -18,7 +18,12 @@ class Array # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding" def to_query(key) prefix = "#{key}[]" - collect { |value| value.to_query(prefix) }.join '&' + + if empty? + nil.to_query(prefix) + else + collect { |value| value.to_query(prefix) }.join '&' + end end end -- cgit v1.2.3 From 4fa8c8b52f2ee7155b18cee2f3fc978075c68db1 Mon Sep 17 00:00:00 2001 From: Noah Lindner Date: Sat, 8 Feb 2014 15:35:12 -0800 Subject: Fixed an issue where reloading of removed dependencies would cause an unexpected circular dependency error --- activesupport/lib/active_support/dependencies.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 6be19771f5..7ea3ff7d3f 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -665,6 +665,14 @@ module ActiveSupport #:nodoc: constants = normalized.split('::') to_remove = constants.pop + # Remove the file path from the loaded list. + file_path = search_for_file(const.underscore) + if file_path + expanded = File.expand_path(file_path) + expanded.sub!(/\.rb\z/, '') + self.loaded.delete(expanded) + end + if constants.empty? parent = Object else -- cgit v1.2.3 From 76af5c1d30b41c25f473c58f0333236b54bf7049 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 8 Feb 2014 23:21:07 -0800 Subject: use feature detection to decide which implementation to use Decouple the code from the particular Ruby version. --- activesupport/lib/active_support/multibyte/unicode.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 84799c2399..7e518d8c39 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -213,7 +213,7 @@ module ActiveSupport end # Ruby >= 2.1 has String#scrub, which is faster than the workaround used for < 2.1. - if RUBY_VERSION >= '2.1' + if '<3'.respond_to?(:scrub) # Replaces all ISO-8859-1 or CP1252 characters by their UTF-8 equivalent # resulting in a valid UTF-8 string. # -- cgit v1.2.3 From dbe3345c4f84f603b8a6d121229d1cc9f5d3be8c Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Sun, 9 Feb 2014 03:06:19 +0200 Subject: Fix grammar of internal comment and modify it's location --- activesupport/lib/active_support/core_ext/module/attr_internal.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/module/attr_internal.rb b/activesupport/lib/active_support/core_ext/module/attr_internal.rb index db07d549b0..67f0e0335d 100644 --- a/activesupport/lib/active_support/core_ext/module/attr_internal.rb +++ b/activesupport/lib/active_support/core_ext/module/attr_internal.rb @@ -27,7 +27,8 @@ class Module def attr_internal_define(attr_name, type) internal_name = attr_internal_ivar_name(attr_name).sub(/\A@/, '') - class_eval do # class_eval is necessary on 1.9 or else the methods a made private + # class_eval is necessary on 1.9 or else the methods are made private + class_eval do # use native attr_* methods as they are faster on some Ruby implementations send("attr_#{type}", internal_name) end -- cgit v1.2.3 From 17b0edde5782c424dbae6020e09a51831e8de7f9 Mon Sep 17 00:00:00 2001 From: Zachary Scott Date: Sun, 9 Feb 2014 03:07:33 +0200 Subject: Specify what #starts_with? we're talking about. Also added a note what kind of exception we should expect for this internal comment. --- activesupport/lib/active_support/dependencies.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 6be19771f5..b519ef9f71 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -407,7 +407,8 @@ module ActiveSupport #:nodoc: end def load_once_path?(path) - # to_s works around a ruby1.9 issue where #starts_with?(Pathname) will always return false + # to_s works around a ruby1.9 issue where String#starts_with?(Pathname) + # will raise a TypeError: no implicit conversion of Pathname into String autoload_once_paths.any? { |base| path.starts_with? base.to_s } end -- cgit v1.2.3 From 07c70245a128cfe42f134be8759963dc98f1a63e Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 10 Feb 2014 08:50:06 +0100 Subject: docs, mention that the current inflection rules are frozen. [ci skip] Closes #13993. --- activesupport/lib/active_support/inflections.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index 4ea6abfa12..d844e70750 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -1,5 +1,9 @@ require 'active_support/inflector/inflections' +# Define the standard inflection rules. These define a starting point for +# new projects and are not considered complete. The current set of inflection +# rules is frozen. This means, we do not change them to become more complete. +# This is a safety measure to keep existing applications from breaking. module ActiveSupport Inflector.inflections(:en) do |inflect| inflect.plural(/$/, 's') -- cgit v1.2.3 From ae28e4beb3d9b395ee269999111b6598802da63f Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Sat, 1 Feb 2014 22:13:07 -0600 Subject: Fix tidy_bytes for JRuby The previous implementation was broken because JRuby (1.7.10) doesn't have a code converter for UTF-8 to UTF8-MAC. --- activesupport/lib/active_support/multibyte/unicode.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 7e518d8c39..ea3cdcd024 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -233,16 +233,16 @@ module ActiveSupport # We're going to 'transcode' bytes from UTF-8 when possible, then fall back to # CP1252 when we get errors. The final string will be 'converted' back to UTF-8 # before returning. - reader = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_8_MAC) + reader = Encoding::Converter.new(Encoding::UTF_8, Encoding::UTF_16LE) source = string.dup - out = ''.force_encoding(Encoding::UTF_8_MAC) + out = ''.force_encoding(Encoding::UTF_16LE) loop do reader.primitive_convert(source, out) _, _, _, error_bytes, _ = reader.primitive_errinfo break if error_bytes.nil? - out << error_bytes.encode(Encoding::UTF_8_MAC, Encoding::Windows_1252, invalid: :replace, undef: :replace) + out << error_bytes.encode(Encoding::UTF_16LE, Encoding::Windows_1252, invalid: :replace, undef: :replace) end reader.finish -- cgit v1.2.3 From 92f567ab30f240a1de152061a6eee76ca6c4da86 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Tue, 11 Feb 2014 09:06:28 +0100 Subject: docs, hide inflector comment targeting only contributors. [ci skip] This is a follow up to: https://github.com/rails/rails/commit/07c70245a128cfe42f134be8759963dc98f1a63e As suggested by @fxn this comment should not be visible in the API: https://github.com/rails/rails/commit/07c70245a128cfe42f134be8759963dc98f1a63e#commitcomment-5331658 --- activesupport/lib/active_support/inflections.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/inflections.rb b/activesupport/lib/active_support/inflections.rb index d844e70750..2ca1124e76 100644 --- a/activesupport/lib/active_support/inflections.rb +++ b/activesupport/lib/active_support/inflections.rb @@ -1,9 +1,11 @@ require 'active_support/inflector/inflections' -# Define the standard inflection rules. These define a starting point for +#-- +# Defines the standard inflection rules. These are the starting point for # new projects and are not considered complete. The current set of inflection # rules is frozen. This means, we do not change them to become more complete. # This is a safety measure to keep existing applications from breaking. +#++ module ActiveSupport Inflector.inflections(:en) do |inflect| inflect.plural(/$/, 's') -- cgit v1.2.3