From 1a36be390e83156940e6bd3e394152496a6c8e72 Mon Sep 17 00:00:00 2001 From: Andrey Voronkov Date: Wed, 8 Apr 2015 19:28:45 +0300 Subject: Fix uniqueness validation with out of range value --- .../validations/uniqueness_validation_test.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'activerecord/test/cases') 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) -- cgit v1.2.3