Commit Graph

13510 Commits

Author SHA1 Message Date
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
eileencodes
336a07b9a4
Revert "Remove deprecated ActionMailer::DeliveryJob and ActionMailer::Parameterized::DeliveryJob"
This reverts commit 0f9249c93f402d276730fcfaba1ed1b876ee7c26.

Reverted because this wasn't warning in custom jobs and therefore
applications may have not seen the deprecation. We'll need to fix the
deprecation to warn for custom jobs so that applications can migrate.
2020-05-12 15:20:07 -04:00
Paul Mannino
4e8650f8b1 Don't load app environment when running encrypted commands
This extends the fix made by a39aa99c814 to the EncryptedCommand class
which suffers from the exact same issue.
2020-05-12 12:06:05 -05:00
Xavier Noria
0dc3f5146d adds credit to CHANGELOG item [ci skip] 2020-05-12 08:16:41 +02:00
Xavier Noria
e9c585096e deprecates the classic autoloader 2020-05-12 08:12:05 +02:00
Jonathan Fleckenstein
dfb5a82b25
Active Storage: allow serving files by proxying 2020-05-11 16:21:58 -04:00
Niklas Häusele
9488712365
Adds a rails test:all rake task (#39221)
* Adds a rails test:all rake task

This task runs all tests, including system tests.

* Better placement + slight tweak of the comment

Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
2020-05-10 17:22:49 -07:00
Ryuta Kamizono
1165401ee9 Remove unused require "active_support/core_ext/kernel/singleton_class"
`singleton_class` is in Ruby 1.9.2, and there is no use singleton class
eval in the files.
2020-05-10 03:20:02 +09:00
yuuji.yaginuma
fde100d18e Add config.generators.after_generate for processing to generated files
Register a callback that will get called right after generators has
finished.

This is useful if users want to process generated files.
For example, can execute an autocorrect of RuboCop for generated files
as like following.

```ruby
config.generators.after_generate do |files|
  system("bundle exec rubocop --auto-correct " + files.join(" "), exception: true)
end
```
2020-05-08 21:06:04 +09:00
Kasper Timm Hansen
f1c7a32e90
Merge pull request #39001 from jonathanhefner/test-runner-recognize-windows-paths
Recognize Windows-style paths in test runner
2020-05-07 22:48:23 +02:00
Kasper Timm Hansen
d143154147
Merge pull request #39036
Closes #39036
2020-05-07 01:05:58 +02:00
Jorge Manrubia
a0f18e6090
Make test file patterns configurable via Environment variables
This makes test file patterns configurable via two environment variables:
`DEFAULT_TEST`, to configure files to test, and `DEFAULT_TEST_EXCLUDE`,
to configure files to exclude from testing.

These values were hardcoded before, which made it difficult to add
new categories of tests that should not be executed by default (e.g:
smoke tests).

It uses environment variables instead of regular Rails config options
because Rails environment is not available when the Runner builds the
list of files to test (unless using Spring). A nicer solution would be
making sure that the Rails environment is always loaded when the runner
starts. This is a first simple step to make these paths configurable for
now

This way at least you could override defaults in `config/boot.rb`:

```ruby
ENV["DEFAULT_TEST_EXCLUDE"] = "test/{dummy,smoke,system}/**/*_test.rb
```

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
2020-05-07 01:04:01 +02:00
Ryuta Kamizono
98a1405f07 Dogfooding "active_support/core_ext/symbol/starts_ends_with"
Any missing thing would be found such like #39159.
2020-05-06 14:19:25 +09:00
Ryuta Kamizono
55e038cf17
Merge pull request #39152 from kamipo/deprecate_starts_ends_with
Deprecate `starts_with?` and `ends_with?` for String core extensions
2020-05-05 22:33:30 +09:00
Ryuta Kamizono
3f883b69a7 Relax required rack-mini-profiler version 2.0.x to 2.x 2020-05-05 17:22:26 +09:00
Ryuta Kamizono
6a4395f466 Deprecate starts_with? and ends_with? for String core extensions
In the past, we sometimes hit missing `Symbol#start_with?` and
`Symbol#end_with?`.

63256bc5d7
a8e812964d

So I proposed `Symbol#start_with?` and `Symbol#end_with?` to allow duck
typing that methods for String and Symbol, then now it is available in
Ruby 2.7.

https://bugs.ruby-lang.org/issues/16348

Using `String#starts_with?` and `String#ends_with?` could not be gained
that conveniency, so it is preferable to not use these in the future.
2020-05-05 15:51:24 +09:00
Rafael Mendonça França
bd87b37d4f
Remove unneeded test after force_ssl removal 2020-05-05 01:13:46 -04:00
Rafael Mendonça França
0f9249c93f
Remove deprecated ActionMailer::DeliveryJob and ActionMailer::Parameterized::DeliveryJob 2020-05-05 00:31:14 -04:00
Brandon Fish
b4ccdcb73a Include parallelize :threads option when fork is not available 2020-05-04 20:26:24 -05:00
Jonathan Hefner
68a3f679d9 Support reentrant calls to RakeCommand.perform
Rake stores the current top-level task and arguments in global state.
Invoking another top-level task within the same process requires
overwriting this state.  Doing so indiscriminately can cause incorrect
behavior, such as infinitely repeating the original task.  In
particular, this is a problem when running one task from another via
`rails_command "...", inline: true`.

The solution is to save and restore the global state in each call to
`RakeCommand.perform` using the `Rake.with_application` method.

Fixes #39128.
2020-05-03 19:28:15 -05:00
Alberto Almagro
8bae32ba2c Add mention to shared section in config_for docs [ci skip]
37913 added the possibility to deeply merge configurations by grouping
them within a shared section. This powerful alternative was not reflected
in any documentation, which made my team think it was not possible until
I found out this feature after looking at the source code.

This patch reflects this change in the documentation so that it is
easier for other developers to know about this behavior.
2020-05-01 15:25:14 +02:00
Ryuta Kamizono
ca3579ad29
Merge pull request #39064 from kamipo/pg-1.1
Update pg gem required version to 1.1
2020-05-01 09:19:30 +09:00
Xavier Noria
92d03850f3 files -> directories in zeitwerk:check warning [skip ci] 2020-04-29 11:12:46 +02:00
Xavier Noria
cd2d1cf731
Merge pull request #38374 from peterb/improve_zeitwerk_check_warning_message
Improve zeitwerk:check warning message [CI skip]
2020-04-29 11:08:17 +02:00
Ryuta Kamizono
592358e182 Update pg gem required version to 1.1
This is required for #39063 to use `PG::TextDecoder::Numeric`.

Ref https://github.com/ged/ruby-pg/pull/25.

The pg gem 1.1.0 was released at August 24, 2018, so I think it is good
timing to bump the required version for improving and cleaning up the
code base.

https://rubygems.org/gems/pg/versions
2020-04-27 16:27:40 +09:00
Tasos Latsas
603403417e Remove redundant begin block from yarn template 2020-04-27 08:32:42 +03:00
Eugene Kenny
c8c549750d Require time core extensions in all environments
These have been required in the generated test environment config since
1c7207a22faca3f07ee9aee1dc00a5b01286de2f, but the generated development
config also uses them (albeit inside a conditional), and the generated
production config contains a comment which uses them.

More generally, we shouldn't require core extensions in one environment
and not others, since applications with `config.active_support.bare`
enabled could rely on them implicitly and exhibit inconsistent behaviour
across environments.
2020-04-26 22:25:14 +01:00
Jonathan Hefner
7bf4520292 Recognize Windows-style paths in test runner
Previously, a test runner argument had to contain a forward slash to be
recognized as a path.  Now, backslashes will also be considered,
enabling the use of Windows-style paths.

Fixes #38243.
2020-04-21 00:48:16 -05:00
Eugene Kenny
cb7b1ea8c8 Add retry_jitter to 6.1 new framework defaults
This was added to the defaults for new applications in
e2cdffce3d4086e33db172cf9722e84f86a80e84, but we also need an entry in
the new framework defaults initializer for upgrading applications.
2020-04-19 23:53:20 +01:00
Eugene Kenny
a254922efa Don't gitignore tmp/pids/.keep
Since 04cfbc807f0567af5a27e8ba45eab52f7b9e6618, a keepfile is generated
in `tmp/pids/` to ensure that the directory always exists. However, the
gitignore pattern for `/tmp/*` meant it wasn't tracked in git.

To override that pattern we have to allow the `tmp/pids/` directory,
ignore everything inside it, then finally allow `tmp/pids/.keep` again.
2020-04-16 22:51:51 +01:00
John Hawthorn
cf525eb7ed
Merge pull request #38893 from leequarella/parallelization
Improve ActiveSupport Parallelization error logging
2020-04-14 10:05:12 -07:00
Ryuta Kamizono
99a4620a19
Merge pull request #38923 from kamipo/remove_dead_test_code
Remove dead test code for unsupported adapters
2020-04-15 00:02:34 +09:00
Rafael França
6f6f4e40ab
Merge pull request #36125 from lulalala/doc-for-model-errors
Document update for ActiveModel#errors
2020-04-13 14:11:55 -04:00
Lee Quarella
b22c4e2a1c Add inflight checks and server shutdown 2020-04-13 09:05:52 -04:00
Ryuta Kamizono
f960948d23 Remove more code for unsupported frontbase and ibm_db adapters
FrontBase and IBM_DB adapters do not work for Rails 5.2.

https://rubygems.org/gems/ruby-frontbase
https://rubygems.org/gems/ibm_db
2020-04-12 11:45:28 +09:00
Haroon Ahmed
6504e97561 update global rails commands to bundled rails i.e. bin/rails 2020-04-11 17:32:26 +01:00
Eugene Kenny
9d8763bceb
Merge pull request #38794 from cromulus/mandrill-ingress-tokenfix
Adding a route for Mandrill's url check.
2020-04-07 20:08:07 +01:00
Bill Cromie
fce29be335 Add a route to handle Mandrill's webhook URL check
Mandrill's Inbound API checks to see if a URL exists before it creates
the webhook. It sends a HEAD request, to which we now return a 200 OK
response to indicate that the route exists.

Now we can generate inbound API calls with ease on Mandrill, without
having to shuffle around tokens in production.

Fixes #37609.
2020-04-07 13:22:36 +01:00
Kasper Timm Hansen
41139f6ba2
Merge pull request #37480 from jonathanhefner/heed-force_ssl-when-build-url
Heed config.force_ssl when building URL
2020-04-06 23:22:27 +02:00
Jonathan Hefner
c7b7d83f70 Heed config.force_ssl when building URL
`url_for` will now use "https://" as the default protocol when
`Rails.application.config.force_ssl` is set to true.

Action Mailer already behaves this way, effectively.  This commit
extends that behavior application-wide.

Closes #23543.
2020-04-05 18:19:31 -05:00
Kasper Timm Hansen
4174f56b6c
Merge pull request #38574 from jonathanhefner/plugin-remove-rdoc-rake-task
Remove :rdoc Rake task in generated plugin
2020-04-05 23:38:21 +02:00
Jonathan Hefner
85808bf177 Clarify database.yml DATABASE_URL instructions
From the instructions in database.yml, it is not clear that Rails will
automatically use ENV['DATABASE_URL'] if it is present.

This commit rewords the instructions to clarify that Rails will do so.
2020-04-04 15:42:09 -05:00
Jonathan Hefner
677eac678d Remove rake rdoc task in generated plugin
The `rdoc lib` command produces nearly the same output as `rake rdoc`.
The `rdoc lib` command also has the benefit of being standard, whereas
Rake subcommands can vary from project to project.  Since the purpose of
either command is to support local development, as opposed to generating
official docs for consumption by e.g. rubygems, the standard command
seems preferable.

Note that the `rdoc` command outputs to the doc/ directory by default,
so this commit also adds that directory to the plugin .gitignore file.
2020-04-04 13:15:16 -05:00
Eugene Kenny
a6711d6e9d Restore tests for 6.0 new framework defaults
These were removed in 74201c3885ae2e33bfff046d503324fd1d7a320f when the
template for the 6.0 new framework defaults initializer was deleted.

While we no longer generate the file, upgrading applications will still
have it, so it's still important to check that these options can be set.
2020-04-04 11:02:31 +01:00
Eugene Kenny
feac3e97cc Trigger load hooks with require in configuration tests
I introduced this pattern of referencing a constant to trigger lazy load
hooks in 458a5502a17ccf58d5708a3b030ac9917a0a8476, and it arrived at its
current form via c98a641ff402d3ca5b754f4621a0764f33eab155 and
c24be369322b9e0211fcef30003375de195ef660.

I now realise autoloading doesn't need to be involved at all; we can
require the files that trigger the lazy load hooks directly.
2020-04-04 10:36:34 +01:00
Eugene Kenny
b5f47f7556
Merge pull request #38863 from eugeneius/utc_to_local_returns_utc_offset_times_new_framework_defaults
Allow utc_to_local_returns_utc_offset_times to be set in new_framework_defaults_6_1.rb
2020-04-03 21:31:01 +01:00
Eugene Kenny
775148c837 Allow utc_to_local_returns_utc_offset_times to be set in new_framework_defaults_6_1.rb
Enabling this option in new_framework_defaults_6_1.rb didn't work
before, as railtie initializers run before application initializers.
2020-04-03 19:41:35 +01:00
Abhay Nikam
bdfffd1355 Update the Rails mailing list URLs to new discuss discourse URL [ci skip] 2020-04-02 22:00:28 +05:30
David Heinemeier Hansson
d56d2e7406
Add a way to deliver inbound emails by source (#38849)
* Add a way to deliver inbound emails by source

Great for testing when you get an eml file and can just paste it in.

* Test updates

* Fix tests

* Fix spacing
2020-03-31 16:46:13 -07:00
David Heinemeier Hansson
3e0cdbeaf4
require, require_relative, load by double quotes (#38841)
* require, require_relative, load by double quotes

We're getting rid of all single quote usage, unless it serves a specific purpose, as per the general style guide.
2020-03-29 16:30:52 -07:00
Eugene Kenny
851773d54e Remove obsolete app:update generator test
This test doesn't assert anything since
e5a6f7ee9e951dbe0e4e9ea2c0743b4dfb135c57.
2020-03-29 23:29:29 +01:00
Kasper Timm Hansen
bf34c808f9
Merge branch 'tzinfo2' 2020-03-28 20:53:24 +01:00
Phil Ross
e9425abe33
Update to TZInfo v2.0.0
Co-authored-by: Jared Beck <jared@jaredbeck.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2020-03-28 20:42:43 +01:00
Eugene Kenny
326d502714 Handle paths with trailing slashes in rails test
The `rails test` command scans its arguments for test paths to load
before handing off option parsing to Minitest. To avoid incorrectly
interpreting a `-n /regex/` pattern as an absolute path to a directory,
it skips arguments that end with a slash. However a relative path ending
in a slash is not ambiguous, so we can safely treat those as test paths.

This is especially useful in bash, where tab completing a directory
leaves a trailing slash in place.
2020-03-26 21:48:17 +00:00
Carlos Antonio da Silva
104aaf5b3f Test with and generate new apps with webpacker 5.0 2020-03-22 16:39:01 -03:00
eileencodes
e33075a0ef
Handle db:rollback and db:rollback:[NAME] for multi-db apps
With a multiple database application `db:rollback` becomes problematic.
We can't rollback just the primary, that doesn't match the behavior in
the other tasks. We can't rollback a migration for every database, that
is unexpected.

To solve this I handled `db:rollback` the same way I handled `:up` and
`:down`. If `db:rollback` is called for a multi-db application then it
will raise an error recommending you use `db:rollback:[NAME]` instead.
Calling `db:rollback:primary` or `db:rollback:animals` will rollback
the migration for the number of steps specified.

Closes: #38513
Follow-up to: #34078
2020-03-19 16:50:46 -04:00
Kasper Timm Hansen
54cb01610e
Merge pull request #38495 from jonathanhefner/isolate-argv-in-command-invoke
Isolate ARGV in Rails::Command.invoke
2020-03-14 02:47:22 +01:00
Rodrigo Ramírez Norambuena
695dc5f984 Quotation mark for gems with options in Gemfile template:
Use the same quote (') for gems with extra options used by  AppGenerator
in the Gemfile template.
2020-03-13 02:10:00 -03:00
Aaron Patterson
690d946db9
Rails::Command.invoke wants kwargs, so give it kwargs
This fixes an exception when generating a new app on Ruby 2.8.  Before
this commit, I get this exception:

```
$ be ruby railties/exe/rails new ~/git/fix-bug --dev
...
...
Traceback (most recent call last):
	31: from railties/exe/rails:10:in `<main>'
	30: from railties/exe/rails:10:in `require'
	29: from /Users/aaron/git/rails/railties/lib/rails/cli.rb:18:in `<top (required)>'
	28: from /Users/aaron/git/rails/railties/lib/rails/command.rb:45:in `invoke'
	27: from /Users/aaron/git/rails/railties/lib/rails/command/base.rb:69:in `perform'
	26: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
	25: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	24: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	23: from /Users/aaron/git/rails/railties/lib/rails/commands/application/application_command.rb:26:in `perform'
	22: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/base.rb:485:in `start'
	21: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/group.rb:232:in `dispatch'
	20: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `invoke_all'
	19: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `map'
	18: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `each'
	17: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:134:in `block in invoke_all'
	16: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	15: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	14: from (eval):1:in `run_webpack'
	13: from /Users/aaron/git/rails/railties/lib/rails/generators/app_base.rb:419:in `run_webpack'
	12: from /Users/aaron/git/rails/railties/lib/rails/generators/actions.rb:255:in `rails_command'
	11: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:197:in `in_root'
	10: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:187:in `inside'
	 9: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/2.8.0/fileutils.rb:139:in `cd'
	 8: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/2.8.0/fileutils.rb:139:in `chdir'
	 7: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:187:in `block in inside'
	 6: from /Users/aaron/.rbenv/versions/ruby-trunk/lib/ruby/gems/2.8.0/gems/thor-1.0.1/lib/thor/actions.rb:197:in `block in in_root'
	 5: from /Users/aaron/git/rails/railties/lib/rails/generators/actions.rb:256:in `block in rails_command'
	 4: from /Users/aaron/git/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:15:in `silence_warnings'
	 3: from /Users/aaron/git/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:28:in `with_warnings'
	 2: from /Users/aaron/git/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:15:in `block in silence_warnings'
	 1: from /Users/aaron/git/rails/railties/lib/rails/generators/actions.rb:257:in `block (2 levels) in rails_command'
/Users/aaron/git/rails/railties/lib/rails/command.rb:31:in `invoke': wrong number of arguments (given 3, expected 1..2) (ArgumentError)
```

After this commit, things seem to work.
2020-03-12 10:04:56 -07:00
OsamaSayegh
ac1d4a6a62 Include rack-mini-profiler gem by default 2020-03-11 18:47:50 +03:00
Nate Berkopec
670026737b
Fix exceptions raised/rescued in dev by IPAddr
Putting ".localhost" at the end causes 4 IPAddr::InvalidAddressError
exceptions to be raised and rescued during every request when the
HostAuthorization middleware attempts to compare an IPAddr with a
"localhost" string.
2020-03-10 12:40:23 -06:00
eileencodes
095f1bfaa0
Refactor schema migration on connection
This method was jumping through extra hoops to find the name of the
class the connection is stored on when we can get it from the connection
itself. Since we already have the connection we don't need to loop through the
pools.

In addition, this was using the wrong class name. The class name for the
schema migration should come from the connection owner class, not from
the `db_config.name`. In this case, `db_config.name` is the name of the
configuration in the database.yml. Rails uses the class name to lookup
connections, not the db config name, so we should be consistent here.

While working on this I noticed that we were generating an extra schema
migration class for `ActiveRecord::Base`. Since `ActiveRecord::Base` can
and should use the default and we don't want to create a new one for
single db applications, we should skip creating this if the spec name is
`ActiveRecord::Base`. I added an additional test that ensures the class
generation is correct.
2020-03-09 09:59:36 -04:00
eileencodes
67b102a57f
Add erb tests for multi-db
If I had had these tests previously I would have not created PR #38658
and then promptly realize I needed to revert it.

We need to load and parse the configurations twice. Once before the
environment is loaded to create the named tasks and once after the
environment is loaded to have the real configurations. The configs
loaded before the env have the ERB stripped out and aren't valid
configs.
2020-03-06 11:23:43 -05:00
eileencodes
2dcf07a53a
Fix test name
Wow this is embarrassing. I literally named this FIXME so I'd remember
to give it some name that made sense and then I totally did not.
2020-03-06 10:01:14 -05:00
eileencodes
150fcf7b37
Fix database configruation for multi-db
The key, value is `replica: true` not `readonly: true`. Fix the database
configuration to be correct.
2020-03-06 09:33:18 -05:00
Eileen M. Uchitelle
712cee1741
Merge pull request #38665 from roramirez/test-master-new-app
Add tests for --master app_generator
2020-03-06 08:40:28 -05:00
Rodrigo Ramírez Norambuena
3b882deb0c Add tests for --master app_generator
These tests verify is added the entry into the Gemfile using
`branch: "master"` for Rails and web-console from Github for
:development
2020-03-05 18:39:03 -03:00
Charles Oliver Nutter
09e0372532
Use optimized subclass of StringInquirer for Rails.env
This adds a StringInquirer subclass EnvironmentInquirer that
predefines the three default environments as query methods, in
order to avoid dispatching through `method_missing` for every call
to those methods. The original StringInquirer was not modified due
to the side effects of having new env-related methods on it. This
new class was not implemented using lazy method definition to
avoid the open-ended possibility of defining a new method for all
query calls. The three default environments should cover a high
percentage of real-world uses, and users with custom environments
could add their own to this class.

Fixes #37803.
2020-03-05 14:57:27 -06:00
Aaron Patterson
227ff44e36
Revert "Merge pull request #37808 from headius/optimize_string_inquirer"
This reverts commit 9e5c6c4c845c176e138927f9fa8774957da55e99, reversing
changes made to 3aacd855cdb5b4543f3b31cd2fa9a5242a8d618e.
2020-03-05 11:12:14 -08:00
Aaron Patterson
9e5c6c4c84
Merge pull request #37808 from headius/optimize_string_inquirer
Use optimized subclass of StringInquirer for Rails.env
2020-03-05 10:00:20 -08:00
Eugene Kenny
d3599d8aff Use index_by and index_with wherever possible
Using `index_by` or `index_with` is more concise than `each_with_object`
and more performant than `map { ... }.to_h` or `Hash[map { ... }]`.
2020-03-05 01:24:14 +00:00
Rafael França
35c2620d23
Merge pull request #38631 from Schwad/master
Allow `rails new . --master` to point to master branch
2020-03-04 13:41:54 -05:00
Nick Schwaderer
6d15fab8ec
Update railties/lib/rails/generators/app_base.rb
Co-Authored-By: Rafael França <rafael@franca.dev>
2020-03-04 17:18:35 +00:00
Humberto
efb62fa3d1
Properly close a tag to avoid errors with some ruby versions
It raises an error if the ruby version is 2.5.0
2020-03-04 16:37:22 +00:00
Nick Schwaderer
531fd3d529 Allow rails new —master to point to master branch
Currently the `rails new` generator supports options `—dev` and `—edge`.

`—dev` points to one’s local rails setup and `--edge` points to the latest stable Rails branch.

However, in the Rails community we often think of the ‘edge’ as the latest merged master. We can see as much in Shopify’s fantastic article showing how they point to the latest master version of Rails: https://engineering.shopify.com/blogs/engineering/living-on-the-edge-of-rails

I would originally have recommended changing ‘edge’ to point to master, as it has tripped me up on numerous occasions now.

However I would rather add the desired functionality then change the current edge functionality.

Therefore this PR adds the `—master` flag.

It is intended to do exactly as `edge` does, simply with the changethat it points to Rails’ master branch instead of latest stable (i.e. 6_0_stable)

Whenever developers see a new feature in Rails, such as the recently committed horizontal sharding (which prompted my PR), we would love to spin up a new Rails App to try out these new features.

This command would allow us to jump right in with no configuration and offer our testing of the features, even those of us who aren’t able to spend a lot of time on OSS support.
2020-03-04 12:20:52 +00:00
Kyle Thompson
4b81e367ef
Dump the schema or structure of a database when calling db:migrate:name 2020-02-27 13:40:00 -05:00
Kyle Thompson
0366cbd742
Reset the ActiveRecord::Base connection after rails db:migrate:name 2020-02-27 13:10:54 -05:00
Ryuta Kamizono
1d3eb7be13 Fixup CHANGELOGs [ci skip] 2020-02-25 14:14:54 +09:00
eileencodes
79ce7d9af6
Deprecate spec_name and use name for configurations
I have so. many. regrets. about using `spec_name` for database
configurations and now I'm finally putting this mistake to an end.

Back when I started multi-db work I assumed that eventually
`connection_specification_name` (sometimes called `spec_name`) and
`spec_name` for configurations would one day be the same thing. After
2 years I no longer believe they will ever be the same thing.

This PR deprecates `spec_name` on database configurations in favor of
`name`. It's the same behavior, just a better name, or at least a
less confusing name.

`connection_specification_name` refers to the parent class name (ie
ActiveRecord::Base, AnimalsBase, etc) that holds the connection for it's
models. In some places like ConnectionHandler it shortens this to
`spec_name`, hence the major confusion.

Recently I've been working with some new folks on database stuff and
connection management and realize how confusing it was to explain that
`db_config.spec_name` was not `spec_name` and
`connection_specification_name`. Worse than that one is a symbole while
the other is a class name. This was made even more complicated by the
fact that `ActiveRecord::Base` used `primary` as the
`connection_specification_name` until #38190.

After spending 2 years with connection management I don't believe that
we can ever use the symbols from the database configs as a way to
connect the database without the class name being _somewhere_ because
a db_config does not know who it's owner class is until it's been
connected and a model has no idea what db_config belongs to it until
it's connected. The model is the only way to tie a primary/writer config
to a replica/reader config. This could change in the future but I don't
see value in adding a class name to the db_configs before connection or
telling a model what config belongs to it before connection. That would
probably break a lot of application assumptions. If we do ever end up in
that world, we can use name, because tbh `spec_name` and
`connection_specification_name` were always confusing to me.
2020-02-24 13:27:07 -05:00
Kyle Thompson
e8c61b6bfd
Adds additional database-specific rake tasks for multi-database users 2020-02-24 12:05:44 -05:00
Carlos Antonio da Silva
6f98614b1f Calculate mailbox and channel test files as Test LOC stats
If they are not included in this "test types" list, they're counted
towards app code lines, not test lines.
2020-02-19 10:10:12 -03:00
Joshua Cody
53348ed820 Count TypeScript files as javascript in rails stats 2020-02-18 16:46:19 -06:00
Jonathan Hefner
8ec7a2b7aa Isolate ARGV in Rails::Command.invoke
Follow-up to #38463.

By isolating ARGV, we guard against commands inadvertently depending on
prior ARGV contents.  Any such command will now behave consistently when
run via `Rails::Command.invoke`, whether coming from the Rails CLI or
from library code.  Likewise, any ARGV mutations done by a command will
not affect code that executes after `Rails::Command.invoke`.
2020-02-18 15:02:56 -06:00
Jonathan Hefner
373ad2c624 Change commands to not depend on ARGV
Follow-up to #38463.

This commit changes additional command classes to not depend on prior
ARGV contents.
2020-02-18 14:08:59 -06:00
Kasper Timm Hansen
0cb6c27344
Merge pull request #38463 from jonathanhefner/fix-rails-new-dev
Fix `rails new --dev`
2020-02-17 00:33:32 +01:00
Jonathan Hefner
9efaa669eb Delete .ruby-version in generated plugin dummy app
A .ruby-version file is not useful in a plugin dummy app because the
plugin itself dictates the required Ruby version.  Indeed, the dummy app
.ruby-version file might fall out of sync with whatever the plugin
dictates, and thus result in unexpected "Could not find gem" errors when
running commands from within the dummy app directory.
2020-02-16 15:02:37 -06:00
Jonathan Hefner
7e54d3bc21 Fix rails new --dev
Follow-up to #38429.

`Rails::Command.invoke` passes arguments through to the appropriate
command class.  However, some command classes were ignoring those
arguments, and instead relying on the contents of ARGV.  In particular,
RakeCommand expected ARGV to contain the arguments necessary to the Rake
task, and no other arguments.  This caused the `webpacker:install` task
to fail when the `--dev` option from `rails new --dev` remained in ARGV.

This commit changes the relevant command classes to not rely on the
previous contents of ARGV.  This commit also adds a missing `require`
for use of `Kernel#silence_warnings`.

Fixes #38459.
2020-02-16 00:44:37 -06:00
Rafael França
d9bfafd9b8
Merge pull request #38441 from fastruby/grammar-update
Grammar update
2020-02-13 16:51:10 -05:00
Rafael França
428509700b
Merge pull request #38442 from roramirez/routes-in-scaffold_controller
scaffold_controller: Include the routes when create a generator Controller
2020-02-13 14:45:19 -05:00
Rodrigo Ramírez Norambuena
55b2264746 scaffold_controller: Include the routes when create a generator Controller
When is use a scaffold_controller add the routes as resources to the
config/route.rb

Also enable to use --skip-routes if doesn't want include the resources
into the config/routes.rb file.
2020-02-13 11:07:21 -03:00
eileencodes
c1a215a06b
Add schema cache tests
The schema cache tests test the following scenarios:

1) The default case works (single db, primary spec name (dev is default
to primary in 2-tier config), standard default schema cache filename)
2) Primary always wins over other entries
3) A custom schema cache filename works when set in the configuration
4) A custom schema cache filename works when set in the ENV

Cases that don't work:

1) A non-primary database entry picks up a namespaced schema cache file

This can't work currently because there's no way of knowing which cache
we actually want. In this railtie we can only load ActiveRecord::Base's
schema cache. If we grab the first config we risk loading a cache for
another connection because order is not guaranteed.

2) Multi-db schema caches

The reasons are similar to above. In addition we can't loop through the
configs, establish a connection, and load the cache because we don't
know what parent class to establish a connection to. In that case AR
Base will always get the cache and it would cause the last one to win
and therefore be loaded on the wrong connection.

The real fix for these issues is to get rid of the railtie entirely, but
for now we needed to set this back to what the behavior was before
recent changes but with the ability to pass a custom key.

Co-authored-by: Katrina Owen <kytrinyx@github.com>
2020-02-13 09:06:18 -05:00
aminamos
149d53e818 removing edits where setup is referred to as a method and not a verb 2020-02-12 13:31:43 -05:00
aminamos
7bb0706f2c update from PR #36222 2020-02-12 13:31:43 -05:00
Jonathan Hefner
f8204cb98a Add tmp/ to generated plugin .gitignore
The documentation for Rails::Generators::TestCase suggests using tmp/ as
the destination directory when testing generators.  Many plugins test
generators, so it makes sense to include tmp/ in the default .gitignore.
2020-02-11 12:54:06 -06:00
Jonathan Hefner
f6f51632e8 Use rails_command :inline option
Follow-up to #37516.
2020-02-10 17:53:41 -06:00
Kasper Timm Hansen
c77a949299
Merge pull request #38067
Closes #38067
2020-02-10 02:52:47 +01:00
Kurtis Rainbolt-Greene
ef7599fe91
Extract internal ActiveSupport::ConfigurationFile object
Rails has a number of places where a YAML configuration file is read,
then ERB is evaluated and finally the YAML is parsed.

This consolidates that into one common class.

Co-authored-by: Kasper Timm Hansen <kaspth@gmail.com>
2020-02-10 02:50:12 +01:00
Kasper Timm Hansen
420d533021
Merge pull request #37988 from abhaynikam/37823-change-action-mailbox-installer-to-generator
Add ActionMailbox install generator
2020-02-10 02:32:08 +01:00
Kasper Timm Hansen
e8070990ef Merge pull request #37516 from jonathanhefner/generator-generate-avoid-shell-out
Avoid shelling out for generator `generate` action
2020-02-09 23:29:23 +01:00
Kasper Timm Hansen
8818d4754d Merge pull request #38421 from jonathanhefner/plugin-anchor-gitignore-entries
Anchor generated plugin .gitgnore entries
2020-02-09 23:16:31 +01:00
Kasper Timm Hansen
b7027099b1
Update git init when generating plugins
* Extract separate test, test with `--skip-git`
* Move `version_control` beneath `gitignore` to match `AppBuilder` from 8989a505
* Add changelog entry
2020-02-09 23:04:29 +01:00
Kasper Timm Hansen
71b6d721f7
Merge pull request #38396 from okuramasafumi/plugin-generator-git-init
Initialize Git when generating plugins
2020-02-09 22:51:34 +01:00
Jonathan Hefner
e0692257b7 Anchor generated plugin .gitgnore entries
This is a good practice to encourage to prevent inadvertent exclusions
from version control.  This also matches generated app .gitignore files.
2020-02-09 15:45:08 -06:00
Kasper Timm Hansen
a0569ff8c3
Group requires together 2020-02-09 17:44:41 +01:00
Kasper Timm Hansen
9128c09448
Merge pull request #38410 from jonathanhefner/plugin-deobfuscate-rake-version-error
Deobfuscate Rake version error in generated plugin
2020-02-09 17:43:12 +01:00
Jonathan Hefner
437896e249 Deobfuscate Rake version error in generated plugin
If the plugin or one of its dependencies requires a version of Rake
that is different than the version executing the Rakefile,
`require 'bundler/setup'` will raise a LoadError with a helpful error
message like: "You have already activated rake 13.0.1, but your Gemfile
requires rake 12.3.3. Prepending `bundle exec` to your command may solve
this."

If that LoadError is swallowed, another LoadError will eventually be
raised with a less helpful / more confusing error message like: "cannot
load such file -- rake".
2020-02-07 15:04:48 -06:00
Jonathan Hefner
f7b5019eea Remove redundant .gitignore entries
Follow-up to #37053.  The `*.sqlite3-*` .gitignore entries added in that
commit subsume previous `*.sqlite3-journal` entries.
2020-02-07 14:05:23 -06:00
OKURA Masafumi
8541ad319a Initialize Git when generating plugins
When generating applications, it initializes Git repository since
8989a5057b
However, it doesn't initialize Git when creating plugins.
Plugins are mostly libraries and are likely hosted on GitHub,
so initializing Git for plugins makes sense.
2020-02-06 20:17:32 +09:00
Ryuta Kamizono
fa986ae0ca Simplify lookup_store
I think allowing nested array parameters is almost useless.
2020-02-05 14:07:56 +09:00
Narendra Rajput
f8059d2383 Fix the environment.rb file path in the benchmark generator template 2020-02-03 17:36:56 +05:30
Peter Baker
f61d5b4767 Improve zeitwerk:check warning message.
The messages that are printed to the console when users run rails zeitwerk:check
can be a little confusing if they've generated a mailer, as the test files aren't
included by default, and a warning appears about this.

To address this issue the warning message has been improved so that it is clearer
that this behaviour is normal and it explicitly states that the user must configure
eager loading to silence these warnings. Fixes #38156
2020-02-02 15:18:23 +00:00
Katrina Owen
e95b3fd21f
Use correct filename for schema cache on load
The initializer that loads the default schema cache on the default
connection doesn't account for the case where an app overrides the
default filename either via ENV["SCHEMA_PATH"], or via the
:schema_cache_path defined in the db config.

Note that as discussed in #34449 this initializer doesn't work for
applications using multiple databases, and this change doesn't fix that.
2020-01-29 21:43:19 +00:00
Kevin Jalbert
cc8eac90cd
Add benchmark generator
Introduce benchmark generator to add benchmarks to Rails applications.

The generator makes use of `benchmark-ips`, and will automatically add
the gem to the Gemfile as needed.

Co-authored-by: Gannon McGibbon <gannon.mcgibbon@gmail.com>
2020-01-24 12:44:33 -05:00
Eileen M. Uchitelle
a6bd34a708
Merge pull request #38250 from vikasvr/skip_keep_fix
Skip keeps option shouldn't restrict from creating empty directories
2020-01-23 11:07:00 -05:00
Jorge Manrubia
34489b2c50 Fix syntax typo in changelog
Fix typo introduced in #38269
2020-01-21 15:17:28 +01:00