Skip to content

Commit

Permalink
Test for many:many has_many :through deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
softcraft-development authored and goncalossilva committed Mar 6, 2012
1 parent 4917eba commit e3f7f7a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions test/more_paranoid_test.rb
@@ -1,6 +1,21 @@
require 'test_helper'


class MoreParanoidTest < ParanoidBaseTest
test "bidirectional has_many :through association delete is paranoid" do
left = ParanoidManyManyParentLeft.create
right = ParanoidManyManyParentRight.create
left.paranoid_many_many_parent_rights << right

child = left.paranoid_many_many_children.first
assert_equal left, child.paranoid_many_many_parent_left, "Child's left parent is incorrect"
assert_equal right, child.paranoid_many_many_parent_right, "Child's right parent is incorrect"

left.paranoid_many_many_parent_rights.delete(right)

assert_paranoid_deletion(child)
end

test "delete by multiple id is paranoid" do
model_a = ParanoidBelongsDependant.create
model_b = ParanoidBelongsDependant.create
Expand Down
36 changes: 36 additions & 0 deletions test/test_helper.rb
Expand Up @@ -118,6 +118,24 @@ def setup_db

t.timestamps
end

create_table :paranoid_many_many_parent_lefts do |t|
t.string :name
t.timestamps
end

create_table :paranoid_many_many_parent_rights do |t|
t.string :name
t.timestamps
end

create_table :paranoid_many_many_children do |t|
t.integer :paranoid_many_many_parent_left_id
t.integer :paranoid_many_many_parent_right_id
t.datetime :deleted_at
t.timestamps
end

end
end

Expand Down Expand Up @@ -269,6 +287,24 @@ def reset
end
end


class ParanoidManyManyParentLeft < ActiveRecord::Base
has_many :paranoid_many_many_children
has_many :paranoid_many_many_parent_rights, :through => :paranoid_many_many_children
end

class ParanoidManyManyParentRight < ActiveRecord::Base
has_many :paranoid_many_many_children
has_many :paranoid_many_many_parent_lefts, :through => :paranoid_many_many_children
end

class ParanoidManyManyChild < ActiveRecord::Base
acts_as_paranoid
belongs_to :paranoid_many_many_parent_left
belongs_to :paranoid_many_many_parent_right
end


ParanoidWithCallback.add_observer(ParanoidObserver.instance)


Expand Down

0 comments on commit e3f7f7a

Please sign in to comment.