aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/validations
Commit message (Collapse)AuthorAgeFilesLines
* Fix spec as generate_message is no longer called during validationlulalala2019-03-311-0/+2
|
* Fix misalignment caused by SHA eebb9ddf9ba559a510975c486fe59a4edc9da97dlulalala2019-03-311-5/+5
|
* Merge pull request #35424 from Korri/validation-rules-locale-fallbackRafael França2019-03-111-2/+18
|\ | | | | Fall back to parent locale before falling back to the :errors namespace
| * Fall back to parent locale before it falls back to the :errors namespaceHugo Vacher2019-03-041-2/+18
| |
* | Replace “can not” with “cannot”.Samantha John2019-03-061-1/+1
| |
* | Deprecate mismatched collation comparison for uniquness validatorRyuta Kamizono2019-03-041-0/+45
|/ | | | | | | | | | | | | | | | | | | | | In MySQL, the default collation is case insensitive. Since the uniqueness validator enforces case sensitive comparison by default, it frequently causes mismatched collation issues (performance, weird behavior, etc) to MySQL users. https://grosser.it/2009/12/11/validates_uniqness_of-mysql-slow/ https://github.com/rails/rails/issues/1399 https://github.com/rails/rails/pull/13465 https://github.com/gitlabhq/gitlabhq/commit/c1dddf8c7d947691729f6d64a8ea768b5c915855 https://github.com/huginn/huginn/pull/1330#discussion_r55152573 I'd like to deprecate the implicit default enforcing since I frequently experienced the problems in code reviews. Note that this change has no effect to sqlite3, postgresql, and oracle-enhanced adapters which are implemented as case sensitive by default, only affect to mysql2 adapter (I can take a work if sqlserver adapter will support Rails 6.0).
* Module#{attr,attr_accessor,attr_reader,attr_writer} become public since Ruby 2.5Ryuta Kamizono2018-12-213-3/+3
| | | | https://bugs.ruby-lang.org/issues/14132
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-24/+24
| | | | Follow up of #32605.
* Replace `assert !` with `assert_not`Daniel Colson2018-04-191-4/+4
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Deprecate update_attributes and update_attributes!Eddie Lebow2018-02-172-2/+2
| | | | Closes #31998
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-5/+5
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-255-59/+59
|
* Change refute to assert_notDaniel Colson2018-01-251-2/+2
|
* Check :scope input in Uniqueness validatorKir Shatrov2017-08-131-0/+7
|
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-197-0/+14
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-027-7/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-017-0/+7
|
* Merge branch 'master' of github.com:rails/docrailsVijay Dev2017-03-041-1/+1
|\
| * Remove duplicated "does" [ci skip]Ryuta Kamizono2017-02-141-1/+1
| |
* | Fix a tests of AR::ValueTooLong when using OracleAdapterKoichi ITO2017-02-141-2/+2
|/
* fix the uniqueness validation scope with a polymorphic associationSergey Alekseev2016-11-261-0/+16
| | | | https://gist.github.com/sergey-alekseev/946657ebdb5e58d1bee115714056ec96
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-1/+1
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But comments was still kept absolute position. This commit aligns comments with method definitions for consistency.
* Add three new rubocop rulesRafael Mendonça França2016-08-163-15/+15
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Add `Style/EmptyLines` in `.rubocop.yml` and remove extra empty linesRyuta Kamizono2016-08-071-1/+0
|
* applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
|
* remove redundant curlies from hash argumentsXavier Noria2016-08-061-4/+4
|
* modernizes hash syntax in activerecordXavier Noria2016-08-064-50/+50
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-067-81/+81
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Add i18n_validation_testsukesan19842016-06-021-4/+2
| | | | add active record uniqueness validation test for { on: [:create, :update] } condition.
* Merge pull request #23523 from kamipo/avoid_truncation_in_uniqueness_validationJeremy Daer2016-04-181-10/+32
|\ | | | | | | Avoid a string value truncation in uniqueness validation
| * Avoid a string value truncation in uniqueness validationRyuta Kamizono2016-02-121-10/+22
| | | | | | | | | | | | | | | | | | In MySQL, PostgreSQL, Oracle and SQLServer, a value over the limit cannot be inserted or updated (See #23522). In SQLite3, a value is inserted or updated regardless of the limit. We should avoid a string value truncation in uniqueness validation.
* | remove outdated comment [ci skip]yuuji.yaginuma2016-03-051-6/+0
| | | | | | | | Currently use minitest mock, mocha is not used.
* | Fix test name typo prescence -> presenceeileencodes2016-02-271-1/+1
| |
* | Fix uniqueness validation with an after_create hook.Joe Rafaniello2016-02-251-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | record.id_was is nil in after_create/after_save, so we should use id in these cases. While this logic feels incomplete, the existing update_record uses the same logic: https://github.com/rails/rails/blob/2fda4e0874a97a76107ab9e88305169f2c625933/activerecord/lib/active_record/relation.rb#L83 This logic was originally added for a similar problem: updates not working with after_create hook. See: 482f8c15b1d699c95bfbc3d836f674a09c0d9031 Followup to #23581 Fixes #23844
* | Revert changes to validations from PR #18612eileencodes2016-02-234-63/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In order to fix issue #17621 we added a check to validations that determined if a record should be validated. Based on the existing tests and behavior we wanted we determined the best way to do that was by checking if `!record.peristed? || record.changed? || record.marked_for_destruction?` This change didn't make it into a release until now. When #23790 was opened we realized that `valid?` and `invalid?` were broken and did not work on persisted records because of the `!record.persisted?`. While there is still a bug that #17621 brought up, this change was too drastic and should not be a RC blocker. I will work on fixing this so that we don't break `valid?` but also aren't validating parent records through child records if that parent record is validate false. This change removes the code changes to validate and the corresponding tests. It adds tests for two of the bugs found since Rails 5 beta2 release. Fixes #17621
* | Merge pull request #23628 from maclover7/fix-23625Sean Griffin2016-02-231-0/+26
|\ \ | | | | | | Fix issue #23625
| * | Fix issue #23625Jon Moss2016-02-181-0/+26
| |/ | | | | | | | | | | This resolves a bug where if the primary key used is not `id` (ex: `uuid`), and has a `validates_uniqueness_of` in the model, a uniqueness error would be raised. This is a partial revert of commit `119b9181ece399c67213543fb5227b82688b536f`, which introduced this behavior.
* | Match test name to test (typo)Ian Fleeton2016-02-211-1/+1
| |
* | Always validate record if validating a virtual attributeeileencodes2016-02-203-0/+45
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #23645 When you're using an `attr_accessor` for a record instead of an attribute in the database there's no way for the record to know if it has `changed?` unless you tell it `attribute_will_change!("attribute")`. The change made in 27aa4dd updated validations to check if a record was `changed?` or `marked_for_destruction?` or not `persisted?`. It did not take into account virtual attributes that do not affect the model's dirty status. The only way to fix this is to always validate the record if the attribute does not belong to the set of attributes the record expects (in `record.attributes`) because virtual attributes will not be in that hash. I think we should consider deprecating this particular behavior in the future and requiring that the user mark the record dirty by noting that the virtual attribute will change. Unfortunately this isn't easy because we have no way of knowing that you did the "right thing" in your application by marking it dirty and will get the deprecation warning even if you are doing the correct thing. For now this restores expected behavior when using a virtual attribute by always validating the record, as well as adds tests for this case. I was going to add the `!record.attributes.include?(attribute)` to the `should_validate?` method but `uniqueness` cannot validate a virtual attribute with nothing to hold on to the attribute. Because of this `should_validate?` was about to become a very messy method so I decided to split them up so we can handle it specifically for each case.
* UniquenessValidator exclude itself when PK changedDiego Silva2016-02-091-0/+11
| | | | | | | When changing the PK for a record which has a uniqueness validation on some other attribute, Active Record should exclude itself from the validation based on the PK value stored on the DB (id_was) instead of its new value (id).
* Improve support for non Active Record objects on `validates_associated`Kassio Borges2015-11-081-0/+12
| | | | | | Skipping `marked_for_destruction?` when the associated object does not responds to it make easier to validate virtual associations built on top of Active Model objects and/or serialized objects that implement a `valid?` instance method.
* File encoding is defaulted to utf-8 in Ruby >= 2.1Akira Matsuda2015-09-181-1/+0
|
* Removed mocha from Active Record Part 1Ronak Jangir2015-08-251-4/+6
|
* uniqueness validation raises error for persisted record without pk.Yves Senn2015-08-201-0/+23
| | | | | | | | Closes #21304. While we can validate uniqueness for record without primary key on creation, there is no way to exclude the current record when updating. (The update itself will need a primary key to work correctly).
* Properly allow uniqueness validations on primary keys.Sean Griffin2015-07-251-0/+19
| | | | | | This is an alternate implementation of #20966. [Sean Griffin & presskey]
* AR absence validator respects `marked_for_destruction?`. Closes #20449.Yves Senn2015-06-221-0/+75
| | | | Associated objects that were marked for destruction are considered absent.
* Merge branch 'fix_uniqueness_validation_when_value_is_out_of_range'Sean Griffin2015-04-081-0/+25
|\
| * Fix uniqueness validation with out of range valueAndrey Voronkov2015-04-081-0/+25
|/
* replace `repair_validations` with a disposable subclass.Yves Senn2015-03-061-32/+33
|