Commit Graph

13424 Commits

Author SHA1 Message Date
Jonathan Hefner
a6e1be7148 Ensure principle tasks go before finish_template
This fixes a regression of #13637, and adds a regression test.
2020-06-23 23:31:47 -05:00
Javan Makhmali
664e94989e
Merge pull request #39521 from rossta/patch/use-import-syntax-in-application-js-template
Use ES module import syntax in application js template
2020-06-18 07:43:09 -04:00
Ross Kaffenberger
04cbaa1475 Use ES module syntax for application.js.tt and docs
This change swaps the CommonJS require() syntax in the Webpacker
application.js pack template file and in documentation examples with ES
module import syntax.

Benefits of this change include:

Provides continuity with the larger frontend community: Arguably, one of
the main draws in adopting Webpacker is its integration with Babel to
support ES module syntax. For a fresh Rails install with Webpacker, the
application.js file will be the first impression most Rails developers
have with webpack and Webpacker.  Most of the recent documentation and
examples they will find online for using other libraries will be based
on ES module syntax.

Reduces confusion: Developers commonly add ES imports to their
application.js pack, typically by following online examples, which means
mixing require() and import statements in a single file. This leads to
confusion and unnecessary friction about differences between require()
and import.

Embraces browser-friendliness: The ES module syntax forward-looking and
is meant to be supported in browsers. On the other hand, require()
syntax is synchronous by design and not browser-supported as CommonJS
originally was adopted in Node.js for server-side JavaScript. That
webpack supports require() syntax is merely a convenience.

Encourages best practices regarding optimization: webpack can statically
analyze ES modules and "tree-shake", i.e., strip out unused exports from
the final build (given certain conditions are met, including
`sideEffects: false` designation in package.json).
2020-06-16 15:12:12 -04:00
Henrik Nyh
63824f9ffb
setup.tt comment: "at anytime" -> "at any time"
https://www.grammarly.com/blog/anytime-any-time/
2020-06-16 16:19:27 +01:00
Rafael França
acf87b4ed2
Merge pull request #39632 from jonathanhefner/springy-boot
Move Spring machinery to boot.rb
2020-06-15 22:42:07 -04:00
Jonathan Hefner
a6c958b3a7 Move Spring machinery to boot.rb
This partially reverts #39225, and folds `boot_with_spring.rb` into
`boot.rb`.

Fixes #39622.
2020-06-15 17:32:55 -05:00
Jonathan Hefner
f67e4cb7e5 Ensure times-called assertions are evaluated
If an assertion is inside a method stub, it may never be evaluated.
This is particularly problematic when asserting a method is called a
non-zero number of times.

This commit moves such assertions outside their method stubs.
2020-06-15 02:10:58 -05:00
Ryuta Kamizono
528b62e386 Address to false negative for Performance/DeletePrefix,DeleteSuffix
Follow up to c07dff72278fb7f2a3c4c71212a0773a2b25c790.

Actually it is not the cop's fault, but we mistakenly use `^`, `$`, and
`\Z` in much places, the cop doesn't correct those conservatively.

I've checked all those usage and replaced all safe ones.
2020-06-14 13:04:47 +09:00
Josef Šimánek
a49dfe38ae
Introduce Rails::TestUnitReporter.app_root to inject app_root when needed. 2020-06-14 00:02:49 +02:00
Josef Šimánek
32aebc76cb
Use COMPONENT_ROOT as app_root when present in test unit reporting. 2020-06-13 20:30:25 +02:00
Étienne Barrié
cf3736dce8
Add application config for URL-safe Base64 CSRF tokens
This allows applications to safely upgrade to Rails 6.1 without
breaking tokens while the deploy is still being rolled out.
2020-06-11 11:39:37 -04:00
Kasper Timm Hansen
4654f4aab6
Merge pull request #39541 from jonathanhefner/silence-rake-task-backtraces
Silence Rake task backtraces
2020-06-05 12:54:11 +02:00
Jonathan Hefner
7ba531be74 Silence Rake task backtraces
Silence Rake task backtraces, similar to Rails::BacktraceCleaner.
Application lines are preserved, but all other lines are hidden.

This also affects unrecognized tasks, causing the backtrace to be hidden
entirely.  Closes #39524.

Co-authored-by: Petrik <petrik@deheus.net>
2020-06-05 02:26:46 -05:00
Ryuta Kamizono
c07dff7227 Auto-correct for delete_prefix/delete_suffix
Follow up to #39409.
2020-06-05 12:40:39 +09:00
Eileen M. Uchitelle
e95edb3d6d
Merge pull request #39536 from eileencodes/remove-assumption-that-primary-exists
Remove assumption that a primary config exists
2020-06-04 16:03:03 -04:00
eileencodes
e7b1e118b9
Fix schema cache load and corresponding test
This test was incorrect. `primary` was winning for the schema cache load
but when you boot an application it's actually the first configuration
that wins (in a multi db app).

The test didn't catch this because I forgot to add a migrations_paths to
the configuration.

We updated the schema cache loader railtie as well because any
application that didn't have a `primary` config would not be able to use
the schema cache. Originally we thought we'd enforce a `primary`
configuration but no longer feel that's correct. It's simpler to say
that the first wins in a 3-tier rather than implementing a solution to
require `primary` and / or allow aliases.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
Co-authored-by: John Hawthorn <john@hawthorn.email>
2020-06-04 15:12:12 -04:00
eileencodes
7b4fdf3ce7
Remove assumption that a primary config exists
Applications may not have a primary configuration so we should not
assume there is one. In both these cases we can get the right connection
without that.

For the databases.rake file we want to re-establish a connection for the
environment we're in. The first config defined under an environment for
a multi-db app will win. This is already the case on application boot so
we should be consistent.

For the info.rb file we already have a connection so we can lookup the
adapter from the connection's db_config. If a primary hadn't existed
this would have thrown an exception.

Followup to https://github.com/rails/rails/pull/39535 which removed the
assumption there was a primary config from the schema cache load
railtie.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-06-04 15:08:59 -04:00
Aaron Patterson
35fe9bc0aa
Merge pull request #39477 from p8/improve-inspect
Make custom inspect methods more consistent
2020-06-03 10:43:35 -07:00
Eugene Kenny
751d46af4f
Merge pull request #39523 from p8/rename-stubs-out-to-generate
Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
2020-06-03 10:40:40 +01:00
Petrik
2b09948637 Replace 'Stubs out' with 'Generates' in generator USAGE's [ci skip]
Generators generate things, but what is meant by 'Stubbing out' might
confuse beginners and non-native English speakers.
While generated tests are stubs that should have an implementation, a
generated model is a valid model that doesn't require any changes.
2020-06-03 08:51:47 +02:00
Haroon Ahmed
7a321d8429
rails new --minimal gives you a minimal rails stack. (#39282) 2020-06-02 13:29:02 -07:00
Petrik
c7a3894667 Fix test name that no longer raises exception 2020-06-02 10:01:30 +02:00
Jonathan Hefner
08aeb01b0f Lazily build path regex in PathParser
Eagerly building the path regex can exclude handlers which are added on
Action View load.

Fixes #39492.
2020-05-31 15:28:24 -05:00
jasl
34adebd4a7 Don't inline run webpacker:install on rails new 2020-05-30 05:44:04 +08:00
Petrik
74cb9a6f38 Make inspect look more like regular Object#inspect
Move the # outside the < > just like regular Object#inspect
2020-05-29 21:53:35 +02:00
Ryuta Kamizono
c65864cdca Prefer no allocation start/end_with? over String#[] == 2020-05-29 10:20:13 +09:00
Eugene Kenny
0ebc720a04 Set retry_jitter to 0.0 for upgraded applications
The point of new framework defaults is that they're opt-in for upgraded
applications, but the default for this option applied the new behaviour.
2020-05-27 22:15:19 +01:00
John Hawthorn
db543ba728
Merge pull request #39361 from jhawthorn/path_parser
Introduce Resolver::PathParser
2020-05-26 20:16:18 -07:00
John Hawthorn
a70ad604cf Add railties test of custom handlers and formats 2020-05-26 19:27:38 -07:00
Ryuta Kamizono
dc94a753d1 require "active_support/core_ext/symbol/starts_ends_with" for Ruby 2.6
And use `Symbol#[]` to strip suffix to avoid intermediate string
allocation.
2020-05-25 05:24:44 +09:00
Jonathan Hefner
a2ca8f062c Utilize Symbol#start_with? and #end_with?
Follow-up to #39155.

Thanks to Symbol#start_with? and #end_with?, these calls no longer need
to be prefixed with `.to_s`.
2020-05-24 14:46:12 -05:00
fatkodima
e24d6ecbfd Update rubocop-performance gem and enable Performance/DeletePrefix and Performance/DeleteSuffix cops 2020-05-24 12:51:35 +03:00
John Hawthorn
096d143c8c Clear cache after setting Template::Types delegate
details_cache_key already references Template::Types.symbols and view
resolvers cache based on default_formats and other values. This
previously wasn't an issue because no views had been looked up before
this was set. Now that we are building a regex from the values of
Template::Types.symbols we need to clear cache after changing this
setting.
2020-05-21 22:43:13 -07:00
George Claghorn
e4b6c719cd Update Railties tests for 7e52d0a 2020-05-21 13:00:56 -04:00
Ryan Davis
c07bcd6573 Fixed up error output tests and added a missing failure output test.
Errors *should* output their stack. Somehow these tests were passing
before. This clarifies all states (skip/fail/error) and works against
@tenderlove's patch.
2020-05-20 15:54:28 -07:00
Aaron Patterson
43ed3c7939
This is causing problems in master wrt backtraces
Before #39304 was merged, backtraces would look like this:

```
$ be ruby -I lib:test test/controller/request_forgery_protection_test.rb -n test_ignores_trailing_slash_during_generation
Run options: -n test_ignores_trailing_slash_during_generation --seed 22205

E

Error:
PerFormTokensControllerTest#test_ignores_trailing_slash_during_generation:
NoMethodError: undefined method `have_cookie_jar?' for #<Object:0x00007f9ce19b9620>
    /Users/aaron/git/rails/actionpack/lib/action_controller/test_case.rb:522:in `ensure in process'
    /Users/aaron/git/rails/actionpack/lib/action_controller/test_case.rb:542:in `process'
    /Users/aaron/git/rails/actionpack/lib/action_controller/test_case.rb:395:in `get'
    test/controller/request_forgery_protection_test.rb:1005:in `test_ignores_trailing_slash_during_generation'

rails test test/controller/request_forgery_protection_test.rb:1004

Finished in 0.213230s, 4.6898 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
```

After #39304 was merged they look like this:

```
$ be ruby -I lib:test test/controller/request_forgery_protection_test.rb -n test_ignores_trailing_slash_during_generation
Run options: -n test_ignores_trailing_slash_during_generation --seed 62892

E

Error:
PerFormTokensControllerTest#test_ignores_trailing_slash_during_generation:
NoMethodError: undefined method `have_cookie_jar?' for #<Object:0x00007fa6d60193c8>

rails test test/controller/request_forgery_protection_test.rb:1004

Finished in 0.211953s, 4.7180 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
```

This patch reverts the part of #39304 that removes the backtrace.
2020-05-20 08:42:36 -07:00
fatkodima
6c4f3be929 Unify raise_on_missing_translations for views and controllers 2020-05-20 02:42:59 +03:00
Rafael França
a80115b7c5
Merge pull request #39204 from prathamesh-sonpatki/template-annotation
Add the configuration option for annotating templates with file names to the generated app
2020-05-19 19:11:31 -04:00
Prathamesh Sonpatki
a673ce69e7
Rename annotate_template_file_names to annotate_rendered_view_with_filenames
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.
2020-05-19 09:28:14 +05:30
Ryuta Kamizono
a2a861d357 ✂️ trailing spaces [ci skip] 2020-05-18 07:16:18 +09:00
Vinicius Stock
98a3644be0
Create update yarn task (#39314)
* Use app:binstub:yarn in Action Text install generator
2020-05-17 19:51:32 +02:00
David Heinemeier Hansson
f4c9d0b014
Add default ENV variable option with BACKTRACE to turn off backtrace cleaning (#39220)
* Add default ENV variable option with BACKTRACE to turn off backtrace cleaning when debugging framework code

* Use runner as the example

Although I think we should consider dropping -b in tests and just relying on this more general option for sidestepping the backtrace cleaner.
2020-05-17 08:52:05 -07:00
Xavier Noria
838d3f73dd The warning for autoloaded constants on boot includes a solution 2020-05-17 10:12:15 +02:00
Xavier Noria
524d678a03 Document how to reload at boot time [ci skip]
Co-authored-by: Haroon Ahmed <haroon.ahmed25@gmail.com>
2020-05-17 10:11:41 +02:00
Kasper Timm Hansen
03e82e2f0d
Merge pull request #39245 from paul-mannino/unload-app
Don't load app environment when running encrypted commands
2020-05-16 23:55:21 +02:00
David Heinemeier Hansson
c6bdfd133f
Use explicit spring boot loader (#39225) 2020-05-16 13:57:45 -07:00
Ryan Davis
d0060f1206 Fix failure in reporter_test.rb
I'm not sure about this one. The gist is, minitest's
UnexpectedError#message includes a backtrace but the reporter tests
here expect there not to be one in inline output.

Personally, I think that's wrong as it removes information you'd want
to debug, but this might be a philosophical difference with the rails
test ethos... or it might just be aesthetic.

I am happy to back out this change and fix the tests if you'd rather.
2020-05-15 16:42:27 -07:00
Haroon Ahmed
9c886c18bc fix wording in rail/engine class 2020-05-14 08:51:27 +01:00
Eileen M. Uchitelle
d08f2d41a1
Merge pull request #39257 from eileencodes/revert-job-deprecation
Revert "Remove deprecated `ActionMailer::DeliveryJob` and `ActionMailer::Parameterized::DeliveryJob`
2020-05-12 19:12:42 -04:00
Eugene Kenny
96a1a2a37c Use binread instead of setting file mode manually
Followup to b31022052a54ef76f347973e23519ba86ffc94ff.
2020-05-13 00:05:32 +01:00