One of the original goals of these checks was to validate that
configuration stays in alphabetical order, as this provides a
deterministic order for the configuration to be validated against.
However, it appears there has been a regression in that check and it has
only been validating that configurations are present. This commit
restores the ordering check and then uses `railspect configuration . -a`
to fix the configurations that ended up out of order.
Introduce Action View bug report template for contributors to reproduce
issues with failing `ActionView::TestCase` instances.
In addition to rendering ERB with the `inline:` keyword, the sample
tests also include a `Helpers` module to demonstrate how to incorporate
view helpers into the reproduction script.
I was reading the Action Mailer guide and noticed the settings and
defaults for the `:file` delivery method were poorly documented. These
docs were originally added back in #13728. #44422 added links to the
relevant sections of the Configuration guide, but did not link
`config.action_mailer.file_settings` because the Configuration guide is
actually missing that section.
I added a short section to the Configuration guide for
`config.action_mailer.file_settings` and linked to it from the Action
Mailer guide, following the style of the other delivery methods. Like
other delivery methods, the relevant options for `file_settings` come
from the allowed options of the `Mail::FileDelivery` class in the mail
gem.
Here's where Rails sets up this delivery method with the default
location:
9064735ec5/actionmailer/lib/action_mailer/delivery_methods.rb (L30-L31)
And here's where the mail gem uses the options:
10a4443b9d/lib/mail/network/delivery_methods/file_delivery.rb (L21)
- Link to Deprecation::Behavior in configuring guide
The current list of options for `config.active_support.deprecation`
was missing the newly added `:report` option. Instead of adding the
missing option and continuing to keep 4 different lists of the same
options in sync, I opted to replace the list with a link to the
options in the Behavior API docs. This had the additional advantage of
giving more information about all of the options which was not
mentioned in the Configuring guide.
- Use symbols for Behavior options
It felt to me like naming the options did not make it explicit that
those were the symbols to pass to `#behavior=`, but by adding the `:`
that becomes more clear.
- Add some API links
There were a few references to `behavior=`, but we may as well link to
the actual method.
In commit 449039a86d,
ActionDispatch::Head was replaced with Rack::Head in the
middleware. However, the documentation was not changed.
Rack::Head code behaviour is not to change HEAD into GET it is to
close the body of all HEAD requests. This commit fixes the docs
to show this.
The left-over ActionDisplayt::Head documentation is,
unsurprisingly, wrong. Rack::Head code behaviour is not to change
HEAD into GET it is to close the body of all HEAD requests.
This commit fixes the docs to show this.
As a contributor, changing a single line to test the desired version does not warrant a separate file for each type of report.
The only argument I can see for keeping the gem versions is that users are likely reporting a bug for a specific version of Rails, typically during an upgrade. As few people are probably testing their applications against Rails main branch.
Additionally, having the gem version templates means that we are testing both main and a stable release of Rails in CI, which has some benefit.
By removing the edge version templates, we also lose that coverage in CI, but I think it's something we can fix in buildkite-config to replace the line in those guides before running them later.
IMO, the cost of separate files and the confusion it will create if we want to add more templates outweighs the benefits mentioned here.
My motivation is that I want to add more report templates, like for additional adapters, and this list will grow to be unmanageable if we keep the gem versions.
Add guidance to the Association Basics and `.belongs_to` method
documentation to encourage the renaming of a model's Ruby class to
coincide with updates to the existing data in the database.
Since Action Text and Active Storage rely on polymorphic associations,
add similar warnings to their guides.
Co-authored-by: Petrik de Heus <petrik@deheus.net>
Co-authored-by: Stephen Hanson <s.hanson5@gmail.com>
Co-authored-by: zzak <zzakscott@gmail.com>
Upgrading Rails to "at least 2.1.1" is outdated advice. Applications
should run 7.0.Z or 7.1.Z.
Also, RedCloth version 4 is from 2009, so I don't think it's that "new".
- Explain the purpose of wrap_parameters_by_default and how it replaces
the wrap_parameters initializer.
- Explain why action_mailer.smtp_timeout exists and why its useful
- Add example to action_view.button_to_generates_button_tag
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.
The new documentation explicitly lists all "autoload paths" for the
reader, and mentions the `add_autoload_paths_to_load_path` config toggle
Co-authored-by: Matt <iMacTia@users.noreply.github.com>
Association callbacks were missing in the callbacks guide.
We can still keep a small section in the associations guide that links
to the callbacks guide.
The ordering can now be configured.
Also update the Configuring guide and API docs. In the Configuring guide
"When true" seems more common than "When false", so that is used
instead.
Co-authored-by: Akhil G Krishnan <akhilgkrishnan4u@gmail.com>
Rename "Dealing With Consistency" heading to "`after_commit` and
`after_rollback`. To be more inline with other headings.
The "Context Matters" heading has been renamed to "Aliases for
`after_commit`", as this section is about aliases and `Context Matters` is
a bit ambiguous.
The warnings for `after_commit` and `after_rollback` better fit with the
section about these callback methods.
Currently only Action Mailbox and Active Storage use initialized apps, so at least in those cases we can ensure the correct defaults are used by bug reporters.
Add documentation for `ActionText::RichText#to_s` and
`ActionText::Content#to_s` that demonstrates Action Text's ability to
sanitize and scrub its content.
Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
* Update ActiveRecord::StrictLoadingViolationError API docs to
reference the guide to help beginners learn how to resolve the error.
* Update Active Record Query Interface guide to cover configuration and
the association option.
Apply suggestions from code review
Co-authored-by: Eileen M. Uchitelle <eileencodes@users.noreply.github.com>
Update the text for config.public_file_server.enabled in the configuring guide as PR #47137 turned on static file server by default for all environments.
Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
For better or worse, the Rails guide settled on double quotes
and a large part of the community also use rubocop which enforce
them by default.
So we might as well try to follow that style when providing code
snippets in the documentation or error messages.
Fix: https://github.com/rails/rails/issues/49822
I certainly didn't get them all, but consistency should be significantly
improved.
Co-Authored-By: Akhil G Krishnan <akhilgkrishnan4u@gmail.com>
Add link providing more details about ERB in the 'Getting Started' documentation [ci skip]
Co-Authored-By: Akhil G Krishnan <akhilgkrishnan4u@gmail.com>
Fix link to point to html [ci skip]
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
Revert "Merge branch 'branch_new' of https://github.com/mguan2020/rails into pr/49640"
This reverts commit 94b8c7d579a74c528c4a85f3ce0f0853c4883fd1, reversing
changes made to 1353ca902f260dfb9bbe7680ede2650a670f659f.
Revert "Revert "Merge branch 'branch_new' of https://github.com/mguan2020/rails into pr/49640""
This reverts commit e9ced85c8f6afe0bc057bc6d8d4387718a7c3916.
If there's a column named `disabled`, we'll still raise
`ActiveRecord::SubclassNotFound`. Setting `inheritance_column` to `nil`
works though.
I had mistakenly thought `:disabled` was the correct way to disable STI,
since this is what is done in [some tests][].
```ruby
Schema: cogs[ id, type, disabled, created_at, updated_at ]
class Cog < ApplicationRecord
self.inheritance_column = nil
end
Cog.create! type: "Sprocket", disabled: true
=> #<Cog type: "Sprocket", disabled: "t">
```
[some tests]: a4751751bc/activerecord/test/models/post.rb (L231)
The docs already talk about how to set up deferrable constraints, but
then rely on the user crafting custom SQL to actually use the feature.
The helper makes it easier to handle juggling multiple specific
constraints and quoting issues.
Since 74264f4 improved the secure_password length validation to match bcrypt limit, this validation can be described more accurately in the ActiveModel basics guide.
* Update broken links in testing.md
The HTTP headers and CGI variables section had broken links. Updated these to direct to the correct locations on datatracker.ietf.org.
* Update to Point to correct section 4.1
ActiveStorage::Attachment records are not directly maintained by
ActiveStorage and it may not be feasible or desired to update the record
when its attachment is saved.
We never explained how migrations paths work for shards. This fixes that
and also adds the appropriate class setup. You no longer need to set a
`default` shard as of #48353. In addition, `ApplicationRecord` should be
used for the non-sharded db that also serves as the tenant/shard router.
Then shards should get their own connection class since the schema
differs.
Otherwise they are considered separate lists instead of a sequence
within the same list. This also renders the code block with extra
indent, as part of the item they belong to.
Also use `Active Record Encryption` with capital letters consistently.
[ci skip]
Detail:
This Pull Request modifies the documentation of Action Text so that all instances of 'contenteditable' and 'execCommand' are now in a code block. This makes the documentation more readable for users.
Follow-up to #47782.
These examples merely illustrate the order of execution when using `up`
and `down`, so we only need one operation before and after.
Follow-up to #48221.
The Active Support Instrumentation guide is about the
`ActiveSupport::Notifications` API. Therefore, move the information
about `config.server_timing` and the `ActionDispatch::ServerTiming`
middleware to the existing sections in the Configuration guide.
These examples show RDoc in the form of Ruby comments, and should
therefore use the `ruby` code fence (which matches the other examples in
this guide).
- This should make it easier for apps or libraries that were
previously relying on the private API.
Also took the opportunity to tweak the doc of the BroadcastLogger
to mention what happens when calling a non-standard method.
Fix#49494
Link to `Rails::Generators::Testing::Behavior` instead of
`Rails::Generators::Testing::Behaviour` in an effort to ensure the Edge
Guides link to the correct API documentation.
* Conditionally print `$stdout` when invoking `run_generator`
In an effort to improve the developer experience when debugging
generator tests, we add the ability to conditionally print `$stdout`
instead of capturing it.
This allows for calls to `binding.irb` and `puts` work as expected.
```sh
PRINT_STDOUT=true ./bin/test test/generators/actions_test.rb
```
* Update railties/CHANGELOG.md
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
* Rename environment variable
* Update generators guides.
* Update guides
---------
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
* Add encryption.add_to_filter_parameters to configuring.md
encryption.add_to_filter_paramters has been merged by https://github.com/rails/rails/pull/46453.
(This PR is a second try of https://github.com/rails/rails/pull/49364 )
* Update entry for encryption.add_to_filter_parameters
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
It's possible since Rails 6 (3ea2857943) to let the framework create Event objects, but the guides and docs weren't updated to lead with this example.
Manually instantiating an Event doesn't record CPU time and allocations, I've seen it more than once that people copy-pasting the example code get confused about these stats returning 0. The tests here show that - just like the apps I've worked on - the old pattern keeps getting copy-pasted.
- An oversight of #48615 is that it changes the `Rails.logger` to be
a broadcast logger after the app is booted. Anything referencing
`Rails.logger` during the boot process will get a simple logger and
ultimately resulting in logs not being broadcasted.
For example `ActionController::Base.logger.info("abc")` would
just output logs in the `development.log` file, not on STDOUT.
----
The only solution I could think of is to create a BroadcastLogger
earlier at boot, and add logger to that broadcast when needed (instead
of modiyfing the `Rails.logger` variable).
Register a callable to decode rendered content for a given MIME type
Each registered decoder will also define a `#rendered.$MIME` helper
method, where `$MIME` corresponds to the value of the `mime` argument.
=== Arguments
`mime` - Symbol the MIME Type name for the rendered content
`callable` - Callable to decode the String. Accepts the String
value as its only argument
`block` - Block serves as the decoder when the
`callable` is omitted
By default, ActionView::TestCase defines a decoder for:
* :html - returns an instance of Nokogiri::XML::Node
* :json - returns an instance of ActiveSupport::HashWithIndifferentAccess
Each pre-registered decoder also defines a corresponding helper:
* :html - defines `rendered.html`
* :json - defines `rendered.json`
=== Examples
To parse the rendered content into RSS, register a call to `RSS::Parser.parse`:
```ruby
register_decoder :rss, -> rendered { RSS::Parser.parse(rendered) }
test "renders RSS" do
article = Article.create!(title: "Hello, world")
render formats: :rss, partial: article
assert_equal "Hello, world", rendered.rss.items.last.title
end
```
To parse the rendered content into a Capybara::Simple::Node,
re-register an `:html` decoder with a call to
`Capybara.string`:
```ruby
register_decoder :html, -> rendered { Capybara.string(rendered) }
test "renders HTML" do
article = Article.create!(title: "Hello, world")
render partial: article
rendered.html.assert_css "h1", text: "Hello, world"
end
```
This change would force a lot of existing applications and libraries
to update their tests.
We included it in the beta to collect feedback from the community and
we had some comments about how negative this change would be.
Developers that care about the typography of their error messages
can easily change it in their applications using the translation
files, so there is no need to inflict pain in the upgrade process
by changing the default in the framework.
Revert "Merge PR #45463"
This reverts commit 9f60cd8dc7, reversing
changes made to 35d574dbfd.
As we (I and @yahonda) talked about the naming in person, naming unique
constraints as unique keys is very confusing to me.
All documents and descriptions says it's unique constraints, but naming
unique keys leads to misunderstanding it's a short-hand of unique
indexes.
Just naming it unique constraints is not misleading.
Expand examples by adding singular associations.
Expand the guides with `strict_loading!`.
Also add `to_a` to code examples as loading the associations is required
to raise the errors.
* Update 7_1_release_notes.md
For context see https://github.com/rails/rails/pull/45867
Include in release notes the deprecation of `true` and `false` values
for `config.action_dispatch.show_exceptions` in favor of `:all`,
`:rescuable` and `:none`.
* Update 7_1_release_notes.md
Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
---------
Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
Change mentions of `app/views/shared` in the guides to be
`app/views/application` instead. View partials rely on the same
[Template Inheritance][] as their template counterparts, so the guides
should encourage end-users to benefit from that inheritance.
> This makes `app/views/application/` a great place for your shared
> partials, which can then be rendered in your ERB as such:
>
```html+erb
<%# app/views/admin/products/index.html.erb %>
<%= render @products || "empty_list" %>
<%# app/views/application/_empty_list.html.erb %>
There are no items in this list <em>yet</em>.
```
To enforce that template resolution, this commit also replaces
references to `shared/` with `application/` in the Rails test suite.
[Template Inheritance]: https://guides.rubyonrails.org/layouts_and_rendering.html#template-inheritance
Motivation / Background
---
While the `ActionView::TestCase` class isn't marked with a `:nodoc:`
comment to indicate that it's internal to Rails, there isn't much
content in the guides that explains how to test view partials.
Libraries like
[view_component](https://github.com/ViewComponent/view_component/) have
[built-in support for
testing](https://viewcomponent.org/guide/testing.html), including
Capybara integration.
While `ActionView::TestCase` already integrates with
`rails-dom-testing`, that integration could be better documented.
Additionally, it wouldn't take much for consuming applications to mimic
the ViewComponent testing experience for their Action View Partials.
Details
---
First, link to the "Testing Rails Applications" page from the
`ActionView::TestCase` class documentation.
Next, add a "Testing View Partials" section to the guides that expands
upon the variety of tooling available to tests that inherit from
`ActionView::TestCase`. In that section, cover topics like:
* the `render` helper method
* the `rendered` helper attribute reader
* calls to `assert_select` with attribute placeholders
* the `document_root_element` helper method
* integration with Ruby's Pattern Matching
* opportunities to integrate with Capybara
Additional Information
---
Additionally, add test coverage that exercise the examples shared in the
new section, including:
* Calls to `assert_select` that utilize attribute placeholders
* Ruby 3.0's Pattern Matching
* Integration with Capybara
* Add Bun support to `rails new -j` generator
* Add additional generation consideration for Bun
* Use development gems to test the whole workflow
* Remove custom gems from local testing
* Revert lock
* Revert errant custom gem declaration
* Fix linting errors
* Fix remnants of bad merge
* Always use latest bun
* Update actioncable/lib/rails/generators/channel/channel_generator.rb
Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
* Update guides/source/working_with_javascript_in_rails.md
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
* Only use the latest bun if nothing is specified
* Hardcode known good version
---------
Co-authored-by: Cadu Ribeiro <mail@cadu.dev>
Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
In #49105, `where` examples were added to the `normalizes` documentation
to demonstrate that normalizations are also applied for `where`.
However, as with the `exists?` examples, we should also demonstrate that
normalizations are only applied to keyword arguments, not positional
arguments. We can also address the original source of the confusion by
changing the wording of "finder methods" to "query methods".
This commit also removes the tests added in #49105. `normalizes` works
at the level of attribute types, so there is no need to test every query
method. Testing `find_by` is sufficient. (And, in point of fact,
`find_by` is implemented in terms of `where`.)