aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
Commit message (Collapse)AuthorAgeFilesLines
* Use Thread.pass instead of Kernel.sleep to trigger race conditionGuilherme Mansur2019-08-051-14/+7
|
* Able to initalize default value for thread_mattr_*Guilherme Mansur2019-08-051-11/+27
| | | | | | | | | | | | | | | | | Added the ability to initialize `thread_mattr_*` methods with default values like so: ``` ruby class MyClass thread_attr_reader :foo, default: :foo thread_attr_writer :bar, default: :bar thread_attr_accessor: baz do "baz" end end ``` This is consistent with the api exposed by `mattr_accessor`.
* Revert "MethodCallAssertions is a regular player of the team ↵Rafael Mendonça França2019-08-021-0/+3
| | | | | | ActiveSupport::TestCase now" This reverts commit 98d0f7ebd34b858f12a12dcf37ae54fdbb5cab64.
* Revert "You give jruby_skip & rubinius_skip a good name"Rafael Mendonça França2019-08-021-0/+13
| | | | This reverts commit 8d2866bb80fbe81acb04f5b0c44f152f571fb29f.
* Missing require AS/core_ext/date/conversionsAkira Matsuda2019-08-022-0/+2
|
* Lazily evaluate FileUpdateCheckerSharedTests when being includedAkira Matsuda2019-08-021-195/+199
| | | | To avoid "uninitialized constant ActiveSupport::Testing (NameError)"
* Let's try not to depend too much on other core extensions in a core ↵Akira Matsuda2019-08-021-1/+1
| | | | extension test
* require only what each test concernsAkira Matsuda2019-08-024-4/+7
|
* You give jruby_skip & rubinius_skip a good nameAkira Matsuda2019-08-021-13/+0
| | | | | | | | This hack prevails everywhere in the codebase by being copy & pasted, and it's actually not a negative thing but a necessary thing for framework implementors, so it should better have a name and be a thing. And with this commit, activesupport/test/abstract_unit.rb now doesn't silently autoload AS::TestCase, so we're ready to establish clearner environment for running AS tests (probably in later commits)
* MethodCallAssertions is a regular player of the team ActiveSupport::TestCase nowAkira Matsuda2019-08-021-3/+0
| | | | It's used everywhere, clean and mature enough
* Use `try` only when we're unsure if the receiver would respond_to the methodAkira Matsuda2019-08-011-5/+5
|
* Prevent error on transliterate with frozen strings.Cliff Pruitt2019-07-311-7/+7
| | | | ActiveSupport::Inflector.transliterate mutates strings by changing encodings. Prior to this commit passing a frozen string would raise a `FrozenError`. This change duplicates the internal string, if frozen, before transliterating.
* Use match? where we don't need MatchDataAkira Matsuda2019-07-294-5/+5
|
* Revert "Use assert_match / assert_no_match for asserting match"Akira Matsuda2019-07-291-3/+3
| | | | | | This reverts commit e9651deea4145f62224af56af027bfbb3e45e4cd. Now we're having both `=~` and `match?` for these objects, and it's nicer to have explicit tests for both of them
* Add AS::TimeZone#match?Akira Matsuda2019-07-291-0/+7
|
* Add AS::Multibyte::Chars#match?Akira Matsuda2019-07-291-0/+6
|
* Merge pull request #36185 from jonathanhefner/optimize-string-first-and-lastRafael França2019-07-281-12/+20
|\ | | | | Improve String#first and #last performance
| * Improve String#first and #last performanceJonathan Hefner2019-05-051-12/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Removes unnecessary conditional and method call for significant performance improvement. As a side effect, this fixes an unexpected behavior where passing a limit of 0 would return a frozen string. This also implements the Rails 6.1 intended behavior with regards to negative limits, and removes the previous deprecation warnings. String#first Comparison: new: 3056515.0 i/s old: 1943310.2 i/s - 1.57x slower String#last Comparison: new: 2691919.0 i/s old: 1924256.6 i/s - 1.40x slower (Note: "old" benchmarks have deprecation warnings commented out, for a more fair comparison.)
* | Use match? where we don't need MatchDataAkira Matsuda2019-07-271-2/+2
| | | | | | | | We're already running Performance/RegexpMatch cop, but it seems like the cop is not always =~ justice
* | Use assert_match / assert_no_match for asserting matchAkira Matsuda2019-07-271-3/+3
| |
* | Remove tough to grasp -1 + 1 = 0 from String#toKasper Timm Hansen2019-07-261-0/+2
| | | | | | | | | | | | | | | | | | | | | | In case a negative position is provided that exceeds the size of the string, we're relying on -1 returned from max to get 0 length by + 1 and let [] with a 0 length returning "" for us. E.g. "hello".to(-7), where -7 + 5 size = -2. That's lower than -1, so we use -1 instead and + 1 would turn it into 0. Instead allow outer bounds access and always return "".
* | Remove comments in test fileCliff Pruitt2019-07-261-7/+0
| |
* | Handle GB18030 strings with invalid characters in transliterateCliff Pruitt2019-07-261-7/+4
| | | | | | | | | | | | GB18030 is Unicode compatible and covers all Unicode code points so we can temporarily convert GB18030 strings to UTF-8 to perform the transliteration. After transliterating we want to convert back to GB18030. In all cases of transcoding, we replace invalid or undefined characters with the default replacement character ("?"). This is in line with the behavior of tidy_bytes which is used on the UTF-8 string before transliterating.
* | Handle US-ASCII strings with invalid characters in transliterateCliff Pruitt2019-07-261-17/+11
| | | | | | | | US-ASCII is a subset of UTF-8 so we can temporarily convert US-ASCII strings to UTF-8 to perform the transliteration. After we've converted characters to ASCII representations, we can set the encoding back to US-ASCII to return the same encoding we accepted.
* | Add encoding tests for ActiveSupport::Inflector.transliterateCliff Pruitt2019-07-261-0/+57
| |
* | Raise errors for ASCII-8BIT encoding in ActiveSupport::Inflector::transliterateCliff Pruitt2019-07-261-0/+8
| | | | | | | | Adds ArgumentErrors to `ActiveSupport::Inflector::transliterate` if a string is with ASCII-8BIT which will raise an error in `unicode_normalize`.
* | Use correct variable in `secure_compare!`yuuji.yaginuma2019-07-261-0/+13
| | | | | | | | | | `Messages::Rotator` has `@on_rotation` not `@rotation`. https://github.com/rails/rails/blob/72bc0806a7b378cd544e8fbf7ab22d74b7913ffb/activesupport/lib/active_support/messages/rotator.rb#L11
* | let autoloaded? support modules with overridden names [closes #36757]Xavier Noria2019-07-251-0/+7
| |
* | Merge pull request #36318 from itsWill/fix_event_object_payloadRafael França2019-07-251-0/+21
|\ \ | | | | | | Merge payload for EventObject subscribers
| * | Merge payload for EventObject subscribersGuilherme Mansur2019-05-221-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When instrumenting a block of code like: ```ruby ActiveSupport::Notifications.instrument("process_action.action_controller", raw_paylaod) do |payload| payload[:view_runtime] = render_view end ``` If we use an evented subscriber like so: ``` ruby ActiveSupport::Notifications.subscribe("process_action.action_controller", raw_payload) do |event| assert event.payload[:view_runtime] end ``` The code breaks because the underlying EventObject's payload does not have the `:view_runtime` key added during instrumentation. This is because the `EventedObject` subscriber calls the `finish` method with the `payload` of the event at the time it was pushed into the stack, before the block executes, but we want to call `finish` with the `payload` after the instrument block executes this way if the `payload` was modified during the block we have access to it. This is consistent with the other types of subscribers who don't have this bug.
* | | Merge pull request #36412 from robotdana/compact_blankRafael Mendonça França2019-07-251-0/+24
|\ \ \ | | | | | | | | | | | | Add compact_blank shortcut for reject(&:blank?)
| * | | Add compact_blank shortcut for reject(&:blank?)Dana Sherson2019-06-051-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I frequently find myself having to .compact but for blank. which means on an array reject(&:blank?) (this is fine), or, on a hash `.reject { |_k, v| v.blank? }` which is slightly more frustrating and i usually write it as .reject(&:blank?) first and am confused when it's trying to check if the keys are blank. I've added the analagous .compact_blank! where there's a reject! to build on (there's also a reject! in Set, but there's no other core_ext touching Set so i've left that alone)
* | | | Make ActiveSupport::Logger Fiber-safeSenya2019-07-241-0/+44
| | | | | | | | | | | | | | | | | | | | Use Fiber.current.__id__ in ActiveSupport::Logger#local_level= in order to make log level local to Ruby Fibers in addition to Threads.
* | | | Merge pull request #36434 from Edouard-chin/ec-securecompare-rotationRafael França2019-07-241-0/+44
|\ \ \ \ | | | | | | | | | | Introduce a new ActiveSupport::SecureCompareRotator class:
| * | | | Introduce a new ActiveSupport::SecureCompareRotator class:Edouard CHIN2019-06-061-0/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - This class is used to rotate a previously determined value to a new one before making the comparions. We use this at Shopify to rotate Basic Auth crendials but I can imagine other use cases. The implementation uses the same `Messages::Rotator` module than the MessageEncryptor/MessageVerifier class so it works exactly the same way. You can use it as follow: ```ruby rotator = ActiveSupport::SecureCompareRotator.new('new_production_value') rotator.rotate('previous_production_value') rotator.secure_compare!('previous_production_value') ```
* | | | | Merge pull request #36370 from ptoomey3/masterRafael França2019-07-231-0/+7
|\ \ \ \ \ | | | | | | | | | | | | Add support for Proc based parameter filtering on arrays of values
| * | | | | Update activesupport/test/parameter_filter_test.rb Patrick Toomey2019-07-231-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove extra newline. Co-Authored-By: Rafael França <rafael@franca.dev>
| * | | | | Add failing test for array values and procsPatrick Toomey2019-05-311-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | Based on the way parameters are currently processed, a parameter value of type Hash is recursively processed. For a value of type Array however, the current behavior is to simply return the original array, with no filtering. It is not clear what the expected behavior should be. But, doing nothing seems incorrect, since it bypasses custom Proc based parameter filtering all together for arrays of values. This change introduces a failing test in preparation to add logic that proposes one possible option for the expected behavior with Array values.
* | | | | | Omit marshal_dump & _dump from delegate_missing_toAaron Lipman2019-07-171-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Exclude missing marshal_dump and _dump methods from being delegated to an object's delegation target via the delegate_missing_to extension. This avoids unintentionally adding instance variables to an object during marshallization, should the delegation target be a method which would otherwise add them. In current versions of Ruby, a bug exists in the way objects are marshalled, allowing for instance variables to be added or removed during marshallization (see https://bugs.ruby-lang.org/issues/15968). This results in a corrupted serialized byte stream, causing an object's instance variables to "leak" into subsequent serialized objects during demarshallization. In Rails, this behavior may be triggered when marshalling an object that uses the delegate_missing_to extension, if the delegation target is a method which adds or removes instance variables to an object being marshalled - when calling Marshal.dump(object), Ruby's built in behavior will check whether the object responds to :marshal_dump or :_dump, which in turn triggers the delegation target method in the responds_to_missing? function defined in activesupport/lib/active_support/core_ext/module/delegation.rb While future versions of Ruby will resolve this bug by raising a RuntimeError, the underlying cause of this error may not be readily apparent when encountered by Rails developers. By excluding marshal_dump and _dump from being delegated to an object's target, this commit eliminates a potential cause of unexpected behavior and/or RuntimeErrors. Fixes #36522
* | | | | | Revert "Make UTF-8 string requirement explicit for ↵Cliff Pruitt2019-07-171-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | `ActiveSupport::Inflector.transliterate`"
* | | | | | Make UTF-8 string requirement explicit for `transliterate`Cliff Pruitt2019-07-161-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's noted in #34062 that String#parameterize will raise an `Encoding::CompatibilityError` if the string is not UTF-8 encoded. The error is raised as a result of passing the string to `.unicode_normalize`. This PR raises a higher level `ArgumentError` if the provided string is not UTF-8 and updates documentation to note the encoding requirement.
* | | | | | Merge pull request #36557 from ↵Matthew Draper2019-07-161-0/+17
|\ \ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | sikachu/fix-source-annotation-extractor-annotation Fix problem with accessing deprecated constant proxy's subclass
| * | | | | | Fix problem with accessing constant proxy subclassPrem Sichanugrist2019-07-051-0/+17
| | |/ / / / | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes #36313. After #32065 moved `SourceAnnotationExtractor` into `Rails` module, it broke the ability to access `SourceAnnotationExtractor::Annotate` directly as user would get this error: TypeError: Rails::SourceAnnotationExtractor is not a class/module This commit fixes the issue by making `DeprecatedConstantProxy` to inherit from `Module` and then defines `method_missing` and `const_missing` to retain the previous functionality. Thank you Matthew Draper for the idea of how to fix the issue! [Prem Sichanugrist & Matthew Draper]
* | | | | | Merge pull request #36656 from Edouard-chin/ec-local-cache-referenceRafael França2019-07-151-0/+9
|\ \ \ \ \ \ | | | | | | | | | | | | | | Return a copy of the cache entry when local_cache exists:
| * | | | | | Return a copy of the cache entry when local_cache exists:Edouard CHIN2019-07-111-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - When the local cache exists (during the request lifecycle), the entry returned from the LocalStore is passed as a reference which means mutable object can accidentaly get modified. This behaviour seems unnecessarily unsafe and is prone to issues like it happened in our application. This patch dup the `Entry` returned from the cache and dup it's internal value.
* | | | | | | Implement UnboundMethod#duplicable?Jean Boussier2019-07-121-1/+1
|/ / / / / /
* | | | | | Delete `DateAndTime` method definition in rails that is compatible with ruby ↵soartec-lab2019-06-163-76/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | definition Tests are also only on the `Time` class Update doc forgetting to erase when moved Update guide `Date` class to `Time` class and defined file Update guide correction omission
* | | | | | Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-1316-19/+1
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* | / / / Allow `on_rotation` in MessageEncryptor to be passed in constructor:Edouard CHIN2019-06-061-0/+28
| |/ / / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Use case: I'm writing a wrapper around MessageEncryptor to make things easier to rotate a secret in our app. It works something like ```ruby crypt = RotatableSecret.new(['old_secret', 'new_secret']) crypt.decrypt_and_verify(message) ``` I'd like the caller to not have to care about passing the `on_rotation` option and have the wrapper deal with it when instantiating the MessageEncryptor object. Also, almost all of the time the on_rotation should be the same when rotating a secret (logging something or StatsD event) so I think it's not worth having to repeat ourselves each time we decrypt a message.
* | | | Fix `subscribed` with no pattern to subscribe all messagesRyuta Kamizono2019-06-031-0/+18
|/ / / | | | | | | | | | | | | | | | | | | This is a regression for #36184. And also, add new `monotonic` argument to the last of the method signature rather than the first.