Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for through relationship #336

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions test/test_associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ParanoidManyManyParentLeft < ActiveRecord::Base
end

class ParanoidManyManyParentRight < ActiveRecord::Base
acts_as_paranoid
has_many :paranoid_many_many_children
has_many :paranoid_many_many_parent_lefts, through: :paranoid_many_many_children
end
Expand Down Expand Up @@ -169,6 +170,7 @@ def setup

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

Expand Down Expand Up @@ -308,6 +310,21 @@ def teardown
teardown_db
end

def test_through_relationships
paranoid_left = ParanoidManyManyParentLeft.create!
paranoid_left.paranoid_many_many_parent_rights.create!
paranoid_left.paranoid_many_many_children.first.destroy

assert_equal 0, ParanoidManyManyChild.count
assert_equal 1, ParanoidManyManyParentLeft.count
assert_equal 1, ParanoidManyManyParentRight.count

assert_equal 0, paranoid_left.paranoid_many_many_children.count
assert_equal 0, paranoid_left.paranoid_many_many_parent_rights.count
assert_equal 1, paranoid_left.paranoid_many_many_parent_rights.with_deleted.count
assert_equal 1, paranoid_left.paranoid_many_many_parent_rights.only_deleted.count
end

def test_removal_with_destroy_associations
paranoid_company = ParanoidDestroyCompany.create! name: "ParanoidDestroyCompany #1"
paranoid_company.paranoid_products.create! name: "ParanoidProduct #1"
Expand Down
Loading