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.
- Add the configuration option for annotating templates with file names to the generated app.
- Add `annotate_rendered_view_with_filenames` option to configuring guide.
* 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.
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.
* 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>
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
```
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>
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.
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.
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.
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.
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.
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.
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.
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.
* 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.
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.
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.
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.