Commit Graph

79664 Commits

Author SHA1 Message Date
Jorge Manrubia
1ad8bf5303 We want to exclude sqlite not target mysql 2021-04-01 15:02:13 +02:00
Jorge Manrubia
83ed6058b7 Fix tests 2021-04-01 15:02:13 +02:00
Jorge Manrubia
002198d212 Don't extend queries by default 2021-04-01 15:02:13 +02:00
Jorge Manrubia
79173314de Move tests to namespace 2021-04-01 15:02:13 +02:00
Jorge Manrubia
ae38e58ef6 Add option to support previous encryption schemes
We want to be able to support extended deterministic queries
without having to enable support_unencrypted_data
2021-04-01 15:02:13 +02:00
Jorge Manrubia
9aca274042 Encryption guide (WIP) 2021-04-01 15:02:13 +02:00
Jorge Manrubia
b06e38c224 Rename task 2021-04-01 15:02:13 +02:00
Jorge Manrubia
51aba3e0b3 Adjust performance thresholds 2021-04-01 15:02:13 +02:00
Jorge Manrubia
638a92f734 Initial extraction from active_record_encryption gem 2021-04-01 15:02:13 +02:00
Eileen M. Uchitelle
c6ee8c5c4f
Merge pull request #41810 from leequarella/forced-test_order
Revert overwriting test_order
2021-04-01 08:36:43 -04:00
Rafael França
886793bdf0
Merge pull request #41808 from p8/upgrade/sdoc-2.1.0
Upgrade sdoc to 2.1.0
2021-03-31 18:18:16 -04:00
Ricardo Díaz
1d50a37a6f Don't override ActiveSupport::TestCase.test_order
Seemingly some test suites depend on this

Updated tests to verify the change to the parallelization flag instead
2021-03-31 15:21:54 -04:00
Lee Quarella
65f350166a Remove overwriting test_order
Reverts a change from
2327ebfdc6
which can overwrite `test_order` that may have been manually set in
config. This can cause a situation where the user is depending on a
particular `test_order` but is unknowingly forced into another.
2021-03-31 11:50:08 -04:00
Petrik
85c20074f0 Upgrade sdoc to 2.1.0
Sdoc 2.1.0 works better on mobile and has improvements for SEO and
Lighthouse.

Changelog:
* #154 Make panel responsive for mobile.
* #153 Add viewport metatag to views for improved Lighthouse score.
* #150 Use semantic headers for better SEO.
2021-03-31 12:51:01 +02:00
Jean Boussier
d612542336
Merge pull request #41801 from Shopify/optimize-numeric-to-s
Optimize ActiveSupport::NumericWithFormat#to_s
2021-03-31 09:22:43 +02:00
Rafael França
e9268f73aa
Merge pull request #41791 from benkoshy/update-action-mailbox-documentation
Add: link to documentation [ci-skip]
2021-03-30 23:10:14 -04:00
BK
178b22f970 Add: link to documentation
Update guides/source/action_mailbox_basics.md

Co-authored-by: Rafael França <rafael@franca.dev>
2021-03-31 10:33:03 +11:00
Abhay Nikam
5de2dbff16 Fixes failing ActionText::ContentTest test cases
The test cases where failing because the test
`test_converts_Trix-formatted_attachments_with_custom_tag_name` set a
custom tag_name to `arbitrary-tag`. This test would also set the
ActionText::AttachmentGallery::ATTACHMENT_SELECTOR private constant
to `arbitrary-tag`.

Other test cases had proper ActionText::Attachment.tag_name set to
`action-text-attachment` but the constant once defined would not
reset.

This PR attempts to fix the issue by converting the
ActionText::AttachmentGallery::{ATTACHMENT_}SELECTOR to class methods

Fixes #41782
2021-03-30 16:38:11 -04:00
John Hawthorn
d89bb4f8ef
Merge pull request #41793 from jhawthorn/fix_buffered_log_subscriber_nil
Fix LogSubscriber for buffered event w/ nil logger
2021-03-30 09:48:29 -07:00
Jean Boussier
31c20e248a Optimize ActiveSupport::NumericWithFormat#to_s
`case format when nil` is very efficient because it end up calling `NilClass === nil`
which pretty much translates to `nil.is_a?(NilClass)`.

On the other hand `format.nil?` benefit from a dedicated op code, so it's quite faster.

In this case `Integer#to_s` is much more often called without any arguments,
so it's worth optimizing for the most common case.

```ruby
class Integer
  alias_method :faster_to_s, :to_s
end
require 'active_support/all'
require 'benchmark/ips'

module FasterNumericWithFormat
  def faster_to_s(format = nil, options = nil)
    if format.nil?
      return super()
    end

    case format
    when Integer, String
      super(format)
    when :phone
      ActiveSupport::NumberHelper.number_to_phone(self, options || {})
    when :currency
      ActiveSupport::NumberHelper.number_to_currency(self, options || {})
    when :percentage
      ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
    when :delimited
      ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
    when :rounded
      ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
    when :human
      ActiveSupport::NumberHelper.number_to_human(self, options || {})
    when :human_size
      ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
    when Symbol
      super()
    else
      super(format)
    end
  end
end

Integer.prepend(FasterNumericWithFormat)

Benchmark.ips do |x|
  x.report('orig no-arg') { 42.to_s }
  x.report('fast no-arg') { 42.faster_to_s }
  x.compare!
end

Benchmark.ips do |x|
  x.report('orig :human') { 42.to_s(:human) }
  x.report('fast :human') { 42.faster_to_s(:human) }
  x.compare!
end
```

Ruby 2.7.2
```
Warming up --------------------------------------
         orig no-arg   567.569k i/100ms
         fast no-arg   692.636k i/100ms
Calculating -------------------------------------
         orig no-arg      5.709M (± 1.3%) i/s -     28.946M in   5.070660s
         fast no-arg      6.892M (± 0.7%) i/s -     34.632M in   5.024961s

Comparison:
         fast no-arg:  6892287.7 i/s
         orig no-arg:  5709450.0 i/s - 1.21x  (± 0.00) slower

Warming up --------------------------------------
         orig :human   575.000  i/100ms
         fast :human   619.000  i/100ms
Calculating -------------------------------------
         orig :human      6.176k (± 1.6%) i/s -     31.050k in   5.028656s
         fast :human      6.179k (± 1.8%) i/s -     30.950k in   5.010372s

Comparison:
         fast :human:     6179.1 i/s
         orig :human:     6176.3 i/s - same-ish: difference falls within error

```
2021-03-30 15:41:20 +02:00
Rafael França
6675f6b785
Merge pull request #41255 from euxx/fix-create-migration-generator-with-pretend-option
Fix create migration generator with `--pretend` option
2021-03-29 22:27:34 -04:00
Rafael França
766ed57903
Merge pull request #41786 from ghiculescu/patch-4
Document `config.require_master_key` [docs] [ci-skip]
2021-03-29 20:44:38 -04:00
John Hawthorn
3a770b2197 Fix LogSubscriber for buffered event w/ nil logger
LogSubscriber overrides start/finish to avoid instrumenting when its
logger is nil. In order to support buffered notification events, as used
by async queries, we need to apply a similar override to
LogSubscriber#publish_event.
2021-03-29 17:31:07 -07:00
Ryuta Kamizono
6ce14ee4bc Address intermittent CI failure due to non-determined sort order
https://buildkite.com/rails/rails/builds/76112#1aa6023d-f58e-4c3e-96cc-027e36f2f415/973-984
2021-03-30 02:18:53 +09:00
Alex Ghiculescu
b9dfa21fbd
Document config.require_master_key [docs] [ci-skip] 2021-03-29 10:57:29 -05:00
Andrew White
bad93fe2a1
Merge pull request #41778 from rails/add-changelog-entry-for-41640
Add CHANGELOG entry for #41640
2021-03-28 09:13:48 +01:00
Andrew White
9d77ca2108
Merge pull request #41764 from steventux/41763-return-argument-error-for-parseable-invalid-iso8601-values
Raise ArgumentError from TimeZone.iso8601 instead of KeyError
2021-03-28 08:55:56 +01:00
Andrew White
7699f12dae
Add CHANGELOG entry for #41640 2021-03-28 08:15:50 +01:00
Ryuta Kamizono
f172129256 Call self.class only once in init_internals
Calling `self.class` multiple times is not cheap.

```ruby
class A
  def self.foo
  end

  def foo1
    self.class.foo
    self.class.foo
    self.class.foo
    self.class.foo
  end

  def foo2
    klass = self.class
    klass.foo
    klass.foo
    klass.foo
    klass.foo
  end
end

a = A.new

Benchmark.ips do |x|
  x.report("foo1") { a.foo1 }
  x.report("foo2") { a.foo2 }
end
```

```
Warming up --------------------------------------
                foo1   341.701k i/100ms
                foo2   414.000k i/100ms
Calculating -------------------------------------
                foo1      3.194M (± 5.4%) i/s -     16.060M in   5.044653s
                foo2      4.276M (± 3.8%) i/s -     21.528M in   5.041999s
```

Similar with #36052.
2021-03-28 11:15:12 +09:00
Ryuta Kamizono
af4ca424eb Follow up to #41765 [ci skip] 2021-03-28 10:55:35 +09:00
Ryuta Kamizono
a0097cd701 Add test case for class level strict_loading_mode 2021-03-28 10:49:15 +09:00
Ryuta Kamizono
4fe1220e57
Merge pull request #41765 from JasonBarnabe/patch-2
Specifiy association :validate option only applies to new associated objects

[ci skip]
2021-03-28 10:35:24 +09:00
George Claghorn
e3075c17ff Add frozen_string_literal pragma 2021-03-27 08:07:47 -04:00
George Claghorn
657b97e223 Active Storage representations: respond with 404 given invalid variation key 2021-03-27 08:03:27 -04:00
Rafael França
513cf351d4
Merge pull request #41770 from csutter/fix-deprecation
Fix deprecation warning on Actionpack request test
2021-03-26 14:25:28 -04:00
George Claghorn
526d630793 Upgrade to Marcel 1.0.0 2021-03-26 14:21:28 -04:00
George Claghorn
62ac25a364 Replace mimemagic with mini_mime 2021-03-26 14:20:40 -04:00
Christian Sutter
eab5a3877e Fix deprecation warning on Actionpack request test
The way this test initializes `ActionDispatch::RemoteIp` has been
deprecated in #40789. This makes the test append to the existing
trusted proxy list instead of assigning a single value.
2021-03-26 17:28:38 +00:00
Steve Laing
d4186a76c8 Raise ArgumentError from TimeZone.iso8601 when invalid value can be parsed by Date._iso8601
Date._iso8601 will return a hash for some values eg. '12936' but this will not contain the expected :mon and :mday keys.
Check for these keys and raise an ArgumentError if they aren't present as this is consistent with other invalid input behaviour.
2021-03-26 09:10:45 +00:00
Rafael França
30ef29289b
Merge pull request #41760 from Shopify/register-task-precedence
Give precedence to the DatabaseTasks registered last
2021-03-25 17:28:46 -04:00
Rafael França
d9494f9ec6
Merge pull request #41756 from c960657/patch-3
Probe with :array? instead of :oid
2021-03-25 17:08:02 -04:00
Jason Barnabe
345384fb1f
Specifiy association :validate option only applies to new associated objects
Per [code comments](6daa2d8315/activerecord/lib/active_record/associations.rb (L1418-L1420)), the `:validate` option only makes a difference for *new* objects. Existing objects are not validated, regardless of the setting.
2021-03-25 15:04:45 -05:00
Rafael França
6daa2d8315
Merge pull request #41759 from p8/rollback-a1a5d37749
Revert "Prevent double save of cyclic associations"
2021-03-25 11:07:55 -04:00
Jean Boussier
f35ca0faf0 Give precedence to the DatabaseTasks registered last 2021-03-25 13:08:37 +01:00
Petrik
1d574ae0d9 Revert "Prevent double save of cyclic associations"
Commit a1a5d37749964b1e1a23914ef13da327403e34cb doesn't properly set the
foreign key on associations. Instead of trying to patch the change
revert it for now, so we can investigate a better solution.

This reverts commit a1a5d37749964b1e1a23914ef13da327403e34cb

It also reverts the follow-up commits:

* Revert "Rename internal `@saving` state to `@_saving`"
  This reverts commit 2eb5458978f3f993ccc414b321b35fb1aef1efd2

* Revert "Add `_` prefix for the internal methods"
  This reverts commit 12c0bec15275fa458bc0ddd6b57f7a0ae7881bd5.

* Revert "protected :can_save?"
  This reverts commit 8cd3b657f8795aedb9bc97e725642cbd04dc09b8.

* Revert "Exclude #saving? from API docs"
  This reverts commit 35d3923ea0c51b3a628e913e3b35f85124de8ac8.
2021-03-25 10:46:07 +01:00
Christian Schmidt
0d5f43ed3c
Probe with :array? instead of :oid 2021-03-25 09:56:31 +01:00
Takumasa Ochi
9131f08904
[ci skip] Fix Grammatical Errors and Eliminate Ambiguous Wordings in Multiple Database Documents (#41670)
* Improve Readability of Guides on Multiple Databases

* Add comma after the introductory clause.
* Add backtick for the symbols used in the program.
  * `primary`
  * `false`
* Add descriptive information on ambiguous words.
  * users => database users
  * use the first configuration => use the first configuration as default
  * a recent write => a recent write by the requesting user
  * for an environment => for each environment
  * both a `role` and `shard` => both a `role` and a `shard`
* Add missing period at the end of a sentence.

* Add double quote inside backtick

[Rafael Mendonça França + Takumasa Ochi]
2021-03-24 23:36:20 -04:00
Svyatoslav Kryukov
cb95c1b14f
ActiveRecord: Optimize cache_key computation (#41741)
* Optimize cache_key computation

* After review

[Svyatoslav Kryukov + Rafael Mendonça França]
2021-03-24 22:42:34 -04:00
Rafael França
44c3ce2207
Merge pull request #41704 from dinahshi/strict-loading-mode
Add n_plus_one_only mode to Core#strict_loading!
2021-03-24 21:39:31 -04:00
Dinah Shi
5ec1cac9f2 Add n_plus_one_only mode to Core#strict_loading!
Add an optional mode argument to
Core#strict_loading! to support n_plus_one_only
mode. Currently, when we turn on strict_loading
for a single record, it will raise even if we are
loading an association that is relatively safe to
lazy load like a belongs_to. This can be helpful
for some use cases, but prevents us from using
strict_loading to identify only problematic
instances of lazy loading.

The n_plus_one_only argument allows us to turn
strict_loading on for a single record, and only
raise when a N+1 query is likely to be executed.
When loading associations on a single record,
this only happens when we go through a has_many
association type. Note that the has_many
association itself is not problematic as it only
requires one query. We do this by turning
strict_loading on for each record that is loaded
through the has_many. This ensures that any
subsequent lazy loads on these records will raise
a StrictLoadingViolationError.

For example, where a developer belongs_to a ship
and each ship has_many parts, we expect the
following behaviour:

  developer.strict_loading!(mode: :n_plus_one_only)

  # Do not raise when a belongs_to association
  # (:ship) loads its has_many association (:parts)
  assert_nothing_raised do
    developer.ship.parts.to_a
  end

  refute developer.ship.strict_loading?
  assert developer.ship.parts.all?(&:strict_loading?)
  assert_raises ActiveRecord::StrictLoadingViolationError do
    developer.ship.parts.first.trinkets.to_a
  end
2021-03-24 20:55:18 -04:00