aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
Commit message (Collapse)AuthorAgeFilesLines
* Accessing ivar with Symbols might be just a very little bit better than with ↵Akira Matsuda2019-07-311-1/+1
| | | | fstrings
* Fixed the typo in the deprecation error messages. Followup #36738Abhay Nikam2019-07-231-1/+1
|
* Modify behaviour of `AM::Errors#to_h`:Edouard CHIN2019-07-231-2/+6
| | | | | | | | | | | | | | | | | | | | | - `AM::Error#to_h` was kind of broken before and would return in the hash values a single error message. ```ruby person = Person.new person.errors.add(:name, "cannot be blank") person.errors.add(:name, "too long") puts person.errors.to_h # {name: 'too long'} ``` Since an attribute can have different errors, the previous behavior didn't make much sense. Now, `ActiveModel::Errors#to_hash` correctly returns an array of error messages containing all the errors for an attribute. However, one can easily be surprised by this change, so let's deprecated it first.
* Deprecated `AM::Errors#to_h`:Edouard CHIN2019-07-231-0/+6
| | | | | | | | | | | | | | | | - In ef4d3215b1198c456780b8d18aa62be7795b9b8c I made a change to pass `AM::Error` object in case the arity of the block passed to `each` accepted less than 2 arguments. This is causing one issue for `to_h` as it expects the argument passed to the block to be an Array (and were are passing it an instance of `AM::Error`). There is no real reason to use `to_h` anymore since `to_hash` exists Deprecating `to_h` inf favor of `to_hash` Co-Authored-By: Rafael França <rafael@franca.dev>
* Fix deprecation on `AM::Errors` when each is called indirectly:Edouard CHIN2019-07-201-1/+1
| | | | | | | | | | | | - `AM::Errors#each` is implemented for the `Enumerator` module and get called indirectly by a bunch of method in the ruby land (map, first, select ...) These methods have a `-1` arity as they are written in C and they wrongly trigger a deprecation warning. This commit fixes that and correctectly return a `AM::Error` object when `each` is called with a negative arity.
* Move the `ActiveModel:Errors#full_message` method to the `Error` class:Edouard CHIN2019-07-161-80/+2
| | | | | | | | | | | | | | | | - One regression introduced by the "AM errors as object" features is about the `full_messages` method. It's currently impossible to call that method if the `base` object passed in the constructor of `AM::Errors` doesn't respond to the `errors` method. That's because `full_messages` now makes a weird back and forth trip `AM::Errors#full_messages` -> `AM::Error#full_message` -> `AM::Errors#full_message` Since `full_message` (singular) isn't needed by AM::Errors, I moved it to the `AM::Error` (singular) class. This way we don't need to grab the `AM::Errors` object from the base.
* Merge pull request #36654 from Edouard-chin/ec-errors-deleteRafael França2019-07-151-1/+1
|\ | | | | Returns `nil` when `AM::Errors#delete` doesn't delete anything:
| * Returns `nil` when `AM::Errors#delete` doesn't delete anything:Edouard CHIN2019-07-111-1/+1
| | | | | | | | | | | | | | | | | | - `AM::Errors#delete` currently returns an empty array when trying to delete an error that doesn't exist. This behaviour is surprising and I think it would be better to no return a truthy value but instead return nil like `Hash#delete` does.
* | active_support/deprecation has to be already required via ↵Akira Matsuda2019-07-121-1/+0
|/ | | | active_support/rails.rb
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-2/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* any? should be delegated to the errors listAaron Patterson2019-04-301-1/+1
| | | | Otherwise we get deprecation warnings in the generated scaffold template files
* Change the deprecation for Enumerating ActiveModel::Errors to Rails 6.1 ↵Abhay Nikam2019-04-251-5/+5
| | | | | | | | instead of 6.0 (#36087) * Change the deprecation for Enumerating ActiveModel::Errors to Rails 6.1 instead of 6.0 * Changed the deprecation message for ActiveModel::Errors methods: slice, values, keys and to_xml
* Set default array to detailslulalala2019-03-311-1/+9
| | | | maintaining behavior errors.details[:foo].any?
* Fix messages[]= does not override valuelulalala2019-03-311-0/+1
|
* Freeze DeprecationHandling array and hashlulalala2019-03-311-13/+20
|
* Split messages and to_hashlulalala2019-03-311-18/+21
| | | | | | Fix double wrapping issue Revert messages_for wrapping. It's a new method so no need to put deprecation warnings.
* Raise deprecation for calling `[:f] = 'b'` or `[:f] << 'b'`lulalala2019-03-311-4/+46
| | | | Revert some tests to ensure back compatibility
* Add deprecation to slice!lulalala2019-03-311-0/+2
|
* String override options in #import to convert to symbollulalala2019-03-311-0/+5
|
* Allow errors to remove duplicates, and ensure cyclic associations w/ ↵lulalala2019-03-311-1/+1
| | | | | autosave duplicate errors can be removed See SHA 7550f0a016ee6647aaa76c0c0ae30bebc3867288
* Add messages_forlulalala2019-03-311-1/+7
|
* Add a transitional method `objects`, for accessing the array directly.lulalala2019-03-311-0/+1
| | | | This is because we try to accommodate old hash behavior, so `first` and `last` now does not return Error object.
* Backward compatibility for errors.collect/select etc.lulalala2019-03-311-2/+2
| | | | | All enumerable methods must go through the `each` so it retain old hash behavior. Revert this after Rails 6.1 in order to speed up enumerable methods.
* Add convenience method group_by_attributelulalala2019-03-311-20/+9
| | | | | | Many operations need grouping of errors by attributes, e.g. ActiveRecord::AutosaveAssociation#association_valid? Refactor other methods using group_by_attribute
* Change errorslulalala2019-03-311-108/+183
| | | | | | | | | | | | Allow `each` to behave in new way if block arity is 1 Ensure dumped marshal from Rails 5 can be loaded Make errors compatible with marshal and YAML dumps from previous versions of Rails Add deprecation warnings Ensure each behave like the past, sorted by attribute
* Add ActiveModel::Error and NestedErrorlulalala2019-03-311-16/+0
| | | | | | | Add initialize_dup to deep dup. Move proc eval and flexible message position out to Errors, because proc eval is needed for Errors#added? and Errors#delete
* Rename `i18n_full_message` config option to `i18n_customize_full_message`Prathamesh Sonpatki2019-03-291-3/+3
| | | | | | - I feel `i18n_customize_full_messages` explains the meaning of the config better. - Followup of https://github.com/rails/rails/pull/32956
* Fall back to parent locale before it falls back to the :errors namespaceHugo Vacher2019-03-041-9/+14
|
* Add `ActiveModel::Errors#of_kind?`bogdanvlviv2019-01-041-9/+30
| | | | Related to https://github.com/rails/rails/pull/34817#issuecomment-451508668
* Add slice! method to ActiveModel::ErrorsDaniel Lopez Prat2018-11-211-0/+11
|
* Fix ignored options in the `#added?` methodRonan Limon Duparcmeur2018-11-131-3/+3
| | | | Fixes #34416
* Call human_attribute_name with a string instead of a symboleMartin Larochelle2018-08-161-1/+1
|
* `ActiveModel.full_message` interaction with `index_errors`Martin Larochelle2018-08-141-3/+6
|
* Ensure attribute is a symbol in the added? methodJeremy Baker2018-07-141-1/+1
|
* Fix active_model/errors docs [ci skip]bogdanvlviv2018-06-121-1/+1
| | | | | | | - Fix indentation. - Add a missing dot to the end of the sentence. Related to #32956
* Add global config for config.active_model.i18n_full_messageMartin Larochelle2018-06-051-1/+6
|
* Allow to override the full_message error formatMartin Larochelle2018-05-221-2/+41
|
* fix bug on added? methodAlessandro Rodi2017-11-131-3/+7
| | | | fix rubocop issues
* Simplify ActiveModel::Errors#generate_messageViktar Basharymau2017-08-181-7/+5
| | | | | | | | | | Besides making the code easier to read, this commit also makes it faster: * We don't eval `@base.class.respond_to?(:i18n_scope)` twice * We only eval `@base.class.i18n_scope` once * We don't call `flatten!` because it's not needed anymore * We don't call `compact` because all elements are Symbols
* Use frozen string literal in activemodel/Kir Shatrov2017-07-161-0/+2
|
* Add ActiveModel::Errors#merge!Jahfer Husain2017-07-071-0/+12
| | | | | | | | | | | | | | | | | ActiveModel::Errors#merge! allows ActiveModel::Errors to append errors from a separate ActiveModel::Errors instance onto their own. Example: person = Person.new person.errors.add(:name, :blank) errors = ActiveModel::Errors.new(Person.new) errors.add(:name, :invalid) person.errors.merge!(errors) puts person.errors.messages # => { name: ["can't be blank", "is invalid"] }
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Fix `warning: extra states are no longer copied`Ryuta Kamizono2017-04-011-4/+4
| | | | | | `messages` has `default_proc` so calling `reject` causes the warning. https://github.com/ruby/ruby/blob/v2_4_1/hash.c#L1335-L1337
* Fix ActiveModel::Errors #keys, #valuesbogdanvlviv2017-03-281-11/+6
| | | | | | | | | | | | | | | | | | Before: person.errors.keys # => [] person.errors.values # => [] person.errors[:name] # => [] person.errors.keys # => [:name] person.errors.values # => [[]] After: person.errors.keys # => [] person.errors.values # => [] person.errors[:name] # => [] person.errors.keys # => [] person.errors.values # => [] Related to #23468
* Make ActiveModel::Errors backward compatible with 4.2Rafael Mendonça França2016-12-081-2/+9
| | | | | | | If a Error object was serialized in the database as YAML in the Rails 4.2 version, if we load in the Rails 5.0 version it will miss the @details instance variable so methods like #clear and #add will start to fail.
* Allow indifferent access in ActiveModel::ErrorsKenichi Kamiya2016-11-221-2/+5
| | | | | | `#[]` has already applied indifferent access, but some methods does not. `#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-2/+2
|
* Removed deprecated methods in ActiveModel::ErrorsRafael Mendonça França2016-10-101-87/+0
| | | | `#get`, `#set`, `[]=`, `add_on_empty` and `add_on_blank`.
* Do not leak the Errors default proc when calling to_hash or as_jsonJean Boussier2016-09-271-1/+1
|