Commit Graph

79559 Commits

Author SHA1 Message Date
Ryuta Kamizono
8c7883d3fc ✂️ [ci skip] 2021-03-22 04:46:11 +09:00
Ryuta Kamizono
043184d903 Fix end alignment 2021-03-21 15:46:36 +09:00
Ryuta Kamizono
1dcad65f80
Merge pull request #41707 from okuramasafumi/add-missing-require-to-hash_with_indifferent_access
Add missing require to hash_with_indifferent_access
2021-03-21 15:19:44 +09:00
Jean Boussier
39341de433 Remove useless include_private parameter in define_proxy_call
Since Ruby 2.7 `self.some_private_method` works fine.
So now that Ruby 2.7 is the minimal supported version,
`define_proxy_call` can always prepend `self.`
2021-03-20 14:27:53 -04:00
OKURA Masafumi
8a56380c53
Add documentation to HashWithIndifferentAccess#except
https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html#method-i-except
Currently HashWithIndifferentAccess#except has no documentation.
Since it's behavior is different from Hash#except, so it deserves
its own documentation.
2021-03-20 10:37:13 -04:00
OKURA Masafumi
e4de1ca9b5 Add missing require to hash_with_indifferent_access
When requiring only "active_support/hash_with_indifferent_access",
calling `slice!` method on `HashWithIndifferentAccess` object
causes `NoMethodError`.
This is caused by `slice!` method calls `super` which is defined
in "active_support/core_ext/hash/slice" that' not required by this file.
Adding `require "active_support/core_ext/hash/slice"` to hwia
resolves this issue.

Note: since all tests `require_relative "abstract_unit"` that requires
"active_support/core_ext/hash/slice" eventually, it's pretty hard to
test method behavior without require.
2021-03-20 22:10:38 +09:00
Ryuta Kamizono
a8a1afd455
Merge pull request #41703 from Shopify/tripple-dot
Use `...` argument forwarding instead of ruby2_keywords when possible
2021-03-20 02:38:59 +09:00
James Brooks
b1b0b22f50
Always render attachment partials as HTML with :html format inside trix editor 2021-03-19 13:35:09 -04:00
Máximo Mussini
1598ad5c4b
Ensure modules are preloaded correctly using rel=modulepreload.
Prior to this change, javascript_include_tag was sending a hint using
rel="preload" for all scripts, including those of type="module".

This causes the browser to make a request to preload the script, but
because the rel is incorrect, it won't be able to reuse it.

When passing type="module", it should use rel=modulepreload instead.

[0] developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
[2] developer.mozilla.org/en-US/docs/Web/HTML/Link_types/modulepreload
2021-03-19 13:22:22 -04:00
Ryuta Kamizono
b5c4af7d52
Merge pull request #41068 from ricardotk002/fix-where-in-stmt-logging
Fix binds logging for "WHERE ... IN ..." statements
2021-03-20 01:41:29 +09:00
Jean Boussier
8a3fcad2d2 Use ... argument forwarding instead of ruby2_keywords when possible 2021-03-19 16:53:06 +01:00
Xavier Noria
6d38553b09 Removes the monkey-patch for Marshal.load
Marshal.load autoloads out of the box with Zeitwerk. See

    https://github.com/fxn/zeitwerk/blob/master/test/lib/zeitwerk/test_marshal.rb

for similar coverage.
2021-03-18 22:08:25 +01:00
eileencodes
8da6ba9cae
Fix schema for members
While working on another branch I noticed that this `resource_id` was
set to a string. I ran all the tests for sqlite, mysql, and postgres and
none failed so I think this is an oversight. As far as I can tell this
was supposed to be an integer.
2021-03-18 10:00:08 -04:00
eileencodes
5e300f1121
Fix test name
I copied the previous test and forgot to remain it. This commit fixes
the test name.
2021-03-17 09:19:55 -04:00
Ryuta Kamizono
6ab3191ed6
Merge pull request #41675 from kamipo/dont_use_cast_in_unboundable
Don't use `type.cast(value)` to emulate unchecked serialized value in `unboundable?`
2021-03-17 20:21:34 +09:00
Ryuta Kamizono
e8a358237e
Merge pull request #41690 from mollerhoj/patch-2
fix typo
2021-03-17 08:25:20 +09:00
Jens Dahl Møllerhøj
7d10ce1c92
fix typo 2021-03-16 23:57:22 +01:00
Eileen M. Uchitelle
6655c78349
Merge pull request #41688 from eileencodes/handle-false-for-strict-loading
Handle false in relation strict loading checks
2021-03-16 17:07:28 -04:00
eileencodes
226007daa1
Handle false in relation strict loading checks
Fixes: #41453
Closes: #41461

Previously when a model had strict loading set to true and then had a
relation set strict_loading to false the false wasn't considered when
deciding whether to raise/warn about strict loading.

Code example:

```ruby
class Dog < ActiveRecord::Base
  self.strict_loading_by_default = true

  has_many :treats, strict_loading: false
end
```

In the example, `dog.treats` would still raise even though
`strict_loading` was set to false. This is a bug effecting more than
Active Storage which is why I made this PR superceeding #41461. We need
to fix this for all applications since the behavior is a little
surprising. I took the test from ##41461 and the code suggestion from #41453
with some additions.

Co-authored-by: Radamés Roriz <radamesroriz@gmail.com>
2021-03-16 16:26:59 -04:00
John Hawthorn
35652100d2
Merge pull request #41597 from jhawthorn/preloader_batch_loader_query
Add Preloader::Association::LoaderQuery
2021-03-16 10:09:28 -07:00
John Hawthorn
eeef0bb26a Add Preloader::Association::LoaderQuery
This class represents the query a Preloader::Association uses to load
its records. This replaces the previous concept of a grouping_key and
serves both to group Preloader::Associations by their query and to run
the query to load the records (which nicely avoids using .first).

This should not change any functionality but should be slightly faster
due to being able to avoid calling `scope.to_sql` unless necessary.
2021-03-15 17:59:29 -07:00
John Hawthorn
3bac3a4e8b Implement hash equality for WhereClause
Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
2021-03-15 17:54:03 -07:00
John Hawthorn
1baa0684a0
Merge pull request #41596 from jhawthorn/preloader_branch
Allow Preloader to group through association queries
2021-03-15 17:50:35 -07:00
Rafael Mendonça França
d5ee11933f
Make sure the version of rake used in Rails apps work
Since 68a3f679d93a22160cca9a8bd9a869b8c766f860, we are requiring rake
0.13, so we need to specify that is the version we want.
2021-03-15 20:48:38 +00:00
Jean Boussier
c9a9dcd383 Reproduce the preloader regression in #41596
It's very peculiar, what seem to happen is that if some associations
are already loaded, the batching is done properly.
2021-03-15 12:36:21 -07:00
John Hawthorn
9cc8375e06 Allow preload grouping of through associations
Co-authored-by: Dinah Shi <dinahshi@github.com>
2021-03-15 12:36:21 -07:00
John Hawthorn
cb99891eac Implement Preloader::Branch
Co-authored-by: Dinah Shi <dinahshi@github.com>
2021-03-15 12:36:21 -07:00
John Hawthorn
0169eadd8c Add ensure_loaded to Preloader::Association
This allows running either load_records or fetch_from_preloaded_records
depending on whether associations are already loaded. This allows
calling preloaded_records without necessarily having called run first.

Co-authored-by: Dinah Shi <dinahshi@github.com>
2021-03-15 12:36:21 -07:00
Ryuta Kamizono
096719ce2a Move where from TreeManager to SelectManager
`TreeManager` is inherited by `InsertManager` but `where` on
`InsertManager` doesn't work.

And also, remove `@ctx` since the instance variable is used only for the
`SelectManager`.
2021-03-15 23:50:44 +09:00
Ryuta Kamizono
92281b4911 Fix update_all/delete_all to use exactly table
https://buildkite.com/rails/rails/builds/75795#4704b28c-fb6e-472b-bc40-7d3647e95292/1069-1078
2021-03-15 18:06:57 +09:00
Ryuta Kamizono
cd809b3176 Improve compile_update and compile_delete
To be used from `update_all` and `delete_all`.
2021-03-15 17:15:35 +09:00
Ryuta Kamizono
c435af140e Don't use type.cast(value) to emulate unchecked serialized value in unboundable?
I used `type.cast(value)` to emulate unchecked serialized value in
`unboundable?`, since `RangeError` was raised only for the integer type,
so the emulation works enough for the integer type.

But since #41516, Enum types are also not always serializable, so
`type.cast(value)` may also be called for the enum types.

I've delegated `type.cast(value)` to the subtype if an unknown label is
passed to work the emulation even on Enum types in 3b6461b. But it is
strange to delegate to the subtype for the emulation only if an unknown
label is passed.

Instead of using `type.cast(value)` for the emulation, extend
`serializable?` to get unchecked serialized value if the value is not
serializable.
2021-03-15 12:23:40 +09:00
Ryuta Kamizono
520bb79411 Fix serializable? on Enum to pass mapped value to subtype 2021-03-15 11:17:30 +09:00
Ryuta Kamizono
62958da8a4
Merge pull request #41672 from kamipo/fix_numericality_validator_without_precision
Fix numericality validator without precision in Active Record
2021-03-15 09:55:23 +09:00
Ryuta Kamizono
38066a3d9b Fix numericality validator without precision in Active Record
Test case which was added at #32852 passes in Active Model but doesn't
pass in Active Record since #38210 due to `Float::DIG` has changed to
`BigDecimal.double_fig`.

```ruby
irb(main):001:0> require 'bigdecimal/util'
=> true
irb(main):002:0> 65.6.to_d
=> 0.656e2
irb(main):003:0> 65.6.to_d(Float::DIG)
=> 0.656e2
irb(main):004:0> 65.6.to_d(BigDecimal.double_fig)
=> 0.6559999999999999e2
```
2021-03-14 13:40:25 +09:00
T.J. Schuck
005e14b2c4
[Docs] Lowercase a word that shouldn't be capitalized [ci skip] 2021-03-12 17:12:53 -05:00
Gannon McGibbon
f55e596ac6
Merge pull request #41524 from robotfelix/clarify_bug_fix_to_security_fix_policy
[ci skip] Clarify maintenance policy for bug fixes to security patches
2021-03-12 16:45:28 -05:00
Felix Kenton
e192fdddcf Clarify maintenance policy for bug fixes to security patches
The policy for security patches is very strict, and some people may find it surprising that even breaking changes as a result of an oversight or bug in a security fix will neither receive a release of their own nor be included in any subsequent security patches to address other security issues. Hopefully this additional text will help clarify this and avoid confusion.
2021-03-12 21:26:44 +00:00
Alex Ghiculescu
bd33ddaf71 Active Storage: Blob creation shouldn't crash if no service selected
https://github.com/rails/rails/issues/41653 noted an issue where if there's service configured (`config.active_storage.service` is commented out), Blob creation via direct upload crashes:

```
Started POST "/rails/active_storage/direct_uploads" for ::1 at 2021-03-09 13:02:57 -0800
Processing by ActiveStorage::DirectUploadsController#create as JSON
  Parameters: {"blob"=>{"filename"=>"banana.jpg", "content_type"=>"image/jpeg", "byte_size"=>577085, "checksum"=>"W/vo/JqBNmJHMCaL+PRlBQ=="}, "direct_upload"=>{"blob"=>{"filename"=>"banana.jpg", "content_type"=>"image/jpeg", "byte_size"=>577085, "checksum"=>"W/vo/JqBNmJHMCaL+PRlBQ=="}}}
Completed 500 Internal Server Error in 12ms (ActiveRecord: 3.3ms | Allocations: 5864)

NoMethodError (undefined method `name' for nil:NilClass):

activestorage (6.1.3) app/models/active_storage/blob.rb:52:in `block in <class:Blob>'
activesupport (6.1.3) lib/active_support/callbacks.rb:427:in `instance_exec'
```

This PR fixes that crash. Blob creation will still fail, but with a more informative error about a `service_name` being required.
2021-03-12 15:12:11 -05:00
Ryuta Kamizono
168ddaa08a Remove unused Arel::Attributes classes
I missed it in #36493, those classes should also no longer be used since
https://github.com/rails/arel/pull/196.
2021-03-11 11:50:42 +09:00
Ryuta Kamizono
8323fb5251 Fix where with >, >=, <, and <= to return correct result even with a large number
Follow up to #30000.
2021-03-11 11:02:43 +09:00
Ryuta Kamizono
5667517b47 Use _primary_key_constraints_hash even in Locking::Optimistic
Follow up to #41427.
2021-03-11 09:24:25 +09:00
Ryuta Kamizono
6d887b208c
Merge pull request #41645 from ghiculescu/form-with-file-field-docs
Clarify when `enctype="multipart/form-data"` gets added to forms [docs]

[ci skip]
2021-03-11 09:09:49 +09:00
Eileen M. Uchitelle
404a7f34c7
Merge pull request #41590 from Shopify/log-subscriber-publish
Forward sql.active_record notifications back into the calling thread
2021-03-10 16:16:36 -05:00
Alex Ghiculescu
0fba70c082 Clarify when enctype="multipart/form-data" gets added to forms [docs]
As noted in https://github.com/rails/rails/issues/41632 the docs for this are incorrect. The `enctype` attribute is automatically added anytime you make a form with a `file_field`.

Resolves https://github.com/rails/rails/issues/41632

Update actionview/lib/action_view/helpers/form_helper.rb

Co-authored-by: Petrik de Heus <petrik@deheus.net>
2021-03-10 13:09:46 -06:00
eileencodes
fc20050ea6
Merge branch 'fix_database_yml_example_in_mutltiple_databases_rails_guide' into main 2021-03-10 10:44:19 -05:00
ryu39
0bbc293b77
Fix database.yml example in multiple databases Rails Guide
* Change :user to :username
* Add :password
2021-03-10 10:44:12 -05:00
Eileen M. Uchitelle
7240fb636b
Merge pull request #41560 from dmilburn/add-rails-development-hosts-env-variable
Add RAILS_DEVELOPMENT_HOSTS env variable
2021-03-10 10:34:44 -05:00
Ryuta Kamizono
4607f13c88 Use serializable? instead of rescue ::RangeError 2021-03-10 21:21:22 +09:00
Ryuta Kamizono
3b6461bb46 Fix between stringify enum values to return the expected result 2021-03-10 20:47:08 +09:00