aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* Fix typo in deprecation messageGeorg Ledermann2016-08-271-1/+1
| | | This fixes a copy-and-paste-issue slipped in by #18996
* Fix broken alignments caused by auto-correct commit 411ccbdRyuta Kamizono2016-08-101-1/+2
| | | | Hash syntax auto-correcting breaks alignments. 411ccbdab2608c62aabdb320d52cb02d446bb39c
* code gardening: removes redundant selfsXavier Noria2016-08-081-2/+2
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-4/+2
|
* applies new string literal convention in activemodel/libXavier Noria2016-08-061-5/+5
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Tiny documentation fixes [ci skip]Robin Dupret2016-06-251-7/+7
| | | | | Fix a tiny typo and vertical-align some return results in the ActiveModel::Errors documentation.
* [ci skip] Add additional documentation to ActiveModel::ErrorsAlex Kitchens2016-06-221-1/+12
|
* Ensure that instances of `ActiveModel::Errors` can be marshalledSean Griffin2016-05-301-2/+23
| | | | | | | | | | | | | | | | We now use default procs inside of the errors object, which gets included by default when marshaling anything that includes `ActiveModel::Validations`. This means that Active Record objects cannot be marshalled. We strip and apply the default proc ourselves. This will ensure the objects are YAML serializable as well, since YAML falls back to marshal implementations now. This is less important, however, as the errors aren't included when dumping Active Record objects. This commit does not include a changelog entry, as 5.0 is still in RC status at the time of writing, and 5.0.0 will not release with the bug this fixes. Fixes #25165
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2016-05-141-2/+11
|\ | | | | | | | | Conflicts: guides/source/configuring.md
| * Add example for UnknownAttributeErrorVipul A M2016-05-021-0/+9
| | | | | | | | [ci skip]
| * Active Model: Messages for strict validation always convert attributes to ↵Prathamesh Sonpatki2016-05-011-2/+2
| | | | | | | | human readable form [ci skip]
* | Change RangeError to a more specific ActiveModel::RangeErrorChristian Blais2016-05-031-0/+4
|/ | | | | | The should make it easier for apps to rescue ActiveModel specific errors without the need to wrap all method calls with a generic rescue RangeError.
* Pass over all Rails 5 warnings, to make sure:Vipul A M2016-04-121-2/+2
| | | | | | | | | | - we are ending sentences properly - fixing of space issues - fixed continuity issues in some sentences. Reverts https://github.com/rails/rails/commit/8fc97d198ef31c1d7a4b9b849b96fc08a667fb02 . This change reverts making sure we add '.' at end of deprecation sentences. This is to keep sentences within Rails itself consistent and with a '.' at the end.
* Allow passing record being validated to error message generatorPrathamesh Sonpatki2016-04-051-1/+2
| | | | | | | | | - Pass object to I18n helper so that when calling message proc, it will pass that object as argument to the proc and we can generate custom error messages based on current record being validated. - Based on https://github.com/rails/rails/issues/856. [Łukasz Bandzarewicz, Prathamesh Sonpatki]
* Do not create a hash key when calling ActiveModel::Errors#include?Esteban Pastorino2016-03-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | From: https://github.com/rails/rails/issues/24279 Problem: By doing `record.errors.include? :foo`, it adds a new key to the @messages hash that defaults to an empty array. This happens because of a combination of these 2 commits: https://github.com/rails/rails/commit/b97035df64f5b2f912425c4a7fcb6e6bb3ddab8d (Added in Rails 4.1) and https://github.com/rails/rails/commit/6ec8ba16d85d5feaccb993c9756c1edcbbf0ba13#diff-fdcf8b65b5fb954372c6fe1ddf284c78R76 (Rails 5.0) By adding the default proc that returns an array for non-existing keys, ruby adds that key to the hash. Solution: Change `#include?` to check with `has_key?` and then check if that value is `present?`. Add test case for ActiveModels::Errors#include?
* Remove unused parameter from methodJon Moss2016-02-171-2/+2
| | | | | | The `attribute` parameter is not used inside the `normalize_detail` method. This does not need to go through a deprecation cycle, since the method is private.
* Add documentation about method to describe how it works [ci skip]Mehmet Emin İNAÇ2016-02-041-0/+9
|
* `ActiveRecord::Base#becomes` should copy the errorsVokhmin Alexey V2015-12-141-0/+12
|
* File encoding is defaulted to utf-8 in Ruby >= 2.1Akira Matsuda2015-09-181-2/+0
|
* formatting changesunknown2015-05-291-3/+3
|
* Adds/Corrects use case for adding an error messageZamith2015-05-041-1/+1
| | | | | I believe this is a use case that was supposed to be supported, and it's a small fix.
* Merge pull request #19021 from morgoth/activemodel-errors-refactoringRafael Mendonça França2015-03-301-24/+4
|\ | | | | Simplify and alias ActiveModel::Errors methods where possible
| * Simplify and alias ActiveModel::Errors methods where possibleWojciech Wnętrzak2015-02-201-24/+4
| |
* | Fix ActiveModel::Errors#delete return value to stay backward compatibleRadan Skoric2015-03-221-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | Rails 5.0 changes to ActiveModel::Errors include addition of `details` that also accidentally changed the return value of `delete`. Since there was no test for that behavior it went unnoticed. This commit adds a test and fixes the regression. Small improvements to comments have also been made. Since `get` is getting deprecated it is better to use `[]` in other methods' code examples. Also, in the module usage example, `def Person.method` was replaced with a more commonly used `def self.method` code style.
* | Fix ActiveModel::Errors deprecation messages failing when used on its ownRadan Skoric2015-03-211-0/+1
| | | | | | | | | | | | Deprecation messages in ActiveModel::Errors are using String#squish from ActiveSupport but were not explicitly requiring it, causing failures when used outside rails.
* | Merge pull request #19077 from robin850/unknown-attribute-errorSean Griffin2015-03-021-0/+11
|\ \ | | | | | | Move `UnknownAttributeError` to a more sane namespace
| * | Follow-up to #10776Robin Dupret2015-02-261-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The name `ActiveModel::AttributeAssignment::UnknownAttributeError` is too implementation specific so let's move the constant directly under the ActiveModel namespace. Also since this constant used to be under the ActiveRecord namespace, to make the upgrade path easier, let's avoid raising the former constant when we deal with this error on the Active Record side.
* | | Removed non-standard and unused require 'active_support/deprecation' from ↵Vipul A M2015-02-271-1/+0
|/ / | | | | | | parts out of active_support.
* / Change the deprecation messages to show the preferred way to work withRafael Mendonça França2015-02-201-6/+6
|/ | | | ActiveModel::Errors
* Merge pull request #18996 from morgoth/deprecate-more-errors-methodsYves Senn2015-02-191-0/+16
|\ | | | | | | Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methods
| * Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methodsWojciech Wnętrzak2015-02-191-0/+14
|/ | | | without replacement.
* Deprecate `ActiveModel::Errors` `get`, `set` and `[]=` methods.Wojciech Wnętrzak2015-02-011-9/+28
| | | | They have inconsistent behaviour currently.
* Fixed duplicating ActiveModel::Errors#detailsWojciech Wnętrzak2015-01-241-1/+2
|
* Add ActiveModel::Errors#detailsWojciech Wnętrzak2015-01-201-20/+37
| | | | | | | | | | | | | | | | To be able to return type of validator, one can now call `details` on Errors instance: ```ruby class User < ActiveRecord::Base validates :name, presence: true end ``` ```ruby user = User.new; user.valid?; user.errors.details => {name: [{error: :blank}]} ```
* Fix error messages scope [skip ci]Anton Davydov2015-01-121-2/+2
|
* Fix inaccurate docs in active_model errors [ci skip]Robson Marques2014-12-221-2/+2
| | | | | | | | | | | | | | The default value for the argument `message` in `ActiveModel::Errors#add` has a new behavior since ca99ab2481d44d67bc392d0ec1125ff1439e9f94. Before person.errors.add(:name, nil) # => ["is invalid"] After person.errors.add(:name, nil) # => [nil]
* Add #key? to ActiveModel::ErrorsGarry Shutler2014-10-141-0/+2
| | | | Mirror Ruby's Hash#key?
* Using `each_with_object` instead of `reduce`Attila Domokos2014-08-221-2/+2
| | | | | This way no new object allocation is taking place. Thanks @jeremy for the suggestion!
* Replacing an each with reduceAttila Domokos2014-08-211-4/+2
| | | | | | | | The functionality has not changed, but the code is more elegant by using `reduce` instead of `each`. This way no accumulator needs to be declared, no explicit return is needed.
* Merge pull request #15889 from carnesmedia/model-nameRafael Mendonça França2014-08-171-1/+1
|\ | | | | | | Use #model_name on instances instead of classes
| * Use #model_name on instances instead of classesAmiel Martin2014-06-241-1/+1
| | | | | | | | | | | | This allows rails code to be more confdent when asking for a model name, instead of having to ask for the class. Rails core discussion here: https://groups.google.com/forum/#!topic/rubyonrails-core/ThSaXw9y1F8
* | [ci skip] Little bit doc code improvement.Santosh Wadghule2014-07-141-1/+1
|/
* Adds explanation of :base attribute to errors.addDavid Underwood2014-03-271-0/+7
| | | [ci skip]
* Fix ActiveModel::Errors#has_key? return valueAdrien Coquio2014-01-221-1/+1
|
* Change all "can not"s to the correct "cannot".T.J. Schuck2014-01-031-20/+20
|