Skip to content

Commit

Permalink
added a failing test because of the lack of support for :dependent =>…
Browse files Browse the repository at this point in the history
… :whatever
  • Loading branch information
goncalossilva committed Apr 2, 2011
1 parent 784f469 commit a9a75fb
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
34 changes: 33 additions & 1 deletion test/rails3_acts_as_paranoid_test.rb
Expand Up @@ -172,7 +172,6 @@ def test_hard_destroy_callbacks
assert @paranoid_with_callback.called_after_destroy
assert @paranoid_with_callback.called_after_commit_on_destroy
end

end

class ValidatesUniquenessTest < ParanoidBase
Expand All @@ -195,3 +194,36 @@ def test_should_validate_without_deleted
end
end
end

class AssociationsTest < ParanoidBase
def test_removal_with_associations
# This test shows that the current implementation doesn't handle
# assciation deletion correctly (when hard deleting via parent-object)
paranoid_company_1 = ParanoidDestroyCompany.create! :name => "ParanoidDestroyCompany #1"
paranoid_company_2 = ParanoidDeleteCompany.create! :name => "ParanoidDestroyCompany #1"
paranoid_company_1.paranoid_products.create! :name => "ParanoidProduct #1"
paranoid_company_2.paranoid_products.create! :name => "ParanoidProduct #2"

assert_equal 1, ParanoidDestroyCompany.count
assert_equal 1, ParanoidDeleteCompany.count
assert_equal 2, ParanoidProduct.count

ParanoidDestroyCompany.first.destroy
assert_equal 0, ParanoidDestroyCompany.count
assert_equal 1, ParanoidProduct.count
assert_equal 1, ParanoidDestroyCompany.with_deleted.count
assert_equal 2, ParanoidProduct.with_deleted.count

ParanoidDestroyCompany.with_deleted.first.destroy!
assert_equal 0, ParanoidDestroyCompany.count
assert_equal 1, ParanoidProduct.count
assert_equal 0, ParanoidDestroyCompany.with_deleted.count
assert_equal 1, ParanoidProduct.with_deleted.count

ParanoidDeleteCompany.with_deleted.first.destroy!
assert_equal 0, ParanoidDeleteCompany.count
assert_equal 0, ParanoidProduct.count
assert_equal 0, ParanoidDeleteCompany.with_deleted.count
assert_equal 0, ParanoidProduct.with_deleted.count
end
end
48 changes: 43 additions & 5 deletions test/test_helper.rb
Expand Up @@ -18,7 +18,6 @@ def setup_db
t.string :name
t.datetime :deleted_at
t.integer :paranoid_belongs_dependant_id

t.integer :not_paranoid_id

t.timestamps
Expand All @@ -34,15 +33,13 @@ def setup_db

create_table :not_paranoids do |t|
t.string :name

t.integer :paranoid_time_id

t.timestamps
end

create_table :has_one_not_paranoids do |t|
t.string :name

t.integer :paranoid_time_id

t.timestamps
Expand Down Expand Up @@ -78,6 +75,29 @@ def setup_db

t.timestamps
end

create_table :paranoid_destroy_companies do |t|
t.string :name
t.datetime :deleted_at

t.timestamps
end

create_table :paranoid_delete_companies do |t|
t.string :name
t.datetime :deleted_at

t.timestamps
end

create_table :paranoid_products do |t|
t.integer :paranoid_destroy_company_id
t.integer :paranoid_delete_company_id
t.string :name
t.datetime :deleted_at

t.timestamps
end
end
end

Expand Down Expand Up @@ -160,5 +180,23 @@ def call_me_after_destroy
def call_me_after_commit_on_destroy
@called_after_commit_on_destroy = true
end

end

class ParanoidDestroyCompany < ActiveRecord::Base
acts_as_paranoid
validates :name, :presence => true
has_many :paranoid_products, :dependent => :destroy
end

class ParanoidDeleteCompany < ActiveRecord::Base
acts_as_paranoid
validates :name, :presence => true
has_many :paranoid_products, :dependent => :delete_all
end

class ParanoidProduct < ActiveRecord::Base
acts_as_paranoid
belongs_to :paranoid_destroy_company
belongs_to :paranoid_delete_company
validates_presence_of :name
end

0 comments on commit a9a75fb

Please sign in to comment.