aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2013-04-19 08:00:17 -0700
committerJon Leighton <j@jonathanleighton.com>2013-04-19 08:00:17 -0700
commite8727d37fc49d5bf9976c3cb5c46badb92cf4ced (patch)
treed853fe8a146e497ed6a6b8f3e9135c9a0b2f70b5 /activerecord/test/cases
parentd098e1c24bc145e0cc14532348436e14dc46d375 (diff)
parent9de28419b1e6312e911eea0c315f326f498b195c (diff)
downloadrails-e8727d37fc49d5bf9976c3cb5c46badb92cf4ced.tar.gz
rails-e8727d37fc49d5bf9976c3cb5c46badb92cf4ced.tar.bz2
rails-e8727d37fc49d5bf9976c3cb5c46badb92cf4ced.zip
Merge pull request #10183 from jholton/fix_association_auto_save
autosave_association issue that occurs when table has unique index
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/autosave_association_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/autosave_association_test.rb b/activerecord/test/cases/autosave_association_test.rb
index 536ff4882c..552bbd3f52 100644
--- a/activerecord/test/cases/autosave_association_test.rb
+++ b/activerecord/test/cases/autosave_association_test.rb
@@ -764,6 +764,20 @@ class TestDestroyAsPartOfAutosaveAssociation < ActiveRecord::TestCase
assert_equal 2, @pirate.birds.reload.length
end
+ def test_should_save_new_record_that_has_same_value_as_existing_record_marked_for_destruction_on_field_that_has_unique_index
+ Bird.connection.add_index :birds, :name, unique: true
+
+ 3.times { |i| @pirate.birds.create(name: "birds_#{i}") }
+
+ @pirate.birds[0].mark_for_destruction
+ @pirate.birds.build(name: @pirate.birds[0].name)
+ @pirate.save!
+
+ assert_equal 3, @pirate.birds.reload.length
+ ensure
+ Bird.connection.remove_index :birds, column: :name
+ end
+
# Add and remove callbacks tests for association collections.
%w{ method proc }.each do |callback_type|
define_method("test_should_run_add_callback_#{callback_type}s_for_has_many") do