Commit Graph

85876 Commits

Author SHA1 Message Date
Nicolas Iragorri Dominguez e708599c85 [issue-46741] remove `require pathname` from `drop` method 2022-12-27 01:24:19 +01:00
Yasuo Honda c14b8c7323
Merge pull request #46817 from yahonda/bump_required_rubygems_version_to_3313
Bump required_rubygems_version to 3.3.13 or higher
2022-12-27 08:56:30 +09:00
Hartley McGuire ba2e06aee9
Use precompute optimization for Rails.env.local?
Ref: 09e0372

This makes #local? behave the same as the predefined environment
predicates (they immediately return a precomputed instance variable).

Benchmark:

```ruby
dev = ActiveSupport::EnvironmentInquirer.new("development")
test = ActiveSupport::EnvironmentInquirer.new("test")
prod = ActiveSupport::EnvironmentInquirer.new("production")

Benchmark.ips do |x|
  x.report("dev local?") { dev.local? }
  x.report("test local?") { test.local? }
  x.report("prod local?") { prod.local? }
  x.compare!
end
```

Before:
```
Warming up --------------------------------------
          dev local?   676.645k i/100ms
         test local?   627.687k i/100ms
         prod local?   671.078k i/100ms
Calculating -------------------------------------
          dev local?      6.785M (± 1.8%) i/s -     34.509M in   5.087679s
         test local?      6.284M (± 2.0%) i/s -     32.012M in   5.096338s
         prod local?      6.759M (± 1.8%) i/s -     34.225M in   5.065240s

Comparison:
          dev local?:  6785134.0 i/s
         prod local?:  6759023.6 i/s - same-ish: difference falls within error
         test local?:  6283910.1 i/s - 1.08x  (± 0.00) slower
```

After:
```
Warming up --------------------------------------
          dev local?     1.076M i/100ms
         test local?     1.049M i/100ms
         prod local?     1.028M i/100ms
Calculating -------------------------------------
          dev local?     10.586M (± 2.3%) i/s -     53.799M in   5.084729s
         test local?     10.350M (± 2.5%) i/s -     52.457M in   5.071399s
         prod local?     10.396M (± 2.2%) i/s -     52.422M in   5.045193s

Comparison:
          dev local?: 10586400.1 i/s
         prod local?: 10395758.6 i/s - same-ish: difference falls within error
         test local?: 10350328.8 i/s - same-ish: difference falls within error
```
2022-12-26 18:26:59 -05:00
Petrik de Heus 85bc6ca9d2
Merge pull request #46829 from p8/activerecord/fix-readme-formating
Fix Active Record README formatting [ci-skip]
2022-12-26 22:03:40 +01:00
Petrik 702421e5c2 Fix Active Record README formatting [ci-skip]
This fixes the indentation of the example code of the first bullet
point. The "Learn more" link was moved to the bottom of the bullet point,
similar to the other bullet points.
2022-12-26 21:57:50 +01:00
Akira Matsuda 9f141a423d
Module name typo in documentation 2022-12-26 23:13:04 +09:00
Akira Matsuda 4732c91d14
Trivial fix on CHANGELOG 2022-12-26 19:53:17 +09:00
Max Chernyak d8c2c3e5ad
Add comparison to i18n error interpolations table 2022-12-25 17:10:48 -05:00
Abhay Nikam 1a03cd4913
[ci skip] Documents the --skip-docker rails command line argument (#46823) 2022-12-25 22:04:38 +05:30
Yasuo Honda 3aa32f2176 Bump required_rubygems_version to 3.3.13 or higher
https://github.com/rails/rails/pull/45979 relies on
https://github.com/rubygems/rubygems/pull/5486 which is included
in https://github.com/rubygems/rubygems/blob/master/CHANGELOG.md#3313--2022-05-04

- RubyGems 3.3.12` Gem.ruby_version` includes patch level
```ruby
$ gem -v
3.3.12
$ irb
irb(main):001:0> Gem.ruby_version
=> Gem::Version.new("3.1.3.p185")
```

- RubyGems 3.3.13` Gem.ruby_version` does not include patch level
```
$ gem -v
3.3.13
$ irb
irb(main):001:0> Gem.ruby_version
=> Gem::Version.new("3.1.3")
irb(main):002:0>
```

The current version 1.8.11 has been updated to use Ruby 1.9.3-p0
https://github.com/rails/rails/pull/4576
2022-12-24 10:46:41 +09:00
Yasuo Honda 40a1f3ae24
Merge pull request #46814 from yahonda/bundle_only_rubocop
Use `BUNDLE_ONLY: rubocop` suported since Bundler 2.3.19
2022-12-24 10:46:11 +09:00
Yasuo Honda cd223db814 Use `BUNDLE_ONLY: rubocop` suported since Bundler 2.3.19
Bundler 2.3.19 can install gems of the specific group now.

Refer to
https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md#2319-july-27-2022
https://github.com/rubygems/rubygems/pull/5759
https://github.com/rails/rails/pull/38836
2022-12-24 10:07:49 +09:00
Yasuo Honda 15576ddedb
Merge pull request #46800 from the-spectator/prefer_local_env
Prefer using new Rails.env.local?
2022-12-24 08:40:42 +09:00
Jonathan Hefner 6d581c43a7
Merge pull request #46808 from seanpdoyle/revert-46249
Revert "Focus editor after calling `fill_in_rich_text_area`"
2022-12-23 14:16:32 -06:00
Sean Doyle 0e9013081e Revert "Focus editor after calling `fill_in_rich_text_area`"
Closes [rails/rails#46803][].

This reverts commit 67a4ac6c56.

Once the system test helper test suite executes in CI, we can
re-introduce the changes as part of [rails/rails#46807][].

[rails/rails#46803]: https://github.com/rails/rails/issues/46803#issuecomment-1364112967
[rails/rails#46807]: https://github.com/rails/rails/pull/46807
2022-12-23 14:19:25 -05:00
Akira Matsuda a790203408
Use Kernel#Array to avoid an extra Array allocation when nil was given 2022-12-23 23:34:34 +09:00
Akshay Birajdar c312bb7e04 Prefer using new shorthand helper Rails.env.local? 2022-12-23 19:04:33 +05:30
Jean Boussier 9d4075c3de
Merge pull request #46798 from skipkayhil/eager-load-rails-backtrace-cleaner
Eager load Rails::BacktraceCleaner
2022-12-23 09:32:19 +01:00
Hartley McGuire 89c2c91ccd
Eager load Rails::BacktraceCleaner
Previously, Rails::BacktraceCleaner was both lazily required and
instantiated. While it would end up being loaded during initialization
for apps that use Active Record (due to active_record.backtrace_cleaner
initializer), it would not be loaded until the first request for those
that don't.

The solution is similar to daff36c, however ::Rails is not currently
in the list of eager_load_namespaces. Therefore simply requiring it
seems like the easiest solution.

The removed comment indicating the lazy require is necessary due to load
order dates back to the addition of Rails::BacktraceCleaner in f42c77f.
This predates the integration of Bundler and reorganization of framework
loading, so it is no longer accurate.
2022-12-23 01:13:10 -05:00
Jean Boussier 9589ef330c
Merge pull request #46726 from braindeaf/dynamic_cookie_domain_per_request
Dynamic cookie domain per request
2022-12-22 21:52:53 +01:00
RobL 83da2e9383 Allow proc for per-request cookie domain
Per-request cookie domain set through proc
2022-12-22 19:49:22 +00:00
Jonathan Hefner 95fb5b4bc1
Merge pull request #44786 from kaiquekandykoga/actiontext-errorswrapping
Add error wrapper when rich_text_area is required
2022-12-22 12:27:52 -06:00
Kaíque Kandy Koga 0dc71acf39 Apply field_error_proc to rich_text_area fields 2022-12-22 11:52:30 -06:00
Jean Boussier 28386bdc0f
Merge pull request #46789 from ezekg/fix-string-keys-for-deterministic-active-record-encryption
Support string keys for queries on deterministic attributes
2022-12-22 16:27:19 +01:00
Zeke Gabrielse 5b8625928d Support string keys for queries on deterministic attributes 2022-12-22 08:56:07 -06:00
Ahmed Shahin c2f6be12a5 increase for more tests 2022-12-22 15:04:05 +02:00
Ahmed Shahin adaea233d0 Apply the new socket_timeout at mocked expectations 2022-12-22 14:57:14 +02:00
Ahmed Shahin 385626fbe7 Increase `socket_timeout` for memcached inside tests
It sounds like a default timeout of 1 second can sometimes not be enough.
In normal operations, this should be fine (will result in a cache miss),
but in these tests, we always expect the cache to return the value, hence doing this change for these tests only.

Co-authored-by: Matthew Draper <matthew@trebex.net>
2022-12-22 14:16:59 +02:00
Akira Matsuda 15ab7223c7
Avoid creating an extra Hash object when no options were given 2022-12-22 18:26:27 +09:00
Akira Matsuda 055f71cece
Reduce a String object allocation 2022-12-22 17:31:12 +09:00
Akira Matsuda 66386d3b4c
Splat the tag names to avoid passing double arrays 2022-12-22 17:31:12 +09:00
Jean Boussier 68664aee48
Merge pull request #46790 from lazaronixon/singular-association-refactor
Small refactor on build singular association
2022-12-22 09:17:48 +01:00
Jean Boussier ac541a6c3f
Merge pull request #46791 from kaiquekandykoga/libxml-ruby
Update libxml-ruby
2022-12-22 09:01:00 +01:00
Jean Boussier 50d59e9c3e Document MySQL numeric quoting behavior in ActiveRecord::Sanitization
Ref: https://github.com/rails/rails/issues/44312
Ref: https://github.com/rails/rails/pull/42440
Fix: https://github.com/rails/rails/pull/46776
2022-12-22 08:58:23 +01:00
George Claghorn 827ae3c449
ActiveRecord::Relation#none?/#any?/#one?: support pattern arg (#46728) 2022-12-22 08:21:54 +01:00
Kaíque Kandy Koga d1ba709b09 Update libxml-ruby
from 3.2.1 to 3.2.4
2022-12-22 01:01:19 -03:00
Nixon 4279b47c91 Small refactor on build singular association 2022-12-22 00:16:48 -03:00
Jonathan Hefner de40fc69ff
Merge pull request #46787 from jonathanhefner/messages-metadata-avoid-parse-non-metadata
Avoid double JSON parse for metadata-less messages
2022-12-21 16:55:18 -06:00
Jonathan Hefner 4c4f4c385a Avoid double JSON parse for metadata-less messages
In #46612, a check was added to only attempt metadata extraction if the
message looks like a JSON object (i.e. starts with "{"), thus avoiding
an unnecessary JSON parse and possible exception.

This commit extends the check to only attempt metadata extraction if the
message looks like a metadata wrapper object (i.e. has the "_rails"
key).  This avoids an unnecessary JSON parse of JSON object messages
that don't have metadata.

**Benchmark**

  ```ruby
  require "benchmark/ips"
  require "active_support/all"

  verifier = ActiveSupport::MessageVerifier.new("secret", serializer: JSON)
  message_100 = verifier.generate({ content: "x" * 100 })
  message_1m = verifier.generate({ content: "x" * 1_000_000 })

  Benchmark.ips do |x|
    x.report("100 chars") do
      verifier.verify(message_100)
    end

    x.report("1m chars") do
      verifier.verify(message_1m)
    end
  end
  ```

**Before**

  ```
  Warming up --------------------------------------
             100 chars     2.803k i/100ms
              1m chars     6.000  i/100ms
  Calculating -------------------------------------
             100 chars     27.762k (± 1.6%) i/s -    140.150k in   5.049649s
              1m chars     83.516  (±16.8%) i/s -    402.000  in   5.037269s
  ```

**After**

  ```
  Warming up --------------------------------------
             100 chars     3.360k i/100ms
              1m chars     9.000  i/100ms
  Calculating -------------------------------------
             100 chars     33.480k (± 1.7%) i/s -    168.000k in   5.019311s
              1m chars    113.373  (±15.0%) i/s -    549.000  in   5.023443s
  ```
2022-12-21 14:12:15 -06:00
Jonathan Hefner 52146dee06
Merge pull request #43945 from jonathanhefner/active_record-normalizes
Add `ActiveRecord::Base::normalizes`
2022-12-21 14:07:55 -06:00
Jonathan Hefner d4c31bd849 Add ActiveRecord::Base::normalizes
`ActiveRecord::Base::normalizes` declares a normalization for one or
more attributes.  The normalization is applied when the attribute is
assigned or updated, and the normalized value will be persisted to the
database.  The normalization is also applied to the corresponding
keyword argument of finder methods.  This allows a record to be created
and later queried using unnormalized values.  For example:

  ```ruby
  class User < ActiveRecord::Base
    normalizes :email, with: -> email { email.strip.downcase }
  end

  user = User.create(email: " CRUISE-CONTROL@EXAMPLE.COM\n")
  user.email                  # => "cruise-control@example.com"

  user = User.find_by(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")
  user.email                  # => "cruise-control@example.com"
  user.email_before_type_cast # => "cruise-control@example.com"

  User.exists?(email: "\tCRUISE-CONTROL@EXAMPLE.COM ")         # => true
  User.exists?(["email = ?", "\tCRUISE-CONTROL@EXAMPLE.COM "]) # => false
  ```
2022-12-21 12:08:36 -06:00
David Heinemeier Hansson 47eaf8881c
Add Rails.env.local? (#46786)
* Add Rails.env.local?

So many checks against Rails.env is whether we're running test or development, so combine into just one.

* Add CHANGELOG

* Prevent 'local' from being used as an environment name

Now that we have it as a combined predicate for dev + test.
2022-12-21 15:38:33 +01:00
David Heinemeier Hansson 2e142d9ae0 Explain the optimization setup 2022-12-21 14:51:02 +01:00
David Heinemeier Hansson 0239401010 Stop recommending sassc-rails. Its been deprecated, and we have dartsass-rails now instead. 2022-12-21 14:44:46 +01:00
Jean Boussier e74526814a
Merge pull request #46768 from skipkayhil/eager-load-execution-context
Eager autoload ActiveSupport::ExecutionContext
2022-12-20 18:44:12 +01:00
Eileen M. Uchitelle 2f0bd27987
Merge pull request #46627 from alison-acuna/46606/docs_serial_tests
Docs: Adds debugger section to contributing guide
2022-12-20 11:41:44 -05:00
David Heinemeier Hansson f8f2590725
Bundle test gems so this image can also be used for CI testing 2022-12-20 16:35:26 +01:00
David Heinemeier Hansson 513be3a3a6
Consistent no-period comments 2022-12-20 15:08:46 +01:00
David Heinemeier Hansson 2ea62b99c8
Run under bash to avoid syntax error in conditional 2022-12-20 15:07:24 +01:00
Nick Janetakis 0819a81fa3
Add CMD and refactor ENTRYPOINT in the Docker generator (#46778)
* Add CMD and refactor ENTRYPOINT

The CMD will run by default when you run the container without supplying
any arguments but you can choose to overwrite this at runtime by
doing: docker container run -it myapp rails c

The ENTRYPOINT will only create or migrate the database when the default
CMD is invoked. If you choose to run a different command such as the
rails console or a background worker process the db:prepare command
will not run.

* Remove extra space from ENTRYPOINT comment
2022-12-20 14:11:23 +01:00