aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext
Commit message (Collapse)AuthorAgeFilesLines
* Move implementation of `before?` and `after?` to `DateAndTime::Calculations`bogdanvlviv2018-03-314-36/+12
| | | | | | | | This prevents duplication of code. Prevent duplication of tests by moving them to `DateAndTimeBehavior`. Related to #32185.
* Merge pull request #32185 from nholden/human_readable_date_time_comparisonsRafael França2018-03-264-0/+50
|\ | | | | Add `before?` and `after?` methods to date and time classes
| * Add `before?` and `after?` methods to date and time classesNick Holden2018-03-064-0/+50
| | | | | | | | | | | | | | | | Equality comparisons between dates and times can take some extra time to comprehend. I tend to think of a date or time as "before" or "after" another date or time, but I naturally read `<` and `>` as "less than" and "greater than." This change seeks to make date/time comparisons more human readable.
* | Use try in tests that try to test try.Kasper Timm Hansen2018-03-211-7/+2
| |
* | URI.unescape handles mixed Unicode/escaped inputAshe Connor2018-03-071-1/+1
|/ | | | | | | | | | | | | | | | | | Previously, URI.enscape could handle Unicode input (without any actual escaped characters), or input with escaped characters (but no actual Unicode characters) - not both. URI.unescape("\xe3\x83\x90") # => "バ" URI.unescape("%E3%83%90") # => "バ" URI.unescape("\xe3\x83\x90%E3%83%90") # => # Encoding::CompatibilityError We need to let `gsub` handle this for us, and then force back to the original encoding of the input. The result String will be mangled if the percent-encoded characters don't conform to the encoding of the String itself, but that goes without saying. Signed-off-by: Ashe Connor <ashe@kivikakk.ee>
* Deprecate "active_support/core_ext/numeric/inquiry"bogdanvlviv2018-03-021-80/+3
| | | | | | Numeric#positive? and Numeric#negative? was added to Ruby since 2.3, see https://github.com/ruby/ruby/blob/ruby_2_3/NEWS Rails 6 requires Ruby 2.4.1+ since https://github.com/rails/rails/pull/32034
* Deprecate `active_support/core_ext/hash/compact`yuuji.yaginuma2018-03-021-34/+4
| | | | | Ruby 2.4+ provides `Hash#compact` and `Hash#compact!` natively, so `active_support/core_ext/hash/compact` is no longer necessary.
* Add separate test to ensure that `delegate` with `:private` option returns ↵bogdanvlviv2018-02-281-6/+16
| | | | | | | | correct value Remove extra comments `# Asking for private method` in activesupport/test/core_ext/module_test.rb Improve docs of using `delegate` with `:private` Update changelog of #31944
* add private: true option for ActiveSupport delegateTomas Valent2018-02-261-0/+57
|
* String#truncate_bytes: limit to N bytes without breaking multibyte charsJeremy Daer2018-02-181-0/+62
| | | | | This faithfully preserves grapheme clusters (characters composed of other characters and combining marks) and other multibyte characters.
* `String#strip_heredoc` preserves frozennessJeremy Daer2018-02-171-0/+4
| | | | | | | | | | | | | | | | | | ```ruby "foo".freeze.strip_heredoc.frozen? # => true ``` Fixes the case where frozen string literals would inadvertently become unfrozen: ```ruby foo = <<-MSG.strip_heredoc la la la MSG foo.frozen? # => false !?? ```
* Rails 6 requires Ruby 2.4.1+Jeremy Daer2018-02-174-79/+9
| | | | | | Skipping over 2.4.0 to sidestep the `"symbol_from_string".to_sym.dup` bug. References #32028
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-162-6/+5
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Add missing requireyuuji.yaginuma2018-02-081-0/+1
| | | | | Without this require, an error occurs when executing only `duration_test.rb`. Ref: https://travis-ci.org/rails/rails/jobs/338817558#L2205-L2210
* Merge pull request #31923 from jdelStrother/duration-deserializationRafael França2018-02-071-0/+6
|\ | | | | Fix yaml deserialization of ActiveSupport::Duration
| * Fix yaml deserialization of ActiveSupport::DurationJonathan del Strother2018-02-071-0/+6
| | | | | | | | | | | | This ensures the duration's @parts hash has a default value, to avoid this regression introduced in 5.1: YAML.load(YAML.dump(10.minutes)) + 1 # => NoMethodError: undefined method `+' for nil:NilClass
* | Remove extra whitespaceDaniel Colson2018-01-253-39/+39
| |
* | Use assert_predicate and assert_not_predicateDaniel Colson2018-01-2511-80/+80
| |
* | Change refute to assert_notDaniel Colson2018-01-251-2/+2
| |
* | Use respond_to test helpersDaniel Colson2018-01-257-33/+33
| |
* | Merge pull request #31648 from dixitp012/rubocop_active_support_testRyuta Kamizono2018-01-081-2/+2
|\ \ | | | | | | | | | Fix rubocop space before comma
| * | Fix rubocop space before commaDixit Patel2018-01-081-1/+1
|/ /
* | Merge pull request #31049 from gwincr11/cg-blankRyuta Kamizono2018-01-041-2/+2
|\ \ | | | | | | Add support for multiple encodings in String.blank?
| * | Add support for multiple encodings in String.blank?Cory Gwin @gwincr112017-11-171-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Motivation: - When strings are encoded with `.encode("UTF-16LE")` `.blank?` throws an `Encoding::CompatibilityError` exception. - We tested multiple implementation to see what the fastest implementation was, rescueing the execption seems to be the fastest option we could find. Related Issues: - #28953 Changes: - Add a rescue to catch the exception. - Added a `Concurrent::Map` to store a cache of encoded regex objects for requested encoding types. - Use the new `Concurrent::Map` cache to return the correct regex for the string being checked.
* | | Merge pull request #31310 from kinnrot/duration-moduloRyuta Kamizono2018-01-011-0/+2
|\ \ \ | | | | | | | | Duration created with no parts will have a default seconds part eqaul to 0
| * | | Empty duration inspect fixChen Kinnrot2017-12-131-0/+2
| | | |
* | | | Handle `FrozenError` if it is availableYasuo Honda2017-12-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This pull request handles `FrozenError` introduced by Ruby 2.5. Refer https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/61131 Since `FrozenError` is a subclass of `RuntimeError` minitest used by master branch can handle it, though it would be better to handle `FrozenError` explicitly if possible. `FrozenError` does not exist in Ruby 2.4 or lower, `frozen_error_class` handles which exception is expected to be raised. This pull request is intended to be merged to master, then backported to `5-1-stable` to address #31508
* | | | Suppress `warning: BigDecimal.new is deprecated`Yasuo Honda2017-12-153-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `BigDecimal.new` has been deprecated in BigDecimal 1.3.3 which will be a default for Ruby 2.5. Refer https://github.com/ruby/bigdecimal/commit/533737338db915b00dc7168c3602e4b462b23503 * This commit has been made as follows: ``` cd rails git grep -l BigDecimal.new | grep -v guides/source/5_0_release_notes.md | grep -v activesupport/test/xml_mini_test.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g" ``` - `activesupport/test/xml_mini_test.rb` Editmanually to remove `.new` and `::` - guides/source/5_0_release_notes.md This is a Rails 5.0 release notes.
* | | | Enable `Layout/LeadingCommentSpace` to not allow cosmetic changes in the futureRyuta Kamizono2017-12-146-29/+29
| | | | | | | | | | | | | | | | Follow up of #31432.
* | | | Enable `Layout/SpaceBeforeComma` rubocop rule, and fixed moreRyuta Kamizono2017-12-124-13/+13
| | | | | | | | | | | | | | | | Follow up of #31390.
* | | | Refactor Date/Time next_occurring and prev_occurringT.J. Schuck2017-11-282-22/+20
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These methods were originally added in https://github.com/rails/rails/pull/26600 This includes a couple of refactors to make these methods behave more similarly to other Date/Time extensions added by Active Support: 1. Use `advance` instead of `since` and `ago` to time-travel — this is particularly important to keep the returned instance’s class matching `self`. Before this change: today = Date.today # => Tue, 28 Nov 2017 today.class # => Date today.next_occurring(:wednesday) # => Wed, 29 Nov 2017 00:00:00 UTC +00:00 today.next_occurring(:wednesday).class # => ActiveSupport::TimeWithZone After this change, a Date (or Time, or DateTime) instance is properly returned (just like is shown in the new docs). This is generally how everything else in DateAndTime::Calculations works. 2. Move the tests from the DateTime tests to the DateAndTimeBehavior tests. The latter location is mixed in to the core_ext tests for _all_ of Date, Time, and DateTime to test the behavior across all of the classes. The previous location is for testing core_ext functionality added specifically just to DateTime. 3. Better docs!
* | | Handle `TZInfo::AmbiguousTime` errorsAndrew White2017-11-151-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make `ActiveSupport::TimeWithZone` match Ruby's handling of ambiguous times by choosing the later period, e.g. Ruby: ``` ENV["TZ"] = "Europe/Moscow" Time.local(2014, 10, 26, 1, 0, 0) # => 2014-10-26 01:00:00 +0300 ``` Before: ``` >> "2014-10-26 01:00:00".in_time_zone("Moscow") TZInfo::AmbiguousTime: 26/10/2014 01:00 is an ambiguous local time. ``` After: ``` >> "2014-10-26 01:00:00".in_time_zone("Moscow") => Sun, 26 Oct 2014 01:00:00 MSK +03:00 ``` Fixes #17395.
* | | These strings should already be frozen where ruby accepts the magic-commentAkira Matsuda2017-11-151-2/+2
| | |
* | | Bump RuboCop to 0.51.0Koichi ITO2017-11-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ## Summary RuboCop 0.51.0 was released. https://github.com/bbatsov/rubocop/releases/tag/v0.51.0 And rubocop-0-51 channel is available in Code Climate. https://github.com/codeclimate/codeclimate-rubocop/issues/109 This PR will bump RuboCop to 0.51.0 and fixes the following new offenses. ```console % bundle exec rubocop Inspecting 2358 files (snip) Offenses: actionpack/lib/action_controller/metal/http_authentication.rb:251:59: C: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. [key.strip, value.to_s.gsub(/^"|"$/, "").delete('\'')] ^^^^ activesupport/test/core_ext/load_error_test.rb:8:39: C: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. assert_raise(LoadError) { require 'no_this_file_don\'t_exist' } ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 2358 files inspected, 2 offenses detected ```
* | | Merge pull request #31027 from PHedkvist/inflector_test_typeRafael França2017-11-091-1/+1
|\ \ \ | | | | | | | | Fixed typo in test for activesupport parameterize
| * | | Fixed typo in test for activesupport parameterizePierre Hedkvist2017-11-011-1/+1
| |/ /
* | | Allow `Range#include?` on TWZ rangesAndrew White2017-11-081-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In #11474 we prevented TWZ ranges being iterated over which matched Ruby's handling of Time ranges and as a consequence `include?` stopped working with both Time ranges and TWZ ranges. However in ruby/ruby@b061634 support was added for `include?` to use `cover?` for 'linear' objects. Since we have no way of making Ruby consider TWZ instances as 'linear' we have to override `Range#include?`. Fixes #30799.
* | | Merge pull request #30620 from ↵Andrew White2017-11-064-24/+50
|\ \ \ | |/ / |/| | | | | | | | bogdanvlviv/method_signature_prev-next-day-month-year_for_time Mirror the API of Ruby stdlib for #prev_day, #next_day, #prev_month, #next_month, #prev_year, #next_year
| * | Allows pass argument for `Time#prev_year` and `Time#next_year`.bogdanvlviv2017-10-244-12/+16
| | |
| * | Allows pass argument for `Time#prev_month` and `Time#next_month`bogdanvlviv2017-10-244-12/+24
| | |
| * | Allows pass argument for `Time#prev_day` and `Time#next_day`bogdanvlviv2017-10-241-0/+10
| | |
* | | removed unnecessary returnsShuhei Kitagawa2017-10-281-4/+4
|/ /
* | Fix `to_s(:db)` for range comprising of alphabets.Aditya Kapoor2017-10-161-0/+5
| |
* | Deprecate `Module#reachable?` methodbogdanvlviv2017-09-171-10/+18
| |
* | Test for the new exception of delegate_missing_to (#30191)Anton Khamets2017-08-121-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add test for the new exception of delegate_missing_to * Add a changelog entry * Only check for nil if NoMethodError was raised * Make method private * Have to pass both target name and value * Inline the re-raise [Rafael Mendonça França + Anton Khamets]
* | Update String#camelize to provide feedback when wrong option is passedRicardo Díaz2017-08-021-0/+7
| | | | | | | | | | | | | | | | | | String#camelize was returning nil without any feedback when an invalid option was passed as parameter. This update makes the method to raises an ArgumentError when the option passed is invalid, similar to what Ruby does for String#downcase (and others) in 2.4.1. https://ruby-doc.org/core-2.4.1/String.html#method-i-downcase
* | Add missing support for modulo operations on durationsSayan Chakraborty2017-07-281-13/+62
| | | | | | | | | | | | | | | | | | | | | | Rails 5.1 introduce an `ActiveSupport::Duration::Scalar` class as a wrapper around a numeric value as a way of ensuring a duration was the outcome of an expression. However the implementation was missing support for modulo operations. This commit adds support for those operations and should result in a duration being returned from expressions involving them. Fixes #29603 and #29743.
* | Fix division where a duration is the denominatorAndrew White2017-07-271-10/+14
| | | | | | | | | | | | | | | | | | PR #29163 introduced a change in behavior when a duration was the denominator in a calculation - this was incorrect as dividing by a duration should always return a `Numeric`. The behavior of previous versions of Rails has been restored. Fixes #29592.
* | Merge branch 'master' into make-reverse-merge-bang-order-consistentSean Griffin2017-07-1755-763/+643
|\ \
| * | [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-1155-0/+55
| | |