In a test environment, rely on the loading of
`:active_support_test_case`.
Introduce the `:active_record_fixture_set` hook for the Active Storage
engine to listen for during the load process in a development
environment (like when running `db:fixtures:load`).
Since this commit moves the task-aware path resolution out of the block
that provided local variables, it recreates part of the fixture
directory path resolution logic.
Apply the same structure as the documentation of `validate` option by
starting the description with "when set to true". This implies, that
the value passed to the option should be a boolean.
Fixes a flaky Active Storage test introduced by [rails/rails#41065][],
and improves the documentation.
It seems that the test is covering the backwards compatibility of an
older interface for retrieving records through
`ActiveStorage::Record#find_signed!`. The test itself would pass
unpredictably. To isolate the failure and reproduce it consistently, a
see value was found after some trial and error:
```
SEED=59729 bin/test test/fixture_set_test.rb test/models/attachment_test.rb
```
This _used_ to pass consistently because [rails/rails][#41065]
introduced a call to `fixtures :all`, which introduces more variation in
the database's ID generation sequence. Without that line, `id` values
start at `1`, so the fact that calls to
`ActiveStorage::Attached::One#id` and `ActiveStorage::Blob#id` **both
return `1`** is purely coincidence.
The proposed resolution changes the test slightly. Prior to this change,
the identifier used during retrieval and verification fetched from
`@user.avatar.id`, where `@user.avatar` is an instance of
`ActiveStorage::Attached::One`. The verifier/retriever combination in
that test expected a signed identifier for an `ActiveStorage::Blob`
instance. The change involved retrieving an instance through
`@user.avatar.blob`.
To better emphasize how global the `fixtures :all` declaration is, move
it from the `test/fixture_set_test.rb` file to the `test/test_helper.rb`
file.
[rails/rails#41065]: https://github.com/rails/rails/pull/41065
The section on needing to use `stylesheet_pack_tag` was lacking the erb
%'s.
I updated the markdown to actually show the helper being used with erb
as well as improve the wording of the sentence.
* Improve ActionText::FixtureSet documentation
Support for Action Text attachments in fixtures was added by [76b33aa][] and
released as part of [6.1.1][], but has not yet been documented.
This commit documents the `ActionText::FixtureSet` for the API
documentation, and mentions it in the Rails Guides pages.
[76b33aa]: 76b33aa3d1
[6.1.1]: https://github.com/rails/rails/releases/tag/v6.1.1
* Fix indention of comments
Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
* Improve Fixture support for Active Storage
Inspired by [76b33aa][], this commit extends the Active Storage
documentation to elaborate on how to declare fixtures.
In support of that, also introduce the `ActiveStorage::FixtureSet.blob`
method for injecting in-line [ActiveStorage::Blob][] attributes directly
into fixture YAML.
[76b33aa]: 76b33aa3d1
[ActiveStorage::Blob]: https://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob.html
* Extra CR for style
* Two-space indention
* Explaining variable didn't explain, inline for style
Co-authored-by: David Heinemeier Hansson <david@loudthinking.com>
When throw was used in a controller action, and there is matching catch
around the request in a Rack middleware, then :exception won't be
present in the event payload.
This is because ActiveSupport::Notifications::Instrumenter.instrument
sets :exception in a rescue handler, but rescue is never called in a
throw/catch scenario:
catch(:halt) do
begin
throw :halt
rescue Exception => e
puts "rescue" # never reached
ensure
puts "ensure"
end
end
Missing :exception was actually handled prior to Rails 6.1.0, but an
optimization updated the code to assume this was present. So this can be
considered a regression fix.
Before this commit, only StandardError exceptions can be handled by
rescue_from handlers.
This changes the rescue clause to catch all Exception objects, allowing
rescue handlers to be defined for Exception classes not inheriting from
StandardError.
This means that rescue handlers that are rescuing Exceptions outside of
StandardError exceptions may rescue exceptions that were not being
rescued before this change.
Co-authored-by: Adrianna Chang <adrianna.chang@shopify.com>
- Fixes typo in the changelog for strict_loading.
- Fixes the example in the changelog for strict_loading. The `strict_loading!` on ActiveRecord object does not disable strict loading on the association if set to strict loading. The example spoke otherwise so updated in a manner to make it more clear.
- Add method level dcoumentation as changelog was only way to communicate how strict_loading could be disabled on the record.
If the media attribute is omitted, the default for web browsers is "all", meaning that by default links apply to all media.
Before:
```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" media="screen" rel="stylesheet" />
```
After:
```ruby
> stylesheet_link_tag "style"
=> <link href="/assets/style.css" rel="stylesheet" />
```
The current behavior is not going to change for existing applications.
For newly built applications, the media attribute is not going to be added by default. Which can be configured using the following:
```
Rails.application.config.action_view.stylesheet_media_default = false
```
Now that Active Record supports multiple databases configuration
we need a way to pass specific flags for dump/load databases since
the options are not the same for different adapters.
We can use in the original way:
```ruby
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = ['--no-defaults', '--skip-add-drop-table']
#or
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = '--no-defaults --skip-add-drop-table'
```
And also use it passing a hash, with one or more keys, where the key
is the adapter
```ruby
ActiveRecord::Tasks::DatabaseTasks.structure_dump_flags = {
mysql2: ['--no-defaults', '--skip-add-drop-table'],
postgres: '--no-tablespaces'
}
```
If the "url" protocol is "jdbc", "http", or "https" the url option will
be passed to the adapter. Previously only urls with the "jdbc" prefix
were passed to the Active Record Adapter, others are assumed to be
adapter specification urls.
Fixes#41137.
Fixed: https://github.com/rails/rails/issues/40559#issuecomment-752056106
When abstract class hasn't own connections, calling `AbstractClass.connection`
returns parent class's connection. We call `AbstractClass.connection.preventing_writes?`
expecting abstract class's state to be returned, but actually it is parent's one.
I think that it isn't expected behavior so I prevents call `connected_to` on the abstract
class that not established the connection.
Prevent raising an error when `options` are given as
kwargs, this is done by overriding `options` with kwargs
if `options` are `nil`; this implies that if both `options` and
kwargs are given, `options` takes precedence.
Fixes#41198