aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/error.rb
Commit message (Collapse)AuthorAgeFilesLines
* Switch to use `class_attribute`:Edouard CHIN2019-07-161-4/+3
| | | | | | | | | - Since `ActiveModel::Error` can now be inherited by `ActiveModel::NestedError`, when the latter generates a `full_message`, the `i18n_customize_full_message` accessor set in the parent class is not set. This commit fixes that by using a `class_attribute` instead.
* Move the `ActiveModel:Errors#full_message` method to the `Error` class:Edouard CHIN2019-07-161-2/+88
| | | | | | | | | | | | | | | | - 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 #36649 from Edouard-chin/ec-errors-strit-match-collectionRafael França2019-07-151-2/+2
|\ | | | | Fix `AM::Errors.added?` trying to generate a message:
| * Fix `AM::Errors.added?` trying to generate a message:Edouard CHIN2019-07-101-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - When a ActiveRecord record get saved and validated as part of a collection association, the errors attribute are changed to reflect the children names. You end up with an error attribute that will look like this: `author.errors # {:'books.title' => [:blank]}` https://github.com/rails/rails/blob/2fe20cb55c76e6e50ec3a4ec5b03bbb65adba290/activerecord/lib/active_record/autosave_association.rb#L331-L340 We then can't check if the `books.title` errors was added using `ActiveModel::Errors#added?` because it tries to generate a message to make the match and end up calling the "books.title" method on the Author. ``` author.errors.added?(:'books.title', :blank) => NoMethodError: undefined method `books.title' ``` This patch modify the behaviour of `strict_match?` to not generate a message to make the comparison but instead make a strict comparison with the `options` from the error.
* | Fix errors getting duplicated when passed validations options:Edouard CHIN2019-07-101-1/+1
|/ | | | | | | | | | | | | | | | | | | | | | | | | | - In 86620cc3aa8e2630bc8d934b1a86453276b9eee9, a change was made on how we remove error duplication on a record for autosave association This fix has one caveat where validation having a `if` / `unless` options passed as a proc would be considered different. Example: ```ruby class Book < ApplicationRecord has_one :author validates :title, presence: true, if -> { true } validates :title, presence: true, if -> { true } end Book.new.valid? # false Book.errors.full_messages # ["title can't be blank", "title can't be blank"] ``` While this example might sound strange, I think it's better to ignore `AM::Validations` options (if, unless ...) when making the comparison.
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+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.
* Fix equality comparison raising error buglulalala2019-03-311-1/+1
|
* Allow errors to remove duplicates, and ensure cyclic associations w/ ↵lulalala2019-03-311-0/+15
| | | | | autosave duplicate errors can be removed See SHA 7550f0a016ee6647aaa76c0c0ae30bebc3867288
* Change errorslulalala2019-03-311-1/+7
| | | | | | | | | | | | 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-0/+60
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