aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/validations/uniqueness_validation_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/validations/uniqueness_validation_test.rb')
-rw-r--r--activerecord/test/cases/validations/uniqueness_validation_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/validations/uniqueness_validation_test.rb b/activerecord/test/cases/validations/uniqueness_validation_test.rb
index 8abb6c9844..4c14d93c66 100644
--- a/activerecord/test/cases/validations/uniqueness_validation_test.rb
+++ b/activerecord/test/cases/validations/uniqueness_validation_test.rb
@@ -53,6 +53,14 @@ class CoolTopic < Topic
validates_uniqueness_of :id
end
+class TopicWithAfterCreate < Topic
+ after_create :set_author
+
+ def set_author
+ update_attributes!(:author_name => "#{title} #{id}")
+ end
+end
+
class UniquenessValidationTest < ActiveRecord::TestCase
INT_MAX_VALUE = 2147483647
@@ -469,6 +477,16 @@ class UniquenessValidationTest < ActiveRecord::TestCase
assert t.save, "Should still save t as unique"
end
+ def test_validate_uniqueness_with_after_create_performing_save
+ TopicWithAfterCreate.validates_uniqueness_of(:title)
+ topic = TopicWithAfterCreate.create!(:title => "Title1")
+ assert topic.author_name.start_with?("Title1")
+
+ topic2 = TopicWithAfterCreate.new(:title => "Title1")
+ refute topic2.valid?
+ assert_equal(["has already been taken"], topic2.errors[:title])
+ end
+
def test_validate_uniqueness_uuid
skip unless current_adapter?(:PostgreSQLAdapter)
item = UuidItem.create!(uuid: SecureRandom.uuid, title: 'item1')