aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
Commit message (Collapse)AuthorAgeFilesLines
...
* | | e4e1b62 broke `to_param` handling:Edouard CHIN2018-07-121-0/+14
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - There was an issue inside controller tests where order params were not respected, the reason was because we were calling `Hash#to_query` which sorts the results lexicographically. 1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack. - However with the fix came another issue where it's now no longer possible to do this ``` post :foo, params: { user: User.first } # Prior to the patch the controller will receive { "user" => "1" } # Whereas now you get { "user": "#<User: ...>" } ``` The fix in this PR is to modify `Hash#to_query` to sort only when it doesn't contain an array structure that looks something like "bar[]" Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396
* | added tests for assert_no_difference with multiple expressionslxxxvi2018-07-081-0/+16
| |
* | Merge pull request #33289 from Edouard-chin/ec-lazy-load-hooksRafael França2018-07-041-0/+49
|\ \ | | | | | | Use class_eval or instance_eval when triggering lazy load hooks
| * | Use class_eval or instance_eval when triggering lazy load hooks:Edouard CHIN2018-07-031-0/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - When lazy load hooks were triggered we were using `Object.instance_eval` which evaluates the block in the context of the class being passed. Most of the time that class was a `Class`. If one wants to define a instance method on the class then it wasn't possible. ```ruby class A; end; A.instance_eval do def foo puts 'bar' end end A.new.foo #> NoMethodError: undefined method `foo` A.foo #> bar ``` - This PR checks what object is passed when triggering the hooks and either call `class_eval` or `instance_eval`. My rational and assumptions being that if an instance of a class is passed, then the blocks needs to evaluate in the context of that instance (i.e. defining a method should only define it on that instance). On the other hand, if a Class or Module is passed when triggering hooks, then defining a method should define it on the class itself - #32776 Pushed me to introduce this change
* | | Refactor #33254.Kasper Timm Hansen2018-07-011-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Firstly, increment and decrement shouldn't care about the particulars of key expiry. They should only know that they have to pass that responsibility on to somewhere else. Secondly, it moves the key normalization back inside the instrumentation like it was originally. I think that matches the original design intention or at the very least it lets users catch haywire key truncation. Thirdly, it moves the changelog entry to the top of the file, where new entries go. I couldn't understand what the entry was saying so I tried to rewrite it.
* | | Fix Cache :redis_store increment/decrement ttl check and add more tests.Jason Lee2018-06-301-4/+20
| | |
* | | Add :expires_in option support for RedisCacheStore increment/decrement method.Jason Lee2018-06-291-0/+24
| | |
* | | Add tests for duration multiplication and divisionEugene Kenny2018-06-251-0/+12
|/ / | | | | | | | | | | | | | | | | | | | | When multiplying or dividing a duration by a scalar, it's tempting to operate directly on the duration's value in seconds and recompute the parts from the result. However this loses information, as there are multiple combinations of parts that map to any given number of seconds (e.g. `2.weeks` or `336.hours`). This is especially problematic when dealing with durations on the scale of months or years, as converting an exact number of seconds to one of those intervals and then using the resulting duration to modify a date will give the wrong result.
* | Merge pull request #33078 from bogdanvlviv/add-remove-requireRyuta Kamizono2018-06-095-13/+5
|\ \ | | | | | | Add/Remove `require`
| * | Add missing `require`bogdanvlviv2018-06-072-0/+5
| | | | | | | | | | | | | | | | | | | | | `activesupport/test/logger_test.rb` requires `tmpdir`. `activesupport/test/multibyte_test_helpers.rb` requires `filutils`, `open-uri`, and `tmpdir`.
| * | Remove unused `require`bogdanvlviv2018-06-073-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - `activesupport/multibyte_normalization_conformance_test.rb` `fileutils`, `tmpdir`, and `open-uri` are unused since c245ca30f248367e07d5d831195b12c93a1e3137, c245ca30f248367e07d5d831195b12c93a1e3137, and 7d7c2d13ba896dd8b58fe91d2fe0c4fc588069ca in accordance. - `activesupport/test/multibyte_conformance_test.rb` `tmpdir`, and `open-uri` are unused since c245ca30f248367e07d5d831195b12c93a1e3137, and 7d7c2d13ba896dd8b58fe91d2fe0c4fc588069ca in accordance. Remove using of `fileutils` since c245ca30f248367e07d5d831195b12c93a1e3137. - `activesupport/test/multibyte_grapheme_break_conformance_test.rb` `fileutils`, `tmpdir`, and `open-uri` are unused since c245ca30f248367e07d5d831195b12c93a1e3137, c245ca30f248367e07d5d831195b12c93a1e3137, and 7d7c2d13ba896dd8b58fe91d2fe0c4fc588069ca in accordance.
* | | Remove extra `include ActiveSupport::Testing::MethodCallAssertions`bogdanvlviv2018-06-081-3/+0
|/ / | | | | | | It includes via `require "abstract_unit"`.
* | Allow Time.zone.at to receive a second argumentJosh Pencheon2018-05-301-0/+10
| | | | | | | | For parity with Ruby's Time::at
* | Merge pull request #32822 from lxxxvi/improved_error_message_in_assert_changesRafael França2018-05-221-1/+1
|\ \ | | | | | | Clearer error message in assert_changes
| * | Clearer error message in assert_changeslxxxvi2018-05-051-1/+1
| | | | | | | | | | | | 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.
* | | Add Enumerable#index_with.Kasper Timm Hansen2018-05-211-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-181-0/+8
| | | | | | | | | | | | 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-041-0/+7
| | | | | | | | | | | | | | | | 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.
* | `SetupAndTeardown` has few caveats that breaks libraries:Edouard CHIN2018-04-271-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* | 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
| | |
* | | 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 #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.
* | | Fix exception in AS::Timezone.all when any tzinfo data is missingDominik Sander2018-04-182-0/+28
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | 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
* | Fix redis store clear keys outside the namespaceRei2018-04-151-0/+18
| | | | | | | | | | | | | | | | | | | | 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 #32539 from chancancode/anticompressRafael França2018-04-123-38/+142
|\ \ | | | | | | Fix ActiveSupport::Cache compression
| * | Fix `ActiveSupport::Cache` compressionGodfrey Chan2018-04-111-2/+21
| | | | | | | | | | | | (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 #31913 from rywall/define-callbacks-descMatthew Draper2018-04-121-0/+10
|\ \ \ | |/ / |/| | Define callbacks on descendants.
| * | Define callbacks on descendants.Ryan Wallace2018-02-061-0/+10
| | | | | | | | | | | | We set callbacks on all descendants, so we need to make sure that they are also defined on all descendants as well.
* | | Fix test class name for `Assertions` moduleyuuji.yaginuma2018-04-081-1/+1
| | | | | | | | | | | | | | | Because this class includes not only `assert_difference` but also tests of other assertion methods.
* | | Rename the class as there is already an existing class with that nameEdouard CHIN2018-04-061-1/+1
| | |
* | | `SetupAndTeardown#teardown` should call any subsequent after_teardown:Edouard CHIN2018-04-061-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | If you have a regular test that have a teardown block, and for any reason an exception get raised, ActiveSupport will not run subsequent after_teardown method provided by other module or gems. One of them being the ActiveRecord::TestFixtures which won't rollback the transation when the test ends making all subsequent test to be in a weird state. The default implementation of minitest is to run all teardown methods from the user's test, rescue all exceptions, run all after_teardown methods provided by libraries and finally re-raise the exception that happened in the user's teardown method. Rails should do the same.
* | | Autocorrect `refute` RuboCop violationsDaniel Colson2018-04-031-2/+2
| | | | | | | | | | | | | | | | | | 73e7aab behaved as expected on codeship, failing the build with exactly these RuboCop violations. Hopefully `rubocop -a` will have been enough to get a passing build!
* | | 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.
* | | Fix: FileStoreTest#test_filename_max_size fails in Ruby 2.5.1utilum2018-03-311-1/+3
| | |
* | | 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.
* | | | Merge pull request #32315 from huacnlee/fix/local-cache-read-multi-entry-returnRafael França2018-03-221-0/+12
|\ \ \ \ | | | | | | | | | | Fix Cache `read_multi` with local_cache bug, should returns raw value, not `ActiveSupport::Cache::Entry` instance.
| * | | | Fix Cache `read_multi` with local_cache return values.Jason Lee2018-03-211-0/+12
| | | | | | | | | | | | | | | | | | | | It should returns raw value, not instance of `ActiveSupport::Cache::Entry`.
* | | | | Use try in tests that try to test try.Kasper Timm Hansen2018-03-211-7/+2
|/ / / /
* | | | Redis cache store: fix constructing with a Redis instanceAdam Richardson2018-03-121-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since `Redis#call` duck types as a Proc, we'd call `#call` on it, thinking it's a Proc. Fixed by check for the Proc explicitly instead of duck typing on `#call`. References #32233
* | | | 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