aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/errors_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-2/+1
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-3/+3
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-4/+4
|
* Use respond_to test helpersDaniel Colson2018-01-251-1/+1
|
* fix bug on added? methodAlessandro Rodi2017-11-131-0/+7
| | | | fix rubocop issues
* 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 ActiveModel::Errors #keys, #valuesbogdanvlviv2017-03-281-0/+16
| | | | | | | | | | | | | | | | | | 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
* Missing require for strip_heredocAkira Matsuda2017-01-171-0/+1
|
* Missing require "yaml"Akira Matsuda2016-12-121-0/+1
|
* Make ActiveModel::Errors backward compatible with 4.2Rafael Mendonça França2016-12-081-0/+20
| | | | | | | 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-3/+8
| | | | | | `#[]` has already applied indifferent access, but some methods does not. `#include?`, `#has_key?`, `#key?`, `#delete` and `#full_messages_for`.
* Removed deprecated methods in ActiveModel::ErrorsRafael Mendonça França2016-10-101-92/+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-0/+10
|
* improve error message when include assertions failMichael Grosser2016-09-161-2/+2
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* applies new string literal convention in activemodel/testXavier Noria2016-08-061-17/+17
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add test to better demonstrate `ActiveModel::Errors#added?` behaviorJon Moss2016-06-211-0/+6
| | | | Fixes #25410.
* Ensure that instances of `ActiveModel::Errors` can be marshalledSean Griffin2016-05-301-0/+9
| | | | | | | | | | | | | | | | 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
* Followup of #18322Vipul A M2016-05-021-1/+1
| | | | Mirror the documented new behavior of including details, when performing errors test.
* Do not create a hash key when calling ActiveModel::Errors#include?Esteban Pastorino2016-03-241-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | 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?
* `ActiveRecord::Base#becomes` should copy the errorsVokhmin Alexey V2015-12-141-0/+10
|
* Use private method call assertions in Active Model tests.Kasper Timm Hansen2015-07-101-24/+9
| | | | Also fix Minitest constant reference.
* Remove use of mocha from Active ModelRoque Pinel2015-05-281-23/+45
|
* Adds/Corrects use case for adding an error messageZamith2015-05-041-0/+6
| | | | | 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-0/+6
|\ | | | | Simplify and alias ActiveModel::Errors methods where possible
| * Simplify and alias ActiveModel::Errors methods where possibleWojciech Wnętrzak2015-02-201-0/+6
| |
* | Fix arguments order on assertionCarlos Antonio da Silva2015-03-221-1/+1
| | | | | | | | The expected value comes first. Related to #19465.
* | Fix ActiveModel::Errors#delete return value to stay backward compatibleRadan Skoric2015-03-221-0/+6
|/ | | | | | | | | | | | 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.
* Deprecate `ActiveModel::Errors` `add_on_empty` and `add_on_blank` methodsWojciech Wnętrzak2015-02-191-7/+21
| | | | without replacement.
* Deprecate `ActiveModel::Errors` `get`, `set` and `[]=` methods.Wojciech Wnętrzak2015-02-011-15/+21
| | | | They have inconsistent behaviour currently.
* Fixed duplicating ActiveModel::Errors#detailsWojciech Wnętrzak2015-01-241-1/+1
|
* Add ActiveModel::Errors#detailsWojciech Wnętrzak2015-01-201-0/+42
| | | | | | | | | | | | | | | | 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}]} ```
* Add #key? to ActiveModel::ErrorsGarry Shutler2014-10-141-0/+11
| | | | Mirror Ruby's Hash#key?
* Tests for indifferent access using full_messages_for. Closes #11916Pavel Penkov2014-03-081-0/+7
|
* Update ActiveModel::Errors.has_key? testAdrien Coquio2014-01-221-1/+1
|
* Add failing test for ActiveModel::Errors#has_key? methodAdrien Coquio2014-01-221-0/+5
| | | | From the doc, this method should return false and not nil if there is no errors for this key
* Change all "can not"s to the correct "cannot".T.J. Schuck2014-01-031-33/+33
|
* Convert ActiveModel to 1.9 hash syntax.Patrick Robertson2013-05-011-4/+4
| | | | | I also attempted to fix other styleguide violations such as { a: :b } over {a: :b} and foo(b: 'bar') over foo( b: 'bar' ).
* Review some tests from AMo::Errors to remove "should" usageCarlos Antonio da Silva2013-03-301-55/+35
| | | | | Also remove duplicated tests for Errors#as_json and minor improvements in some tests.
* Merge pull request #8527 from shockone/patch-1Rafael Mendonça França2013-03-251-0/+20
|\ | | | | Add a method full_messages_for to the Errors class
| * Add a method full_messages_for to the Errors classshock_one2013-03-241-0/+20
| |
* | Add Error#full_message test; Fix typosVipul A M2013-03-221-0/+1
|/ | | | | Introduce test on Error#full_message for attribute with underscores; Fix some typos
* added more accurate test for add_on_emptyAngelo capilleri2013-02-191-0/+7
| | | | | with the current tests, if delete the assignment of is_empty in add_on_empty method the tests not fail. With this test, if we delete is_empty, the test fails
* Covering untested methods for ActiveModel::ErrorsAttila Domokos2013-01-101-0/+53
|
* Actually test that ActiveModel::Errors#add defaults to :invalid.Renato Mascarenhas2012-12-011-1/+1
|
* Call `full_messages` instead of `to_a` in its spec.Renato Mascarenhas2012-12-011-2/+1
|
* use Array() instead flattenVasiliy Ermolovich2012-11-051-1/+39
| | | | | * move ActiveModel::Errors tests to errors_test.rb * add spec coverage for add_on_empty and add_on_blank
* AM::Errors: allow :full_messages parameter for #as_jsonBogdan Gusiev2012-02-201-0/+10
|