Commit Graph

76118 Commits

Author SHA1 Message Date
Rafael França d2d8b2892d
Merge pull request #38702 from aditya-vector/activejob-jitter-documentation-update
Updates to ActiveJob::Exceptions.retry_on with jitter documentation [skip ci]
2020-03-11 13:43:19 -04:00
Rafael França 08cbf44287
Merge pull request #38686 from Edouard-chin/ec-job-test-adapter
AJ `perform_enqueued_jobs` shouldn't perform job retries:
2020-03-11 13:41:58 -04:00
Aditya Narsapurkar 895c39fe96 Updates to ActiveJob::Exceptions.retry_on with jitter documentation [skip ci]
- Changelog updated
- Method documentation updated
2020-03-11 21:49:55 +05:30
Rafael França 2f1fefe456
Merge pull request #38693 from yahonda/explain_parallel_workers_example
[skip ci] How to run Action View and Action Pack unit test in serial
2020-03-10 15:13:29 -04:00
Rafael França 30d092d26b
Merge pull request #38694 from nateberkopec/patch-2
Fix exceptions raised/rescued in dev by IPAddr
2020-03-10 15:10:34 -04:00
Nate Berkopec 670026737b
Fix exceptions raised/rescued in dev by IPAddr
Putting ".localhost" at the end causes 4 IPAddr::InvalidAddressError
exceptions to be raised and rescued during every request when the
HostAuthorization middleware attempts to compare an IPAddr with a
"localhost" string.
2020-03-10 12:40:23 -06:00
Dino Maric 2a0823ecba Support creating variants of `webp` images out of the box
This PR adds `image/webp` to the default array of variable content
types. Without this commit if we want to "handle" webp images
overwriting `config.active_storage.variable_content_types` was
necessary.
2020-03-10 12:38:17 -04:00
Yasuo Honda 368dcdd0e7 [skip ci] How to run Action View and Action Pack unit test in serial
Follow up #38613 and #38094

Action View and Action Pack unit tests run in parallel by default
and the number of parallel workers is defined by `PARALLEL_WORKERS` value.

To investigate some random failures with SEED,
Disabling Parallel testing sometimes helps to isolate these failures.
2020-03-10 22:47:37 +09:00
Ryuta Kamizono 1ef8c60dfc Avoid extra string allocation in the methods generated by eval 2020-03-10 17:43:35 +09:00
Ryuta Kamizono d5be4f1a46 Always respond to `set_server_option` since mysql2 0.5.0
https://github.com/brianmario/mysql2/pull/943
https://github.com/rails/rails/pull/37191
2020-03-10 17:20:45 +09:00
Rafael França a3f4a62e2c
Merge pull request #38677 from eugeneius/index_by_index_with_docs
Clarify index_by and index_with docs [ci skip]
2020-03-09 22:18:21 -04:00
Edouard CHIN 17e304def8 AJ `perform_enqueued_jobs` shouldn't perform job retries:
- ### Problem

  If we use `perform_enqueued_jobs` without a block, a job that
  uses a retry mechanism to reeenqueue itself would get performed
  right away.
  This behaviour make sense when using `perform_enqueued_jobs` with
  a block.

  However I'm expecting `perform_enqueued_jobs` without a block to
  perform jobs that are **already** in the queue not the ones that
  will get enqueued afterwards.

  ### Solution

  Dup the array of jobs given to avoid future mutation.
2020-03-09 19:46:11 -04:00
Edouard CHIN 13cb5b78a8 Fix AJ `TestAdapter#performed_jobs` not properly counting job:
- ### Problem

  If we use `perform_enqueued_jobs` without a block,
  a job that raises an error wouldn't be appended to
  the list of `performed_jobs`.

  ### Solution

  Push the job in the array before it is actually performed.
2020-03-09 19:46:11 -04:00
Eugene Kenny 94b7453089 Clarify index_by and index_with docs [ci skip]
Make it clearer how the key and value are derived in both cases, and use
the same sentence structure so that it's easier understand one method in
terms of the other.

Also add an example of passing a default value to `index_with`.
2020-03-09 22:33:12 +00:00
Rafael França fc764f0639
Merge pull request #38662 from olivierlacan/doc/update-windows-setup
Stop recommending RailsInstaller in favor of RubyInstaller
2020-03-09 13:57:07 -04:00
Eileen M. Uchitelle 9519c1aadc
Merge pull request #38684 from eileencodes/refactor-schema-migration
Refactor schema migration on connection
2020-03-09 12:05:10 -04: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
Atul Bhosale ec69083cf3
Add method ActionCable::Channel#stream_or_reject_for to stream if record is present, otherwise reject the connection (#38375) 2020-03-07 10:09:08 -08:00
Eileen M. Uchitelle e00f9c8aae
Merge pull request #38672 from eileencodes/remove-owner_name
Remove owner_name
2020-03-07 10:06:50 -05:00
eileencodes 7400d195e2
Remove owner_name
We don't actually need this since the only reason it exists is to pass
the owning class name down to the `handler`. This removes a level of
indirection and an unnecessary accessor on db_config. db_config
shouldn't have to know what class owns it, so we can just remove this
and pass it to the handler.

The Symbol case is needed to preserve current behavior. This doesn't
need a changelog because it's changing un-released behavior.

Co-authored-by: John Crepezzi <john.crepezzi@gmail.com>
2020-03-07 09:00:43 -05:00
Eileen M. Uchitelle 526dd6472b
Merge pull request #38670 from eileencodes/remove-unnecessary-lines
Remove unnecessary creation of new hash config
2020-03-06 17:35:32 -05:00
eileencodes 1da6a90699
Remove unnecessary creation of new hash config
This line was creating a new hash config, but we should always have a
hash config to lookup at this point.

Previously we needed this code because the pool name was merged into the
hash. Now it's an accessor on the db_config, so we have no reason to
create a new hash config.

Also, change env_name to name since it's only an env in a single db
application or an application with no arguments for
establish_connection.
2020-03-06 16:43:23 -05:00
eileencodes 0946cb929c
Move nil config_or_env handling
`config_or_env` can only be `nil` if called by `establish_connection`.
If `connects_to` had a `connects_to database: { writing: nil }` that
would make no sense.

This is a really minor refactoring that moves the assignment if `nil`
into the only method that can actually receive nil. Then
`resolve_config_for_connection` will never get nil passed to it.
2020-03-06 15:57:58 -05:00
eileencodes 67b102a57f
Add erb tests for multi-db
If I had had these tests previously I would have not created PR #38658
and then promptly realize I needed to revert it.

We need to load and parse the configurations twice. Once before the
environment is loaded to create the named tasks and once after the
environment is loaded to have the real configurations. The configs
loaded before the env have the ERB stripped out and aren't valid
configs.
2020-03-06 11:23:43 -05:00
eileencodes 2dcf07a53a
Fix test name
Wow this is embarrassing. I literally named this FIXME so I'd remember
to give it some name that made sense and then I totally did not.
2020-03-06 10:01:14 -05:00
eileencodes 150fcf7b37
Fix database configruation for multi-db
The key, value is `replica: true` not `readonly: true`. Fix the database
configuration to be correct.
2020-03-06 09:33:18 -05:00
Eileen M. Uchitelle 712cee1741
Merge pull request #38665 from roramirez/test-master-new-app
Add tests for --master app_generator
2020-03-06 08:40:28 -05:00
Olivier Lacan 39ba2915e5 Stop recommending RailsInstaller in favor of RubyInstaller
RailsInstaller is no longer maintained and its latest supported Ruby
version is 2.3 which Rails no longer supports.

In contrast, RubyInstaller supports Ruby 2.7, 2.6, 2.5, 2.4, 2.3, and 2.2 which
are the only Ruby versions necessary for Rails 6.x and 5.x at this point.

Fixes #38654

[ci skip]
2020-03-05 18:56:38 -05:00
Eileen M. Uchitelle 82d7e3e217
Merge pull request #38661 from eileencodes/revert-refactor-on-for-each
Revert "Merge pull request #38658 from eileencodes/refactor-for-each-…
2020-03-05 18:20:51 -05:00
eileencodes 2d37ea04c8
Revert "Merge pull request #38658 from eileencodes/refactor-for-each-databases-code"
This reverts commit 9a5bc246d7, reversing
changes made to 227ff44e36.

I realized afterwards that this was written this way for a reason and it
wasn't accidental. The databases loaded in `for_each` are not complete
database configs because these are generated from the database yaml
before the Rails env is loaded. So we actually do need to refetch the
correct database configuration objects after we've loaded the Rails env.
2020-03-05 18:15:47 -05:00
Rafael Mendonça França cfd1ed5a32
Add attribution to the author
Closes #38648
2020-03-05 18:08:41 -05:00
Rafael França fb3ab475ad
Merge pull request #38657 from headius/optimize_string_inquirer
Use optimized subclass of StringInquirer for Rails.env
2020-03-05 17:13:15 -05:00
Rodrigo Ramírez Norambuena 3b882deb0c Add tests for --master app_generator
These tests verify is added the entry into the Gemfile using
`branch: "master"` for Rails and web-console from Github for
:development
2020-03-05 18:39:03 -03:00
Charles Oliver Nutter 09e0372532
Use optimized subclass of StringInquirer for Rails.env
This adds a StringInquirer subclass EnvironmentInquirer that
predefines the three default environments as query methods, in
order to avoid dispatching through `method_missing` for every call
to those methods. The original StringInquirer was not modified due
to the side effects of having new env-related methods on it. This
new class was not implemented using lazy method definition to
avoid the open-ended possibility of defining a new method for all
query calls. The three default environments should cover a high
percentage of real-world uses, and users with custom environments
could add their own to this class.

Fixes #37803.
2020-03-05 14:57:27 -06:00
Eileen M. Uchitelle 9a5bc246d7
Merge pull request #38658 from eileencodes/refactor-for-each-databases-code
Refactor for_each(databases) code
2020-03-05 14:59:18 -05:00
eileencodes 37f35aba80
Refactor for_each(databases) code
While working on something else I noticed this code was duplicated. It
was returning `name` from `for_each` and then we'd have to lookup the
`db_config` again from the `name` and `env`. We can instead just return
`db_config` from `for_each` and clean up these tasks a little bit.
2020-03-05 14:32:09 -05:00
Aaron Patterson 227ff44e36
Revert "Merge pull request #37808 from headius/optimize_string_inquirer"
This reverts commit 9e5c6c4c84, reversing
changes made to 3aacd855cd.
2020-03-05 11:12:14 -08:00
Aaron Patterson 9e5c6c4c84
Merge pull request #37808 from headius/optimize_string_inquirer
Use optimized subclass of StringInquirer for Rails.env
2020-03-05 10:00:20 -08:00
Aditya Narsapurkar 3aacd855cd parent 6d0895a489
author Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1582316102 +0530
committer Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1583159505 +0530

parent 6d0895a489
author Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1582316102 +0530
committer Aditya Narsapurkar <adityanarsapurkar@yahoo.com> 1583159327 +0530

Randomize jitter
- This PR attempts to fix a problem with ActiveJob jitter where the `determine_jitter_for_delay` value may not always be randomized. Especially when the jitter delay multplier is between 1 and 2 it always returns 0.
- With this change, we pass a range to `Kernel.rand` beginning with 0 to the `jitter_multiplier`. With positive float values, the return value will be a random float number from the range.
- Includes test cases to verify random wait time when the jitter_multiplier is between 1 and 2.
- Updated relevant test cases stubbing the `Kernel.rand` method, refactored some by removing unwanted stubs for `Kernel.rand` method where jitter is falsey.

Fixed rubocop issue - used assert_not_equal instead of refute_equal in test case

Fixed rubocop issue - used assert_not_equal instead of refute_equal in test case

Fixed rubocop issue - used assert_not_equal instead of refute_equal in test case

Review updates - separated test cases for random wait time with default and exponentially retrying jobs
- Another test case added to make sure negative wait time does not affect the randomization

Review updates
- Instead of using Kernel.rand with range, used simple multiplication with Kernel.rand for calculating delay for jitter
- Updates to the tests according to changes
2020-03-05 07:45:33 -08:00
Kasper Timm Hansen aeac2f5216
Merge pull request #38646 from eugeneius/index_by_index_with
Use index_by and index_with wherever possible
2020-03-05 02:50:44 +01:00
Eugene Kenny d3599d8aff Use index_by and index_with wherever possible
Using `index_by` or `index_with` is more concise than `each_with_object`
and more performant than `map { ... }.to_h` or `Hash[map { ... }]`.
2020-03-05 01:24:14 +00:00
Rafael França 6a1759a085
Merge pull request #38641 from yashLadha/refactor/query_methods
refactor: Refactored code in functions of query_methods.
2020-03-04 16:04:21 -05:00
Xavier Noria bf60ed36d0
Merge pull request #38644 from andreleoni/master
Remove unused space from disk controller of activestorage
2020-03-04 21:42:03 +01:00
André Leoni a5789e7a90 Remove unused space from disk controller of activestorage 2020-03-04 17:22:56 -03:00
Yash Ladha 373e1fc44c
refactor: Refactored code in functions of query_methods.
This is done because concerns of respective steps can be separated,
which in turns leads to easier walkthrough and verbosity. Also
stretching a function to large horizontal bounds doesn't looks good.
2020-03-05 01:10:50 +05:30
Rafael França 35c2620d23
Merge pull request #38631 from Schwad/master
Allow `rails new . --master` to point to master branch
2020-03-04 13:41:54 -05:00
Rafael França 1caaa79cea
Merge pull request #38642 from frenesim/frenesim-patch-1
Properly close a tag to avoid errors with some ruby versions
2020-03-04 13:41:23 -05:00
Nick Schwaderer 6d15fab8ec
Update railties/lib/rails/generators/app_base.rb
Co-Authored-By: Rafael França <rafael@franca.dev>
2020-03-04 17:18:35 +00:00
Xavier Noria fcc8c6868c \Z -> \z
Here we want end of string, no optional newlines are to
be expected, so \z is more concise.
2020-03-04 18:16:30 +01:00
Xavier Noria 09b15145d6
Merge pull request #38640 from Shopify/module_parent_name_dedup
Deduplicate Module#module_parent_name cache
2020-03-04 18:13:38 +01:00