Commit Graph

75269 Commits

Author SHA1 Message Date
utilum 858e429bca Update mysql2, json, to fix ruby 2.7 warnings (#37967)
* Update mysql2 to the latest version

Fixes keyword arguments warning:
brianmario/mysql2/pull/1084

Fixes taint mechanism deprecation warning:
brianmario/mysql2@785969fbce

* Update json to the latest version

Fixes warning from trying to access an uninitialized ivar, and
keyword arguments warning:

flori/json/commit/de14dea34074558dc671d7edc71513f0216ce21d
flori/json/commit/19da336333e63dc9dde7baea47b179e162b7568e
2019-12-14 12:56:48 +09:00
John Hawthorn 34de785971
Merge pull request #37927 from jhawthorn/cache_url_helpers
Cache routes.url_helpers built modules
2019-12-13 17:17:39 -08:00
John Hawthorn 9fbe349006
Merge pull request #37965 from yahonda/revert-37953-workaround_for_github_action_errors
Revert "Workaroud to address apt-get update at GitHub Actions"
2019-12-13 17:09:12 -08:00
John Hawthorn b6fa3ff874 Add regression test for url_helpers duplication
This adds a regression test that previously failed checking controllers
don't have multiple ancestors which include url_helpers or path_helpers.

This is checked by digging through the ancestors and seeing if they
include either the url_helpers_module or path_helpers_module and making
sure only one ancestor does that.

We usually don't test performance changes (and also would not prefer to
test implementation this closely), but because this has regressed in the
past, and I think it would be relatively easy to accidentally introduce
again, I think we should test this one.
2019-12-13 15:59:46 -08:00
John Hawthorn 37e778b6b4 Cache routes.url_helpers built modules
Previously, every time this was called it would return a new module.

Every time a new controller is built, it had one of these module
included onto it (see AbstractController::Railties::RoutesHelper).
Because each time this was a new module we would end up with a different
copy being included on each controller. This would also include a
different copy on a controller than on its superclass (ex.
ApplicationController). Furthermore, each generated module also extended
the url helper modules.

    +--------------+     +-------------+
    |              |     |             |
    | path_helpers |     | url_helpers | (named routes added here)
    |              |     |             |
    +------+----+--+     +----+--+-----+
           ^    ^             ^  ^
           |    |             |  |
           |  +---------------+  |
           |  | |                |
           |  | +-----------+    |
           |  |             |    |
    +------+--+---+      +--+----+-----+
    |             |      |             |
    | (singleton) +------+ url_helpers | (duplicated for each controller)
    |             |      |             |
    +-------------+      +-----+-------+
                               ^
                               |
                               |
                     +---------+-------+
                     |                 |
                     | UsersController |
                     |                 |
                     +-----------------+

The result of this is that when named routes were added to the two
top-level modules, defining those methods became extremely slow because
Ruby has to invalidate the class method caches on all of the generated
modules as well as each controller. Furthermore because there were
multiple paths up the inheritance chain (ex. one through
UsersController's generated module and one through
ApplicationController's genereated module) it would end up invaliding
the classes multiple times (ideally Ruby would be smarter about this,
but it's much easier to solve in Rails).

Caching this module means that all controllers should include the same
module and defining these named routes should be 3-4x faster.

This method can generate two different modules, based on whether
supports_path is truthy, so those are cached separately.
2019-12-13 15:58:28 -08:00
Yasuo Honda 2dc2876965
Revert "Workaroud to address apt-get update at GitHub Actions" 2019-12-14 08:20:00 +09:00
Vipul A M 4500ebba21
Merge pull request #37958 from yoones/fix_typo_in_autoloading_guide
Fixes typo in autoloading_and_reloading_constants guide
2019-12-13 20:17:18 +05:30
Younes SERRAJ 6e6019b9bf Fixes typo in autoloading_and_reloading_constants guide [ci skip]
The javascript directory under app/ is in a singular form (app/javascript) but the documentation was mentionning it in the plural form (app/javascripts).
2019-12-13 15:37:55 +01:00
Rafael França 1421f70ff3
Merge pull request #37950 from Edouard-chin/ec-activejob-too-much-deprecation
Fix deprecation being thrown at boot time:
2019-12-13 11:16:29 -03:00
Ryuta Kamizono 867df5952c
Merge pull request #37953 from yahonda/workaround_for_github_action_errors
Workaroud to address apt-get update at GitHub Actions
2019-12-13 22:47:56 +09:00
Yasuo Honda 2b15fbf5ed Workaroud to address apt-get update at GitHub Actions
https://github.com/rails/rails/pull/37950/checks?check_run_id=346759027

```
Reading package lists...
W: Conflicting distribution: https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic InRelease (expected bionic but got stable)
E: Repository 'https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic InRelease' changed its 'Origin' value from 'microsoft-ubuntu-bionic-prod bionic' to 'vscode stable'
E: Repository 'https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic InRelease' changed its 'Label' value from 'microsoft-ubuntu-bionic-prod bionic' to 'vscode stable'
E: Repository 'https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic InRelease' changed its 'Suite' value from 'bionic' to 'stable'
E: Repository 'https://packages.microsoft.com/repos/microsoft-ubuntu-bionic-prod bionic InRelease' changed its 'Codename' value from 'bionic' to 'stable'
W: Conflicting distribution: https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease (expected xenial but got stable)
E: Repository 'https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease' changed its 'Origin' value from 'microsoft-ubuntu-xenial-prod xenial' to 'vscode stable'
E: Repository 'https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease' changed its 'Label' value from 'microsoft-ubuntu-xenial-prod xenial' to 'vscode stable'
E: Repository 'https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease' changed its 'Suite' value from 'xenial' to 'stable'
E: Repository 'https://packages.microsoft.com/ubuntu/16.04/prod xenial InRelease' changed its 'Codename' value from 'xenial' to 'stable'
```

Refer:
https://github.community/t5/GitHub-Actions/ubuntu-latest-Apt-repository-list-issues/td-p/41122/page/2
3842b0b8a1
2019-12-13 18:14:02 +09:00
Ryuta Kamizono 58df9a452f Generate 45% faster query methods
`DEFAULT_VALUES` access is a bit slower, avoiding that makes about 45%
faster query methods.

https://gist.github.com/kamipo/e64439f7a206e1c5b5c69d92d982828e

Before (ff299f17):

```
Warming up --------------------------------------
        #limit_value   263.800k i/100ms
    #limit_value = 1   241.758k i/100ms
Calculating -------------------------------------
        #limit_value      7.044M (± 1.5%) i/s -     35.349M in   5.019511s
    #limit_value = 1      6.044M (± 2.3%) i/s -     30.220M in   5.003292s
```

After (this change):

```
Warming up --------------------------------------
        #limit_value   246.295k i/100ms
    #limit_value = 1   244.398k i/100ms
Calculating -------------------------------------
        #limit_value     10.303M (± 2.1%) i/s -     51.722M in   5.022568s
    #limit_value = 1      6.021M (± 6.1%) i/s -     30.061M in   5.015545s
```
2019-12-13 17:45:33 +09:00
Edouard CHIN 9eb4b4ed01 Fix deprecation being thrown at boot time:
-
  ### Problem

  In rails/rails@bbfab0b33a I introduced a change which outputs
  a deprecation whenever a class inherits from ActiveJob::Base.

  This has the negative effect to trigger a massive amount of
  deprecation at boot time especially if your app is eagerloaded
  (like it's usually the case on CI).

  Another issue with this approach was that the deprecation will
  be output no matter if a job define a `after_perform` callbacks
  i.e.
  ```ruby
    class MyJob < AJ::Base
      before_enqueue { throw(:abort) }
    end

    # This shouldn't trigger a deprecation since no after callbacks are defined
    # The change in 6.2 will be already safe for the app.
  ```

  ### Solution

  Trigger the deprecation only when a job is abort
  (during enqueuing or performing) AND a `after_perform`
  callback is defined on the job.
2019-12-13 03:25:03 +01:00
Kasper Timm Hansen ff299f1741
Set default directly with default: 2019-12-13 02:09:08 +01:00
Kasper Timm Hansen 5ded839cfb
Strip default_ prefix from retry_jitter config to match conventions 2019-12-13 01:42:58 +01:00
Carlos Antonio da Silva 8739729072
Merge pull request #37947 from liljack/rails-documentation-contribution
Clarify documentation by removing charged words [ci skip]
2019-12-12 19:56:46 -03:00
Kasper Timm Hansen 2bcf24795b
Merge pull request #37928 from CGA1123/fix-race-in-action-view
Make ActionView::LookupContext::DetailsKey thread-safe
2019-12-12 22:47:30 +01:00
Mark McDonald 16e77e4975 Reorder active support instrumentation guide (#37639)
* Keep consistent verb tenses

[ci skip]

* Add link to "creating your own events"

[ci skip]

* Move section on how to subscribe to events above list of events

The list of events is really long, and most people only care about a
specific event or type of event.

[ci skip]
2019-12-12 22:40:29 +01:00
Aaron Patterson fa292703e1
Merge pull request #37075 from woahdae/fix-multiple-choice-route-options
Fix route from "(:a)(foo/:b)" when only given :b
2019-12-12 12:34:30 -08:00
Aaron Patterson 285cc00128
Merge pull request #37073 from woahdae/fix-hierarchical-route-options
Fix route from "(:a)(:b)" when given only :a or :b
2019-12-12 12:25:19 -08:00
Kevin Jacoby b0743dda8c Clarify documentation by removing charged words
Using words such as 'just', 'simply' and 'easy' implies to the reader
that the tasks they are trying to accomplish are tasks that anyone can
do, which might then frustrate them if they find it difficult to
complete.

This commit rephrases some usage of these words to aid understanding in
the readers without making them feel belittled.

[ci skip]
2019-12-12 19:43:51 +00:00
Eileen M. Uchitelle cad13033fc
Merge pull request #37847 from pwim/action-mailbox-mail-ext-tests
Test extensions to Mail gem
2019-12-12 10:15:07 -05:00
Eileen M. Uchitelle 477ec2675d
Merge pull request #37939 from joelhawksley/class_names-changelog
Add changelog entry for https://github.com/rails/rails/pull/37918
2019-12-11 16:08:33 -05:00
Joel Hawksley e1545682eb
Add changelog entry for https://github.com/rails/rails/pull/37918
Per request from @bogdanvlviv.
2019-12-11 09:20:38 -07:00
Vipul A M f185190a7a
Merge pull request #37936 from s-mori/fix_typo_in_ar_dirty
Fix typo in ActiveRecord::AttributeMethods::Dirty
2019-12-11 19:53:41 +05:30
s-mori ce0b8ffbd6 [ci skip] Fix typo, will_save_change_to_attribute -> will_save_change_to_attribute? 2019-12-11 23:02:38 +09:00
Ryuta Kamizono 42111f85df
Merge pull request #37924 from itohiro73/improve_contributing_guide_for_rdoc
Improve contributing guide for RDoc [ci skip]
2019-12-11 11:11:29 +09:00
Ryuta Kamizono c727d30f51
Merge pull request #37931 from giraffate/remove_unused_requires
Remove unused requires
2019-12-11 10:36:31 +09:00
Takayuki Nakata d0bd3cdc06 Remove unused requires
`reporting` was removed at 7e75dc5d86.
`singleton_class` was removed at b342d2baef.
2019-12-11 10:07:27 +09:00
Eileen M. Uchitelle ab6f7f756f
Merge pull request #37926 from eileencodes/move-records-and-loaded-ivar-to-load
Move records and loaded ivar up to load
2019-12-10 15:14:11 -05:00
eileencodes 847643a55a Move records and loaded ivar up to load
We should set the `@records` and `@loaded` ivar inside `#load` rather
than in `#exec_queries`. Since `#load` is running `#exec_queries` and
`@records` can only be assigned if `loaded?` is true and `@loaded` can
only be set if `loaded?` is true then `#load` should do the assignment.
This is cleaner but also we came across this while working on an
internal gem and realized that the ivar assignment was happening in the
wrong place.

Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
2019-12-10 14:15:11 -05:00
Eileen M. Uchitelle 19c5bd38f4
Merge pull request #37923 from cpruitt/add-config-for-activejob-retry-jitter
Add ActiveJob::Base.default_retry_jitter config option to specify jitter value
2019-12-10 14:09:58 -05:00
eileencodes 25daafbc00 Revert "Merge pull request #37798 from Edouard-chin/ec-sqlite3-connection-transaction"
This reverts commit b4ab1f19d8, reversing
changes made to 9926fd8662.

This is causing CI to fail about 50% of the time, and can be reproduced
locally 100% of the time on my machine.

Ex failing build https://buildkite.com/rails/rails/builds/65467#efaa1dd5-aaf4-43a1-a204-d1c42abf614d

Error:

```
SQLite3::BusyException: database is locked (ActiveRecord::StatementInvalid)
```
2019-12-10 14:07:03 -05:00
Cliff Pruitt 64649cec8b Add explaination of default_retry_jitter to configuring guide 2019-12-10 12:11:46 -05:00
Cliff Pruitt e2cdffce3d Add config option for ActiveJob::Base.default_retry_jitter 2019-12-10 12:11:46 -05:00
Hiroshi Ito 4bed3337f4 Improve contributing guide for RDoc [ci skip] 2019-12-10 23:33:14 +09:00
Eileen M. Uchitelle 774e77c2cc
Merge pull request #37918 from joelhawksley/class_names_helper
Introduce class_names helper
2019-12-10 09:27:37 -05:00
Eileen M. Uchitelle e36097a950
Merge pull request #37919 from joelhawksley/controller-render-in
Render objects that respond_to render_in in controllers
2019-12-10 09:18:26 -05:00
Eileen M. Uchitelle 836fbf2f86
Merge pull request #37921 from hmtanbir/37829-fix-docs-about-etag
Fix docs about etag
2019-12-10 09:16:03 -05:00
Tanbir Hasan 15365de5a4
Fix docs about etag 2019-12-10 15:55:16 +06:00
Joel Hawksley 20a83f52d7
Render objects that respond_to render_in in controllers
In https://github.com/rails/rails/pull/36388,
we supported passing objects that `respond_to` `render_in`
to `render`, but _only_ in views.

This change does the same for controllers, as Rails
generally gives the expectation that `render` behaves
the same in both contexts.

Co-authored-by: Aaron Patterson <tenderlove@github.com>
2019-12-09 16:43:18 -07:00
Joel Hawksley f24734a7e1
Introduce class_names helper
As a follow-up to https://github.com/rails/rails/pull/37872,
this change introduces a class_names view helper
to make it easier to conditionally apply class names
in views.

Before:
<div class="<%= item.for_sale? ? 'active' : '' %>">

After:
<div class="<%= class_names(active: item.for_sale?) %>">

We've been using this helper in the GitHub monolith
since 2016.

Co-authored-by: Aaron Patterson <tenderlove@github.com>
2019-12-09 16:41:18 -07:00
Joel Hawksley 4fbb1e9f5b
Add test case 2019-12-09 15:37:27 -07:00
Richard Schneeman 32b363b246
Merge pull request #37738 from joshuaflanagan/allow_equals_in_db_url_query_value
Database URL supports query value with equal sign
2019-12-09 16:20:01 -06:00
Rafael França 2ab8364bde
Merge pull request #37916 from Edouard-chin/ec-fix-actionview-tag-option
Fix input value not properly applied:
2019-12-09 19:10:16 -03:00
Edouard CHIN 95bc8d0a23 Fix input value not properly applied:
- #37872 introduced a regression and you can't do

  ```html.erb
    hidden_field_tag('token', value: [1, 2, 3])
  ```

  This will result in a `<input type="hidden" value=""`>.

  I chose `hidden_field_tag` and the `value` attribute as an example
  but this issue applies to any tag helper and any attributes.

  https://github.com/rails/rails/pull/37872#issuecomment-561806468
  mention that the feature should only apply for "class" attribute.

  This commit fix original intent of #37872
2019-12-09 22:54:25 +01:00
Rafael Mendonça França 73e079a184
Merge pull request #35210 from pjrebsch/fix-joins-include-select
Retain selections with `includes` and `joins`
2019-12-09 15:28:46 -03:00
Joshua Flanagan 43a6420e17 Database URL supports query value with equal sign
A querystring value should be allowed to include an equal sign `=`.

This is necessary to support passing `options` for a PostgresSQL connection.

```

development:
  url: postgresql://localhost/railsdevapp_development?options=-cmysetting.debug=on
```

Before this PR, attempting to start the rails process with that configuration would result in an error:

```
> bundle exec rails console
Traceback (most recent call last):
	49: from bin/rails:4:in `<main>'
	48: from bin/rails:4:in `require'
...
	 1: from /rails/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb:58:in `query_hash'
/rails/activerecord/lib/active_record/database_configurations/connection_url_resolver.rb:58:in `[]': invalid number of elements (3 for 1..2) (ArgumentError)
```

After this PR, rails can properly parse the configuration:

```
> bundle exec rails console
Loading development environment (Rails 6.1.0.alpha)
2.6.5 :001 > ActiveRecord::Base.connection.select_all("show mysetting.debug").to_a
   (0.4ms)  show mysetting.debug
 => [{"mysetting.debug"=>"on"}]
```
2019-12-09 12:11:58 -06:00
Rafael França b4ab1f19d8
Merge pull request #37798 from Edouard-chin/ec-sqlite3-connection-transaction
Added posibility to open a `read_uncommitted` transaction on SQLite:
2019-12-09 14:32:53 -03:00
Rafael França 9926fd8662
Merge pull request #37827 from Edouard-chin/ec-activejob-enqueuing
Don't run AJ after_enqueue / after_perform when chain is halted:
2019-12-09 13:50:48 -03:00