Commit Graph

248 Commits

Author SHA1 Message Date
Ryuta Kamizono c3fd9f1776 Remove reverted CHANGELOG entry [ci-skip]
Follow up to #45553.
2022-07-10 10:02:27 +09:00
Gannon McGibbon 17b4b8fd63 Revert "Provide pattern matching for ActiveModel"
This reverts commit 7e499b25ac.
2022-07-09 00:13:23 -04:00
fatkodima 91cd5cbc93 Support infinite ranges for `LengthValidator`s `:in`/`:within` options 2022-05-20 20:41:18 +03:00
Bo Jeanes 28e40a6405 Add beginless range support to clusivity 2022-05-20 07:46:01 +10:00
fatkodima 00b269ec8d Make validators accept lambdas without record argument 2022-05-18 19:53:29 +03:00
Kevin Newton 7e499b25ac
Provide pattern matching for ActiveModel
It would be nice to be able to pattern match against ActiveModel (and
transitively ActiveRecord). If you want to check multiple attributes
with conditions, it's nice to be able use the pattern matching syntax.

For example:

```ruby
case Current.user
in { superuser: true }
  "Thanks for logging in. You are a superuser."
in { admin: true, name: }
  "Thanks for logging in, admin #{name}!"
in { name: }
  "Welcome, #{name}!"
end
```
2022-05-11 12:47:59 -04:00
fatkodima 0f4b030c44 Fix casting long strings to Date, Time or DateTime 2022-05-11 16:40:31 +03:00
Chris Salzberg 81519dec1a Use different namespace for proxy calls 2022-02-03 10:10:07 +01:00
Rafael Mendonça França 83d85b2207
Start Rails 7.1 development 2021-12-07 15:52:30 +00:00
Rafael Mendonça França 1f3cfb272c
Remove support to Marshal load Rails 5.x `ActiveModel::AttributeSet` format 2021-11-17 21:51:32 +00:00
Rafael Mendonça França 2996732089
Remove support to Marshal and YAML load Rails 5.x error format 2021-11-17 21:51:31 +00:00
Rafael Mendonça França 70dc990ad2
Remove deprecated support to use `[]=` in `ActiveModel::Errors#messages` 2021-11-17 21:51:30 +00:00
Rafael Mendonça França bab78b5d54
Remove deprecated support `delete` errors from `ActiveModel::Errors#messages` 2021-11-17 21:51:29 +00:00
Rafael Mendonça França ef40a92c1c
Remove deprecated support `clear` errors from `ActiveModel::Errors#messages` 2021-11-17 21:51:26 +00:00
Rafael Mendonça França 884c97fad0
Remove deprecated support concat errors to `ActiveModel::Errors#messages` 2021-11-17 21:51:25 +00:00
Rafael Mendonça França 73872c7220
Remove deprecated `ActiveModel::Errors#to_xml` 2021-11-17 21:51:23 +00:00
Rafael Mendonça França edc4e7dfb5
Remove deprecated `ActiveModel::Errors#keys` 2021-11-17 21:51:22 +00:00
Rafael Mendonça França 6fed53b694
Remove deprecated `ActiveModel::Errors#values` 2021-11-17 21:51:21 +00:00
Rafael Mendonça França 362e17e899
Remove deprecated `ActiveModel::Errors#slice!` 2021-11-17 21:51:20 +00:00
Rafael Mendonça França a743656ae4
Remove deprecated `ActiveModel::Errors#to_h` 2021-11-17 21:51:19 +00:00
Rafael Mendonça França 05b18d2694
Remove deprecated enumeration of `ActiveModel::Errors` instances as a Hash 2021-11-17 21:51:18 +00:00
Markus Doits 9bd186a0e8
clear secure password cache if password is set to `nil`
```rb
# before:
user.password = 'something'
user.password = nil

user.password # => 'something'

# now:
user.password = 'something'
user.password = nil

user.password # => nil
```
2021-10-10 11:54:35 +02:00
Rafael Mendonça França d177551c30
Preparing for 7.0.0.alpha2 release 2021-09-15 18:22:51 -04:00
Rafael Mendonça França 9b7be48212
Preparing for 7.0.0.alpha1 release 2021-09-15 17:55:08 -04:00
Petrik c477d95604 Introduce ActiveModel::API
Currently `ActiveModel::Model` is defined as the minimum API to talk
with Action Pack and Action View.
Its name suggests it can be included to create Active Record type
models, but for creating models it's probably too minimal. For example
it's very common to include ActiveModel::Attributes as well.

By moving `ActiveModel::Model`'s implementation to a new
`ActiveModel::API` we keep a definition of the minimum API to talk with
Action Pack and Action View.

For `ActiveModel::Model` we only need to include `ActiveModel::API`.
This will allow adding more funcationality to `ActiveModel::Model` while
keeping backwards compatibility.

Co-authored-by: Nathaniel Watts <1141717+thewatts@users.noreply.github.com>
2021-09-15 18:24:47 +02:00
Jean Boussier 8512118f43
Merge pull request #42832 from lulalala/slim-errors-inspect
Slimmer ActiveModel::Errors#inspect message
2021-07-23 09:05:08 +02:00
lulalala 1523838567 Slimmer ActiveModel::Errors#inspect
Only show @errors array and hide @base
2021-07-23 12:29:46 +08:00
Marcelo Lauxen d1df4c100f
Fix dirty check for Float::NaN and BigDecimal::NaN
Float::NaN and BigDecimal::NaN in Ruby are [special values](https://bugs.ruby-lang.org/issues/1720) and can't be compared with `==`.
2021-07-22 09:49:16 -03:00
Ryuta Kamizono e50b0e3ab3 Fixup CHANGELOGs [ci skip] 2021-07-21 10:08:08 +09:00
Zachary Scott bead3221c7 ✂️ 2021-06-30 08:31:17 +09:00
Anil Kumar Maurya ab1a58281c Fixes #41521, ActiveModel::Dirty fails on to_json 2021-06-24 10:31:48 +00:00
Chris Salzberg caced27393 Add ActiveModel::AttributeSet#values_for_database 2021-06-08 16:39:23 +09:00
Benoit Daloze 5d86e32ae2 Fix delegation in ActiveModel::Type.lookup
* Without the change the new test fails like this:
  Failure:
  ActiveModel::TypeTest#test_registering_a_new_type [test/cases/type_test.rb:21]:
  Expected: #<struct args={}>
    Actual: #<struct args=nil>
* (*args, **kwargs)-delegation is not correct on Ruby 2.7 unless the
  target always accepts keyword arguments (not the case for `Struct.new(:args).new`).
  See https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
2021-05-25 16:01:17 +02:00
Benoit Daloze 8ccc3bfc2d Fix delegation in ActiveModel::Type::Registry
* Without the change the new test fails like this:
  Failure:
  ActiveModel::Type::RegistryTest#test_a_class_can_be_registered_for_a_symbol [test/cases/type/registry_test.rb:16]:
  Expected: [{}, {}]
    Actual: [nil, nil]
* (*args, **kwargs)-delegation is not correct on Ruby 2.7 unless the
  target always accepts keyword arguments (not the case for `Array.new`).
  See https://eregon.me/blog/2021/02/13/correct-delegation-in-ruby-2-27-3.html
2021-05-21 13:50:33 +02:00
John Bampton 6e85b6b86e Add spell checking with codespell as a GitHub Action
`codespell` works with a small custom dictionary and seems to find perhaps more spelling mistakes than `misspell` which really only fixes commonly misspelled English words.

Not all spell checkers can check all file types and most spell checkers can't find all the errors.

https://github.com/codespell-project/codespell
https://pypi.org/project/codespell/
2021-05-04 14:46:21 +10:00
Jean Boussier ca5542fed3 Cache and reuse generated attribute methods 2021-05-03 09:27:59 +02:00
Ryuta Kamizono 978308ac87 Fix markup in CHANGELOGs [ci skip] 2021-02-07 05:45:53 +09:00
Michal Papis 2486e887de
Add validate numericality in range 2021-01-05 22:56:58 +01:00
Rafael Mendonça França 4740a2a02c
Add changelog entry for #40961 2020-12-29 19:25:04 +00:00
Rafael Mendonça França 59f7f5889e
Start Rails 6.2 development 🎉 2020-12-03 01:35:29 +00:00
Rafael Mendonça França 8389f9902c
Preparing for 6.1.0.rc1 release 2020-11-02 21:12:47 +00:00
Rafael Mendonça França 7eed607b12
Fix CHANGELOG [ci skip] 2020-11-02 18:16:45 +00:00
Filipe Sabella ac677fb1e3 Update CHANGELOG 2020-10-22 16:50:33 -03:00
Ryuta Kamizono f93b04afab Deprecate marshalling load from legacy attributes format
Since #31827, marshalling attributes hash format is changed to improve
performance because materializing lazy attribute hash is too expensive.

In that time, we had kept an ability to load from legacy attributes
format, since that performance improvement is backported to 5-1-stable
and 5-0-stable.

Now all supported versions will dump attributes as new format, the
backward compatibity should no longer be needed.
2020-05-02 15:49:09 +09:00
Ryuta Kamizono 6f2126c760 Fixup CHANGELOGs [ci skip] 2020-04-15 21:23:24 +09:00
Rafael Mendonça França a4deb63798
No need to deprecate Errors#first
This deprecation is useless since the result is still an Error object
and there is no way to fix the code to remove the deprecation.

Let's just accept as a breaking change.
2020-04-13 19:07:59 -04:00
Rafael França 6f6f4e40ab
Merge pull request #36125 from lulalala/doc-for-model-errors
Document update for ActiveModel#errors
2020-04-13 14:11:55 -04:00
Ryuta Kamizono 1d3eb7be13 Fixup CHANGELOGs [ci skip] 2020-02-25 14:14:54 +09:00
George Claghorn a6841c720a Allow checking whether an attribute previously changed from/to a particular value 2020-01-27 16:38:24 -05:00
lulalala bbf839d1a8 Add list of deprecated methods 2020-01-15 00:17:23 +08:00