diff options
author | Andrey Voronkov <andrey.voronkov@medm.com> | 2015-04-08 19:28:45 +0300 |
---|---|---|
committer | Andrey Voronkov <andrey.voronkov@medm.com> | 2015-04-08 19:28:45 +0300 |
commit | 1a36be390e83156940e6bd3e394152496a6c8e72 (patch) | |
tree | f72b26bae158456f12fea0a46ef011cd888ccc82 /activerecord/test/cases | |
parent | 0a120a818d413c64ff9867125f0b03788fc306f8 (diff) | |
download | rails-1a36be390e83156940e6bd3e394152496a6c8e72.tar.gz rails-1a36be390e83156940e6bd3e394152496a6c8e72.tar.bz2 rails-1a36be390e83156940e6bd3e394152496a6c8e72.zip |
Fix uniqueness validation with out of range value
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/validations/uniqueness_validation_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb index 062bc733f9..778697e225 100644 --- a/activerecord/test/cases/validations/uniqueness_validation_test.rb +++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb @@ -34,6 +34,19 @@ class TopicWithUniqEvent < Topic validates :event, uniqueness: true end +class BigIntTest < ActiveRecord::Base + PG_MAX_INTEGER = 2147483647 + self.table_name = 'cars' + validates :engines_count, uniqueness: true, inclusion: { in: 0..PG_MAX_INTEGER } +end + +class BigIntReverseTest < ActiveRecord::Base + PG_MAX_INTEGER = 2147483647 + self.table_name = 'cars' + validates :engines_count, inclusion: { in: 0..PG_MAX_INTEGER } + validates :engines_count, uniqueness: true +end + class UniquenessValidationTest < ActiveRecord::TestCase fixtures :topics, 'warehouse-things' @@ -86,6 +99,18 @@ class UniquenessValidationTest < ActiveRecord::TestCase assert t2.errors[:title] end + if current_adapter? :PostgreSQLAdapter + def test_validate_uniqueness_when_integer_out_of_range + entry = BigIntTest.create(engines_count: (BigIntTest::PG_MAX_INTEGER + 1)) + assert_equal entry.errors[:engines_count], ['is not included in the list'] + end + + def test_validate_uniqueness_when_integer_out_of_range_show_order_does_not_matter + entry = BigIntReverseTest.create(engines_count: (BigIntTest::PG_MAX_INTEGER + 1)) + assert_equal entry.errors[:engines_count], ['is not included in the list'] + end + end + def test_validates_uniqueness_with_newline_chars Topic.validates_uniqueness_of(:title, :case_sensitive => false) |