aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
Commit message (Collapse)AuthorAgeFilesLines
...
* [ci skip] "brethen" is misspelled and unclearMichael Gee2018-05-311-1/+1
|
* Merge pull request #33020 from joshpencheon/time_zone_frac_microsecondsRafael França2018-05-302-2/+17
|\ | | | | Align Time.zone.at method signature with that of Time::at
| * Allow Time.zone.at to receive a second argumentJosh Pencheon2018-05-302-2/+17
| | | | | | | | For parity with Ruby's Time::at
* | Remove unused `require "active_support/file_update_checker"`yuuji.yaginuma2018-05-301-1/+0
|/ | | | This is unnecessary since #22269.
* Improve grammar for DateAndTime before? and after? calculations [ci skip]Aaron Sumner2018-05-241-2/+2
|
* Merge pull request #32822 from lxxxvi/improved_error_message_in_assert_changesRafael França2018-05-222-2/+4
|\ | | | | Clearer error message in assert_changes
| * Clearer error message in assert_changeslxxxvi2018-05-052-2/+4
| | | | | | | | When `to:` is passed to `assert_changes`, it now prints the well-known `"Expected: x\n Actual: y"` message. Before, the message only contained the actual value.
* | Merge pull request #32851 from yskkin/doc_require_dependencyRafael França2018-05-221-0/+4
|\ \ | | | | | | Document require_dependency [ci skip]
| * | Document require_dependency [ci skip]Yoshiyuki Kinjo2018-05-091-0/+4
| | |
* | | add CHANGELOG/Docutilum2018-05-221-0/+11
| | |
* | | Allow Range#=== and Range#cover? on Rangeutilum2018-05-223-23/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ruby/ruby@989e07c features switching `Range#===` to use internal `r_cover_p` instead of rubyland `include?`. This breaks expected behavior of `ActiveSupport::CoreExt::Range` documented since at least 8b67a02. This patch adds overrides on `Range#cover?` and `Range#===` and places all three in a single module, `CompareWithRange`. *Requiring core_ext/range/include_range now causes a deprecation warnning*
* | | [ci skip] Add documentation/changelog entry.Kasper Timm Hansen2018-05-211-0/+15
| | |
* | | Add Enumerable#index_with.Kasper Timm Hansen2018-05-212-1/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the app I'm working on I've wished that index_by had a buddy that would assign the hash value instead of the key multiple times. Enter index_with. Useful when building a hash from a static list of symbols. Before you'd do: ```ruby POST_ATTRIBUTES.map { |attr_name| [ attr_name, public_send(attr_name) ] }.to_h ``` But now that's a little clearer and faster with: ````ruby POST_ATTRIBUTES.index_with { |attr_name| public_send(attr_name) } ``` It's also useful when you have an enumerable that should be converted to a hash, but you don't want to muddle the code up with the overhead that it takes to create that hash. So before, that's: ```ruby WEEKDAYS.each_with_object(Hash.new) do |day, intervals| intervals[day] = [ Interval.all_day ] end ``` And now it's just: ```ruby WEEKDAYS.index_with([ Interval.all_day ]) ``` It's also nice to quickly get a hash with either nil, [], or {} as the value.
* | | Raise a better exception when a invalid depreation behavior is setRafael Mendonça França2018-05-182-0/+12
| | | | | | | | | | | | Fixes #32928.
* | | Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-137-26/+26
|/ / | | | | | | Follow up of #32605.
* / Remove `test_match_p` since Rails 6 requires Ruby 2.4.1 or newerRyuta Kamizono2018-05-071-24/+0
|/ | | | Follow up of #32034.
* Fix #29632 - nil #path leads to NoMethodError in LoadError#is_missing?Neil Souza2018-05-042-1/+8
| | | | | | | | See #29632 for details. In short, it's possible to enter `LoadError#is_missing?` when `LoadError#path` returns `nil`, leading to `path.sub` throwing an none-to-helpful `NoMethodError`. This tiniest of patch inserts `#to_s` before the `sub` call to make sure it succeeds. Affected surface area should be just as tiny since something has already gone wrong to get us into `#is_missing?` and the current behavior when `#path` returns `nil` seems clearly not intended. [Gannon McGibbon + Neil Souza]
* Fix test: threads being nil in ensurePavel Valena2018-04-301-4/+4
| | | | when connection_pool is not installed.
* Improve the performance of `ActiveSupport::Inflector.ordinal`Ryuta Kamizono2018-04-291-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves the performance for the most ordinalized numbers (1st, 2nd, 3rd, etc). ``` require "benchmark/ips" def o1(number) abs_number = number.to_i.abs if (11..13).include?(abs_number % 100) "th" else case abs_number % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end def o3(number) case number when 1; "st" when 2; "nd" when 3; "rd" when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else num_modulo = number.to_i.abs % 100 if 11 <= num_modulo && num_modulo <= 13 "th" else case num_modulo % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end end def o4(number) case number when 1; "st" when 2; "nd" when 3; "rd" when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else num_modulo = number.to_i.abs % 100 num_modulo %= 10 if num_modulo > 13 case num_modulo when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end puts RUBY_DESCRIPTION Benchmark.ips do |x| x.report("orig") { o1(1); o1(2); o1(3); o1(4); o1(11); o1(111); o1(1523) } x.report("ord3") { o3(1); o3(2); o3(3); o3(4); o3(11); o3(111); o3(1523) } x.report("ord4") { o4(1); o4(2); o4(3); o4(4); o4(11); o4(111); o4(1523) } x.compare! end ``` ``` ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin15] Warming up -------------------------------------- orig 25.305k i/100ms ord3 121.146k i/100ms ord4 124.944k i/100ms Calculating ------------------------------------- orig 275.496k (± 2.4%) i/s - 1.392M in 5.054720s ord3 1.649M (± 5.0%) i/s - 8.238M in 5.009801s ord4 1.700M (± 7.0%) i/s - 8.496M in 5.031646s Comparison: ord4: 1700059.6 i/s ord3: 1649154.9 i/s - same-ish: difference falls within error orig: 275496.3 i/s - 6.17x slower ``` Closes #25020. [lvl0nax, Jeremy Daer, Ryuta Kamizono]
* Merge pull request #32733 from Edouard-chin/ec-setupand-teardownRafael França2018-04-273-13/+11
|\ | | | | `SetupAndTeardown` has few caveats that breaks libraries
| * `SetupAndTeardown` has few caveats that breaks libraries:Edouard CHIN2018-04-273-13/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - In #32472 I introduced a fix in order for all `after_teardown` method provided by libraries and Rails to run, even if the application's `teardown` method raised an error (That's the default minitest behavior). However this change wasn't enough and doesn't take in consideration the ancestors chain. If a library's module containing an `after_teardown` method get included after the `SetupAndTeardown` module (one example is the [ActiveRecord::TestFixtures module](https://github.com/rails/rails/blob/7d2400ab61c8e3ed95e14d03ba3844e8ba2e36e4/activerecord/lib/active_record/fixtures.rb#L855-L856), then the ancestors of the test class would look something like ```ruby class MyTest < ActiveSupport::TestCase end puts MyTest.ancestors # [MyTest, ActiveSupport::TestCase, ActiveRecord::TestFixtures, ActiveSupport::Testing::SetupAndTeardown] ``` Any class/module in the ancestors chain that are **before** the `ActiveSupport::Testing::SetupAndTeardown` will behave incorrectly: - Their `before_setup` method will get called **after** all regular setup method - Their `after_teardown` method won't even get called in case an exception is raised inside a regular's test `teardown` A simple reproduction script of the problem here https://gist.github.com/Edouard-chin/70705542a59a8593f619b02e1c0a188c - One solution to this problem is to have the `AS::SetupAndTeardown` module be the very first in the ancestors chain. By doing that we ensure that no `before_setup` / `after_teardown` get executed prior to running the teardown callbacks
* | Don't dup Strings when jsonifyingAkira Matsuda2018-04-271-2/+6
|/ | | | This method would be called so many times and would create so many temporary garbage Strings
* Reduce extra object creations in TaggedLoggingAkira Matsuda2018-04-271-1/+3
| | | | | | | | | | | | | | | | | | | | | | tags_text method creates 3 Ruby objects per each logger call when no custom tags are given (which is the default setting, and so presumably the majority use case). This patch reduces two temporary object creations in this case. require 'allocation_tracer' ObjectSpace::AllocationTracer.setup(%i{type}) tags = ['a'] pp before: ObjectSpace::AllocationTracer.trace { tags.collect { |tag| "[#{tag}] " }.join } pp after: ObjectSpace::AllocationTracer.trace { "[#{tags[0]}] " } {:before=>{[:T_ARRAY]=>[1, 0, 0, 0, 0, 0], [:T_STRING]=>[2, 0, 0, 0, 0, 0]}} {:after=>{[:T_STRING]=>[1, 0, 0, 0, 0, 0]}}
* Merge pull request #32681 from bdewater/rubocop-0-54Ryuta Kamizono2018-04-221-1/+1
|\ | | | | Rubocop 0.54
| * Fix Style/RedundantReturn offensesBart de Water2018-04-211-1/+1
| |
* | Fix typo in constant name [ci skip]yuuji.yaginuma2018-04-221-1/+1
|/
* Merge pull request #32642 from bogdanvlviv/fix-name-test-added-by-32613Andrew White2018-04-201-1/+1
|\ | | | | Fix name of the test added by #32613
| * Fix name of the test added by #32613bogdanvlviv2018-04-191-1/+1
| |
* | Return back "/" to the end of RAILS_GEM_ROOTbogdanvlviv2018-04-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | - The "/" was removed in 40bdbce191ad90dfea43dad51fac5c4726b89392 during refactoring. It may cause regression since looks like was added intentionaly because it is possible that a name of any another gem can start with /rails/, so slash was added to ensure that it is "rails" gem. I would like to backport this to `5-2-stable` too. - Use `__dir__` instead of `__FILE__`. Follow up #29176.
* | Merge pull request #32648 from ↵Rafael França2018-04-195-11/+11
|\ \ | | | | | | | | | | | | bogdanvlviv/improve-pattern-filenames-to-catch-more-style-offences Allow rubocop check more files
| * | Allow rubocop check more filesbogdanvlviv2018-04-195-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fix pattern of filenames for `CustomCops/AssertNot` and `CustomCops/RefuteNot`. rubocop should check every file under `test/`. Related to #32441, #32605
* | | Merge pull request #32168 from christianblais/activesupport-ordinalize-i18nRafael França2018-04-194-13/+59
|\ \ \ | |/ / |/| | `#ordinal` and `#ordinalize` now support I18n
| * | `ActiveSupport::Inflector#ordinal` and `ActiveSupport::Inflector#ordinalize`Christian Blais2018-03-054-13/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | now support translations through I18n. { fr: { number: { nth: { ordinals: lambda do |_key, number:, **_options| if number.to_i.abs == 1 'er' else 'e' end end, ordinalized: lambda do |_key, number:, **_options| "#{number}#{ActiveSupport::Inflector.ordinal(number)}" end } } } }
* | | Merge pull request #32605 from composerinteralia/assert-notRafael França2018-04-1926-88/+88
|\ \ \ | |_|/ |/| | Add RuboCop for `assert_not` over `assert !`
| * | Replace `assert !` with `assert_not`Daniel Colson2018-04-1926-88/+88
| | | | | | | | | | | | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* | | Merge branch 'master' into fix-as-timezone-allAndrew White2018-04-192-6/+18
|\| |
| * | Redis cache store: avoid blocking the server in `#delete_matched`Gleb Mazovetskiy2018-04-182-6/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #32610. Closes #32614. Lua scripts in redis are *blocking*, meaning that no other client can execute any commands while the script is running. See https://redis.io/commands/eval#atomicity-of-scripts. This results in the following exceptions once the number of keys is sufficiently large: BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. This commit replaces the lua-based implementation with one that uses `SCAN` and `DEL` in batches. This doesn't block the server. The primary limitation of `SCAN`, i.e. potential duplicate keys, is of no consequence here, because `DEL` ignores keys that do not exist.
* | | Fix exception in AS::Timezone.all when any tzinfo data is missingDominik Sander2018-04-184-1/+35
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change missing timezone data for any of the time zones defined in `ActiveSupport::Timezone::MAPPING` caused a `comparison of NilClass with ActiveSupport::TimeZone failed` exception. Attempting to get a timezone by passing a number/duration to `[]` or calling `all` directly will try to sort sort the values of `zones_map`. Those values are initialized by the return value of `create(zonename)` which returns `nil` if `TZInfo` is unable to find the timezone information. In our case the exception was triggered by an outdated tzdata package which did not include information for the "recently" added time zones. Before 078421bacba178eac6a8e607b16f3f4511c5d72f `zones_map` only returned the information that have been loaded into `@lazy_zone_map` which ignored time zones for which the data could not be loaded, this change restores the previous behaviour.
* | Merge pull request #32556 from utilum/splatRyuta Kamizono2018-04-171-2/+2
|\ \ | | | | | | 2.6 warning: passing splat keyword arguments as a single Hash
| * | 2.6 warning: passing splat keyword arguments as a single Hashutilum2018-04-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ruby 2.6.0 warns about this. ``` ruby -v ruby 2.6.0dev (2018-04-04 trunk 63085) [x86_64-linux] ``` Before, see: https://travis-ci.org/rails/rails/jobs/365740163#L1262-L1264 https://travis-ci.org/rails/rails/jobs/365944863#L2121-L2174
* | | Inclusive Language in Documentation Examples [ci skip]Cassidy Kobewka2018-04-151-2/+2
|/ /
* | Fix redis store clear keys outside the namespaceRei2018-04-152-1/+19
| | | | | | | | | | | | | | | | | | | | Namespace not working in RedisCacheStore#clear method. Bacause namespace = merged_options(options)[namespace] is always nil, Correct is namespace = merged_options(options)[:namespace]
* | Use `SecureRandom.random_bytes` instead of `SecureRandom.bytes`yuuji.yaginuma2018-04-131-1/+1
| | | | | | | | | | | | | | | | | | | | `SecureRandom.byes` was added in Ruby 2.4. So, 5-2-stable build is broken because using `SecureRandom.bytes`. https://travis-ci.org/rails/rails/jobs/365740667 Also, `SecureRandom.byes` seems to an undocumented method. If need random binary strings, should use `SecureRandom.random_bytes`. https://github.com/ruby/ruby/blob/trunk/lib/securerandom.rb
* | Merge pull request #32551 from chrisarcand/no-doc-original-sumRafael França2018-04-121-1/+1
|\ \ | | | | | | Don't doc _original_sum_with_required_identity
| * | Don't doc _original_sum_with_required_identityChris Arcand2018-04-121-1/+1
| | | | | | | | | | | | It's not public API so don't document it.
* | | Merge pull request #32539 from chancancode/anticompressRafael França2018-04-125-73/+181
|\ \ \ | |/ / |/| | Fix ActiveSupport::Cache compression
| * | Fix `ActiveSupport::Cache` compressionGodfrey Chan2018-04-113-37/+60
| | | | | | | | | | | | (See previous commit for a description of the issue)
| * | Add failing test for compression bugGodfrey Chan2018-04-113-38/+123
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Rails 5.2, when compression is enabled (which it is by default), the actual value being written to the underlying storage is actually _bigger_ than the uncompressed raw value. This is because the `@marshaled_value` instance variable (typically) gets serialized with the entry object, which is then written to the underlying storage, essentially double-storing every value (once uncompressed, once possibly compressed). This regression was introduced in #32254.
* | | Merge pull request #32542 from ↵George Claghorn2018-04-121-2/+3
|\ \ \ | | | | | | | | | | | | | | | | teddywing/active-support-cache-store--fix-end-tag-in-read-method-documentation Cache::Store#read: Fix fixed-width end tag in docs
| * | | Cache::Store#read: Fix fixed-width end tag in docsTeddy Wing2018-04-121-2/+3
| |/ / | | | | | | | | | | | | | | | | | | | | | * Fix the ending `</tt>` tag for `:expires_in`. Otherwise, the "or" is set in fixed-width also. * Re-wrap paragraph to 80 columns. [ci skip]