aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/validations/uniqueness_validation_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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).
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-24/+24
| | | | Follow up of #32605.
* Deprecate update_attributes and update_attributes!Eddie Lebow2018-02-171-1/+1
| | | | Closes #31998
* Use assert_empty and assert_not_emptyDaniel Colson2018-01-251-5/+5
|
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-251-20/+20
|
* 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-191-0/+2
|
* 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
|
* 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
* modernizes hash syntax in activerecordXavier Noria2016-08-061-23/+23
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-25/+25
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* 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.
* | 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-231-17/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | 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.
* 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).
* 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]
* 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
|/
* Removed magic comments # encoding: utf-8 , since its default from ruby 2.0 ↵Vipul A M2015-02-031-1/+0
| | | | onwards.
* Fix validations on child record when record parent has validate: falseeileencodes2015-02-011-0/+17
| | | | | | | | | | | | | | Fixes #17621. This 5 year old (or older) issue causes validations to fire when a parent record has `validate: false` option and a child record is saved. It's not the responsibility of the model to validate an associated object unless the object was created or modified by the parent. Clean up tests related to validations `assert_nothing_raised` is not benefiting us in these tests Corrected spelling of "respects" It's better to use `assert_not_operator` over `assert !r.valid`
* pg tests, move uniqueness validation test to array tests.Yves Senn2014-12-021-17/+0
|
* Fixes a bug found when running individual tests against #17217 after mergingSammy Larbi2014-11-101-1/+1
|
* passing an instance of an AR object to `find` is deprecatedAaron Patterson2014-03-131-1/+1
| | | | please pass the id of the AR object by calling `.id` on the model first.
* Merge pull request #13061 from ↵Rafael Mendonça França2013-11-261-0/+8
| | | | | | | | laurocaetano/fix-uniqueness-validation-for-aliased-attribute Fix bug when validating the uniqueness of an aliased attribute. Conflicts: activerecord/CHANGELOG.md
* Fix validation on uniqueness of empty associationEvgeny Li2013-11-221-0/+19
|
* Don't skip tests if we don't need to.Rafael Mendonça França2013-11-081-10/+10
| | | | | | | We can conditional define the tests depending on the adapter or connection. Lets keep the skip for fail tests that need to be fixed.
* Fix wrong `case_sensitive` in uniqueness validity testVipul A M2013-05-201-1/+1
|
* Fixed typos in activerecordPrathamesh Sonpatki2013-03-271-1/+1
|
* Change uniq validation with conditions examples to use where with hashesCarlos Antonio da Silva2013-03-091-2/+2
| | | | Take the opportunity to showcase where.not.
* Uniqueness validation uses a proc to specify the `:conditions` option.Yves Senn2013-03-091-1/+7
| | | | | This is a follow up to #5321 and follows the general direction in AR to make things lazy evaluated.
* Added support for validates_uniqueness_of in PostgreSQL array columns. ↵Pedro Padron2012-12-181-3/+20
| | | | Fixes: #8075.
* Deprecate ActiveRecord::Base.scoped.Jon Leighton2012-07-271-1/+1
| | | | | | | It doesn't serve much purpose now that ActiveRecord::Base.all returns a Relation. The code is moved to active_record_deprecated_finders.
* Fixes "Cannot visit ..." with validates_uniqueness_ofbeerlington2012-07-171-0/+16
| | | | | | Fixes issue with overrding ActiveRecord reader methods with a composed object and using that attribute as the scope of a validates_uniqueness_of validation.
* remove deprecated callsJon Leighton2012-04-271-1/+1
|
* remove tests for #with_scope (it's now deprecated)Jon Leighton2012-04-251-2/+2
|
* removed unused variablesArun Agrawal2012-03-271-2/+2
|
* Change syntax to accept an AR::Relation instead of old conditions hash/array.Mattias Pfeiffer2012-03-071-1/+1
|
* Add :conditions option to uniqueness validatorMattias Pfeiffer2012-03-071-0/+12
|
* allow association as 1st uniqueness validation argDan Pickett2012-01-061-0/+12
| | | #4321
* allow an association as a scope parameterDan Pickett2012-01-061-0/+12
| | | #4321
* Fixed nil field value uniqueness checkpyromaniac2012-01-061-0/+12
|
* Revert "Merge pull request #2325 from pyromaniac/master"José Valim2012-01-061-12/+0
| | | | | | | It breaks the build for mysql. This reverts commit 958d25df4a1b0d41ce5deeeb0739c93b49bbd18d, reversing changes made to 8f309e31057e1b26fefedb199ab0526126fb1fe4.