1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Tests for removing a HABTM association when optimistic locking is enabled.

This commit is contained in:
Nick Rogers 2012-03-07 23:56:23 -05:00
parent 03888825e2
commit 2931f413a5
4 changed files with 25 additions and 1 deletions

View file

@ -22,7 +22,7 @@ class ReadonlyFirstNamePerson < Person
end
class OptimisticLockingTest < ActiveRecord::TestCase
fixtures :people, :legacy_things, :references, :string_key_objects
fixtures :people, :legacy_things, :references, :string_key_objects, :peoples_treasures
def test_non_integer_lock_existing
s1 = StringKeyObject.find("record1")
@ -239,6 +239,16 @@ class OptimisticLockingTest < ActiveRecord::TestCase
end
assert car.destroyed?
end
def test_removing_has_and_belongs_to_many_associations_upon_destroy
p = RichPerson.create!
p.treasures.create!
assert !p.treasures.empty?
p.destroy
assert p.treasures.empty?
assert RichPerson.connection.select_all("SELECT * FROM peoples_treasures WHERE rich_person_id = 1").empty?
end
end
class OptimisticLockingWithSchemaChangeTest < ActiveRecord::TestCase

View file

@ -0,0 +1,3 @@
michael_diamond:
rich_person_id: <%= ActiveRecord::Fixtures.identify(:michael) %>
treasure_id: <%= ActiveRecord::Fixtures.identify(:diamond) %>

View file

@ -83,3 +83,9 @@ class TightPerson < ActiveRecord::Base
end
class TightDescendant < TightPerson; end
class RichPerson < ActiveRecord::Base
self.table_name = 'people'
has_and_belongs_to_many :treasures, :join_table => 'peoples_treasures'
end

View file

@ -467,6 +467,11 @@ ActiveRecord::Schema.define do
t.references :best_friend_of
t.timestamps
end
create_table :peoples_treasures, :id => false, :force => true do |t|
t.column :rich_person_id, :integer
t.column :treasure_id, :integer
end
create_table :pets, :primary_key => :pet_id ,:force => true do |t|
t.string :name