Commit Graph

1793 Commits

Author SHA1 Message Date
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
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
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
Lee Quarella
b22c4e2a1c Add inflight checks and server shutdown 2020-04-13 09:05:52 -04: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
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
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
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
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
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
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
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
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
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
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
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
Ryuta Kamizono
fa986ae0ca Simplify lookup_store
I think allowing nested array parameters is almost useless.
2020-02-05 14:07:56 +09: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
eileencodes
2a53fe638d
Deprecate and replace #default_hash and #[]
Database configurations are now objects almost everywhere, so we don't
need to fake access to a hash with `#default_hash` or it's alias `#[]`.
Applications should `configs_for` and pass `env_name` and `spec_name` to
get the database config object. If you're looking for the default for
the test environment you can pass `configs_for(env_name: "test", spec_name:
"primary")`. Change test to developement to get the dev config, etc.

`#default_hash` and `#[]` will be removed in 6.2.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-01-17 16:08:12 -05:00
Xavier Noria
ad04bc0d62 addresses RuboCop feedback 2020-01-07 21:41:33 +01:00
Xavier Noria
c0d91a4f9d restores the ability to manually eager load applications
The main interface to eager loading is config.eager_load. The logic that
implies happens during the boot process.

With the introduction of Zeitwerk, application code is loaded in the
finisher as everything else, but in previous versions of Rails users
could eager load the application code regardless of config.eager_load.

Use cases:

   * Some gems like indexers need to have everything in memory and would
   be a bad user experience to ask users to conditionally set the eager
   load flag.

   * Some tests may need to have everything in memory and would be a bad
   experience to have the flag enabled globally in the test environment.

I personally feel that the contract between this method and the entire
eager loading process is ill-defined. I believe this method is
essentially internal. The purpose of this patch is simply to restore this
functionality emulating what it did before because rethinking the design
of this interface may need time.
2020-01-07 21:34:28 +01:00
Rafael Mendonça França
667b150c20
Merge pull request #37404 from joshmn/respect_the_force
Fix collision check when using a generator and using the force option
2020-01-06 21:32:43 -03:00
Haroon Ahmed
db1ae8cbb4 remove reference to global rails command and replace with bin/rails 2019-12-27 19:32:37 +00:00
Ryuta Kamizono
5324f2cb09 Revert "Merge pull request #37215 from utilum/avoid_test_flunking_on_warning"
This reverts commit ed78e96408f3f83e779a71c65b86aeb1cfc5616e, reversing
changes made to eca6c273fe2729b9634907562c2717cf86443b6b.
2019-12-25 17:13:09 +09:00
yuuji.yaginuma
c8b88dd4df Use the single line editor in console test
It's a bit difficult to deal properly with IRB's multi line and color,
and I think we don't need to check it out in `rails console` tests.
2019-12-24 20:47:21 +09:00
Brian Buchalter
53e9438ef2 Ignore test env in DatabaseTasks when DATABASE_URL is present
Fixes https://github.com/rails/rails/issues/28827.

The steps to reproduce are as follows:

git clone git@github.com:bbuchalter/rails-issue-28827.git
cd rails-issue-28827
bundle install
bin/rails db:create

Observe that we create two databases when invoking db:create: development and test. Now observe what happens when we invoke our drop command while using DATABASE_URL.

DATABASE_URL=sqlite3://$(pwd)/db/database_url.sqlite3 bin/rails db:create

As expected, the development environment now uses the DATABASE_URL. What is unexpected is that the test environment does not.

It's unclear what the expected behavior should be in this case, but the cause of it is this: 9f2c74eda0/activerecord/lib/active_record/tasks/database_tasks.rb (L494)

Because of each_local_configuration, there seems to be no way invoke these database rake on only the development environment to ensure DATABASE_URL is respected.

The smallest scope of change I can think to make would be to conditionalize this behavior so it does not get applied when DATABASE_URL is present.
2019-12-20 14:22:31 -08:00
Rafael França
e36d4a0381
Merge pull request #38026 from Edouard-chin/ec-av-base-loadorder
Don't require "action_view/base" in action pack:
2019-12-19 13:40:56 -03:00
Edouard CHIN
88ee52f9d9 Don't require "action_view/base" in action pack:
- ### Problem

  ActionPack requires "action_view/base" at boot time, this
  causes a variety of issue that I described in detail in #38024.

  There is no real reason to require av/base in the
  ActionDispatch::Debugexceptions class.

  ### Solution

  Like any other components (such as ActiveRecord, ActiveJob...),
  ActionView::Base shouldn't be loaded at boot time.

  Here are the two main changes needed for this:

  1) Actionview has a special initializer that needs to run
     before the app is fully booted (adding a executor needs to be done
     before application is done booting)
  63ec70e700/actionview/lib/action_view/railtie.rb (L81-L84)

     That initializer used a lazy load hooks but we can't do that anymore
     because Action::Base view won't be triggered during booting process.
     When it will get triggered, (presumably on the first request),
     it's too late to add an executor.

  ------------------------------------------------

  2) Compare to other components, ActionView doesn't use `Base` for
     configuration flag. A lot of flags ares instead set on modules
     (FormHelper, FormTagHelper).
     The problem is that those module depends on AV::Base to be
     loaded, as otherwise configuration set by the user aren't applied.
     (Since the lazy load hooks hasn't been triggered)
     63ec70e700/actionview/lib/action_view/railtie.rb (L66-L69)

     We shouldn't wait for AB::Base to be loaded in order to set these
     configuration. However, we need to do it inside an
     `after_initialize` block in order to let application
     set it to the value they want.

  Closes #28538

  Co-authored-by: betesh <iybetesh@gmail.com>"
2019-12-19 17:28:24 +01:00
eileencodes
3dffacd16e Fix remaining connection_config calls
We missed these in rails/rails#38005 because deprecation warnings are
silently swallowed by these tests.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2019-12-18 09:12:27 -05:00
yuuji.yaginuma
1555fcf32c Load an application before use
Without this, `Rails.application` returns `nil`.
Ref: https://buildkite.com/rails/rails/builds/65683#e86ec58e-53a5-41be-8aeb-11c5705ee580/1042-1053
2019-12-18 18:01:02 +09:00
Ryuta Kamizono
72af0bbc3d Fix typos 2019-12-18 16:47:18 +09:00
Rafael Mendonça França
ed5f2c6192
Merge pull request #28209 from tjoyal/railties/add-config-rake_eager_load
[Railties] Add config rake_eager_load
2019-12-17 22:10:14 -03:00
Kasper Timm Hansen
5c3b6c73c4
Add helper method to slim down config_for test set up 2019-12-17 02:02:27 +01:00
Jean Boussier
21c7199c0f
Allow non-hash values in config files
Fix: https://github.com/rails/rails/issues/37800
2019-12-17 01:46:15 +01:00
Kasper Timm Hansen
2da5439b85
Fix test name and test 6.1 default 2019-12-15 02:43:35 +01:00
Cédric Fabianski
7ccaa125ba
Add SameSite protection to every written cookie
Enabling `SameSite` cookie protection is an addition to CSRF protection,
where cookies won't be sent by browsers in cross-site POST requests when set to `:lax`.

`:strict` disables cookies being sent in cross-site GET or POST requests.

Passing `:none` disables this protection and is the same as previous versions albeit a `; SameSite=None` is appended to the cookie.

See upgrade instructions in config/initializers/new_framework_defaults_6_1.rb.

More info [here](https://tools.ietf.org/html/draft-west-first-party-cookies-07)

_NB: Technically already possible as Rack supports SameSite protection, this is to ensure it's applied to all cookies_
2019-12-15 01:37:24 +01:00
Kasper Timm Hansen
5ded839cfb
Strip default_ prefix from retry_jitter config to match conventions 2019-12-13 01:42:58 +01:00
Cliff Pruitt
e2cdffce3d Add config option for ActiveJob::Base.default_retry_jitter 2019-12-10 12:11:46 -05:00
Edouard CHIN
bbfab0b33a Don't run AJ after_enqueue / after_perform when chain is halted:
- ### Problem

  ```ruby
    MyJob < ApplicationJob
      before_enqueue { throw(:abort) }
      after_enqueue { # enters here }
    end
  ```
  I find AJ behaviour on after_enqueue and after_perform callbacks
  weird as they get run even when the callback chain is halted.
  It's counter intuitive to run the after_enqueue callbacks even
  though the job wasn't event enqueued.

  ### Solution

  In Rails 6.2, I propose to make the new behaviour the default
  and stop running after callbacks when the chain is halted.
  For application that wants this behaviour now or in 6.1
  they can do so by adding the `config.active_job.skip_after_callbacks_if_terminated = true`
  in their configuration file.
2019-12-09 17:17:23 +01:00
kirikiriyamama
4d858b3f2a Merge shared configuration deeply 2019-12-08 22:18:08 +09:00
Peter Zhu
fbb83d78c3 Use DiskController for both public and private files 2019-12-06 16:02:16 -05:00
Edouard CHIN
33bf253282 Bring back feature that allows loading external route iles:
= This feature existed back in 2012 5e7d6bba79
  but got reverted with the incentive that there was a better approach.
  After discussions, we agreed that it's a useful feature for apps
  that have a really large set of routes.

  Co-authored-by: Yehuda Katz <wycats@gmail.com>
2019-12-06 14:20:12 +01:00
Alan Tan
767cec041d Revert "Use app.config.file_watcher for watcher in RoutesReloader"
This reverts commit 28e44f472d1cd6853726f85eeb7623e5901c4d37.

A limitation of Listen is that it currently only supports watching directories.
Therefore, watching `config/routes.rb` will end up watching the entire `config` directory
if we use the evented file watcher. This causes problems especially if symlinks are present
in the `config` directory.
2019-12-06 14:58:07 +08:00
Ryuta Kamizono
3b0c3124b1
Merge pull request #37853 from tgxworld/use_proper_file_watcher
Use `app.config.file_watcher` for watcher in `RoutesReloader`
2019-12-06 09:59:14 +09:00
Étienne Barrié
e5e9c558a3 Remove deprecated non-symbol access to nested config_for hashes 2019-12-04 09:55:56 -05:00
Alan Tan
28e44f472d Use app.config.file_watcher for watcher in RoutesReloader 2019-12-03 10:25:36 +08:00
Ryuta Kamizono
d558febe32 Auto-correct rubocop offences 2019-11-24 09:54:47 +09:00
John Hawthorn
75afb43a25 Use rails() instead of system() 2019-11-14 12:31:56 -08:00
Xavier Noria
43863bfc57 let environments configure load-related paths
Co-authored-by: Allen Hsu <allen.hsusp@gmail.com>
2019-11-06 20:40:39 +01:00
eileencodes
042b6fec87 Appease rubocop
Rubocop wants double quoted strings, not single. I missed this when I
merged #37601
2019-11-01 15:43:43 -04:00
Edouard CHIN
c9e44d1a06 Reestablish connection to previous database after migrating:
- The migrate task iterates and establish a connection over each db
  resulting in the last one to be used by subsequent rake tasks.
  We should reestablish a connection to the connection that was
  established before the migrate tasks was run
- Fix #37578
2019-10-30 19:31:22 +01:00
Gannon McGibbon
74201c3885 Make has_many inversing opt-in
Make has_many inversing support available through an opt-in config
variable. This behaviour is likely to break existing applications, but
it is correct behaviour.
2019-10-11 15:55:46 -04:00
Peter Zhu
feab7031b5 Permanent URLs for public storage blobs
Services can be configured in `config/storage.yml` with a new key
`public: true | false` to indicate whether a service holds public
blobs or private blobs. Public services will always return a
permanent URL.

Deprecates `Blob#service_url` in favor of `Blob#url`.
2019-10-11 15:14:43 -04:00
John Hawthorn
72b1ae6a5a Sprockets uses debug. not self. now 2019-10-10 14:43:03 -07:00
John Hawthorn
441917629e Link .js from manifest.js in assets_test
We no longer link JS by default, we need to modify manifest.js for that
now.
2019-10-10 14:43:03 -07:00
John Hawthorn
8d037fd3dd Remove a javascript from test 2019-10-10 14:43:03 -07:00
John Hawthorn
e63695535e Use a stylesheet instead of a javascript in test
We no longer link all js by default, so we should do this test with a
css instead (we don't care about that specifics of the dir just that its
in the manifest and in this dir).
2019-10-10 14:43:03 -07:00
John Hawthorn
5a4d4c7492 Maybe we understand index.js better now? 2019-10-10 14:43:03 -07:00
John Hawthorn
added06d3f Add a few more assertions 2019-10-10 14:43:03 -07:00
John Hawthorn
4cb93a39e2 Fix Sprockets::DoubleLinkError in test 2019-10-09 21:48:37 -07:00
Josh Brody
1dd2b73cb2 Generators skip collision check if force option is passed. 2019-10-08 19:07:38 -05:00
Kasper Timm Hansen
ed78e96408
Merge pull request #37215 from utilum/avoid_test_flunking_on_warning
Avoid flunking tests on warnings in output
2019-10-07 02:22:09 +02:00
Masaki Hara
89f5789aad Delay ActionDispatch::Response configuration to load-time
It fixes the problem in propagating return_only_media_type_on_content_type
and fixes the corresponding test being ineffective.

The mentioned test addes the following line:
...config.action_dispatch.return_only_media_type_on_content_type = true
to the config and checks if it takes effect. However, in this scenario,
the value is already true before this line.
Moreover, the users are supposed to flip this from true to false in real
situations.

This commit flips the config in the test, making it to fail as
expected. The next commit will fix the failure.

In order for return_only_media_type_on_content_type to appropriately
take effect on ActionDispatch::Response, we want to know when
ActionDispatch::Response is loaded.
As load hooks for ActionDispatch would be too broad, the appropriate
registry is for ActionDispatch::Response itself.

Looking into other examples, a hook name is a full class name in
snake case with `_base` suffix omitted, if any. Therefore, in this case,
:action_dispatch_response seems appropriate.
2019-10-01 17:42:05 +09:00
utilum
e0b8c918a0 Avoid flunking tests on warning in output 2019-09-28 12:52:31 +02:00
John Crepezzi
4e66e2dffc Update test to avoid Puma output format change
We are seeing some test failures for this test in #37291. It looks like
what's going on is that Puma has changed the output for this command
between 4.1 and 4.2

Previously:

```
...
* Environment: development
* Listening on tcp://localhost:3000
...

```

Now:

```
...
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
...

```

So to get around this, instead of checking the binding address, just
check for the presence of 'Listening' generally like we do on server
start.

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-09-25 13:11:58 -04:00
Jean Boussier
48c716bbfa Instantiate ConnectionPool with a DatabaseConfig rather than a ConnectionSpecification 2019-09-24 15:12:22 +02:00
John Crepezzi
b8b2d40659 Make all reads on configuration_hash use methods
Convert all uses of `db_config.configuration_hash[*]` to use methods
defined on an implementation of `DatabaseConfigurations::DatabaseConfig`.

Since we want to get away from accessing properties directly on the
underlying configuration hash, we'll move here to accessing those values
via the implementations on `DatabaseConfig` (or more specifically,
`HashConfig`).

There are still codepaths that are passing around `configuration_hash`,
and follow-on PRs will address those with the goal of using
configuration objects everywhere up until the point we pass a resolved
hash over to the underlying client.

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-09-23 16:46:05 -04:00
Eileen M. Uchitelle
9b6433bb82
Merge pull request #37199 from seejohnrun/reduce-surface-area-of-connection-specification
Reduce surface area of ConnectionSpecification
2019-09-16 09:35:22 -04:00
Akira Matsuda
9bce8c3c02 form_authenticity_token takes keyword arguments 2019-09-15 03:05:52 +09:00
eileencodes
b8fc0150d6 Reduce surface area of ConnectionSpecification
Eventually we'd like to get rid of this class altogether but for now
this PR reduces the surface area by removing methods from the class and
moving classes out into their own files.

* `adapter_method` was moved into database configurations
* `initialize_dup` was removed because it was only used in tests
* Resolver is now it's own class under connection adapters
* ConnectionUrlResolver, only used by the configurations, is in a class
under DatabaseConfigurations

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2019-09-13 22:05:02 -04:00
eileencodes
ce9b197cc9 Use symbols everywhere for database configurations
Previously in some places we used symbol keys, and in some places we used
string keys. That made it pretty confusing to figure out in a particular
place what type of configuration object you were working with.

Now internally, all configuration hashes are keyed by symbols and
converted to such on the way in.

A few exceptions:

- `DatabaseConfigurations#to_h` still returns strings for backward compatibility
- Same for `legacy_hash`
- `default_hash` previously could return strings, but the associated
  comment mentions it returns symbol-key `Hash` and now it always does

Because this is a change in behavior, a few method renames have happened:

- `DatabaseConfig#config` is now `DatabaseConfig#configuration_hash` and returns a symbol-key `Hash`
- `ConnectionSpecification#config` is now `ConnectionSpecification#underlying_configuration_hash` and returns the `Hash` of the underlying `DatabaseConfig`
- `DatabaseConfig#config` was added back, returns `String`-keys for backward compatibility, and is deprecated in favor of the new `configuration_hash`

Co-authored-by: eileencodes <eileencodes@gmail.com>
2019-09-13 08:53:22 -04:00
Akira Matsuda
352560308b Fix keyword arguments warnings 2019-09-09 22:49:09 +09:00
y-yagi
ef4bf83a1b
Merge pull request #37102 from y-yagi/fixes_37011
Correctly classify the files and directories that pass to watcher
2019-09-03 07:57:41 +09:00
Stefan Wrobel
b9689aefe5 Add title tag to mailer previews 2019-09-02 14:44:46 -07:00
yuuji.yaginuma
81befcf267 Correctly classify the files and directories that pass to watcher
Currently, autoload paths pass to the watcher as directories. If using evented
watcher, this possibly pass as it is to `Listen`.
But autoload paths include files and `Listen` raise an error when was passed
file. So, it is necessary to classify files and directories correctly.

Fixes #37011.
2019-09-02 11:22:39 +09:00
Rafael França
9ad68a4cf1
Merge pull request #36803 from andrewkress/fix-issue-36799
read webpacker config to populate autoload paths
2019-08-15 18:53:47 -04:00
Rafael Mendonça França
b5a52ad55b Fix the test to check for the right config 2019-08-15 18:39:46 -04:00
Andrew Kress
36beec7b55 add test to check we read new path correctly 2019-08-14 12:36:59 -05:00
Andrew Kress
ffaee477bd create an attribute so that webpacker can set its default path instead of hardcoding 2019-08-13 15:20:59 -05:00
Xavier Noria
5a70f33909 defines Rails.autoloaders.log! 2019-08-13 18:14:50 +02:00
John Hawthorn
ba093a5ada Sync test DB from schema using its SHA1
Previously, we used the migration status to determine whether the test
database(s) needed to be reloaded from the schema. This worked in most
cases, but if a schema.rb was modified outside of migrations or if a
migration was rolled back, it would require a manual db:test:prepare.

This commit updates load_schema to record the SHA1 of the loaded schema
file inside of the ar_internal_metadata table. We can then use this SHA
to determine whether we should reload the schema.

This ensures that the test DB stays exactly in sync with the schema
file, including rollbacks which fixes a test marked TODO.
2019-08-06 12:44:22 -07:00
Akira Matsuda
af2129b4c7 Use try only when we're unsure if the receiver would respond_to the method 2019-08-01 17:58:00 +09:00
eileencodes
cd148be072 Fix db:seed
The `rake db:seed` command was broken for the primary environment if the
application is using multiple databases. We never implemented `rake
db:seed` for other databases (coming soon), but that shouldn't break the
default case.

The reason this was broken was because `abort_if_pending_migrations`
would loop through the configs for all databases and check for
migrations but would leave the last established connection. So `db:seed`
was looking in the wrong database for the table to seed.

This PR doesn't fix the fact that `db:seed` doesn't work for multiple
databases but does fix the default case.

Fixes #36817

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2019-07-31 12:22:01 -04:00
Ryuta Kamizono
4c8c8c87b0 Address to rubocop offences 2019-07-31 17:48:14 +09:00
Akira Matsuda
0196551e60 Use match? where we don't need MatchData 2019-07-29 14:23:10 +09:00
Xavier Noria
bfc9065d58 Improves compatibility of require_dependency in zeitwerk mode [Closes #36774]
Applications are not supposed to use require_dependency in their own
code if running in zeitwerk mode, and require_dependency was initially
aliased to require with that use case in mind.

However, there are situations in which you cannot control the mode and
need to be compatible with both. There, you might need require_dependency
in case you are being executed in classic mode. Think about engines that
want to support both modes in their parent applications, for example.

Furthermore, Rails itself loads helpers using require_dependency.

Therefore, we need better compatibility.
2019-07-28 14:09:01 +02:00
Abhay Nikam
8fdf6d934e Removed webpacker:compile step from scaffold test as it is not required and assets are already precompiled in build_app step 2019-07-26 20:20:07 +05:30
Xavier Noria
59c6d29ffa let autoloaded? support modules with overridden names [closes #36757] 2019-07-25 23:14:29 +02:00
Andrew Kress
7f21e04e61 read configuration to determine excluded eager loaded directory (#36354)
* read config/webpacker.yml to determine which path to exclude for zeitwerk:check

* fix test errors

* more changes to fix test errors

* refactor webpacker_path

[Andrew Kress + Rafael Mendonça França]
2019-07-25 17:10:59 -04:00
Eileen M. Uchitelle
bee689dad9
Merge pull request #36741 from Edouard-chin/ec-system-test-url-options
Define the `url_options` needed for SytemTest inside the route proxy:
2019-07-24 08:16:23 -04:00
Wojciech Wnętrzak
5c1f6d1ff6
Fixed db:prepare task to not touch schema when dump_schema_after_migration is false. 2019-07-24 09:19:13 +02:00
Edouard CHIN
e6cf57df8a Define the url_options needed for SytemTest inside the route proxy:
- I made a change in https://github.com/rails/rails/pull/36691 to
  delegate route helper to a proxy class.
  This didn't take into account that the `url_options` we redefine
  in SystemTest would be ignored.

  This PR fixes that by definin the url_options inside the proxy
2019-07-24 01:18:00 +02:00
Gannon McGibbon
3cf65bcb8e Make Active Storage routes optional
Add configuration option to turn off drawing of Active Storage routes.
2019-07-22 12:35:04 -04:00
Yuji Yaginuma
c5a24c8ebb
Merge pull request #36603 from y-yagi/add_skip_collision_check_option
Add `skip-collision-check` option to generator
2019-07-18 07:17:47 +09:00
Eileen M. Uchitelle
79ef8310be
Merge pull request #36663 from igor04/load_database_yaml_fix
Prevent exception of loading database yaml with blank config file
2019-07-15 09:11:36 -04:00
igor04
0fa41f72fc Prevent exception of loading database yaml with blank config file [closes: #36661] 2019-07-12 19:23:09 +03:00
Jacob Bednarz
bf19b8774e Adds support for configuring HTTP Feature Policy (#33439)
A HTTP feature policy is Yet Another HTTP header for instructing the
browser about which features the application intends to make use of and
to lock down access to others. This is a new security mechanism that
ensures that should an application become compromised or a third party
attempts an unexpected action, the browser will override it and maintain
the intended UX.

WICG specification: https://wicg.github.io/feature-policy/

The end result is a HTTP header that looks like the following:

```
Feature-Policy: geolocation 'none'; autoplay https://example.com
```

This will prevent the browser from using geolocation and only allow
autoplay on `https://example.com`. Full feature list can be found over
in the WICG repository[1].

As of today Chrome and Safari have public support[2] for this
functionality with Firefox working on support[3] and Edge still pending
acceptance of the suggestion[4].

#### Examples

Using an initializer

```rb
# config/initializers/feature_policy.rb
Rails.application.config.feature_policy do |f|
  f.geolocation :none
  f.camera      :none
  f.payment     "https://secure.example.com"
  f.fullscreen  :self
end
```

In a controller

```rb
class SampleController < ApplicationController
  def index
    feature_policy do |f|
      f.geolocation "https://example.com"
    end
  end
end
```

Some of you might realise that the HTTP feature policy looks pretty
close to that of a Content Security Policy; and you're right. So much so
that I used the Content Security Policy DSL from #31162 as the starting
point for this change.

This change *doesn't* introduce support for defining a feature policy on
an iframe and this has been intentionally done to split the HTTP header
and the HTML element (`iframe`) support. If this is successful, I'll
look to add that on it's own.

Full documentation on HTTP feature policies can be found at
https://wicg.github.io/feature-policy/. Google have also published[5] a
great in-depth write up of this functionality.

[1]: https://github.com/WICG/feature-policy/blob/master/features.md
[2]: https://www.chromestatus.com/feature/5694225681219584
[3]: https://bugzilla.mozilla.org/show_bug.cgi?id=1390801
[4]: https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/33507907-support-feature-policy
[5]: https://developers.google.com/web/updates/2018/06/feature-policy
2019-07-10 15:33:15 -07:00
yuuji.yaginuma
6fec4c3a0a Add skip-collision-check option to generator
Until Rails 5.2, generators can run same name multi times without destroying.
But Rails 6.0(with Zeitwerk) can't this. In Rails 6.0, an error occurs
due to class name collision check.

The check uses `const_defined?`, which assumes that the autoload object
is also defined.
https://ruby-doc.org/core-2.6.3/Module.html#method-i-const_defined-3F

It did not work until Rails 5.2, but Zeitwerk seems to be able to
correctly check this against the application's code.

However, this is a little inconvenient if want to run the generator
again like mistake an attribute name(need to run `destoy` before).

In order to solve this, this PR adds an option to skip the collision check.
With this option, you can overwrite files just as did until Rails 5.2.
2019-07-05 18:55:47 +09:00
Yuji Yaginuma
141b30630c
Merge pull request #36534 from y-yagi/fixes_35137
Add the ability to set the CSP nonce only to the specified directives
2019-07-03 08:23:48 +09:00
yuuji.yaginuma
4b621df384 Make bin/setup test pass even if the database does not exist 2019-06-30 10:15:26 +09:00
eileencodes
df6b0de7d9 Load initial database.yml once, and warn if we can't create tasks
For multiple databases we attempt to generate the tasks by reading the
database.yml before the Rails application is booted. This means that we
need to strip out ERB since it could be reading Rails configs.

In some cases like https://github.com/rails/rails/issues/36540 the ERB
is too complex and we can't overwrite with the DummyCompilier we used in
https://github.com/rails/rails/pull/35497. For the complex causes we
simply issue a warning that says we couldn't infer the database tasks
from the database.yml.

While working on this I decided to update the code to only load the
database.yml once initially so that we avoid having to issue the same
warning multiple times. Note that this had no performance impact in my
testing and is merely for not having to save the error off somewhere.
Also this feels cleaner.

Note that this will not break running tasks that exist, it will just
mean that tasks for multi-db like `db:create:other_db` will not be
generated. If the database.yml is actually unreadable it will blow up
during normal rake task calls.

Fixes #36540
2019-06-27 09:54:25 -04:00
yuuji.yaginuma
09d55b3022 Add the ability to set the CSP nonce only to the specified directives
I changed to set CSP nonce to `style-src` directive in #32932.
But this causes an issue when `unsafe-inline` is specified to `style-src`
(If a nonce is present, a nonce takes precedence over `unsafe-inline`).

So, I fixed to nonce directives configurable. By configure this, users
can make CSP as before.

Fixes #35137.
2019-06-22 12:44:37 +09:00
yuuji.yaginuma
ddb6d788d6 Make ActionDispatch::Response#content_type behavior configurable
I changed return value of `ActionDispatch::Response#content_type` in #36034.
But this change seems to an obstacle to upgrading. https://github.com/rails/rails/pull/36034#issuecomment-498795893

Therefore, I restored the behavior of `ActionDispatch::Response#content_type`
to 5.2 and deprecated old behavior. Also, made it possible to control the
behavior with the config.
2019-06-21 07:17:14 +09:00
eileencodes
7cc27d749c Move SchemaMigration to migration_context
This PR moves the `schema_migration` to `migration_context` so that we
can access the `schema_migration` per connection.

This does not change behavior of the SchemaMigration if you are using
one database. This also does not change behavior of any public APIs.
`Migrator` is private as is `MigrationContext` so we can change these as
needed.

We now need to pass a `schema_migration` to `Migrator` so that we can
run migrations on the right connection outside the context of a rake
task.

The bugs this fixes were discovered while debugging the issues around
the SchemaCache on initialization with multiple database. It was clear
that `get_all_versions` wouldn't work without these changes outside the
context of a rake task (because in the rake task we establish a
connection and change AR::Base.connection to the db we're running on).

Because the `SchemaCache` relies on the `SchemaMigration` information we
need to make sure we store it per-connection rather than on
ActiveRecord::Base.

[Eileen M. Uchitelle & Aaron Patterson]
2019-06-14 11:15:08 -04:00
Ryuta Kamizono
98a57aa5f6
Merge pull request #36472 from kamipo/empty_line_only_before_access_modifier
Enable `Layout/EmptyLinesAroundAccessModifier` cop
2019-06-13 18:36:23 +09:00
Ryuta Kamizono
75eb3d0cec Don't drop_table before schema cache tests
Since 5cab34449, `drop_table` clears schema cache.
2019-06-13 13:43:26 +09:00
Ryuta Kamizono
c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00
Mark Lee
cb8b57d07e Convert the db:abort_if_pending_migrations task to be multi-DB aware 2019-06-10 18:01:32 -07:00
Eileen M. Uchitelle
ccb30615a3
Merge pull request #36416 from freeletics/fix-db-prepare
Fixed db:prepare task for multiple databases.
2019-06-05 10:31:52 -04:00
Eileen M. Uchitelle
71a019efe8
Merge pull request #36394 from eileencodes/treat-application-record-as-primary
Treat ActiveRecord::Base and ApplicationRecord as "primary"
2019-06-05 10:01:18 -04:00
eileencodes
2f8b397258 Treat ActiveRecord::Base and ApplicationRecord as "primary"
When someone has a multi-db application their `ApplicationRecord` will
look like:

```ruby
class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  connects_to database: { writing: :primary, reading: :replica }
end
```

This will cause us to open 2 connections to ActiveRecord::Base's
database when we actually only want 1. This is because Rails sees
`ApplicationRecord` and thinks it's a new connection, not the existing
`ActiveRecord::Base` connection because the
`connection_specification_name` is different.

This PR changes `ApplicationRecord` classes to consider themselves the
same as the "primary" connection.

Fixes #36382
2019-06-05 09:29:29 -04:00
Wojciech Wnętrzak
87796b3c81
Fixed db:prepare task for multiple databases.
When one database existed already, but not the other,
during setup of missing one, existing database was wiped out.
2019-06-05 12:17:02 +02:00
yuuji.yaginuma
689b371a52 Extract default log file open operation to method
This allows customize a default log file(e.g. `reopen`) by an application.

Fixes #32211.
2019-06-05 11:19:15 +09:00
John Hawthorn
9fd02d181a Fail parallel tests if workers exit early
Previously, if a test worker exited early, the in-flight test it was
supposed to run wasn't reported as a failure.

If all workers exited immediately, this would be reported as ex.

    Finished in 1.708349s, 39.2192 runs/s, 79.0237 assertions/s.
    67 runs, 135 assertions, 0 failures, 0 errors, 2 skips

This commit validates that all workers finish running tests by ensuring
that the queue is empty after they exit. This works because we signal
the workers to exit by pushing nil onto the queue, so that there should
be a number of items left in the queue matching potentially missed
tests.
2019-05-30 21:34:47 -07:00
Vishal Telangre
ae9be13713
Fix: DummyCompiler embeds invalid YAML content
Fixes https://github.com/rails/rails/issues/36285.

Follow up of https://github.com/rails/rails/pull/36237.
2019-05-15 22:26:07 +05:30
eileencodes
5df84533d5 Fix database loading when ERB is single line ternary
*sigh* this seems like the never ending bug. I don't love or even like
this fix but it does _work_.

Rafael suggested using `dummy_key: dummy_value` but unfortunately
that doesn't work. So we're left with checking whethere there might be
ternary type things in the content and then assuming that we want to
replace the line with a key value pair.

Technically fixes https://github.com/rails/rails/issues/36088
2019-05-10 16:28:08 -04:00
Eileen M. Uchitelle
d155f61b64 Merge pull request #36196 from st0012/fix-29947
Hide malformed parameters from error page

Accidentally merged this to 6-0-stable so forward porting it to master
here instead.
2019-05-07 15:14:14 -04:00
Xavier Noria
b6e17b6a4b new config to opt-out from adding app directories to $LOAD_PATH 2019-04-28 13:48:26 +02:00
Xavier Noria
1b2efe5a11 upgrades Zeitwerk to 2.1.4
This commit more or less undoes 9b5401f, restores autoloaded? not to
touch the descendants tracker, and autoloaded_constants because it is
documented in the guide.
2019-04-23 01:18:21 +02:00
Rafael França
b62b038d9a
Revert "Include Caching module for ActionController::API" 2019-04-22 17:20:48 -04:00
Guillermo Iguaran
216ef01d14
Merge pull request #36038 from st0012/fix-35602
Include Caching module for ActionController::API
2019-04-22 16:05:51 -05:00
Richard Macklin
ef12ccfd8b Make system tests take failed screenshots in before_teardown hook
Previously we were calling the `take_failed_screenshot` method in an
`after_teardown` hook. However, this means that other teardown hooks
have to be executed before we take the screenshot. Since there can be
dynamic updates to the page after the assertion fails and before we
take a screenshot, it seems desirable to minimize that gap as much as
possible. Taking the screenshot in a `before_teardown` rather than an
`after_teardown` helps with that, and has a side benefit of allowing
us to remove the nested `ensure` commented on here:
https://github.com/rails/rails/pull/34411#discussion_r232819478
2019-04-20 19:32:30 -07:00
eileencodes
f9244c6585 Handle up/down for multiple databases
This change adds the ability to run up/down for a database in a multi-db
environment.

If you have an app with a primary and animals database the following
tasks will be generated:

```
VERSION=123 rake db:migrate:up:primary
VERSION=123 rake db:migrate:up:primary

VERSION=123 rake db:migrate:down:primary
VERSION=123 rake db:migrate:up:animals
```

I didn't generate descriptions with them since we don't generate a
description for a single database application.

In addition to this change I've made it so if your application has
multiple databases Rails will raise if you try to run `up` or `down`
without a namespace. This is because we don't know which DB you want to
run `up` or `down` against unless the app tells us, so it's safer to
just block it and recommend using namespaced versions of up/down
respectively.

The output for the raise looks like:

```
You're using a multiple database application. To use `db:migrate:down`
you must run the namespaced task with a VERSION. Available tasks are
db:migrate:down:primary and db:migrate:down:animals.
```
2019-04-19 13:14:24 -04:00
st0012
7814d1c0ae Make sure api controllers can perform caching as well
Currently ActionController::API doesn't include Caching module, so it
can't perform caching. And even if users include it later manually, it
won't inherit application's default cache store for action_controllers.
So the only way to solve this issue is to include Caching module in
ActionController::API, too.

This closes #35602
2019-04-19 22:50:42 +09:00
Genadi Samokovarov
54df392bc5 Manage ActionDispatch::ActionableExceptions from the default middleware stack 2019-04-19 14:15:22 +09:00
David Stosik
6f73a31c0c
Factorize bin/update in bin/setup, and make bin/setup idempotent
`bin/setup` and `bin/update` are currently almost the same file. The
only thing that keeps them apart is that one is running `bin/rails
db:setup` and the other `bin/rails db:migrate`.

I'm suggesting here that they should be a unique script, which needs to
be idempotent.

- New to a project, need to get started? `bin/setup`
- Need to install new dependencies that were added recently? `bin/setup`.

Before deprecating `bin/update`, I'm suggesting we just have it call
`bin/setup`.
2019-04-17 00:45:17 +02:00
Rafael França
19df75dc3d
Merge pull request #35997 from tjoyal/Rails/MailersController/do-not-leak-I18n-global-setting-changes
[Rails::MailersController] Do not leak I18n global setting changes
2019-04-16 15:45:20 -04:00
Thierry Joyal
963d11a000 [Rails::MailersController] Do not leak I18n global setting changes 2019-04-16 18:54:51 +00:00
utilum
742d2b2c66 Squash warning: possibly useless use of a constant
in void context
2019-04-16 18:45:25 +02:00
George Claghorn
f480cfabcd
Remove the Amazon SES ingress
It's unusable and not ready to ship in Rails 6.0. We'll rewrite it for 6.1.
2019-04-14 12:15:54 -04:00
Xavier Noria
3e66ba91d5 deprecates autoloading constants during initialization [closes #35745]
See rationale in the warning message included in the patch.
2019-04-14 12:09:09 +02:00
Xavier Noria
7b6b10542d improves the reloading disabled error message
The original message from Zeitwerk is "can't reload, please call
loader.enable_reloading before setup (Zeitwerk::Error)", which is not
very informative for Rails programmers.

Rails should err with a message worded in terms of its interface.
2019-04-11 23:10:13 +02:00
Xavier Noria
ac786cd1f2 cleanup up constant in test suite 2019-04-09 12:13:05 +02:00
Xavier Noria
9b5401fcc9 depend on Zeitwerk 2.1.0 2019-04-09 11:06:44 +02:00
Xavier Noria
57c7cbb162 depend on Zeitwerk 2 2019-04-07 13:05:26 +02:00
Ryuta Kamizono
b2209ca59d Auto-correct rubocop offences 2019-04-03 08:40:15 +09:00
Eileen M. Uchitelle
2c4dab11d1
Merge pull request #35768 from robertomiranda/r/rake-db-prepare
Add db:prepare rake task.
2019-04-02 15:33:57 -04:00
Roberto Miranda
1c7dcffb64 Add migration in case of db:drop assertion 2019-04-02 17:50:28 +01:00
Roberto Miranda
900e566a6b 💇 2019-04-02 17:04:32 +01:00
Roberto Miranda
098e4d25f1 Add test cases for rake db:prepare 2019-04-02 16:25:48 +01:00
Sharang Dashputre
771973c13d url -> URL where apt except inside actionpack/ 2019-04-01 22:56:35 +05:30
Abhay Nikam
759c4ff0ed [ci skip] Fix typo directores -> directories 2019-03-30 17:50:37 +05:30
Xavier Noria
a3e061def1 optimizes eager loading in :zeitwerk mode
During initialization, the eager load paths of engines are unshifted
into AS::Dependencies.autoload_paths. After that, the collection is
frozen. (See the initializers in railties/lib/rails/engine.rb.)

Hence, there is no eager load path that is not an autoload path too, and
so the array difference in the deleted code is always an empty array.

Just do nothing.
2019-03-30 13:01:42 +01:00
Xavier Noria
278f0dfeac fixes eager loading edge case in :zeitwerk mode 2019-03-30 09:33:48 +01:00
Prem Sichanugrist
b27105252b Add config.disable_sandbox option to Rails console
A long-running `rails console --sandbox` could cause a database server
to become out-of-memory as it's holding on to changes that happen on the
database.

Given that it's common for Ruby on Rails application with huge
traffic to have separate write database and read database, we should
allow the developers to disable this sandbox option to prevent someone
from accidentally causing the Denial-of-Service on their server.
2019-03-23 19:31:03 +09:00
yuuji.yaginuma
efb706daad Fix server restart test on Puma 3.12.1
Since https://github.com/puma/puma/pull/1700, the default host is
correctly used. So `localhost` is used instead of `0.0.0.0`.

As a result, the log output on restart is changed, and the restart test
fails on Puma 3.12.1.
https://travis-ci.org/rails/rails/jobs/509239592#L2303-L2305

Specify binding explicitly to avoid being affected by Puma changes.
2019-03-22 07:49:38 +09:00
Xavier Noria
a47c84d584 Engines are reloaded in Zeitwerk mode [closes #35618] 2019-03-15 22:59:03 +01:00
yuuji.yaginuma
c801b232bc Properly expand the environment's name in all commands
Since 3777701f1380f3814bd5313b225586dec64d4104, the environment's name is
automatically expanded in console and dbconsole commands.
In order to match the behavior between the commands, fixes it to have the
same behavior of all the commands.

This behavior is defined in `EnvironmentArgument`. Since
`EnvironmentArgument` also defines the environment option, it is reused.

However, since desc was not content that can be used in all comments,
fixed desc to be defined for each command.
2019-03-15 07:43:10 +09:00
yuuji.yaginuma
0187053109 Make application work without tmp directory
The tmp directory is added to version control in the newly created
application. This was added in Rails 5.0.0(f06ce4c12a).

However, applications created before that are not guaranteed to have the
tmp directory. If the tmp directory does not exist, writing to the key file
raise error.

This is a bit incompatible. So I fixed that create the directory before
writing a key.
2019-03-14 16:14:15 +09:00
eileencodes
e0c6bce203 Fix secret_key_base for Railties
This was missed in the security fix for local dev. CI doesn't have a tmp
directory in the apps built for testing so these end up failing. This
adds the secret_key_base so we don't need to generate one.
2019-03-13 16:41:29 -04:00
eileencodes
a2bd669ed2 v6.0.0.beta3 release
-----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEEvJkGf0BARV+D0L2ulxXUSC76N8FAlyJN4cACgkQulxXUSC7
 6N9ZXAf/Wx7edIct8kZzcC6irlROx4DzpNbrrH792sO1OAcnoFDE7DPkokllTEP/
 4kzC42lca/XG27MCl7E0dtVD8hIyAl89nxid6cwKFVZVTPIRVc1wjXkoiWy/cvd7
 6+9IjxhlgrzxGnw3aWZJG7H3iqz69yr55aoSDU/TbMqq5kQrqNF95vr2nc8LEUco
 SLQj0pO/tfJdHquSeX0JiXn3VSEHT+5TdLGQ3J/w0wFU6mkecH4MJMJvMwLFx/v4
 llnvF6HyfSLASWbrpdD3h6MQHpImDoee5vILXAHzPdSaEVcVa1cDFtMcPMYiu8Dw
 AGdCAaHQhZFFGoYK472+o6pur0dxEA==
 =5dET
 -----END PGP SIGNATURE-----

Merge tag 'v6.0.0.beta3'

v6.0.0.beta3 release
2019-03-13 13:11:10 -04:00
yuuji.yaginuma
5ab0c1a8cc Add test for runner command with environment option 2019-03-13 10:09:41 +09:00
Cliff Pruitt
44f3530274 Add additional ERB DummyCompiler tests
This adds a few additional tests to the commits by eileencodes (https://github.com/rails/rails/pull/35497) and rafaelfranca (cfa22f1a4b). The additional tests cover several more ERB tag formatting cases such as multiline tags, conditional statements that result in duplicate keys, and multiple erb statements on a single line.
2019-03-12 10:23:29 -04:00
Rafael Mendonça França
cfa22f1a4b
Do not generate dummy string when the tag used is not the <%= 2019-03-11 17:49:27 -04:00
Aaron Patterson
4c743587ad Fix possible dev mode RCE
If the secret_key_base is nil in dev or test generate a key from random
bytes and store it in a tmp file. This prevents the app developers from
having to share / checkin the secret key for dev / test but also
maintains a key between app restarts in dev/test.

[CVE-2019-5420]

Co-Authored-By: eileencodes <eileencodes@gmail.com>
Co-Authored-By: John Hawthorn <john@hawthorn.email>
2019-03-10 21:30:03 -07:00
Shailesh Kalamkar
70192cec42 [ci skip] Minor documentation fixes for consistency 2019-03-09 12:15:00 +05:30
Sharang Dashputre
b2b29b06fa Minor text changes to the db:seed:replant tests 2019-03-09 02:17:59 +05:30
Jean Boussier
6d624f2de9 Allow autoloader inflectors to be swaped out 2019-03-08 17:31:29 +01:00
eileencodes
37d1429ab1 Load YAML for rake tasks without parsing ERB
This change adds a new method that loads the YAML for the database
config without parsing the ERB. This may seem odd but bear with me:

When we added the ability to have rake tasks for multiple databases we
started looping through the configurations to collect the namespaces so
we could do `rake db:create:my_second_db`. See #32274.

This caused a problem where if you had `Rails.config.max_threads` set in
your database.yml it will blow up because the environment that defines
`max_threads` isn't loaded during `rake -T`. See #35468.

We tried to fix this by adding the ability to just load the YAML and
ignore ERB all together but that caused a bug in GitHub's YAML loading
where if you used multi-line ERB the YAML was invalid. That led us to
reverting some changes in #33748.

After trying to resolve this a bunch of ways `@tenderlove` came up with
replacing the ERB values so that we don't need to load the environment
but we also can load the YAML.

This change adds a DummyCompiler for ERB that will replace all the
values so we can load the database yaml and create the rake tasks.
Nothing else uses this method so it's "safe".

DO NOT use this method in your application.

Fixes #35468
2019-03-06 08:59:27 -05:00
Bogdan
a8c0ebccbd Allow truncate for SQLite3 adapter and add rails db:seed:replant (#34779)
* Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter.

SQLite doesn't support `TRUNCATE TABLE`, but SQLite3 adapter can support
`ActiveRecord::Base.connection.truncate` by using `DELETE FROM`.

`DELETE` without `WHERE` uses "The Truncate Optimization",
see https://www.sqlite.org/lang_delete.html.

* Add `rails db:seed:replant` that truncates database tables and loads the seeds

Closes #34765
2019-03-04 14:57:38 -08:00
Xavier Noria
e87a833c97 Make this test stronger
We test the inflections for both autoloaders, but we can
also autoload the constant as a sort of integration test.
2019-02-23 15:27:24 -08:00
Xavier Noria
39b2a6374b Let Zeitwerk autoloaders inflect with Active Support
[Harry Brundage & Xavier Noria]
2019-02-23 14:37:20 -08:00
Xavier Noria
b7fe3bddef simplifies Rails.autoloaders.logger=
Possible thanks to Zeitwerk 1.3.0.
2019-02-21 14:51:28 -08:00
Xavier Noria
f2e51e3123 simplify AS::Dependencies.verbose=
Possible thanks to Zeitwerk 1.3.0.
2019-02-21 14:51:28 -08:00
Xavier Noria
39aaa0264a Define Rails.autoloaders.logger= 2019-02-21 01:57:21 -08:00
Xavier Noria
2607b57917 let Zeitwerk integration unhook AS::Dependencies 2019-02-19 15:22:48 -08:00
Xavier Noria
3aa3c0684d Implement AS::Dependencies.verbose= compatibility for :zeitwerk mode 2019-02-15 14:49:44 -08:00
Xavier Noria
870377915a Replace autoloader accessors with Rails.autoloaders.{main,once}
Rails.autoloader and Rails.once_autoloader was just tentative API good
enough for a first patch. Rails.autoloader is singular and does not
convey in its name that there is another autoloader. That might be
confusing, for example if you set a logger and miss traces. On the other
hand, the name `once_autoloader` is very close to being horrible.

Rails.autoloaders.main and Rails.autoloaders.once read better for my
taste, and have a nice symmetry. Also, both "main" and "once" are four
letters long, short and same length.

They are tagged as "rails.main" and "rails.once", respectively.

References #35235.
2019-02-14 22:34:16 -08:00
Edouard CHIN
4f7231da70 Fix the config_for to always return a NonSymbolAccessDeprecatedHash:
- If you have hashes inside array, the hashes were getting initialized
  as regular HWIA wereas we want them to be
  NonSymbolAccessDeprecatedHash in order to trigger a deprecation
  warning when keys are accessed with string.

  This patch fixes that by overwriting the `[]=` to to the same
  as what HWIA does (with the difference that we don't call
  `convert_key` to not trigger a deprecation when setting value).

  I also took the liberty to extract `hash.nested_under_indifferent_access`,
  into a separate method to allow subclasses to return whatever
  they want.
  Inheriting HWIA is not common, but I think it's useful for cases
  like this one where we want to preprocess reading and writing values
  in the hash (for deprecation purposes or other reasons).
2019-02-14 14:11:05 +01:00
Xavier Noria
96de00e5a7 style 2019-02-12 03:07:22 -08:00
Xavier Noria
821d6c694c Zeitwerk integration 2019-02-12 02:28:04 -08:00
Ufuk Kayserilioglu
de96628c76 Fix assertion excpected/actual order
The assertion from the previous PR had the expected and the actual
values in the wrong order, so when a test failed the error message was
confusing.

This commit fixes the problem by switching the order.
2019-02-11 14:12:12 -05:00
Ufuk Kayserilioglu
325e917f5a Allow deprecated non-symbol access to nested config_for hashes
A change to `Rails::Application.config_for` in
https://github.com/rails/rails/pull/33815 and
https://github.com/rails/rails/pull/33882 has altered the behaviour of
the returned object in a breaking manner. Before that change, nested
hashes returned from `config_for` could be accessed using non-symbol keys.
After the change, all keys are recursively symbolized so non-symbol access
fails to read the expected values.

This is a breaking change for any app that might be relying on the
nested hashes returned from `config_for` calls, and thus should be
deprecated before being removed from the codebase.

This commit introduces a temporary `NonSymbolAccessDeprecatedHash` class
that recursively wraps any nested hashes inside the `OrderedOptions`
object returned from `config_for` and issues a deprecation notice when a
non-symbol based access is performed.

This way, apps that are still relying on the ability to access these
nested hashes using non-symbol keys will be able to observe the
deprecation notices and have time to implement changes before non-symbol
access is removed for good.

A CHANGELOG entry is also added to note that non-symbol access to nested
`config_for` hashes is deprecated.
2019-02-11 14:12:10 -05:00
yuuji.yaginuma
25d8afb3a6 Fix rubocop violations 2019-02-09 10:50:58 +09:00
Aaron Patterson
7761ddbebb
Deprecate finalizer configuration (it doesn't do anything)
Revert "Remove finalizer and configuration"

This reverts commit 9e7b4a3173788ea43b11e74a4d2f69a5f1565daa.
2019-02-06 16:57:34 -08:00
Aaron Patterson
7d0ce785d4
Remove finalizer and configuration 2019-02-06 16:57:04 -08:00
Matthew Draper
287920ca7d Respect ENV variables when finding DBs etc for the test suite
If they're not set we'll still fall back to localhost, but this makes it
possible to run the tests against a remote Postgres / Redis / whatever.
2019-02-06 01:20:06 +10:30
Gannon McGibbon
5da63c1d56
Merge pull request #35086 from gsamokovarov/cleanup-whitelisting-refs
Cleanup the whitelisting references after #33145
2019-02-04 11:09:46 -05:00
Genadi Samokovarov
ca62dfeede Cleanup the whitelisting references after #33145
During the development of #33145, I have named a few concepts in the
code as `whitelisted`. We decided to stay away from the term and I
adjusted most of the code afterwards, but here are the cases I forgot to
change.

I also found a case in the API guide that we could have cleaned up as
well.

[ci skip]
2019-02-03 10:58:10 +02:00
alkesh26
79c3cef444 Railities typo fixes. 2019-02-01 16:42:40 +05:30
Eileen Uchitelle
1a4f613072 Rename methods and update docs
This is a minor update to the named methods for the following:

- s/desired_capabilities/capabilities
- s/driver_options/capabilities

Since they are all the same thing we should keep the name the same
throughout the feature.

Updated docs to match / be a little bit clearer

Also updated the Gemfile for selenium-webdriver.
2019-01-29 11:55:30 -05:00
Edouard CHIN
01a26e581f Implement a way to add browser capabilities:
* There is currently no way to define specific browser capabilities since our SystemTest driver override the `option` key [Ref](a07d068078/actionpack/lib/action_dispatch/system_testing/driver.rb (L35))
  This option key is used internally by selenium to add custom capabilities on the browser.

  Depending on the Browser, some option are allowed to be passed inside a hash, the driver takes care of setting whatever you passed on the driver option. An example [here](a07d068078/actionpack/lib/action_dispatch/system_testing/driver.rb (L35)) where you are allowed to pass args such as `--no-sandbox` etc
  However this behavior was only meant for backward compatibility and as you can see it's deprecated.
  The non-deprecated behavior is to create a `<Driver>::Option` object containing all the capabilities we want. This is what we [currently do](a07d068078/actionpack/lib/action_dispatch/system_testing/browser.rb (L34-L36)) when chrome or firefox are in headless mode.

  This PR allows to pass a block when calling `driven_by`, the block will be pased a `<Driver>::Option` instance. You can modify this object the way you want by adding any capabilities. The option object will be then passed to selenium.

  ```ruby
    driven_by :selenium, using: :chrome do |driver_option|
      driver_option.add_argument('--no-sandbox')
      driver_option.add_emulation(device: 'iphone 4')
    end
  ```
2019-01-29 08:50:29 -05:00
Rafael França
d1456e3ad5
Merge pull request #34993 from schuetzm/allow-subdomains-of-localhost
Subdomains of localhost are safe against DNS rebinding
2019-01-23 13:15:15 -05:00
Marc Schütz
4dfb1a3961 Subdomains of localhost are safe against DNS rebinding 2019-01-23 13:30:35 +01:00
bogdanvlviv
7ec67c1d31
Add Channel tests to rails stats
Rails generates `test/channels`(#34933) and
even allows `rails test:channels` (#34947).
`rails stats` has been providing info about `app/channels`,
it makes sense to add `test/channels` as well.

(I've changed test because we generate `test/channels` with some code)
2019-01-21 10:45:08 +00:00
Rafael Mendonça França
553b86fc75
Remove deprecated support to old config.ru that use the application class as argument of run 2019-01-17 16:08:34 -05:00
Rafael Mendonça França
e20589c9be
Remove deprecated environment argument from the rails commands 2019-01-17 16:08:34 -05:00
Rafael Mendonça França
46ac5fe69a
Remove deprecated config.secret_token 2019-01-17 16:08:34 -05:00
Rafael Mendonça França
f59b08119b
Change SQLite3Adapter to always represent boolean values as integers 2019-01-17 16:08:32 -05:00
Javan Makhmali
385d31d209 Minimize boilerplate setup code for JavaScript libraries 2019-01-16 16:15:43 -05:00
bogdanvlviv
d7097cf5e0
Add rails test:channels.
Add this rake task to test channels only.
We've added `rails test:mailboxes` recently in the same way #34828.
2019-01-16 16:34:34 +00:00
Kasper Timm Hansen
37c948ce67
Restructure credentials after environment overrides.
Follow up to: e0d3313

- Revert renames from `encrypted` and `encrypted_file` back to `credentials`.
  They might be using our Encrypted* generators but from that level of abstraction
  they're still about credentials.

- Same vein: extract a `credentials` method for the `encrypted` local variable. But
  don't call it `encrypted` just because it uses that under the hood. It's about
  capturing the credentials. It's also useful in `change_credentials_in_system_editor`.

- Remove lots of needless argument passing. We've abstracted content_path and key_path
  into methods for a reason, so they should be used. Also spares a conspicuous rename
  of content_path into file_path in other methods.

- Reorders private methods so they're grouped into: command building blocks, option
  parsers, and the generators.

- Extracts commonality in the credentials application tests. A tad unsure about this.
  But I do like that we go with key, content thus matching the command and remove the
  yield which isn't really needed.

- Moves test/credentials_test.rb to beneath the test/application directory. It's a
  Rails application test, so it should be in there.

- Uses `root.join` — a neat trick gleaned from the tests! — and composes the configuration
  private methods such that the building block is below the callers.
2019-01-14 20:13:00 +01:00
George Claghorn
512b5316dd
Add Exim and Qmail support to Action Mailbox 2019-01-12 21:38:26 -05:00
George Claghorn
58d52079c1
Merge pull request #34907 from wildbit/actionmailbox-postmark
Add Postmark ingress support to ActionMailbox
2019-01-09 19:07:11 -05:00
Tomek Maszkowski
b77d2d9a03 Added Postmark ingress support 2019-01-09 18:00:27 -05:00
Gannon McGibbon
e5f2d2906a Move MailDeliveryJob default to 6.0 defaults 2019-01-07 17:38:21 -05:00
bogdanvlviv
1d53654a98
Test Action Mailbox configurations
Related to 0d40c62213
2019-01-04 21:32:07 +02:00
George Claghorn
663f6cc14f
Send Active Storage jobs to dedicated queues by default
Match Action Mailbox, which sets a default queue for each of its two jobs.
2019-01-04 12:43:51 -05:00
Kasper Timm Hansen
6f0cda8f8e
Merge pull request #33985 from eugeneius/attribute_methods_schema_cache
Only define attribute methods from schema cache
2019-01-03 15:03:06 +01:00
George Claghorn
e7bcbf7b29
Add Rake task for testing mailboxes 2018-12-30 16:17:16 -05:00
George Claghorn
a5b2fff64c Import Action Mailbox 2018-12-25 21:32:35 -05:00
Yasuo Honda
05781f1f9c No need to handle if FrozenError is available
Rails 6 requires Ruby 2.5, which introduces `FrozenError`
https://docs.ruby-lang.org/en/2.5.0/NEWS.html

Related to #31520
2018-12-23 13:26:20 +00:00
Ryuta Kamizono
892e38c78e Enable Style/RedundantBegin cop to avoid newly adding redundant begin block
Currently we sometimes find a redundant begin block in code review
(e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205).

I'd like to enable `Style/RedundantBegin` cop to avoid that, since
rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5
(https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with
that situation than before.
2018-12-21 06:12:42 +09:00
Ryuta Kamizono
8034dde023 Module#{define_method,alias_method,undef_method,remove_method} become public since Ruby 2.5
https://bugs.ruby-lang.org/issues/14133
2018-12-21 01:39:18 +09:00
Kasper Timm Hansen
abae9d0e0a
Clarify implicit meaning of 'workers: 2' in parallelization tests. 2018-12-19 17:19:28 +01:00
Bogdan
e9f6ce617b Add option to set parallel test worker count to the physical core count of the machine (#34735)
* Add option to set parallel test worker count to the physical core count of the machine

Also, use the physical core count of the machine as
the default number of workers, and  generate the `test_helper.rb` file
with `parallelize(workers: :number_of_processors)`

Closes #34734

* Ensure that we always test parallel testing

Since #34734 we decided to use the physical core count of the machine as
the default number of workers in the parallel testing, we need to
ensure that some tests use at least 2 workers because we could
run those tests on VM that has only 1 physical core.
It also fixes tests failures on the CI since Travis server we are using
has only one physical core.
See https://travis-ci.org/rails/rails/jobs/469281088#L2352
2018-12-18 10:25:35 -08:00
Genadi Samokovarov
07ec8062e6 Introduce a guard against DNS rebinding attacks
The ActionDispatch::HostAuthorization is a new middleware that prevent
against DNS rebinding and other Host header attacks. By default it is
included only in the development environment with the following
configuration:

    Rails.application.config.hosts = [
      IPAddr.new("0.0.0.0/0"), # All IPv4 addresses.
      IPAddr.new("::/0"),      # All IPv6 addresses.
      "localhost"              # The localhost reserved domain.
    ]

In other environments, `Rails.application.config.hosts` is empty and no
Host header checks will be done. If you want to guard against header
attacks on production, you have to manually permit the allowed hosts
with:

    Rails.application.config.hosts << "product.com"

The host of a request is checked against the hosts entries with the case
operator (#===), which lets hosts support entries of type RegExp,
Proc and IPAddr to name a few. Here is an example with a regexp.

    # Allow requests from subdomains like `www.product.com` and
    # `beta1.product.com`.
    Rails.application.config.hosts << /.*\.product\.com/

A special case is supported that allows you to permit all sub-domains:

    # Allow requests from subdomains like `www.product.com` and
    # `beta1.product.com`.
    Rails.application.config.hosts << ".product.com"
2018-12-15 20:18:51 +02:00
Rafael Mendonça França
884310fdd0
Improve deprecation message for enqueue returning false
And make sure new applications in Rails 6.0 has this config enabled.

Also, improve test coverage and add a CHANGELOG entry.
2018-12-05 13:52:44 -05:00
Rafael França
25c076117c
Merge pull request #33882 from mberlanda/mberlanda/as-inheritable-options-intialization
[Realties] config_for as ActiveSupport::OrderedOptions
2018-11-30 11:42:44 -05:00
yuuji.yaginuma
6d854f9d07 Compile packs before run test
Sometimes `test_scaffold_tests_pass_by_default` test fails in CI.
https://travis-ci.org/rails/rails/jobs/457621750#L2095-L2120
It seems `manifest.json` was broken.

`webpacker` will compile automatically if packs is not compiled.
If parallel test is enabled, it seems that this compilation process is
executed simultaneously in multiple processes, and it may become an
inconsistent state.
In order to avoid this, compile before running the test.
2018-11-22 18:20:28 +09:00
yuuji.yaginuma
90266a7f1e Correctly handle unknown object in parallel tests
DRb wraps in `DRbUnknown` if the data contains a type that can not be
resolved locally. This can happen if an error occurs in the test and the
error class can not be resolved on the server side.

When this happens, an instance of `DRbUnknown` is passed to the `result`
of `Server#record`. This causes another error(undefined method assertions
for #<DRb::DRbUnknown:> (NoMethodError)) in `reporter.record`.
This can confirm by the following steps.

```
$ rails new app -B --dev; cd app
$ rails g scaffold user name:string
$ edit `config.action_controller.allow_forgery_protection = true` in environments/test.rb
$ bin/rails t
```

In the case of `DRbUnknown` occurs, can't resolve error exception. So wrap
exception with `DRbRemoteError` in the same way as an unmarshalled object.
2018-11-17 13:56:51 +09:00
Rafael França
0b75743e34
Merge pull request #34400 from gmcgibbon/rm_autoload_app_javascripts
Remove asset paths from autoload_paths
2018-11-13 17:53:55 -05:00
Rafael França
6741e70518
Merge pull request #34411 from N0xFF/master
Reset Capybara sessions if failed system test screenshot raising an exception
2018-11-13 17:21:04 -05:00
Yasuo Honda
8ac8396259 Ignore warnings such as Psych.safe_load is deprecated
Addressing warnings are important but it should be out of this test scope.

https://travis-ci.org/rails/rails/jobs/454145524#L4122-L4131

```
.F
Failure:
ApplicationTests::BinSetupTest#test_bin_setup_output [test/application/bin_setup_test.rb:49]:
--- expected
+++ actual
@@ -1,4 +1,5 @@
 "== Installing dependencies ==
+warning: Passing permitted_classes with the 2nd argument of Psych.safe_load is deprecated. Use keyword argument like Psych.safe_load(yaml, permitted_classes: ...) instead.
 The Gemfile's dependencies are satisfied

 == Preparing database ==
rails test test/application/bin_setup_test.rb:38
```
2018-11-13 11:19:03 +00:00
Maxim Perepelitsa
59895db44b Reset sessions on failed system test screenshot
Reset Capybara sessions if `take_failed_screenshot` raise exception
in system test `after_teardown`.
2018-11-13 03:30:41 +07:00
Gannon McGibbon
cffbf73a47 Remove asset paths from eager_load_paths and autoload_paths
Remove `app/assets` and `app/javascript` from `eager_load_paths`
and `autoload_paths`.
2018-11-09 14:48:15 -05:00
yuuji.yaginuma
9bd5fc84cc Add test for parallel tests with unmarshable exception
Follow up #34131.
2018-11-09 18:25:26 +09:00
bogdanvlviv
a444bae3f2
Remove unused argument expected_database
This argument was added in fa5a028ed9f, and #34137 but hasn't been used.
2018-11-08 16:12:34 +02:00
yuuji.yaginuma
7f7e7e8b39 Compile packs for test
`Webpacker` handles testing / development packs separately by default.
If do not specify `RAILS_ENV`, there is no merit to precompile.
2018-11-08 12:21:25 +09:00
Gannon McGibbon
ac18bda92d Add multi-db support to schema cache dump and clear
Adds support for multiple databases to `rails db:schema:cache:dump`
and `rails db:schema:cache:clear`.
2018-11-07 14:11:46 -05:00
Mauro Berlanda
264152af2b
chore: implement config_for as ActiveSupport::OrderedOptions 2018-10-19 14:37:06 +02:00
Yoshiyuki Kinjo
32b03b4615 Implement AR#inspect using ParamterFilter.
AR instance support `filter_parameters` since #33756.
Though Regex or Proc is valid as `filter_parameters`,
they are not supported as AR#inspect.

I also add :mask option and #filter_params to
`ActiveSupport::ParameterFilter#new` to implement this.
2018-10-19 14:16:03 +09:00
Gannon McGibbon
287c0de8a1 Add multi-db support to rails db:migrate:status 2018-10-09 16:40:06 -04:00
Gannon McGibbon
b596346038 Remove bundler warnings from bin/setup output 2018-10-05 15:37:00 -04:00
David Heinemeier Hansson
4838c1716a
Make Webpacker the default JavaScript compiler for Rails 6 (#33079)
* Use Webpacker by default on new apps

* Stop including coffee-rails by default

* Drop using a js_compressor by default

* Drop extra test for coffeescript inclusion by default

* Stick with skip_javascript to signify skipping webpack

* Don't install a JS runtime by default any more

* app/javascript will be the new default directory for JS

* Make it clear that this is just for configuring the default Webpack framework setup now

* Start using the Webpack tag in the default layout

* Irrelevant test

* jQuery is long gone

* Stop having asset pipeline compile default application.js

* Add rails-ujs by default to the Webpack setup

* Add Active Storage JavaScript to application.js pack by default

* Consistent quoting

* Add Turbolinks to default pack

* Add Action Cable to default pack

Need some work on how to set the global consumer that channels will
work with. @javan?

* Require all channels by default and use a separate consumer stub

* Channel generator now targets Webpack style

* Update task docs to match new generator style

* Use uniform import style

* Drop the JS assets generator

It was barely helpful as it was. It’s no longer helpful in a Webpacked
world. Sayonara!

* Add app/javascript to the stats directories

* Simpler import style

Which match the other imports.

* Address test failures from dropping JS compilation (and compression)

* webpacker-default: Modify `AssetsGeneratorTest`

Before:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 46201

F

Failure:
AssetsGeneratorTest#test_assets [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:12]:
Expected file "app/assets/javascripts/posts.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/assets_generator_test.rb:10

.

Finished in 0.031343s, 63.8101 runs/s, 95.7152 assertions/s.
2 runs, 3 assertions, 1 failures, 0 errors, 0 skips
```

After:

```
$ bin/test test/generators/assets_generator_test.rb
Run options: --seed 43571

..

Finished in 0.030370s, 65.8545 runs/s, 65.8545 assertions/s.
2 runs, 2 assertions, 0 failures, 0 errors, 0 skips
```

* webpacker-default: Modify `ChannelGeneratorTest`

Before:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 8986

.F

Failure:
ChannelGeneratorTest#test_channel_with_multiple_actions_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:43]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:34

.F

Failure:
ChannelGeneratorTest#test_channel_is_created [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:29]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:22

E

Error:
ChannelGeneratorTest#test_cable_js_is_created_if_not_present_already:
Errno::ENOENT: No such file or directory @ apply2files - /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/fixtures/tmp/app/assets/javascripts/cable.js

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:60

F

Failure:
ChannelGeneratorTest#test_channel_suffix_is_not_duplicated [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:87]:
Expected file "app/assets/javascripts/channels/chat.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:80

F

Failure:
ChannelGeneratorTest#test_channel_on_revoke [/Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:77]:
Expected file "app/assets/javascripts/cable.js" to exist, but does not

bin/test /Users/ttanimichi/ghq/github.com/ttanimichi/rails/railties/test/generators/channel_generator_test.rb:68

Finished in 0.064384s, 108.7227 runs/s, 481.4861 assertions/s.
7 runs, 31 assertions, 4 failures, 1 errors, 0 skips
```

After:

```
$ bin/test test/generators/channel_generator_test.rb
Run options: --seed 44857

.......

Finished in 0.060243s, 116.1961 runs/s, 697.1764 assertions/s.
7 runs, 42 assertions, 0 failures, 0 errors, 0 skips
```

* Fix shared generator tests.

* webpacker-default: Modify `ControllerGeneratorTest`

The JS assets generator was dropped. ref. 46215b1794

* Revert "Simpler import style". It's currently failing with an error of "TypeError: undefined is not an object (evaluating '__WEBPACK_IMPORTED_MODULE_2_activestorage___default.a.start')". Waiting for @javan to have a look.

This reverts commit 5d3ebb71059f635d3756cbda4ab9752027e09256.

* require webpacker in test app

* Add webpacker without making the build hang/timeout. (#33640)

* use yarn workspaces to allow for installing unreleased packages and only generate js/bootsnap when required

* no longer need to have webpacker in env templates as webpacker moved this config to yml file

* Fix rubocop violation

* Got the test passing for the running scaffold

* update expected lines of code

* update middleware tests to account for webpacker

* disable js in plugins be default to get the tests passing (#34009)

* clear codeclimate report issues

* Anything newer than currently released is good

* Use Webpacker development version during development of Rails

* Edge should get development webpacker as well

* Add changelog entry for Webpacker change
2018-09-30 22:31:21 -07:00
Eugene Kenny
0007501669 Only define attribute methods from schema cache
To define the attribute methods for a model, Active Record needs to know
the schema of the underlying table, which is usually achieved by making
a request to the database. This is undesirable behaviour while the app
is booting, for two reasons: it makes the boot process dependent on the
availability of the database, and it means every new process will make
one query for each table, which can cause issues for large applications.

However, if the application is using the schema cache dump feature, then
the schema cache already contains the necessary information, and we can
define the attribute methods without causing any extra database queries.
2018-09-28 21:16:21 +01:00
Eugene Kenny
3b954786e7 Eagerly define attribute methods in production
The attribute methods for a model are currently defined lazily the first
time that model is instantiated, even when `config.eager_load` is true.
This means the first request to use each model incurs the cost, which
usually involves a database round trip to fetch the schema definition.

By defining the attribute methods for all models while the application
is booting, we move that work out of any individual request. When using
a forking web server, this also reduces the number of times the schema
definition is queried by doing it once in the parent process instead of
from each forked process during their first request.
2018-09-24 03:20:35 +01:00
Rafael Mendonça França
d3b952184d
Make sure this test check the issue solved in #31135
Before this change this test was passing even if we revert #31135. The
reason for that is that `app 'development'` will load the environment in
the test process and it is happening before db_create_and_drop is
called.

This was not asserting that the environment was loaded in the db:create
task itself.

To test it we enhance the db:create task with a block that writes to a
tmp file the value of the config. If the environment is loaded before
that task enhancement runs the content of the file will have "true"
insteand of "false".
2018-09-22 00:46:44 -04:00
schneems
3424bd83d6 Switch to supports_cache_versioning? check to a class method
- Moving the `supports_cache_versioning?` check to a class method. 
- Shorten the method doc. 
- Expand on the error message.
2018-09-20 20:40:31 -05:00
schneems
135d3e15b7 [close #33907] Error when using "recyclable" cache keys with a store that does not support it
If you are using the "in cache versioning" also known as "recyclable cache keys" the cache store must be aware of this scheme, otherwise you will generate cache entries that never invalidate.

This PR adds a check to the initialization process to ensure that if recyclable cache keys are being used via 

```
config.active_record.cache_versioning = true
```

Then the cache store needs to show that it supports this versioning scheme. Cache stores can let Rails know that they support this scheme by adding a method `supports_in_cache_versioning?` and returning true.
2018-09-20 15:31:38 -05:00
yuuji.yaginuma
70b5a7594e Add test for config.active_storage.routes_prefix
Follow up #33883.
2018-09-15 10:22:04 +09:00
Rafael Mendonça França
a8359d837c
Add a test that exercice better the behavior we expect in the query cache
In production the query cache was already being loaded before the first
request even without #33856, so added a test to make sure of it.

This new test is passing even if #33856 is reverted.
2018-09-12 20:57:52 -04:00
bogdanvlviv
d1a14865e0
Build string set when filter_attributes is assigned
It would allow `filter_attributes` to be reused across multiple
calls to `#inspect` or `#pretty_print`.

- Add `require "set"`
- Remove `filter_attributes` instance reader. I think there is no need
to keep it.
2018-09-12 18:51:55 +03:00
Eileen Uchitelle
349db176d8 Fix query cache to load before first request
In a test app we observed that the query cache was not enabled on the
first request. This was because the query cache hooks are installed on
load and active record is loaded in the middle of the first request.

If we remove the `on_load` from the railtie the query cache hooks will
be installed before the first request, allowing the cache to be enabled
on that first request.

This is ok because query cache doesn't load anything else, only itself
so we're not eager loading all of active record before the first
request, just the query cache hooks.

[Eileen M. Uchitelle & Matthew Draper]
2018-09-12 10:09:59 -04:00
Rafael França
21b32bb2a8
Merge pull request #33815 from mberlanda/mberlanda/enhance-config-for
Use ActiveSupport::InheritableOptions and deep_symbolize_keys in config_for
2018-09-11 18:26:59 -04:00
Mauro Berlanda
b167d521ab
refacto: config_for with ActiveSupport::InheritableOptions and symbolized keys 2018-09-11 23:47:41 +02:00
yuuji.yaginuma
5b0b1ee8fd Use correct variable
Follow up of 3e81490717a314437f9123d86fa3e9dc55558e95.
2018-09-11 07:06:30 +09:00