Commit Graph

89955 Commits

Author SHA1 Message Date
Jean Boussier
1aa4bd3823 Lock irb to < 1.10 for now
It breaks various `rails console` related integration tests:

```
Failure:
FullStackConsoleTest#test_sandbox [test/application/console_test.rb:123]:
"> " expected, but got:

(END).
Expected "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n--More--\r        \r(END)" to include "> ".
```

I tried to figure out a fix, but ran out of time, so in order
to fix CI we can lock IRB for now.
2023-12-05 16:31:01 +01:00
Jean Boussier
98df193aaf
Merge pull request #50268 from Shopify/opt-time-at
Optimize `Time.at_with_coercion`
2023-12-05 16:08:28 +01:00
Jean Boussier
7cfc4ee676 Optimize Time.at_with_coercion
By using `ruby2_keyword` style delegation we we can avoid a
few allocations and some extra checks.

```
$ ruby --yjit /tmp/bench-as-time-at.rb
ruby 3.2.2 (2023-03-30 revision e51014f9c0) +YJIT [arm64-darwin22]
=== Complex call ====
Warming up --------------------------------------
        Time.without   320.514k i/100ms
           Time.with    68.433k i/100ms
       Time.opt_with   167.532k i/100ms
Calculating -------------------------------------
        Time.without      3.781M (± 4.8%) i/s -     18.910M in   5.014574s
           Time.with      1.586M (± 3.5%) i/s -      7.938M in   5.010525s
       Time.opt_with      2.003M (± 2.4%) i/s -     10.052M in   5.021309s

Comparison:
        Time.without:  3781330.9 i/s
       Time.opt_with:  2003025.9 i/s - 1.89x  slower
           Time.with:  1586289.9 i/s - 2.38x  slower

Time.without: 2.003 alloc/iter
Time.with: 9.002 alloc/iter
Time.opt_with: 7.002 alloc/iter

=== Simple call ====
Warming up --------------------------------------
        Time.without   749.097k i/100ms
           Time.with   342.855k i/100ms
       Time.opt_with   416.063k i/100ms
Calculating -------------------------------------
        Time.without      9.289M (± 3.4%) i/s -     46.444M in   5.005361s
           Time.with      3.601M (± 2.1%) i/s -     18.171M in   5.048794s
       Time.opt_with      4.373M (± 8.1%) i/s -     22.051M in   5.084967s

Comparison:
        Time.without:  9289271.2 i/s
       Time.opt_with:  4373226.2 i/s - 2.12x  slower
           Time.with:  3600733.6 i/s - 2.58x  slower

Time.without: 1.002 alloc/iter
Time.with: 3.001 alloc/iter
Time.opt_with: 3.002 alloc/iter
```

```ruby
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'activesupport', require: 'active_support/all', github: 'rails/rails'
  gem 'benchmark-ips'
end

class Time
  class << self
    def opt_at_with_coercion(time_or_number, *args)
      if args.empty?
        if time_or_number.is_a?(ActiveSupport::TimeWithZone)
          at_without_coercion(time_or_number.to_r).getlocal
        elsif time_or_number.is_a?(DateTime)
          at_without_coercion(time_or_number.to_f).getlocal
        else
          at_without_coercion(time_or_number)
        end
      else
        at_without_coercion(time_or_number, *args)
      end
    end
    ruby2_keywords :opt_at_with_coercion
  end
end

puts RUBY_DESCRIPTION

puts "=== Complex call ===="
Benchmark.ips do |x|
  x.report("Time.without") do
    ::Time.at_without_coercion(223423423, 32423423, :nanosecond, in: "UTC")
  end

  x.report("Time.with") do
    ::Time.at_with_coercion(223423423, 32423423, :nanosecond, in: "UTC")
  end

  x.report("Time.opt_with") do
    ::Time.opt_at_with_coercion(223423423, 32423423, :nanosecond, in: "UTC")
  end

  x.compare!(order: :baseline)
end

def measure_allocs(title, iterations: 1_000)
  before = GC.stat(:total_allocated_objects)
  iterations.times do
    yield
  end
  allocs = GC.stat(:total_allocated_objects) - before
  puts "#{title}: #{allocs.to_f / iterations} alloc/iter"
end

measure_allocs("Time.without") do
  ::Time.at_without_coercion(223423423, 32423423, :nanosecond, in: "UTC")
end

measure_allocs("Time.with") do
  ::Time.at_with_coercion(223423423, 32423423, :nanosecond, in: "UTC")
end

measure_allocs("Time.opt_with") do
  ::Time.opt_at_with_coercion(223423423, 32423423, :nanosecond, in: "UTC")
end

puts "=== Simple call ===="
Benchmark.ips do |x|
  x.report("Time.without") do
    ::Time.at_without_coercion(223423423)
  end

  x.report("Time.with") do
    ::Time.at_with_coercion(223423423)
  end

  x.report("Time.opt_with") do
    ::Time.opt_at_with_coercion(223423423)
  end

  x.compare!(order: :baseline)
end

def measure_allocs(title, iterations: 1_000)
  before = GC.stat(:total_allocated_objects)
  iterations.times do
    yield
  end
  allocs = GC.stat(:total_allocated_objects) - before
  puts "#{title}: #{allocs.to_f / iterations} alloc/iter"
end

measure_allocs("Time.without") do
  ::Time.at_without_coercion(223423423)
end

measure_allocs("Time.with") do
  ::Time.at_with_coercion(223423423)
end

measure_allocs("Time.opt_with") do
  ::Time.opt_at_with_coercion(223423423, 32423423)
end
```
2023-12-05 12:42:40 +01:00
John Hawthorn
1c8be9c67a
Merge pull request #50266 from rails/revert-50164-do-not-overwrite-aj-logger
Revert "Do not overwrite AJ logger if it is supplied"
2023-12-04 17:52:57 -08:00
John Hawthorn
1a4474e7ee
Revert "Do not overwrite AJ logger if it is supplied" 2023-12-04 17:32:50 -08:00
Hartley McGuire
1544455776
Merge pull request #50249 from akhilgkrishnan/add-actionview-deprecation
Add actionview deprecation to 7.2 release note [skip ci]
2023-12-04 19:25:44 -05:00
Akhil G Krishnan
cc55785f4d Add actionview deprecation to 7.2 release note 2023-12-04 22:41:10 +05:30
Jean Boussier
a35ceb429c
Merge pull request #50262 from Techbrunch/patch-1
Use RedCloth GitHub instead of an expired domain
2023-12-04 16:52:58 +01:00
Jean Boussier
439e8be98e
Merge pull request #50217 from fastjames/document_variant_preprocessed_option
Document the `preprocessed` variant option [ci skip]
2023-12-04 16:49:05 +01:00
Jim Kane
87c614a1d4 Document the preprocessed variant option 2023-12-04 09:21:01 -06:00
Techbrunch
a86e8c875a
Use RedCloth GitHub instead of an expired domain 2023-12-04 14:44:30 +01:00
Ryuta Kamizono
06d9c3cbe6
Merge pull request #50251 from abeidahmed/has_secure_token-call-setter-method
[Fix #49874] `has_secure_token` calls the setter method on initialize
2023-12-04 09:34:29 +09:00
Jonathan Hefner
0ad2050c6e
Merge pull request #50179 from akhilgkrishnan/improve-documentation-for-highlight
Improve documentation for highlight text helper [skip ci]
2023-12-03 15:42:19 -06:00
Jonathan Hefner
41edc5a13a
Merge pull request #50255 from seanpdoyle/action-text-rich-text-area-helper-test
Add test coverage for `rich_text_area` helper
2023-12-03 15:41:42 -06:00
Sean Doyle
16c28d0a09 Add test coverage for rich_text_area helper
Follow-up to [#50252][]

Similar to the reliance on a `FormBuilder` in the helper methods
documentation examples, the template test coverage for `#rich_text_area`
relied on invocations through a `FormBuilder` instance.

This commit adds explicit coverage for calling the `#rich_text_area`
helper method directly with both an `object_name` and `method_name`
positional arguments.

[#50252]: https://github.com/rails/rails/pull/50252
2023-12-03 14:53:44 -05:00
Akhil G Krishnan
204d86b1a2 Improve documentation for highlight text helper
Update actionview/lib/action_view/helpers/text_helper.rb

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>

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

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>

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

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-12-04 01:03:19 +05:30
Jonathan Hefner
da871cc28a
Merge pull request #50252 from seanpdoyle/rich-text-area-docs
Action Text `rich_text_area` code samples [ci-skip]
2023-12-03 11:04:12 -06:00
Sean Doyle
638c9d5722 Action Text rich_text_area code samples [ci skip]
The API documentation for the `rich_text_area` Action View helper
demonstrates how to invoke the helper through a `FormBuilder` instance,
instead of through the `ActionView::Base` instance.

This commit removes the `form.` prefix, and includes examples of calling
the method with an `object_name` positional argument.
2023-12-03 11:40:55 -05:00
abeidahmed
c8caf6d867 [Fix #49874] has_secure_token calls the setter method on initialize
Follow-up to #49146

The original behavior of `has_secure_token` was to use the
`send("#{attribute}=", some_value)` method so that the setter method, if
defined, was called. PR #49146 replaced the `send` method with
`write_attribute` which doesn't call the setter method and breaks
existing applications.
2023-12-03 14:35:19 +04:00
Petrik de Heus
6908a66c50
Merge pull request #50245 from seanpdoyle/field-id-field-name-docs
Action View Docs: `field_id` and `field_name` examples [ci skip]
2023-12-02 18:49:21 +01:00
Jean Boussier
c5d519f93a
Merge pull request #50240 from joshuay03/preserve-timezone-in-active-job-time-with-zone-serializer
[Fix #50230] Preserve serialized timezone when deserializing with `ActiveJob::Serializers::TimeWithZoneSerializer`
2023-12-02 16:05:46 +01:00
Joshua Young
18098ccc4c [Fix #50230] Preserve serialized timezone when deserializing with ActiveJob::Serializers::TimeWithZoneSerializer 2023-12-03 00:37:09 +10:00
Sean Doyle
9de8f1a26a Action View Docs: field_id and field_name examples [ci skip]
Several code samples for `field_id` and `field_name` cite the use of
[text_field_tag][]-style helper. That usage is incorrect. The helper
interface that `field_id` and `field_name` mimic is the
[text_field][]-style helper, without the `_tag` suffix.

[text_field_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag
[text_field]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_field
2023-12-02 09:04:12 -05:00
Jean Boussier
67fb4414e5
Merge pull request #50236 from 907th/fix-travel-to
Fix `Time.now`/`DateTime.now`/`Date.today` to return results in a system timezone after `#travel_to`
2023-12-02 10:24:54 +01:00
Jean Boussier
90daef6928
Merge pull request #50241 from seanpdoyle/fieldset-tag-alias
Alias `field_set_tag` helper to `fieldset_tag`
2023-12-02 10:23:24 +01:00
Jean Boussier
9ec451f086
Merge pull request #50239 from seanpdoyle/form-builder-code-generator-batch
Batch define `FormBuilder` methods with `CodeGenerator`
2023-12-02 10:21:35 +01:00
Sean Doyle
0803405fdb Batch define FormBuilder methods with CodeGenerator
Define the `ActionView::Helpers::FormBuilder` methods that wrap the
`@template` instance methods inside an
`ActiveSupport::CodeGenerator.batch` call so that the underlying `class`
extensions aren't invoked more than once.
2023-12-02 10:08:24 +01:00
Jean Boussier
fac9a03afe
Merge pull request #50242 from yysaki/security_md_typo
Update security.md typo about HTTP Strict-Transport-Security [ci-skip]
2023-12-02 10:06:25 +01:00
Aleksei Chernenkov
aedb808829 Fix Time.now/DateTime.now/Date.today to return results in a system timezone after #travel_to
There is a bug in the current implementation of #travel_to:
it remembers a timezone of its argument, and all stubbed methods start
returning results in that remembered timezone. However, the expected
behaviour is to return results in a system timezone.

It can lead to bugs in tests like this one:
https://github.com/faker-ruby/faker/issues/2861
2023-12-02 10:05:31 +01:00
Jean Boussier
469c3dbeea
Merge pull request #50233 from rails/lock-json-gem
Lock json gem
2023-12-02 09:52:28 +01:00
eileencodes
a8e07924d6 Fix dependency on JSON gem
Don't use `json` 2.7.0 release that has a regression.

Ref: https://github.com/flori/json/pull/554
2023-12-02 09:41:55 +01:00
yysaki
7f94cb9483 Update security.md typo about HTTP Strict-Transport-Security [ci-skip] 2023-12-02 17:23:23 +09:00
Sean Doyle
c5ae44d659 Alias field_set_tag helper to fieldset_tag
The [field_set_tag][] renders a `<fieldset>` element. At times, the
desire to render a `fieldset` results in calling `fieldset_tag`, only to
be surprised by a `NoMethodError`.

Originally, the method's name was `fieldset_tag` helper (defined in
[0e6c8e5][] in 2007), but was renamed in [73c7083][] (3 days later).

This commit aliases `field_set_tag` to `fieldset_tag` so that both are
available.

Additionally, defines the method so that it utilizes the [content_tag][]
so that it isn't responsible for manually managing the closing
(`</fieldset>`) of the opening `<fieldset>` tag.

[field_set_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-field_set_tag
[0e6c8e5]: 0e6c8e5f6c
[73c7083]: 73c7083651
[content_tag]: https://edgeapi.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag
2023-12-02 01:09:42 -05:00
Eileen M. Uchitelle
b3b230c08e
Merge pull request #50231 from rails/revert-50205-ac-validate-migration-timestamps
Revert "Add config for validating migration timestamps"
2023-12-01 12:46:02 -05:00
Adrianna Chang
5a09d32ee6
Add regression test for copying migrations at timestamp boundary
We'd like to add validation to migration timestamps (attempted in 2854e37),
but this is problematic for copied migrations, e.g. engine migrations:
migrations are copied by adding one to every migration timestamp number,
which may produce an invalid timestamp.

This commit adds a regression test for this case, ensuring that if / when
we revisit migration timestamp validation, we handle the case for copied
migrations.
2023-12-01 12:17:08 -05:00
Adrianna Chang
2854e378c8
Revert "Add config for validating migration timestamps" 2023-12-01 11:58:53 -05:00
Eileen M. Uchitelle
d6197c5efc
Merge pull request #50159 from skipkayhil/hm-deprecate-void-content
Deprecate content for void elements in TagBuilder
2023-12-01 09:34:30 -05:00
Eileen M. Uchitelle
831810c342
Merge pull request #50158 from fatkodima/fix-alias_attribute-sti
Fix defining `alias_attribute` for STI classes with abstract class in the inheritance chain
2023-12-01 09:31:25 -05:00
Eileen M. Uchitelle
c60d064fd5
Merge pull request #50205 from rails/ac-validate-migration-timestamps
Add config for validating migration timestamps
2023-11-30 16:20:49 -05:00
Adrianna Chang
06575d1d75
Add active_record.config.validate_migration_timestamps option.
When set, validates that the timestamp prefix for a migration is in the form YYYYMMDDHHMMSS.
This is designed to prevent migration timestamps from being modified by hand.

It is turned off by default.
2023-11-30 16:04:06 -05:00
Jean Boussier
da2dbbb292
Merge pull request #50157 from Earlopain/update-erb-trim-mode-docs
Update docs for `erb_trim_mode`
2023-11-30 19:15:43 +01:00
Jean Boussier
9b9468566a
Merge pull request #50188 from skipkayhil/hm-fix-ci-env
Fix test infra depending on CI=true
2023-11-30 19:13:02 +01:00
Jonathan Hefner
52affa8357 Fix example output for truncate helper [ci-skip]
The previous output was incorrect for the default truncation length, and
it included unescaped quotes.
2023-11-30 11:19:37 -06:00
Jonathan Hefner
c05d8ed9cd Link methods for Rails::Engine [ci-skip] 2023-11-30 11:04:38 -06:00
Jonathan Hefner
47b2f68f52
Merge pull request #50178 from akhilgkrishnan/improve-documentation-for-truncate
Improve documentation for truncate text helper [skip ci]
2023-11-30 11:04:26 -06:00
Jean Boussier
3f4261638a
Merge pull request #50214 from zzak/gha/rails-new-docker/read-permissions-only
Ensure all GH Actions set to read-only contents
2023-11-30 17:41:50 +01:00
Hartley McGuire
91dedc0436
Fix Railties tests
These tests have never run in CI due to CI using a root user. This
commit keeps that behavior without using the skip so that we can enable
raise on skips.
2023-11-30 11:11:23 -05:00
Hartley McGuire
e67b8d0dcc
Fix Active Support test warnings
The namespace ivar needs a definition check to not warn on Ruby 2.7
2023-11-30 11:11:22 -05:00
Hartley McGuire
d64acfdcac
Fix Active Job skips
Similarly to Action Mailbox, these tests didn't pass because the skip
patch was included before ActiveSupport::TestCase was defined. Moving
the patch to the bottom of the file fixes the issue.

Once the skip patch was fixed, all of the skips were due to differences
in adapters which aren't really test skips as much as tests that should
not ever run against those adapters.
2023-11-30 11:11:22 -05:00
Hartley McGuire
ec3d392e20
Fix skips in Action Pack
We can't run this test on Ruby 2.7 due to minitest being locked in the
Gemfile to an older version, so we should use that as a condition
instead of skipping if minitest doesn't have metadata.
2023-11-30 11:11:22 -05:00