Commit Graph

1793 Commits

Author SHA1 Message Date
Xavier Noria
1d6355f6e1 Move Zeitwerk to railties
Active Support should not know about Rails. Once classic has been removed,
AS should get anything it needs from the application as usual.
2021-09-05 03:37:46 +02:00
Xavier Noria
5346dfdf74 Move the default autoloaders inflector to railties 2021-09-04 20:44:39 +02:00
Jean Boussier
4eeca2af40
Merge pull request #43097 from Shopify/ar-query-transformers
Refactor ActiveRecord::QueryLogs hook point
2021-08-27 10:21:33 +02:00
David Heinemeier Hansson
d5b9618da1
Remove default reliance on Sass and CSS generators (#43110)
* No benefit to having actiontext css as scss

* Update test

* Update docs

* No more css assets to be generated

New world, new CSS frameworks, new needs.

* SCSS is becoming optional

* Remove Sass as a default-on setting

But continue to make it easy to add.

* Update docs

* No longer used

* Update tests

* Update docs

* Update docs

* No longer used

* No longer by default

* Fix tests

* Promote Tailwind CSS as an alternative to Sass

* Fix test and copy task

* Update railties/lib/rails/generators/rails/app/templates/Gemfile.tt

Co-authored-by: Kevin Newton <kddnewton@gmail.com>

Co-authored-by: Kevin Newton <kddnewton@gmail.com>
2021-08-26 13:40:25 +02:00
David Heinemeier Hansson
af7428c4ac
Replace webpack with importmapped Hotwire as default js (#42999)
* Turbolinks is being replaced with Hotwire

* Make --webpack opt-in

* Don't use specific webpacker installers any more in preparation for next Webpacker

* Update railties/lib/rails/app_updater.rb

Co-authored-by: Alex Ghiculescu <alex@tanda.co>

* Trailing whitespace

* Convert to Turbo data attribute for tracking

* Default is no webpack, no hotwire

* Swap out turbolinks references for hotwire

* Drop explicit return

* Only generate package.json if using webpack

* Only create package.json in webpack mode

* Only create app/javascript in webpack mode

* Generate correct style/js links based on js mode

* Fix tests from changed output format

Not sure why these are showing up in this PR, though.

* Rubocopping

* Stick with webpack for the test app for now

* Adjust tests

* Replace minitest-reporters with minitest-ci (#43016)

minitest-reporters is used to create junit xml reports on CI.

But when it loads before rails minitest plugin makes
`Rails::TestUnitReporter` not being added as a reporter.

minitest-ci is now only loaded at ci and does not interferes with
rails minitest plugins. And keeps junit reports workings

* Too heavy handed to actually run bundle

Just like we don't auto-migrate

* Pin js frameworks in importmap

Instead of having importmap preconfigure it.

* Match updated app/javascript path

* No need for the explaining comment

* Fixes test cases for replace webpack with importmapped Hotwire as default js (#42999)

* Fix rubocop issues

* Fix more railities test cases

* Fix plugin generator railties shared test cases

* Fix Action Text install generator asset pipeline spec

* They're modules, not files

* Let dev use the latest release as well

So we don't have to replace unexisting dev releases with latest release

* Make Webpack responsible for generating all the JS files it needs

Webpacker 6 has already moved from app/javascript to app/packs.

* Don't add rails/ujs by default any longer

All the ajax/form functionality has been superseded by Turbo. The rest lives in a weird inbetween land we need to address through other means.

* Use new importmap location

* Switch to using turbo-rails and stimulus-rails directly

The hotwire-rails gem does not offer enough value for its indirection

* Use latest Webpacker

* Prevent version resolution requests from getting swallowed

* Use ESM syntax for imports

* Move management of yarn, package.json, etc to Webpacker 6

* Update for Webpacker 6

* Move bin/setup addition to Webpacker as well

* Remove dead tests

* Bump to Webpacker 6.0.0.rc.2

* No longer relevant given the new default is no webpacker

* Rely on Webpacker 6

* No longer relevant

* No longer relevant

* Make cable channel generator work for both webpacker and importmap setups

* Fix tests

* For tests testing importmap way

* Use Webpacker 6 dummy

* RuboCopping

* One more bump to fix webpack-dev-server

* Another bump. Hopefully the last one!

* Also enough to not want turbo tracking on

* Fix tests

* Latest

* Fix tests

* Fix more tests

* Fix tests

Co-authored-by: Alex Ghiculescu <alex@tanda.co>
Co-authored-by: André Luis Leal Cardoso Junior <andrehjr@gmail.com>
Co-authored-by: Abhay Nikam <nikam.abhay1@gmail.com>
Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2021-08-26 10:39:36 +02:00
Jean Boussier
12cc24a733 Refactor ActiveRecord::QueryLogs hook point
Hooking into `execute` and `exec_query` is problematic
because some adapters like MySQL2 have `exec_query` call `execute`
which forces QueryLogs to first check wether the comment was already
applied.

Using a prepended module is also a bit problematic because it
means it has to be prepended to the "final" adapter classes
but if the user application has a custom adapter that inherits
from a built-in one, the built-in one no longer have QueryLogs
working.

So instead this PR introduce `ActiveRecord.query_transformers`,
and the adpters are responsible for applying to transformers only
once.
2021-08-25 14:25:42 +02:00
Jean Boussier
703d4b216a
Merge pull request #43079 from Shopify/ar-query-logs-instance-exec
Pass `ActiveRecord::QueryLogs` as argument rather than `instance_exec`
2021-08-24 09:01:48 +02:00
Jean Boussier
b9635ccc05 Pass ActiveRecord::QueryLogs as argument rather than instance_exec
Otherwise we expose all the interal state of `QueryLogs` as an API.

It also makes the API more friendly to typing frameworks.
2021-08-23 20:29:45 +02:00
John Hawthorn
723ccf8fec Add require to failing multi_db test
This started failing related to the removal of the classic autoloader.
This adds the require of environment.rb that other tests already had.
2021-08-23 11:27:22 -07:00
Xavier Noria
891189d9b8
Merge pull request #43080 from rails/del-as-clear
Final touches deleting the classic autoloader
2021-08-23 18:04:16 +02:00
Xavier Noria
fddfaa08af Move AS::Dependencies.clear to the main file 2021-08-23 17:49:48 +02:00
Eileen M. Uchitelle
a81aeb63a0
Merge pull request #43050 from intrip/42912-restore-db-connection-on-schema-load-name
Reestablish connection to previous database after after running db:schema:load:name
2021-08-23 09:20:02 -04:00
Xavier Noria
61d7f33f67 Delete AS::Dependencies.autoloaded_constants 2021-08-23 10:05:13 +02:00
Xavier Noria
b99b14a1cf Delete AS::Dependencies.autoloaded? 2021-08-23 09:04:35 +02:00
Xavier Noria
340b39ea31 Remove autoloading logic from AS::DescendantsTracker
The descendants tracker is a generic tracker that you can use anywhere.
In particular, outside Rails applications.

Should provide API to clear only a subset of classes, but in my view
should know nothing about autoloading. That is a concern of client code.
2021-08-23 00:24:26 +02:00
Xavier Noria
38e82daee8 Delete AS::Dependencies.safe_constantize 2021-08-20 17:51:05 +02:00
Xavier Noria
3e3504bdaa Delete AS::Dependencies.constantize 2021-08-20 09:47:22 +02:00
Jacopo
718c71e051 Reestablish connection to previous database after after running db:schema:load:name
After running `db:schema:load:name` the previous connection is restored.

Fixes #42912
2021-08-20 08:56:07 +02:00
Koichi ITO
65af100ddd Tweak unreachable assertion tests in the block of assert_raises
I found an unexpected use of assertion in the block of `assert_raise`
when I implemented https://github.com/rubocop/rubocop-minitest/pull/137.
It is expected to be asserted after an exception is raised in
`assert_raise` block, but in actually it is not asserted after an
exception is raised. Therefore, this PR removes or updates assertions
that have not been asserted after an exception has raised.

This PR will add `rubocop-minitest` and enable
`Minitest/UnreachableAssertion` cop to able similar auto-detection,
but will remove `rubocop-minitest` from this PR if you don't like it.
2021-08-17 20:33:08 +09:00
Xavier Noria
2306a8e645 Setup the once autoloader on bootstrap 2021-08-17 05:23:51 +02:00
Xavier Noria
bbe74a8c97 Delete AS::Dependencies.unhook! 2021-08-17 05:18:22 +02:00
eileencodes
dfef44716a
Fix rubocop and cleanup test
Followup to #42794. This fixes a rubocop failure for the spacing before
the curly brace and uses a more common/correct approach to testing the
error message.
2021-08-16 15:30:14 -04:00
Weston Ganger
a77dd104ea Implement db config option database_tasks: false 2021-08-16 11:18:49 -07:00
Xavier Noria
3401139842 Move require_dependencies suite to the one for dependencies
require_dependency has now one single definition, and its implementation
does not depend on Zeitwerk or even applications. It only depends on
having some autoload paths in place.

We can test that in the AS test suite.
2021-08-11 00:12:53 +02:00
David Heinemeier Hansson
adec7e7ba8
Sprockets shouldn't be in debug mode by default in development (#42984)
* Sprockets shouldn't be in debug mode by default in development

As we move to separate files with ESM, we won't be concatenating or even preprocessing large JavaScript at all. Debug mode is thus irrelevant.

* Debug mode is no longer default
2021-08-10 12:27:50 +02:00
Xavier Noria
0375657ce0 Delete the initializer initialize_dependency_mechanism
The concept of dependencies mechanism disappears.

We do not remove the attribute in AS::Dependencies itself here, that
class is going to have a lot of code delete later.
2021-08-10 11:48:20 +02:00
Xavier Noria
6983a89c72 Deletes the classic implementation of require_dependency 2021-08-09 17:26:51 +02:00
Keeran Raj Hawoldar
2408615154 Add QueryLogTags to Rails
Co-authored-by: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2021-08-09 15:21:08 +01:00
Eileen M. Uchitelle
843c0a3fcd
Merge pull request #42938 from Modern-Treasury/rh/multidb-tasks
Add database specific setup and reset tasks for multidb configurations
2021-08-09 08:21:40 -04:00
Xavier Noria
36e716cdc1 Implement support for before_remove_const in zeitwek mode
This needs Zeitwerk 2.5 for the on_unload hook.
2021-08-09 13:15:10 +02:00
Ryan Hall
0a296be9e1 Add database specific setup and reset tasks 2021-08-08 13:52:47 -07:00
Alex Ghiculescu
ea3185ebdd Allow entirely opting out of deprecation warnings
Previously if you did `app.config.active_support.deprecation = :silence`, some work would still be done on each call to `ActiveSupport::Deprecation.warn`. Specifically [checking the backtrace](12372c5482/activesupport/lib/active_support/deprecation/reporting.rb (L21)), generating the [deprecation warning](12372c5482/activesupport/lib/active_support/deprecation/reporting.rb (L22)), and [checking if the warning is disallowed](12372c5482/activesupport/lib/active_support/deprecation/reporting.rb (L23)).

In very hot paths, this could cause performance issues. This PR lets you turn off deprecation reporting entirely for a specific environment.

```ruby
config.active_support.report_deprecations = false
```

^ so has the same outcome as:

```ruby
config.active_support.deprecation = :silence
config.active_support.disallowed_deprecation = :silence
```

But it will short circuit [here](12372c5482/activesupport/lib/active_support/deprecation/reporting.rb (L19)).
2021-07-29 16:00:02 -05:00
Rafael Mendonça França
f24d10c285
Merge branch 'vips-as-default' into main 2021-07-29 00:25:41 +00:00
Rafael França
e1170909e2
Merge pull request #41442 from p8/improve-help-for-rake-tasks
Improve help for Rake tasks
2021-07-28 17:43:33 -04:00
Jorge Manrubia
a29884d733 Remove mechanism to disable test parallelization when runnin gonly 1 test
#42761 made the old system of disable paralleling testing when
only one test file was included obsolete.
2021-07-27 10:33:09 -07:00
Eugene Kenny
cca3911c16
Merge pull request #42860 from dixpac/dix/remove_deprecated_time_zone_initializer
FIX: Setting remove_deprecated_time_with_zone_name in new framework defaults
2021-07-27 08:36:35 +01:00
Eugene Kenny
e9b7403bb9
Merge pull request #42808 from eugeneius/log_rescued_responses_env_config
Pass log_rescued_responses as environment config
2021-07-26 02:05:48 +01:00
Dino Maric
a6c0e84f02 FIX: Setting remove_deprecated_time_with_zone_name in new framework defaults
Setting `remove_deprecated_time_with_zone_name` didn't work because
the value is checked in a framework initialiser, which runs before application initialiser.

This PR moves the setting inside the `config.after_initialize` block.
I've also added 2 tests for this behaviour.

Fixes #42820
2021-07-24 16:47:49 +02:00
Gannon McGibbon
5e93cff835
Raise error on unpermitted open redirects.
Add `allow_other_host` options to `redirect_to`.
Opt in to this behaviour with `ActionController::Base.raise_on_open_redirects = true`.
2021-07-22 14:03:59 -04:00
Petrik
718814a4f2 Improve help for Rake tasks
When running `bin/rails -h` the following messages is shown:

> All commands can be run with -h (or --help) for more information.

This doesn't apply to the commands that are Rake tasks like db:migrate.
If you run `bin/rails db:migrate -h` you'll get the Rake help, which
can be confusing...

Instead, if we replace the `-h` argument with `--describe db:migrate`
Rails outputs the Rake task descriptions, which are a lot more helpful:

    rails db:migrate
        Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog).

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2021-07-21 22:12:08 +02:00
eileencodes
10ca60a16b
Add option to disable schema dumb per-database
Dumping the schema is on by default for all databases in an application. To turn it off for a
specific database use the `schema_dump` option:

```yaml
  # config/database.yml

  production:
  schema_dump: false
```

Co-authored-by: Luis Vasconcellos <vasconcelloslf@gmail.com>
2021-07-19 07:58:49 -04:00
Eugene Kenny
d6b66ebb6e Pass log_rescued_responses as environment config
This lets us remove the reference to DebugExceptions from the Action
Dispatch railtie, which was causing load order issues since it depends
on ActionDispatch::Request.
2021-07-19 00:08:30 +01:00
Jorge Manrubia
675d9ffb6e
Add an option threshold: to .parallel() setup method (#42789)
This adds an additional method to configure the parallelization
threshold. Before this, the only way of configuring the threshold was
via an option:

```
config.active_support.test_parallelization_minimum_number_of_tests
```
2021-07-16 11:32:23 -07:00
Breno Gazzola
9bf523559f Make vips the default variant processor for new apps 2021-07-14 14:26:43 -03:00
Akshay Mohite
b3aacdc512 Used already defined method parallelized? and fixed semantics of the test name.
- Related to https://github.com/rails/rails/pull/42761
- Used `parallelized?` method instead of calling a method `should_parallelize?` to figure out if parallezation is enabled.
- Fixed semantics of the test name corresponding to the change
- Updated test name as per the code review suggestion.
2021-07-14 22:35:21 +05:30
Jorge Manrubia
ecc5afed30 Parallelize tests only when overhead is justified
Parallelizing tests has a cost in terms of database setup and fixture
loading. This change makes Rails disable parallelization when the number
of tests is below a configurable threshold.

When running tests in parallel each process gets its own database
instance. On each execution, each process will update each database
schema (if needed) and load all the fixtures. This can be very expensive
for non trivial datasets.

As an example, for HEY, when running a single file with 18 tests,
running tests in parallel in my box adds an overhead of 13 seconds
versus not parallelizing them. Of course parallelizing is totally worthy
when there are many tests to run, but not when running just a few tests.

The threshold is configurable via
config.active_support.test_parallelization_minimum_number_of_tests,
which is 30 50 by default.

This also adds some tracing to know how tests are being executed:

When in parallel:

```
Running 2829 tests in parallel in 8 processes
```

When not in parallel:

```
Running 15 tests in a single process (parallelization threshold is 30)
```
2021-07-14 13:36:28 +02:00
Alex Ghiculescu
47467fe33d Verify foreign keys after loading fixtures
When writing fixtures, it's currently possible to define associations that don't exist, even if a foreign key exists. For example:

```yml
george:
  name: "Curious George"
  pirate: redbeard

blackbeard:
  name: "Blackbeard"
 ```

When the fixtures are created, `parrots(:george).pirate` will be nil, but it's not immediately clear why. This can make it hard to debug tests and can give false confidence in passing ones.

This can happen because Rails [disables referential integrity](f263530bf7/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb (L407)) when inserting fixtures. This makes the fixtures algorithm much simpler - it can just create the fixtures in alphabetical order and assume that the other side of a foreign key constraint will *eventually* be added.

Ideally we would check foreign keys once all fixtures have been loaded, so that we can be sure that the foreign key constraints were met. This PR introduces that. To enable it:

```ruby
config.active_record.verify_foreign_keys_for_fixtures = true
```

I'm proposing we enable this in 7.0 for new apps and have added it to new framework defaults. When run against our app, it found 3 fixture files with unmet FK constraints - turns out all those fixtures weren't being used and were safe to delete.
2021-07-07 15:41:05 -05:00
Loïc Delmaire
056b70ee4f
config_for accepts root shared as an array
Fix a bug introduced by
3fe0ab52df
that raised an undefined method when trying to deep merge an array with
an empty config hash

It also adds a test to clarify config_for behaviour with root arrays: when there's
an env array and a shared array, it should only returns the env key (and not a concatenation)

Closes #42698
2021-07-06 11:57:21 +02:00
Ryuta Kamizono
db767c332a Fix CI failure caused by error_highlight gem
Since https://github.com/ruby/ruby/pull/4586, error.message includes the
line of code that raised.

https://bugs.ruby-lang.org/issues/17930
2021-07-02 17:44:10 +09:00
Andrew White
f263530bf7
Merge pull request #42634 from HackerIntro/actionmailbox-storage-service
Problem: ActionMailbox uses default ActiveStorage service
2021-07-01 16:15:37 +01:00