Commit Graph

88522 Commits

Author SHA1 Message Date
Adrianna Chang cef3109856
Add ActionDispatch::Cookies middleware test with Rack::Lint
This adds an additional test to the ActionDispatch::Cookies middleware
test suite to ensure that the middleware sets the expected cookie header
when the request contains a cookie jar. Additionally, the test wraps the
Cookies middleware in Rack::Lint to ensure that ActionDispatch::Cookies
complies with the Rack SPEC.
2023-07-27 11:18:47 -04:00
Jean Boussier 8c23eaa4eb
Merge pull request #48824 from Shopify/sort-schema-cache
Sort SchemaCache members when dumping it
2023-07-27 10:56:53 +02:00
Keaton Roux dc4eb0f3b5 Add tags to audio analyzer metadata 2023-07-27 10:30:49 +02:00
Jean Boussier 3c7f48b8b9 Sort SchemaCache members when dumping it
Ref: https://github.com/rails/rails/issues/42717

This allow to result to be consistent, allowing to use its digest
for cache keys and such.
2023-07-27 10:29:56 +02:00
Jean Boussier af0d2c3ba7 Remove an extra whitespace in activesupport/CHANGELOG
This is not my day...
2023-07-27 09:35:38 +02:00
Jean Boussier 008cbbd351 Fix a rebase mistake in activesupport/CHANGELOG 2023-07-27 09:31:28 +02:00
Jean Boussier b7b741b02a
Merge pull request #48638 from p8/activesupport/cache-delete-return
Make all cache stores return a boolean for `#delete`
2023-07-27 08:48:53 +02:00
Petrik 3601a236dd Make all cache stores return a boolean for `#delete`
`Rails.cache.delete('key')` is supposed to return `true` if an entry
exists and `false` otherwise. This is how most stores behave.

However, the `RedisCacheStore` would return a `1` when deleting an entry
that does exist and a `0` otherwise.
As `0` is truthy this is unexpected behaviour.

`RedisCacheStore` now returns true if the entry exists and false
otherwise, making it consistent with the other cache stores.

Similarly the `FileCacheStore` now returns `false` instead of `nil` if
the entry doesn't exist.

A test is added to make sure this behaviour applies to all stores.

The documentation for `delete` has been updated to make the behaviour
explicit.
2023-07-27 08:48:30 +02:00
Jean Boussier d53e67281a
Merge pull request #48817 from Shopify/return-false-early-if-non-AR-value-passed-in-include
Return `false` early when a non-AR object passed to `FinderMethods#include?`
2023-07-27 08:29:47 +02:00
Jean Boussier ca9ff083da
Merge pull request #48792 from akhilgkrishnan/add-test-for-no-skip-docker
Added test for --no-skip-docker command line argument
2023-07-27 08:28:12 +02:00
Akhil G Krishnan 5cabd9edbe Added test for --no-skip-docker command line argument
Update railties/test/generators/app_generator_test.rb

Co-authored-by: zzak <zzakscott@gmail.com>

removed unwanted spacing

Added a newline
2023-07-27 10:28:11 +05:30
Hartley McGuire 34947521d9
Add and remove some links in IntegrationTest docs
Add direct links to #get, #post, #parsed_body, and #open_session.

Remove links to Session when already on the Session page.
2023-07-26 18:14:07 -04:00
Jonathan Hefner 1334919732
Merge pull request #48451 from jonathanhefner/cache-compressor
Support replacing cache compressor

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-07-26 16:39:22 -05:00
Nikita Vasilevsky 6798b43bef
Return `false` early when a non-AR object passed to `FinderMethods#include?`
This PR fixes a bug introduced in https://github.com/rails/rails/pull/48761
which leads to a `NoMethodError` when a non Active Record object passed
to `include?` or `member?` since only Active Record objects
respond to `composite_primary_key?`.
2023-07-26 18:05:50 +00:00
Hartley McGuire 4991525abb
Add Rack::Lint to PermissionsPolicy tests
This adds additional test coverage to PermissionsPolicy::Middleware to
validate that it conforms to the Rack SPEC.

The only changes necessary were to use the appropriate header casing for
Content-Type and Feature-Policy. Since this was the only usage of the
CONTENT_TYPE constant, I opted to remove it, but I can replace it with a
DeprecatedConstantProxy if that's more desirable.
2023-07-26 13:34:14 -04:00
Jonathan Hefner 3efb84486e Support replacing cache compressor
This commit adds support for replacing the compressor used for
serialized cache entries.  Custom compressors must respond to `deflate`
and `inflate`.  For example:

  ```ruby
  module MyCompressor
    def self.deflate(string)
      # compression logic...
    end

    def self.inflate(compressed)
      # decompression logic...
    end
  end

  config.cache_store = :redis_cache_store, { compressor: MyCompressor }
  ```

As part of this work, cache stores now also support a `:serializer`
option.  Similar to the `:coder` option, serializers must respond to
`dump` and `load`. However, serializers are only responsible for
serializing a cached value, whereas coders are responsible for
serializing the entire `ActiveSupport::Cache::Entry` instance.
Additionally, the output from serializers can be automatically
compressed, whereas coders are responsible for their own compression.

Specifying a serializer instead of a coder also enables performance
optimizations, including the bare string optimization introduced by cache
format version 7.1.
2023-07-26 11:59:09 -05:00
Hartley McGuire 0c92013158
Add Rack::Lint to ActionableExceptions tests
This adds additional test coverage to ActionableExceptions to validate
that its behavior conforms to the Rack SPEC.

The changes neccesary were to ensure that Response headers are downcased
when using Rack 3. For Content-Type and Content-Length, this is trivial
because Rack provides constants who's casing is dependent on the version
(Rack 2 is mixed, and Rack 3 is downcased). Since Rack does not include
a LOCATION constant, the Response::LOCATION constant was updated to
have a downcased value when using Rack 3.

Additionally, there was some missing coverage for invalid redirect URLs
which was addressed as well.
2023-07-26 10:13:57 -04:00
Hartley McGuire 37522f1596
Add Rack::Lint to HostAuthorization tests
This adds additional test coverage to HostAuthorization to validate that
its behavior conforms to the Rack SPEC.

By using Rack:: constants for Content-Type and Content-Length, we are
able to use the "correct" versions of the headers for applications using
each Rack version.

Additionally, two tests had to be updated that use an ipv6 address
without brackets in the HOST header because Rack::Lint warned that these
addresses were not valid HOST values. Rack::Lint checks HOST headers using
`URI.parse("http://#{HOST}/")`, and from what I could find, this
requirement follows RFC 3986 Section 3.2.2:

```
host        = IP-literal / IPv4address / reg-name
IP-literal = "[" ( IPv6address / IPvFuture  ) "]"
IPvFuture  = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
```
2023-07-26 09:50:06 -04:00
Nuno Silva df2616e20b
Add Rack::Lint to AssumeSSL middleware tests
To ensure Rails is and remains compliant with [the Rack 3
spec](6d16306192/UPGRADE-GUIDE.md)
we can add `Rack::Lint` to the Rails middleware tests.

There was no test file for ActionDispatch::AssumeSSL, so this change
adds one and validating that its input and output follow the Rack SPEC.
2023-07-26 11:08:43 +00:00
Nuno Silva 425decee6f
Add Rack::Lint to ActionDispatch::Callbacks tests
This adds additional test coverage for ActionDispatch::Callbacks by
validating that its input and output follow the Rack SPEC.

The `"rack.input" => StringIO.new("")` header value raised the following error:

```
Rack::Lint::LintError: rack.input #<StringIO:0x00007fd7513fe550> does not have ASCII-8BIT as its external encoding
```

Since this header is not required for the test, it is now removed.
2023-07-26 08:52:23 +00:00
Shouichi Kamiya 5931a68158 Support filtering tests by line ranges
The new syntax allows you to filter tests by line ranges. For example, the
following command runs tests between line 10 to 20.

```bash
$ rails test test/models/user_test.rb:10-20
```

Co-authored-by: Seonggi Yang <seonggi.yang@gmail.com>
Co-authored-by: Ryohei UEDA <ueda@anipos.co.jp>
Co-authored-by: oljfte <oljfte@gmail.com>
2023-07-26 15:00:08 +09:00
zzak 2e0c302df3
Revert "Merge pull request #46386 from lazaronixon/fix-has-one-create-record"
This reverts commit d2cb5b7469, reversing
changes made to 348e609da3.
2023-07-26 14:52:31 +09:00
zzak 09c1a85ab7
Revert "Merge pull request #48416 from Shopify/fix-has-one-deletion"
This reverts commit 6be41aded8, reversing
changes made to 55c3066da3.
2023-07-26 14:51:17 +09:00
Jonathan Hefner 3bdd57fba6 Support option aliases in RedisCacheStore#initialize
`ActiveSupport::Cache::UNIVERSAL_OPTIONS` already defines the list of
base options, and it includes option aliases such as `:expire_in` and
`:expired_in`.  Thus, using `UNIVERSAL_OPTIONS` allows `RedisCacheStore`
to support these aliases.
2023-07-25 15:57:21 -05:00
Jonathan Hefner c3bf6bf38d Raise more specific error for cache format version
Follow-up to #48449.

Since #48449 changed the list of accepted cache format versions back to
just `6.1`, `7.0`, and `7.1`, we can raise a more specific error.
2023-07-25 15:57:21 -05:00
Eileen M. Uchitelle 0c78ab2cc7
Merge pull request #48796 from adrianna-chang-shopify/ac-fix-previously-new-record
Fix `#previously_new_record?` on destroyed records
2023-07-25 16:55:34 -04:00
Adrianna Chang 7981988fa0
Fix #previously_new_record? on destroyed records
Ref: #48794

`#previously_new_record?` should return false for records that are
created and then destroyed.
2023-07-25 15:49:49 -04:00
Jean Boussier d580a776c3
Merge pull request #48800 from robinjam/fix-humanize-nil
Fix `ActiveSupport::Inflector.humanize(nil)`
2023-07-25 21:34:27 +02:00
James Robinson 016b81f0b2 Fix `ActiveSupport::Inflector.humanize(nil)` 2023-07-25 17:00:28 +01:00
Eileen M. Uchitelle 06e8bb5b4c
Merge pull request #48795 from Shopify/tweak-alias-attribute-deprecation-message
Tweak `alias_attribute` deprecation message
2023-07-25 10:51:13 -04:00
Nikita Vasilevsky 408b1b95d4
Tweak `alias_attribute` deprecation message 2023-07-25 13:53:55 +00:00
Alex Ghiculescu 455e922b49
Introduce `capture_emails` and `capture_broadcasts` (#48798) 2023-07-25 06:42:54 +02:00
Jean Boussier 5f3eb2195b
Merge pull request #48773 from nirvdrum/thread-safe-quoted-names
Make ActiveRecord's quoted name caches thread-safe on JRuby/TruffleRuby
2023-07-24 18:17:50 +02:00
Kevin Menard 68d572a5d1 Make ActiveRecord's quoted name caches thread-safe. 2023-07-24 12:04:10 -04:00
Jean Boussier 19c661463f
Merge pull request #48783 from Shopify/do-not-use-alias-attribute-for-associations
Do not use `alias_attribute` to alias an association
2023-07-24 17:34:26 +02:00
Nikita Vasilevsky 686336f579
Do not use `alias_attribute` to alias an association
Using `alias_attribute` to alias an association is not an indented
use case. This commit removes `alias_attribute` calls to alias an
association along with the relevant tests. However, it doesn't mean
that the commit brakes any current behaviors.
2023-07-24 14:45:09 +00:00
Jean Boussier de765e37c1 Never connect to the database in define_attribute_methods initializer
Followup: https://github.com/rails/rails/pull/48743

After careful consideration, unless users have a schema cache dump loaded
and `check_schema_cache_dump_version = false`, we have no choice but
to arbitrate between resiliency and performance.

If we define attribute methods during boot, we allow them to be shared
between forked workers, and prevent the first requests to be slower.

However, by doing so we'd trigger a connection to the datase, which
if it's unresponsive could lead to workers not being able to restart
triggering a cascading failure.

Previously Rails used to be in some sort of middle-ground where
it would define attribute methods during boot if for some reason
it was already connected to the database at this point.

But this is now deemed undesirable, as an application initializer
inadvertantly establishing the database connection woudl lead to
a readically different behavior.
2023-07-24 16:37:50 +02:00
Guillermo Iguaran f6c423a1fc
Merge pull request #48791 from akhilgkrishnan/add-dev-gems-skip-option-to-guide
[ci skip] Add --skip-dev-gems rails command line argument to the guide
2023-07-24 01:02:46 -07:00
Akhil G Krishnan f4233f5bd0 [ci skip] Add --skip-dev-gems rails command line argument to the guide 2023-07-24 12:57:01 +05:30
Adrianna Chang 04c97aec8a
Merge pull request #48784 from santib/fix-active-storage-guides
[ci skip] ActiveStorage guides don't recommend using a deprecated config
2023-07-21 15:24:29 -04:00
Santiago Bartesaghi 76da537a39 [ci skip] ActiveStorage guides don't recommend using a deprecated config 2023-07-21 16:11:23 -03:00
Eileen M. Uchitelle daca4cbf5d
Merge pull request #48779 from etiennebarrie/fix-writing-credentials
Fix inconsistencies writing credentials values
2023-07-21 11:03:03 -04:00
Eileen M. Uchitelle f9b7059816
Merge pull request #48774 from djpowers/patch-2
Improve readability of case sensitivity description
2023-07-21 09:06:22 -04:00
Jean Boussier 3ee73bff39
Merge pull request #48533 from Shopify/delay-alias-attribute-defition
Call proxy methods from `alias_attribute` generated methods
2023-07-21 14:08:30 +02:00
Xavier Noria 5a36344334 Fixes the documentation of with_transaction_returning_status
This method was refactored in d916c62, but the documentation was not updated.
2023-07-21 13:07:55 +02:00
Étienne Barrié b6ce10bcc6 Fix inconsistencies writing credentials values
Using [] or the dynamic accessors don't result in the same value because
`[]` is delegated to `config` (the decrypted deserialized YAML), whereas
`[]=` and the dynamic accessors are delegated to `options`, an
ActiveSupport::OrderedOptions instance.
2023-07-21 11:32:57 +02:00
Matthew Draper ea9b647806
Merge pull request #48772 from mhib/tagged-logger-proxy-block-support
Prevent inspecting transmit data if not necessary
2023-07-21 16:15:08 +09:30
Guillermo Iguaran bb599f5ec1
Merge pull request #48777 from Shopify/uk-use-kernel-warn-for-warnings
Change load error messages to use `Kernel#warn` instead of `$stderr.puts`
2023-07-20 15:31:03 -07:00
Ufuk Kayserilioglu c2b195e1e3
Change load error messages to use `Kernel#warn` instead of `$stderr.puts`
When development tools try to load Rails components, they sometimes end up loading files that will error out since a dependency is missing. In these cases, the tooling can catch the error and change its behaviour.

However, since the warning is printed directly to `$stderr`, the tooling cannot catch and suppress it easily, which ends up causing noise in the output of the tool.

This change makes Rails print these warnings using `Kernel#warn` instead, which can be suppressed by the tooling.
2023-07-21 00:38:12 +03:00
Dave Powers f7c5e7e75c
Improve readability of case sensitivity description 2023-07-20 16:30:16 -04:00