aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Add `rfc3339` aliases to `xmlschema`Andrew White2017-03-032-0/+15
| | | | | For naming consistency when using the RFC 3339 profile of ISO 8601 in applications.
* Add `Time.rfc3339` parsing methodAndrew White2017-03-031-0/+31
| | | | | | | The `Time.xmlschema` and consequently its alias `iso8601` accepts timestamps without a offset in contravention of the RFC 3339 standard. This method enforces that constraint and raises an `ArgumentError` if it doesn't.
* Deprecate implicit coercion of `ActiveSupport::Duration`Andrew White2017-03-021-3/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `ActiveSupport::Duration` implicitly converts to a seconds value when used in a calculation except for the explicit examples of addition and subtraction where the duration is the receiver, e.g: >> 2 * 1.day => 172800 This results in lots of confusion especially when using durations with dates because adding/subtracting a value from a date treats integers as a day and not a second, e.g: >> Date.today => Wed, 01 Mar 2017 >> Date.today + 2 * 1.day => Mon, 10 Apr 2490 To fix this we're implementing `coerce` so that we can provide a deprecation warning with the intent of removing the implicit coercion in Rails 5.2, e.g: >> 2 * 1.day DEPRECATION WARNING: Implicit coercion of ActiveSupport::Duration to a Numeric is deprecated and will raise a TypeError in Rails 5.2. => 172800 In Rails 5.2 it will raise `TypeError`, e.g: >> 2 * 1.day TypeError: ActiveSupport::Duration can't be coerced into Integer This is the same behavior as with other types in Ruby, e.g: >> 2 * "foo" TypeError: String can't be coerced into Integer >> "foo" * 2 => "foofoo" As part of this deprecation add `*` and `/` methods to `AS::Duration` so that calculations that keep the duration as the receiver work correctly whether the final receiver is a `Date` or `Time`, e.g: >> Date.today => Wed, 01 Mar 2017 >> Date.today + 1.day * 2 => Fri, 03 Mar 2017 Fixes #27457.
* Update `DateTime#change` to support usec and nsecAndrew White2017-03-021-11/+18
| | | | | | | | | | | Adding support for these options now allows us to update the `DateTime#end_of` methods to match the equivalent `Time#end_of` methods, e.g: datetime = DateTime.now.end_of_day datetime.nsec == 999999999 # => true Fixes #21424.
* Add Duration#before and #after as aliases for #ago and #sinceNick Johnstone2017-02-261-0/+13
| | | | | | | | | | | | | | It's common in test cases at my job to have code like this: let(:today) { customer_start_date + 2.weeks } let(:earlier_date) { today - 5.days } With this change, we can instead write let(:today) { 2.weeks.after(customer_start_date) } let(:earlier_date) { 5.days.before(today) } Closes #27721
* Merge pull request #28157 from robin850/hwia-soft-deprecationMatthew Draper2017-02-251-0/+28
|\ | | | | | | Soft-deprecate the `HashWithIndifferentAccess` constant
| * Add few tests for the top level `HashWithIndifferentAccess`Robin Dupret2017-02-251-0/+24
| | | | | | | | | | This ensures that if we try to hard-deprecate it again in the future, we won't break these behaviors.
| * Soft-deprecate the top-level HashWithIndifferentAccess classRobin Dupret2017-02-251-0/+4
| | | | | | | | | | | | | | Since using a `ActiveSupport::Deprecation::DeprecatedConstantProxy` would prevent people from inheriting this class and extending it from the `ActiveSupport::HashWithIndifferentAccess` one would break the ancestors chain, that's the best option we have here.
* | add optional second argument to ActiveSupport core extension for ↵Jeff Latz2017-02-241-0/+13
|/ | | | Marshal#load so it can take a proc
* Make HWIA#compact not return nil when no nilsPavel Pravosud2017-02-231-0/+10
|
* Add more missing requiresAndrew White2017-02-221-0/+1
| | | | Further missing requires for Timeout exposed due to Bundler 1.14.5
* Preload to_datetime before freezing a TimeWithZone instanceAdam Rice2017-02-221-0/+1
|
* Revert "Merge pull request #27925 from robin850/hwia-removal"Kasper Timm Hansen2017-02-201-23/+0
| | | | | | | | | Pointed out by @matthewd that the HWIA subclass changes the AS scoped class and top-level HWIA hierarchies out from under existing classes. This reverts commit 71da39097b67114329be6d8db7fe6911124531af, reversing changes made to 41c33bd4b2ec3f4a482e6030b6fda15091d81e4a.
* Deprecate the top-level `HashWithIndifferentAccess` contantRobin Dupret2017-02-191-0/+23
| | | | | | | | | This constant was kept for the sake of backward compatibility; it is still available under `ActiveSupport::HashWithIndifferentAccess`. Furthermore, since Ruby 2.5 (https://bugs.ruby-lang.org/issues/11547) won't support top level constant lookup, people would have to update their code anyway.
* Add Time#blank? to blank_testkenta-s2017-02-121-1/+1
|
* Merge pull request #27919 from bf4/correct_spellingArthur Nogueira Neves2017-02-061-2/+2
|\ | | | | Correct spelling
| * Correct spellingBenjamin Fleischer2017-02-051-2/+2
| | | | | | | | | | | | | | ``` go get -u github.com/client9/misspell/cmd/misspell misspell -w -error -source=text . ```
* | Add tests for `blank?`kenta-s2017-02-063-0/+12
|/
* Uninterned Symbol can be duped since ruby 2.4.1Akira Matsuda2017-01-261-1/+4
| | | | | | https://github.com/ruby/ruby/commit/11e6bd5ac2a2eebfa589bd6db8c9c4daa337733e Leaving the 2.4.0 conditional for now, in order never to forget backporting r57407 to 2.4.1
* Give a message to `#test_duplicable` assertionyui-knk2017-01-251-1/+1
| | | | | Giving a message helps us to know what happened when we look at Travis CI.
* Allocation free Integer#to_sJean Boussier2017-01-191-0/+4
|
* Unused class for testing since 93559da4826546d07014f8cfa399b64b4a143127Akira Matsuda2017-01-181-16/+0
|
* Adjust `Module.parent_name` to work when frozen; fixes #27637Corey Ward2017-01-172-30/+37
|
* Constant look-up would no longer fall back to top-level constant since ruby 2.5Akira Matsuda2017-01-131-2/+2
| | | | | See: https://github.com/ruby/ruby/commit/44a2576f798b07139adde2d279e48fdbe71a0148 https://github.com/ruby/ruby/commit/9df88e9cae57aa421230f14500e88f33f127414f
* class Foo < Struct.new(:x) creates an extra unneeded anonymous classAkira Matsuda2017-01-131-1/+1
| | | | because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
* Add additional tests for #27610Andrew White2017-01-121-1/+38
| | | | | | | Since 1.month no longer equals 30.days add some tests to ensure that addition maintains the same day in the month or is the last day in the month if the month has less days than the current day. Also add a test for the behaviour of 12.months == 1.year.
* Reduce string objects by using \ instead of + or << for concatenating stringsAkira Matsuda2017-01-121-1/+1
| | | | (I personally prefer writing one string in one line no matter how long it is, though)
* Fix inconsistent results when parsing large durations and constructing ↵Andrey Novikov2017-01-092-5/+6
| | | | | | | | | | | | | | | | | | | | | | | | | durations from code ActiveSupport::Duration.parse('P3Y') == 3.years # It should be true Duration parsing made independent from any moment of time: Fixed length in seconds is assigned to each duration part during parsing. Changed duration of months and years in seconds to more accurate and logical: 1. The value of 365.2425 days in Gregorian year is more accurate as it accounts for every 400th non-leap year. 2. Month's length is bound to year's duration, which makes sensible comparisons like `12.months == 1.year` to be `true` and nonsensical ones like `30.days == 1.month` to be `false`. Calculations on times and dates with durations shouldn't be affected as duration's numeric value isn't used in calculations, only parts are used. Methods on `Numeric` like `2.days` now use these predefined durations to avoid duplicating of duration constants through the codebase and eliminate creation of intermediate durations.
* Merge pull request #27392 from y-yagi/use_same_class_on_compactSean Griffin2017-01-061-0/+10
|\ | | | | ensure `#compact` of HWIDA to return HWIDA
| * ensure `#compact` of HWIDA to return HWIDAyuuji.yaginuma2017-01-061-0/+10
| | | | | | | | | | | | | | | | `Hash#compact` of Ruby native returns new hash. Therefore, in order to return HWIDA as in the past version, need to define own `#compact` to HWIDA. Related: #26868
* | Fix style guide violationsRafael Mendonça França2017-01-051-1/+1
|/
* Fix Symbol#duplicable? for Ruby 2.4.0.Kasper Timm Hansen2017-01-011-2/+2
| | | | | | | | | | | | | Ruby 2.4.0 has trouble duplicating certain symbols created from strings via `to_sym`. It didn't happen with `'symbol'.to_sym.dup` for some reason, but works fine with the longer string sample. Once a newer Ruby version with a fix is released we'll get have a failing test case we can fix. Ref: #27532
* Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-1/+1
| | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* assert_equal takes expectation firstAkira Matsuda2016-12-265-44/+44
|
* "Use assert_nil if expecting nil from ...:in `...'. This will fail in ↵Akira Matsuda2016-12-251-2/+2
| | | | minitest 6."
* Expectation firstAkira Matsuda2016-12-251-4/+4
|
* "Use assert_nil if expecting nil from ...:in `...'. This will fail in MT6."Akira Matsuda2016-12-251-1/+1
|
* "Use assert_nil if expecting nil. This will fail in minitest 6."Akira Matsuda2016-12-258-16/+16
|
* Fix Complex and Rational are duplicable?utilum2016-12-211-2/+2
| | | | See [this test](https://gist.github.com/utilum/78918f1b64f8b61ee732cb266db7c43a).
* Fix Fixnum deprecated warning in Ruby 2.4+utilum2016-12-161-1/+1
|
* change return value of `duplicable?` with Ruby 2.4+yuuji.yaginuma2016-12-131-2/+7
| | | | | | | `NilClass`, `FalseClass`, `TrueClass`, `Symbol` and `Numeric` can dup with Ruby 2.4+. Ref: https://bugs.ruby-lang.org/issues/12979
* :nail_care:Akira Matsuda2016-12-131-2/+1
|
* nil, true, 1, etc. don't raise on #dup since Ruby 2.4Akira Matsuda2016-12-131-1/+1
| | | | https://bugs.ruby-lang.org/issues/12979
* Exclude singleton classes from `subclasses` and `descendants`Sean Griffin2016-12-011-0/+10
| | | | | | | | This behavior changed in Ruby starting with 2.3.0, as a result of https://bugs.ruby-lang.org/issues/11360. This results in a change in behavior of these methods which is likely undesirable. Fixes #27238
* Treat combined durations as a single unitSean Griffin2016-11-291-0/+11
| | | | | | | | | | | | Prior to this commit, `3.months - 3.months` would result in a duration that has the "parts" of `[[:months, 3], [:months, -3]]`. This would mean that it was subtly different than `2.months - 2.months`. When applied to a time, the date might actually change if the resulting day doesn't exist however many months in the future, even though in both cases we just wanted to add `0`, which should always be an identity operation. With this change, we now store the parts as a hash, so `3.months - 3.months` is simply stored as `{ months: 0 }`.
* Merge pull request #27035 from rails/remove-active-support-deprecationsAndrew White2016-11-146-395/+0
|\ | | | | Remove Active Support deprecations
| * Remove deprecated separator argument from parameterizeAndrew White2016-11-141-16/+0
| |
| * Remove deprecated method Numeric#to_formatted_sAndrew White2016-11-141-6/+0
| |
| * Remove deprecated method alias_method_chainAndrew White2016-11-141-215/+0
| |
| * Remove deprecated constant MissingSourceFIleAndrew White2016-11-141-8/+0
| |