Commit Graph

2579 Commits

Author SHA1 Message Date
Matthew Draper
308dd9c504 Ensure binary-destined values have binary encoding during type cast 2023-05-29 18:21:20 +09:30
zzak
722d4f6582
Unlink Rails constant from READMEs 2023-05-29 15:14:44 +09:00
zzak
d7d24b02c1
Fix linking on ActiveModel::API 2023-05-29 12:40:48 +09:00
zzak
8674d53cd0
Fix heading for StrictValidationFailed 2023-05-27 06:56:26 +09:00
zzak
38bef29064
Replace all occurrences of '<tt>(\w+::\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>Rails::Command::NotesCommand</tt> -> +Rails::Command::NotesCommand+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
2023-05-25 06:56:17 +09:00
zzak
e3c73fd183
Replace all occurrences of '<tt>(\w+::\w+)</tt>' with '+$1+'
E.g.:

* <tt>ActiveRecord::Base</tt> -> +ActiveRecord::Base+

Co-authored-by: Hartley McGuire <skipkayhil@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-05-25 06:52:32 +09:00
Jean Boussier
108617eb74 Fix change_in_place? for binary serialized columns
Followup: https://github.com/rails/rails/pull/40383
Fix: https://github.com/rails/rails/issues/48255
Fix: https://github.com/rails/rails/pull/48262

If the serialized attribute is backed by a binary column, we must ensure
that both the `raw_old_value` and the `raw_new_value` are casted to
`Binary::Data`.

Additionally, `Binary::Data` must cast it's backing string in
`Encoding::BINARY` otherwise comparison of strings containing bytes
outside the ASCII range will fail.
2023-05-22 13:01:42 +02:00
zzak
0ec9e750ea
Merge pull request #48083 from skipkayhil/document-dirty-methods
Document ActiveModel::Dirty dispatch targets [ci skip]
2023-05-19 06:39:25 +09:00
Eileen M. Uchitelle
bc34f356e3
Merge pull request #48177 from eileencodes/unrevert-46444
Revert "Merge pull request #46444 from eileencodes/revert-forgetting-…
2023-05-09 13:29:28 -04:00
Jonathan Hefner
d6da86a476 Prevent non-anonymous modules from becoming frozen
In #48106, `Module#deep_dup` was changed to return the module itself
(not a copy) when the module is not anonymous.  However, that causes
non-anonymous modules to become frozen via `value.deep_dup.freeze` when
passed to `ActiveModel::Type::Helpers::Mutable#immutable_value`.  So,
for example, class attributes can no longer be set on the module.

To prevent such issues, this commit removes the `freeze` from
`immutable_value`.  `immutable_value` is only called by
`ActiveRecord::PredicateBuilder#build_bind_attribute`, which only cares
that other code cannot mutate the value, not that the value is actually
frozen.
2023-05-09 10:51:00 -05:00
eileencodes
38141681cc
Revert "Merge pull request #46444 from eileencodes/revert-forgetting-assignment-changes"
This reverts commit 586436d370126322a1470c10c1fde73cf8dc8875, reversing
changes made to 866e053732636e64685a72e22d76e7988d06a000.

This is an unrevert of https://github.com/rails/rails/pull/46282. I
should have reverted the revert sooner but it kept falling off my radar.

Closes #46446
2023-05-09 11:19:12 -04:00
Jean Boussier
b717a5a0d4 Revert "Merge pull request #47352 from basecamp/ar-freeze-cached"
This reverts commit 2c20f90ebae3fdd4d7e3351aeaffc4ad2c472069, reversing
changes made to 912096d4ce930b8e7e5d91e0c86bae2091fda0e4.
2023-05-02 10:53:14 +02:00
Jorge Manrubia
f195e033ac Freeze casted values instead of original values in database queries
This deals with a problem introduced in #7743ab95b8e15581f432206245c691434a3993d1a751b9d451170956d59457a9R8
that was preventing query `Class` serialized attributes. Duplicating the original
`Class` argument generates an anonymous class that can't be serialized as YAML.

This change makes query attributes hasheable based on their frozen casted values
to prevent the problem.

This solution is based on an idea by @matthewd from https://github.com/rails/rails/issues/47338#issuecomment-1424402777.
2023-05-02 10:09:20 +02:00
Hartley McGuire
7c1a5639c4
Document ActiveModel::Dirty dispatch targets
As part of my Railsconf talk I mentioned that attribute_changed? was an
undocumented method. Sage was surprised by this, and suggested that we
should probably be documenting this, since *_changed? methods are part
of the public API of Active Model.

I discussed this further with Rafael at Railsconf and we believe that in
addition to attribute_changed?, we should probably be documenting the
other dispatch targets in ActiveModel::Dirty as well.

Co-authored-by: Sage Griffin <sage@sagetheprogrammer.com>
2023-04-27 14:45:05 -04:00
Petrik de Heus
f2327e8df1
Merge pull request #48024 from p8/docs/headers-active-model-types
Fix ActiveModel type headings [ci-skip]
2023-04-22 12:09:47 +02:00
Petrik de Heus
0d02e5d4c3
Merge pull request #48022 from p8/docs/fix-header-level
Fix header level for ActiveModel::Naming and DelegatedType
2023-04-22 12:08:52 +02:00
Petrik
5a3daa626d Fix ActiveModel type headings [ci-skip] 2023-04-22 12:02:41 +02:00
Petrik
17b3e05133 Fix header level for ActiveModel::Naming and DelegatedType
A class should have a h1 instead of a h2.
2023-04-22 11:25:27 +02:00
Petrik
3042111944 Add some missing headers to Active Model Type docs [ci-skip] 2023-04-22 11:22:16 +02:00
Christopher Lake
42a4fcecf2
Update CHANGELOG example
CHANGELOG was not updated with subsequent changes to the PR #47708
2023-04-21 15:35:53 -07:00
Guillermo Iguaran
a60785cc27 Update password validation and error messages
- Simplify password validation to only check byte size for BCrypt limit (72 bytes)
- Replace specific error messages with a single "is too long" message
- Update test cases to reflect new error message

Co-authored-by: ChatGPT
2023-04-19 15:57:51 -07:00
Guillermo Iguaran
63f091409d Update CHANGELOG examples
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-04-19 15:57:18 -07:00
Guillermo Iguaran
74264f4467 Improve password length validation in ActiveModel::SecurePassword for BCrypt compatibility
- Validate password length in both characters and bytes
- Provide user-friendly error message for character length
- Add byte size validation due to BCrypt's 72-byte limit

Co-authored-by: ChatGPT

[Fix #47600]
2023-04-19 15:56:19 -07:00
Petrik
62c6cb3449 Fix more missing Active Model documentation headers [ci-skip]
This adds headers to the remaining Active Model Errors.
2023-04-01 15:46:04 +02:00
Petrik
f8e5dab6a4 Use h1 for Active Model documentation titles [ci-skip]
Most of the other frameworks use a h1(`=`) instead of h2(`==`) for
class/module documentation. Having a h1 will improve SEO and makes
things look more consistent.

This also adds a missing title and escapes a namespace so it won't be
linked.
2023-03-31 13:07:31 +02:00
Petrik de Heus
dc0f20595d
Merge pull request #47717 from p8/docs/include-readmes
Include READMEs in main framework pages of the API documentation
2023-03-30 16:43:14 +02:00
Jean Boussier
fcff4c8b4f ActiveModel::Type::SerializeCastValue only compute compatibility once per class
All instances of the same type will return the same thing, so we
might as well save some work and save an ivar.
2023-03-29 15:07:39 +02:00
Petrik
7c94708d24 Include READMEs in main framework pages of the API documentation
Currently when opening the main framework pages there is no introduction
to the framework. Instead we only see a whole lot of modules and the
`gem_version` and `version` methods.

By including the READMEs using the `:include:` directive each frameworks
has a nice introduction.
For markdown READMEs we need to add the :markup: directive.

[ci-skip]

Co-authored-by: zzak <zzakscott@gmail.com>
2023-03-21 21:16:28 +01:00
Matthew Draper
bb7f3be138
Revert "Quote binary strings in Arel" 2023-03-15 19:50:50 +10:30
Jonathan Hefner
db8f664b50
Merge pull request #47490 from lazaronixon/has_secure_password_salt
Enhance has_secure_password to also generate a password_salt method

Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2023-03-09 14:53:10 -06:00
Nixon
ebe9e575b7 Enhance has_secure_password to also generate a password_salt method 2023-03-09 16:44:10 -03:00
Ole Friis Østergaard
f4242739aa Move SQLite3 blob encoding to ActiveModel 2023-03-09 09:23:00 +00:00
zzak
aa2052ec4c
💅 AM CHANGELOG fixed-width re: #45463, #47569 2023-03-04 08:51:05 +09:00
Rafael Mendonça França
9f60cd8dc7
Merge PR #45463 2023-03-03 22:58:01 +00:00
Petrik
661c995f3b Add class name to ActiveModel::MissingAttributeError error message.
When an attribute is missing the current message is unclear about which
class is missing the attribute, especially when there are multiple
classes that could miss the attribute.

By adding the classs name to the error message it is easier to debug:

```ruby
user = User.first
user.pets.select(:id).first.user_id
=> ActiveModel::MissingAttributeError: missing attribute 'user_id' for Pet
```

This also makes the error message more inline with the
UnknownAttributeError message:

```ruby
=> ActiveModel::UnknownAttributeError: unknown attribute 'name' for Person
```

Co-authored-by: Yasuo Honda <yasuo.honda@gmail.com
2023-03-03 14:31:22 +01:00
joernchen of Phenoelit
2030530865 Fix issue with attr_protected where malformed input could circumvent
protection

Fixes: CVE-2013-0276
2023-02-26 22:20:26 +01:00
Jon Dufresne
da82e587f2 Improve typography of user facing validation messages
With the universal adoption of UTF-8 in browsers, user facing text can
use more optimal Unicode typography. In digital and print design, using
RIGHT SINGLE QUOTATION MARK (U+2019) is normally preferred over
APOSTROPHE (U+0027) in contractions.

For details, see the Unicode Standard Section 6.2:
https://www.unicode.org/versions/Unicode13.0.0/ch06.pdf

> Punctuation Apostrophe. U+2019 right single quotation mark is
> preferred where the character is to represent a punctuation mark, as
> for contractions: “We’ve been here before.” In this latter case,
> U+2019 is also referred to as a punctuation apostrophe.
2023-02-25 08:21:19 -08:00
zzak
d2af670dba
Remove Copyright years (#47467)
* Remove Copyright years

* Basecamp is now 37signals... again

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>

---------

Co-authored-by: David Heinemeier Hansson <dhh@hey.com>
2023-02-23 11:38:16 +01:00
Yasuo Honda
f838a74212
Merge pull request #46866 from ghousemohamed/change-year-2022-to-2023 2023-02-13 13:15:43 +09:00
Étienne Barrié
c958bc1342 Remove unparsed :method directive
RDoc doesn't parse this directive since the method is defined below.
It's only useful for metaprogrammed methods.

https://github.com/ruby/rdoc/blob/v6.5.0/lib/rdoc/parser/ruby.rb#L138-L139
2023-02-07 13:15:07 +01:00
zzak
8feec6d452 Tiny knits from AM::Validator docs 2023-02-06 16:39:00 +09:00
zzak
f8544410a2 Use stable guides link for package READMEs
E.g.: These show up here:
https://api.rubyonrails.org/files/actioncable/README_md.html
2023-02-04 09:01:00 +09:00
Jean Boussier
aa7d78d9b1 Improve Rails' Shape friendliness (second pass)
Followup: https://github.com/rails/rails/pull/47023

```
Shape Edges Report
-----------------------------------
snip...
       238  @errors
snip...
       219  @options
snip...
       129  @_request
       128  @type
       125  @virtual_path
       124  @_assigns
       123  @_config
       123  @_controller
       123  @output_buffer
       123  @view_flow
       122  @_default_form_builder
snip...
        89  @_already_called
        75  @validation_context
snip...
        65  @_new_record_before_last_commit
snip...
        58  @_url_options
snip...
```
2023-01-17 13:55:49 +01:00
Rafael Mendonça França
a52596c943
Merge pull request #47022 from zzak/callbacks-links-continued
Fix more links for callbacks
2023-01-16 15:38:27 -05:00
Jean Boussier
fc950324bd Improve Rails' Shape friendliness
Ruby 3.2 significantly changed how instance variables are store.
It now use shapes, and in short, it's important for performance
to define instance variables in a consistent order to limit the
amount of shapes.

Otherwise, the number of shapes will increase past a point where
MRI won't be able to cache instance variable access. The impact
is even more important when YJIT is enabled.

This PR is data driven. I dump the list of Shapes from Shopify's
monolith production environment, and Rails is very present among
the top offenders:

```
Shape Edges Report
-----------------------------------
       770  @default_graphql_name
       697  @own_fields
       661  @to_non_null_type
       555  @own_interface_type_memberships
       472  @description
       389  @errors
       348  @oseid
       316  @_view_runtime
       310  @_db_runtime
       292  @visibility
       286  @shop
       271  @attribute_method_patterns_cache
       264  @namespace_for_serializer
       254  @locking_column
       254  @primary_key
       253  @validation_context
       244  @quoted_primary_key
       238  @access_controls
       234  @_trigger_destroy_callback
       226  @_trigger_update_callback
       224  @finder_needs_type_condition
       215  @_committed_already_called
       214  @api_type
       203  @mutations_before_last_save
       202  @access_controls_overrides
       201  @options
       198  @mutations_from_database
       190  @_already_called
       183  @name
       179  @_request
       176  @own_arguments
       175  @_assigns
       175  @virtual_path
       174  @context
       173  @_controller
       173  @output_buffer
       173  @view_flow
       172  @_default_form_builder
       169  @cache
       159  @_touch_record
       151  @attribute_names
       151  @default_attributes
       150  @columns_hash
       149  @attribute_types
       148  @columns
       147  @marked_for_same_origin_verification
       146  @schema_loaded
       143  @_config
       143  @type
       141  @column_names
```

All the changes are of similar nature, the goal is to preset the instance
variable to nil when objects are allocated, or when classes are created.

For classes I leverage the `inherited` hook. If the patern becomes common enough
it might make sense to add a helper for this in `ActiveSupport::Concern`.
2023-01-16 12:31:37 +01:00
zzak
ae8ca668d8 Fix more links for callbacks
Some of these are linked unnecessarily, while some should be added.
2023-01-16 19:04:26 +09:00
Akira Matsuda
bd11e520a2
Merge pull request #46868 from amatsuda/Time.new_string
Use Ruby 3.2's native ISO 8601-ish String parser to cast String to Time in Active Record
2023-01-11 03:56:25 +09:00
Jonathan Hefner
3eadf057db Fix typos in API docs [ci-skip] 2023-01-08 15:47:20 -06:00
Jonathan Hefner
33557c5dca Indent private methods in code examples [ci-skip]
This matches the indentation used in generated code, such as code from
`railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt`.
2023-01-08 15:47:20 -06:00
zzak
50507abe44
Merge pull request #46856 from zzak/validations-api-default-error-messages
[ci-skip] Document default error messages for some validations
2023-01-08 08:29:52 +09:00