Commit Graph

81032 Commits

Author SHA1 Message Date
Breno Gazzola a3de68b66b Update active storage guide to match recent PRs 2021-07-09 15:44:36 -03:00
Zachary Scott d45baa3444 💅 remove space before colon on config list 2021-07-09 16:39:42 +09:00
Jonathan Hefner afc6abb674
Merge pull request #42736 from FestaLab/improve-contributing-guide
Ask contributors to update the documentation [ci-skip]
2021-07-08 15:02:56 -05:00
Breno Gazzola 74acfa394f Ask contributors to update the documentation 2021-07-08 16:53:50 -03:00
Ryuta Kamizono de8d345323
Merge pull request #42726 from dark-panda/truncate-actioncable-server-logging
Truncate more ActionCable broadcast messages to 300 chars
2021-07-09 02:43:15 +09:00
Ryuta Kamizono f01166ddea
Merge pull request #42728 from ghiculescu/patch-4
Handle paths with spaces when editing credentials
2021-07-09 02:12:01 +09:00
Ryuta Kamizono f189e4c4a4
Merge pull request #42733 from okuramasafumi/small-improvements-on-active-model
Small improvements on active model
2021-07-09 02:03:57 +09:00
Alex Ghiculescu 5ca37eae12 Handle paths with spaces when editing credentials
Fixes https://github.com/rails/rails/issues/41617

Co-authored-by: Alexander Riccio <alexander@riccio.com>
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2021-07-08 11:47:44 -05:00
OKURA Masafumi 67adc94e00 Add `:nodoc` to `ActiveModel::Errors`
Three classes in `active_model/errors` look internal only.
2021-07-09 00:01:10 +09:00
OKURA Masafumi f96929ae5f Add missing require to `active_model/naming`
Using `delegate` at L151 causes `NoMethodError`.
Adding `require` resolves this.
2021-07-08 23:02:09 +09:00
Jean Boussier 317547e0e7
Merge pull request #42729 from Shopify/fix-has-many-inversing-remove
Fix clearing the inverse relation when has_many_inversing is enabled
2021-07-08 12:18:14 +02:00
Jean Boussier 6d7235dd20 Fix clearing the inverse relation when has_many_inversing is enabled
https://github.com/rails/rails/pull/42601 fixed clearing the inverse relation,
but it didn't account for collection associations.

For these, just assigning `nil` isn't possible because we need the record to
remove it from the collection.

So this PR introduce an explicit method for this purpose rather than
reuse `inversed_from(nil)`.
2021-07-08 11:25:32 +02:00
Jean Boussier 197fb159ec
Merge pull request #42666 from justin808/patch-1
Improve logging of schema cache at startup.
2021-07-08 10:02:41 +02:00
Justin Gordon 9f9c1bf79e Improve logging of schema cache at startup.
This allows verification if the schema cache was used at startup.
2021-07-07 21:33:00 -10:00
Rafael França 37fb99e2c5
Merge pull request #41283 from tywhang/more_accurate_error_for_missing_file
Handle error when file does not exist at filepath
2021-07-07 18:36:34 -04:00
Rafael França 831031a8ce
Merge pull request #42674 from ghiculescu/verify-fk-after-fixture-insert
Verify foreign keys after loading fixtures
2021-07-07 17:38:15 -04:00
Alex Ghiculescu 47467fe33d Verify foreign keys after loading fixtures
When writing fixtures, it's currently possible to define associations that don't exist, even if a foreign key exists. For example:

```yml
george:
  name: "Curious George"
  pirate: redbeard

blackbeard:
  name: "Blackbeard"
 ```

When the fixtures are created, `parrots(:george).pirate` will be nil, but it's not immediately clear why. This can make it hard to debug tests and can give false confidence in passing ones.

This can happen because Rails [disables referential integrity](f263530bf7/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb (L407)) when inserting fixtures. This makes the fixtures algorithm much simpler - it can just create the fixtures in alphabetical order and assume that the other side of a foreign key constraint will *eventually* be added.

Ideally we would check foreign keys once all fixtures have been loaded, so that we can be sure that the foreign key constraints were met. This PR introduces that. To enable it:

```ruby
config.active_record.verify_foreign_keys_for_fixtures = true
```

I'm proposing we enable this in 7.0 for new apps and have added it to new framework defaults. When run against our app, it found 3 fixture files with unmet FK constraints - turns out all those fixtures weren't being used and were safe to delete.
2021-07-07 15:41:05 -05:00
Rafael França 0fc31fe28a
Merge pull request #42719 from jdelStrother/hash-optimization
Micro-optimize ActiveRecord::Core#hash
2021-07-07 15:06:49 -04:00
Jonathan del Strother 0c25a0baee
Micro-optimize ActiveRecord::Core#hash
Avoids calling _read_attribute("id") more than necessary

```ruby
require "active_record"
require "benchmark/ips"

ActiveRecord::Base.establish_connection(adapter: "sqlite3", database:  ":memory:")
ActiveRecord::Base.connection.create_table :users do |t|
  t.text :name
end

class User < ActiveRecord::Base
  # This is the current implementation from ActiveRecord::Core
  def hash
    if id
      self.class.hash ^ id.hash
    else
      super
    end
  end
end
class UserFastHash < ActiveRecord::Base
  self.table_name = "users"
  def hash
    if i = id
      self.class.hash ^ i.hash
    else
      super
    end
  end
end

1_000.times { |i| User.create(name: "test #{i}") }
slow_users = User.take(1000)
fast_users = UserFastHash.take(1000)

Benchmark.ips do |x|
  x.report("slowhash") {
    hash = {}
    slow_users.each { |u| hash[u] = 1 }
  }
  x.report("fasthash") {
    hash = {}
    fast_users.each { |u| hash[u] = 1 }
  }
  x.compare!
end
```

```
Warming up --------------------------------------
            slowhash   129.000  i/100ms
            fasthash   177.000  i/100ms
Calculating -------------------------------------
            slowhash      1.307k (± 0.7%) i/s -      6.579k in   5.033141s
            fasthash      1.764k (± 2.4%) i/s -      8.850k in   5.021749s

Comparison:
            fasthash:     1763.5 i/s
            slowhash:     1307.2 i/s - 1.35x  (± 0.00) slower
```
2021-07-07 19:07:22 +01:00
J Smith 460735e03f Truncate more ActionCable broadcast messages to 300 chars
Truncation to ActionCable logging was added way back in 2016, but here's
another location where the logging messages can get out of hand.
2021-07-07 14:52:29 -03:00
Rafael França e9559f45a8
Merge pull request #42722 from p8/railties/add-missing-new-defaults
Add missing new defaults to new_framework_defaults_7_0.rb.tt
2021-07-07 13:32:34 -04:00
Rafael França 2d1e6aea58
Merge pull request #42655 from ghiculescu/middleware-delete-raise
Deleting an item from the Middleware stack should raise if the item is not found
2021-07-07 13:22:01 -04:00
Petrik 4d3a8a0bf0 Add missing new defaults to new_framework_defaults_7_0.rb.tt
`railties/lib/rails/application/configuration.rb` contains defaults that
haven't been added to the `new_framework_defaults_7_0.rb.tt`.
This adds these defaults to ease migration.
2021-07-07 19:08:10 +02:00
Rafael França b995208587
Merge pull request #42703 from ceritium/fix-active-storage-guide-links
Fix ActiveStorage guide links [ci-skip]
2021-07-07 12:09:21 -04:00
Rafael França 28fbdfc8db
Merge pull request #42720 from p8/railties/framework-defaults-rewording
Clarify new_framework_defaults instructions
2021-07-07 10:32:53 -04:00
Petrik 34d0b3d7cf Clarify new_framework_defaults instructions
Framework defaults cause confusion for contributors when adding new
defaults. Should the defaults be defined in:
`railties/lib/rails/application/configuration.rb` and/or
`config/initializers/new_framework_defaults_7_0.rb.tt`
And should these define the new or old defaults?

Hopefully this clarifies it by making it clear the
new framework defaults are commented out.
By mentioning `config.load_defaults` it hopefully clarifies that these
defaults should be similar to the onces defined by `load_defaults`.

Also reword "flip" to "uncomment" to make it clear you should uncomment
the config instead of setting `true` to `false`.
2021-07-07 12:29:27 +02:00
Zachary Scott 7373b5819a 💅 complete sentence in railties/CHANGELOG 2021-07-07 08:20:18 +09:00
Guillermo Iguaran 9f33178a2d
Merge pull request #42714 from robertomiranda/patch-3
destroy_all_in_batches is off by default for newly generated Rails apps.
2021-07-06 11:50:27 -07:00
Roberto Miranda 7834a783b8
destroy_all_in_batches is off by default for newly generated Rails apps.
Following up https://github.com/rails/rails/pull/42673#issuecomment-874744582
2021-07-06 19:43:44 +01:00
Jean Boussier d305be0742
Merge pull request #42707 from skelz0r/bugfix/42698
config_for accepts root shared as an array
2021-07-06 12:22:53 +02:00
Loïc Delmaire 056b70ee4f
config_for accepts root shared as an array
Fix a bug introduced by
3fe0ab52df
that raised an undefined method when trying to deep merge an array with
an empty config hash

It also adds a test to clarify config_for behaviour with root arrays: when there's
an env array and a shared array, it should only returns the env key (and not a concatenation)

Closes #42698
2021-07-06 11:57:21 +02:00
Jean Boussier e7eac0ae3e
Merge pull request #42706 from nadrooJ/fix-record-not-destroyed-docs-typo
Fix link to incorrect method in API docs
2021-07-06 11:49:26 +02:00
Jordan 385c4a0771
Fix link to incorrect method in API docs 2021-07-06 10:21:32 +01:00
Jose Galisteo 5ff7116117 Fix ActiveStorage guide links [ci-skip] 2021-07-05 20:46:21 +02:00
Ryuta Kamizono 398561bfbb
Merge pull request #42694 from p8/railties/generators-raise-on-invalid-index
Generators should raise an error if an attribute has an invalid index
2021-07-05 22:57:53 +09:00
Ryuta Kamizono 70bbc3706b
Merge pull request #42693 from p8/railties/format-framework-defaults
Remove linebreak from hash_digest_class framework defaults for consistency
2021-07-05 22:38:16 +09:00
Ryuta Kamizono e9e8ea2b20 :nodoc: `FakeRuntime` [ci skip]
People should not reference the fake class in their apps.
2021-07-05 18:12:19 +09:00
Ryuta Kamizono 5f45aeaaae :nodoc: for corrections
Like all others for corrections already does.
2021-07-05 17:59:22 +09:00
Ryuta Kamizono 32bac31cc0 Spell checking if `record` and `association_name` are provided for `AssociationNotFoundError` 2021-07-05 17:29:54 +09:00
Ryuta Kamizono 2f078aafad Migrate `DidYouMean.correct_error` to `DidYouMean::Correctable` for `MissingTemplate`
Follow up to #42333.
2021-07-05 15:47:07 +09:00
Ryuta Kamizono 4121014bff
Merge pull request #42333 from p8/didyoumean-remove-checks
Clean up checks to see if DidYouMean.correct_error is defined
2021-07-05 14:52:58 +09:00
Petrik 76f9b7531f Generators should raise an error if an attribute has an invalid index type
When passing an invalid index type to a generator, the index is silently
ignored. For example when misspelling the index:

    bin/rails g model post title:string:indxe

Instead of silently ignoring the invalid index, the generator should
raise an error.

This continues the work in d163fcd620
where we started raising errors if the attribute types are invalid.
2021-07-04 19:13:24 +02:00
Petrik e61ff2baa2 Remove linebreak from hash_digest framework defaults for consistency
All new 7.0 framework defaults don't have an extra linebreak between the
explanation and the actual config.
For consistency we should remove it for `hash_digest_class` as well.
2021-07-04 13:45:17 +02:00
Petrik 0409ed57ac Clean up checks to see if DidYouMean is defined
As of Ruby 2.7 DidYouMean is included as a default gem, so there is no
need to check if DidYouMean is defined in the test suite. We still need
to check if the DidYouMean modules are defined in the actual code, as
someone might run Rails with DidYouMean disabled by using the
`--disable-did_you_mean` flag. This is ussually done for performance
reasons.

This commit also includes some of the changes made by Yuki in:
https://github.com/rails/rails/pull/39555
These changes include replacing Jaro with the more accurate
SpellChecker, and using DidYouMean::Correctable for simplere
corrections.

The DidYouMean::SpellChecker does have a treshold for corrections.
If there is not enough similarity it might not return a suggestion.
To stop the tests from failing some test data had to be changed.

For example, `non_existent` does not meet the treshold for `hello`, but
`ello` does:

DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('non_existent')
=> []
DidYouMean::SpellChecker.new(dictionary: %w[hello]).correct('ello')
=> ["hello"]

The treshold makes sense for spelling errors. But maybe we should add a
different SpellChecker that helps to get a suggestion even if there is
little overlap. For example for when a model only has 2 attributes
(title and body), it's helpful to get a suggestion for `name`

Co-Authored-By: Yuki Nishijima <yk.nishijima@gmail.com>
2021-07-04 13:43:50 +02:00
Ryuta Kamizono 7179dcb269
Merge pull request #42687 from NatMorcos/psych_4_load_secrets_with_aliases
unsafe_load secrets.yml with psych 4
2021-07-04 00:37:58 +09:00
Nat Morcos 0ebb7084f4 unsafe_load secrets.yml with psych 4 2021-07-03 09:19:22 -04:00
Jean Boussier ccb66572b1
Merge pull request #42601 from mdemare/has_one_cache
Clear cached has_one association after removing belongs_to association
2021-07-03 08:58:54 +02:00
Ryuta Kamizono 30033e6a1d
Merge pull request #42657 from abhaynikam/ensure-foreign-key-type-respect-generator-config
Ensure Action Text migration use config set primary_key_type
2021-07-03 11:36:36 +09:00
Ryuta Kamizono 91593af849 Merge pull request #41559 from jonathanhefner/sms_to-country_code
Add :country_code option to sms_to
2021-07-03 11:19:20 +09:00
Eileen M. Uchitelle 56d8ff8372
Merge pull request #42673 from ghiculescu/patch-4
Fix new framework defaults for `destroy_all_in_batches`
2021-07-02 09:05:59 -04:00