aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
Commit message (Collapse)AuthorAgeFilesLines
* Cache: test coverage for cleanup behavior with local cache strategyEugene Kenny2017-06-101-0/+15
| | | | | | No need to pass `#cleanup` options through to `LocalCache#clear`. Fixes #29081. References #25628.
* Split up the cache test suite so it's easier to understand and extend (#29404)Jeremy Daer2017-06-1020-1359/+1383
| | | | | | | | | Split up the caching tests as prep for adding a new cache store. Slices the mega test/caching_test.rb into behavior modules, concrete store tests, and cross-cutting store tests. Considering moving cache store behavior modules into lib/ so they may be used for acceptance testing by third parties.
* Cache: write_multi (#29366)Jeremy Daer2017-06-061-0/+58
| | | | | | | | | | | Rails.cache.write_multi foo: 'bar', baz: 'qux' Plus faster `fetch_multi` with stores that implement `write_multi_entries`. Keys that aren't found may be written to the cache store in one shot instead of separate writes. The default implementation simply calls `write_entry` for each entry. Stores may override if they're capable of one-shot bulk writes, like Redis `MSET`.
* Implement mattr_acessor :default optionGenadi Samokovarov2017-06-031-1/+37
|
* Add next occur and previous occurred day of week API (#26600)Shota Iguchi2017-05-301-0/+22
|
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-1/+9
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Merge pull request #26628 from mjhoy/fix-number-to-human-25742Eileen M. Uchitelle2017-05-291-0/+6
|\ | | | | round before calculating exponent in number_to_human_converter
| * number_to_human_converter: round before calculating exponentMichael Hoy2017-03-161-0/+6
| | | | | | | | fixes #25664
* | Merge pull request #29097 from ↵Matthew Draper2017-05-281-0/+7
|\ \ | | | | | | | | | | | | | | | EilisHamilton/fix_uncountable_pluralization_locale Fix pluralization of uncountables when given a locale
| * | Fix pluralization of uncountables when given a localeEilis Hamilton2017-05-191-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | Previously apply_inflections would only use the :en uncountables rather then the ones for the locale that was passed to pluralize or singularize. This changes apply_inflections to take a locale which it will use to find the uncountables.
* | | ActiveSupport::CurrentAttributes provides a thread-isolated attributes ↵David Heinemeier Hansson2017-05-261-0/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | singleton (#29180) * Add ActiveSupport::CurrentAttributes to provide a thread-isolated attributes singleton * Need to require first * Move stubs into test namespace. Thus they won't conflict with other Current and Person stubs. * End of the line for you, whitespace! * Support super in attribute methods. Define instance level accessors in an included module such that `super` in an overriden accessor works, akin to Active Model. * Spare users the manual require. Follow the example of concerns, autoload in the top level Active Support file. * Add bidelegation support * Rename #expose to #set. Simpler, clearer * Automatically reset every instance. Skips the need for users to actively embed something that resets their CurrentAttributes instances. * Fix test name; add tangible name value when blank. * Try to ensure we run after a request as well. * Delegate all missing methods to the instance This allows regular `delegate` to serve, so we don't need bidelegate. * Properly test resetting after execution cycle. Also remove the stale puts debugging. * Update documentation to match new autoreset
* | | Merge pull request #29234 from y-yagi/remove_unused_test_classGuillermo Iguaran2017-05-261-3/+0
|\ \ \ | | | | | | | | Remove unused test class
| * | | Remove unused test classyuuji.yaginuma2017-05-261-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `AlsoDoingNothingTest` was added in cf9be89. It seems that it added to confirm that the test works in the child class of `ActiveSupport::TestCase`. But now basically use `ActiveSupport::TestCase` in test, so I think it is unnecessary.
* | | | Define path with __dir__bogdanvlviv2017-05-234-14/+14
|/ / / | | | | | | | | | | | | | | | ".. with __dir__ we can restore order in the Universe." - by @fxn Related to 5b8738c2df003a96f0e490c43559747618d10f5f
* / / Fix implicit calculations with scalars and durationsAndrew White2017-05-201-0/+34
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously calculations where the scalar is first would be converted to a duration of seconds but this causes issues with dates being converted to times, e.g: Time.zone = "Beijing" # => Asia/Shanghai date = Date.civil(2017, 5, 20) # => Mon, 20 May 2017 2 * 1.day # => 172800 seconds date + 2 * 1.day # => Mon, 22 May 2017 00:00:00 CST +08:00 Now the `ActiveSupport::Duration::Scalar` calculation methods will try to maintain the part structure of the duration where possible, e.g: Time.zone = "Beijing" # => Asia/Shanghai date = Date.civil(2017, 5, 20) # => Mon, 20 May 2017 2 * 1.day # => 2 days date + 2 * 1.day # => Mon, 22 May 2017 Fixes #29160, #28970.
* | Use recyclable cache keys (#29092)David Heinemeier Hansson2017-05-181-0/+90
| |
* | Merge pull request #29086 from mikeycgto/message-encryptor-auth-tag-checkKasper Timm Hansen2017-05-151-7/+19
|\ \ | | | | | | | | | | | | Message encryptor auth tag check Fixes MessageEncryptor when used in AEAD mode. Specifically, we need to check if the `auth_tag` is nil. This may arise when an AEAD encryptor is used to decrypt a ciphertext generated from a different mode, such as CBC-HMAC. Basically, the number of double dashes will differ and `auth_tag` may be nil in this case.
| * | Updates to MessageEncryptor AEAD testsMichael Coyne2017-05-151-10/+14
| | |
| * | Fix for AEAD auth_tag check in MessageEncryptorMichael Coyne2017-05-151-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | When MessageEncryptor tries to +decrypt_and_verify+ ciphertexts generated in a different mode (such CBC-HMAC), the +auth_tag+ may be +nil+ and must explicitly check for it. See the discussion here: https://github.com/rails/rails/pull/28132#discussion_r116388462
* | | Don't cache locally if unless_exist was passedEugene Kenny2017-05-141-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some cache backends support the `unless_exist` option, which tells them not to overwrite an existing entry. The local cache currently always stores the new value, even though the backend may have rejected it. Since we can't tell which value will end up in the backend cache, we should delete the key from the local cache, so that the next read for that key will go to the backend and pick up the correct value.
* | | Merge pull request #29034 from peterjm/handle_loops_in_exception_handlingRafael França2017-05-111-1/+33
|\ \ \ | | | | | | | | Handle loops in the cause chain in Rescuable#rescue_with_handler
| * | | handle loops in the cause chain in Rescuable#rescue_with_handlerPeter McCracken2017-05-101-1/+33
| | | |
* | | | Should escape meta characters in regexpRyuta Kamizono2017-05-072-3/+3
|/ / /
* | | Update test names to match method nameT.J. Schuck2017-05-041-6/+6
| | | | | | | | | The method is named `delegate_missing_to`, not `delegate_to_missing`
* | | Remove checks for Enumerator#size methodEugene Kenny2017-04-251-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | The Enumerator#size method was introduced in Ruby 2.0. These tests were added when Rails 4.1 was current, and Ruby 1.9.3 was still supported. Since Rails 5 only Ruby >= 2.2.2 is supported, so the checks are no longer necessary.
* | | Fixes Hash.from_xml with frozen strings for all backendsJosh Nussbaum2017-04-201-0/+5
| | |
* | | Send deprecation horizon and gem name as arguments to deprecation heavier ↵Willem van Bergen2017-04-191-6/+29
| | | | | | | | | | | | handler, and make sure they are used for the ActiveSupport::Notifications message.
* | | Add additional options to time `change` methodsAndrew White2017-04-143-0/+16
| | | | | | | | | | | | | | | | | | | | | Support `:offset` in `Time#change` and `:zone` or `:offset` in `ActiveSupport::TimeWithZone#change`. Fixes #28723.
* | | Implement `fetch_values` for HashWithIndifferentAccess (#28316)Josh Pencheon2017-04-101-0/+12
| | | | | | | | | | | | | | | | | | | | | `fetch_values` was added to Hash in Ruby 2.3.0: https://bugs.ruby-lang.org/issues/10017 This patch adds an implemention for instances of HWAI, in line with the existing definitions of `fetch` and `values_at`.
* | | delegate_missing_to should fall back to superMatthew Draper2017-04-091-0/+22
| | |
* | | delegate_to_missing doesn't delegate private methodsMatthew Draper2017-04-091-0/+10
| | | | | | | | | | | | So we shouldn't claim they're there, even when asked explicitly.
* | | Fix `warning: already initialized constant ↵Ryuta Kamizono2017-04-071-1/+0
| | | | | | | | | | | | | | | | | | HashWithIndifferentAccessTest::HashWithIndifferentAccess` Caused since #28607.
* | | Move HashWithIndifferentAccess tests to separate fileMichael Stock2017-03-302-712/+734
| | |
* | | Add aliases for reverse_merge to with_defaultsMatt Casper2017-03-291-0/+25
| | | | | | | | | | | | | | | | | | In the context of controller parameters, reverse_merge is commonly used to provide defaults for user input. Having an alias to reverse_merge called with_defaults feels more idiomatic for Rails.
* | | Merge pull request #28480 from ↵Rafael Mendonça França2017-03-283-0/+40
|\ \ \ | | | | | | | | | | | | | | | | | | | | mubashirhanif/add_keep_id_suffix_option_to_humanize_new Add keep id suffix option to humanize new
| * | | Added options hash to titleize method and keep_id_suffix option to humanizeMubashir Hanif2017-03-213-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | some documentation remove extra whitespace. Added id in the middle test case and corrected some testcases. Some Coding standard guidelines corrections as suggested by codeclimate. Some more corrections suggested by codeclimate.
* | | | Return unmapped timezones from `country_zones`Andrew White2017-03-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | If a country doesn't exist in the MAPPINGS hash then create a new `ActiveSupport::Timezone` instance using the supplied timezone id. Fixes #28431.
* | | | Fix duplicable? for Ratiional and Complex on ruby master, since they are now ↵Vipul A M2017-03-231-1/+4
| | | | | | | | | | | | | | | | duplicable
* | | | Add AS::Deprecation::DeprecatedConstantAccessorDominic Cleal2017-03-221-0/+23
| |_|/ |/| | | | | | | | | | | | | | | | | An alternative to DeprecatedConstantProxy which works more transparently with exceptions because it returns the object that the new constant refers to rather than a proxy. This is then compatible with `rescue OldException`.
* | | Fix test warningsAndrew White2017-03-161-5/+5
| | |
* | | Merge pull request #28147 from kmcphillips/master-time-freezeAndrew White2017-03-162-15/+180
|\ \ \ | | | | | | | | Allow Time#to_time on frozen objects. Return frozen time rather than "RuntimeError: can't modify frozen Time"
| * | | Handle #to_time and memoization taking into account memoization, frozen ↵Kevin McPhillips2017-03-062-15/+180
| | | | | | | | | | | | | | | | state, and preserve_timezone flag.
* | | | Remove implicit coercion deprecation of durationsAndrew White2017-03-151-25/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In #28204 we deprecated implicit conversion of durations to a numeric which represented the number of seconds in the duration because of unwanted side effects with calculations on durations and dates. This unfortunately had the side effect of forcing a explicit cast when configuring third-party libraries like expiration in Redis, e.g: redis.expire("foo", 5.minutes) To work around this we've removed the deprecation and added a private class that wraps the numeric and can perform calculation involving durations and ensure that they remain a duration irrespective of the order of operations.
* | | | Make sure local cache cleared even it's throwing:Lin Jen-Shin2017-03-101-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We (GitLab) hit into an issue that somewhere in the middleware chain was throwing `:warden`, which was caught in the wrapping middleware, but `LocalCache::Middleware` was not aware of it. It should look like: ``` ruby result = catch(:warden) do @app.call(env) end ``` Source: https://github.com/hassox/warden/blob/090ed153dbd2f5bf4a1ca672b3018877e21223a4/lib/warden/manager.rb#L35-L37 Using `ensure` could make sure that we would always do the cleanup, and better yet, avoid `rescue Exception` which we all should know that could cause some issues which could be very hard to debug. Please check the discussion thread for more context: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/1402#note_25128108
* | | | Update `titlelize` regex to allow apostrophesAndrew White2017-03-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 4b685aa the regex in `titlelize` was updated to not match apostrophes to better reflect the nature of the transformation. Unfortunately this had the side effect of breaking capitalization on the first word of a sub-string, e.g: >> "This was 'fake news'".titleize => "This Was 'fake News'" This is fixed by extending the look-behind to also check for a word character on the other side of the apostrophe. Fixes #28312.
* | | | 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.
* | | | Add `ActiveSupport::TimeZone.rfc3339` parsing methodAndrew White2017-03-031-0/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously there was no way to get a RFC 3339 timestamp into a specific timezone without either using `parse` or chaining methods. The new method allows parsing directly into the timezone, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.rfc3339("1999-12-31T14:00:00Z") => Fri, 31 Dec 1999 14:00:00 HST -10:00 This new method has stricter semantics than the current `parse` method and will raise an `ArgumentError` instead of returning nil, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.rfc3339("foobar") ArgumentError: invalid date >> Time.zone.parse("foobar") => nil It will also raise an `ArgumentError` when either the time or offset components are missing, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.rfc3339("1999-12-31") ArgumentError: invalid date >> Time.zone.rfc3339("1999-12-31T14:00:00") ArgumentError: invalid date
* | | | Add `ActiveSupport::TimeZone.iso8601` parsing methodAndrew White2017-03-031-0/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously there was no way to get a ISO 8601 timestamp into a specific timezone without either using `parse` or chaining methods. The new method allows parsing directly into the timezone, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.iso8601("1999-12-31T14:00:00Z") => Fri, 31 Dec 1999 14:00:00 HST -10:00 If the timestamp is a ISO 8601 date (YYYY-MM-DD) then the time is set to midnight, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.iso8601("1999-12-31") => Fri, 31 Dec 1999 00:00:00 HST -10:00 This new method has stricter semantics than the current `parse` method and will raise an `ArgumentError` instead of returning nil, e.g: >> Time.zone = "Hawaii" => "Hawaii" >> Time.zone.iso8601("foobar") ArgumentError: invalid date >> Time.zone.parse("foobar") => nil
* | | | 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.