Permalink
Browse files

Tests for making sure that recover doesn't fail when there are :depen…

…dent => :destroy assocations against non-paranoid models
  • Loading branch information...
1 parent 111347a commit 5713eb4d856c2cbd898e56f69d592b911b94fa2d @cheerfulstoic cheerfulstoic committed Dec 10, 2010
Showing with 36 additions and 0 deletions.
  1. +16 −0 test/rails3_acts_as_paranoid_test.rb
  2. +20 −0 test/test_helper.rb
@@ -95,12 +95,21 @@ def setup_recursive_recovery_tests
paranoid_boolean = @paranoid_time_object.paranoid_booleans.create(:name => "boolean_#{i}")
paranoid_boolean.create_paranoid_has_one_dependant(:name => "has_one_#{i}")
paranoid_boolean.save
+
+ @paranoid_time_object.not_paranoids.create(:name => "not_paranoid_a#{i}")
+
end
+ @paranoid_time_object.create_not_paranoid(:name => "not_paranoid_belongs_to")
+
+ @paranoid_time_object.create_has_one_not_paranoid(:name => "has_one_not_paranoid")
+
assert_equal 3, ParanoidTime.count
assert_equal 3, ParanoidHasManyDependant.count
assert_equal 3, ParanoidBelongsDependant.count
assert_equal 3, ParanoidHasOneDependant.count
+ assert_equal 5, NotParanoid.count
+ assert_equal 1, HasOneNotParanoid.count
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
@paranoid_time_object.destroy
@@ -110,6 +119,9 @@ def setup_recursive_recovery_tests
assert_equal 0, ParanoidHasManyDependant.count
assert_equal 0, ParanoidBelongsDependant.count
assert_equal 0, ParanoidHasOneDependant.count
+ puts NotParanoid.all.inspect
+ assert_equal 1, NotParanoid.count
+ assert_equal 0, HasOneNotParanoid.count
assert_equal @paranoid_boolean_count, ParanoidBoolean.count
end
@@ -122,6 +134,8 @@ def test_recursive_recovery
assert_equal 3, ParanoidHasManyDependant.count
assert_equal 3, ParanoidBelongsDependant.count
assert_equal 3, ParanoidHasOneDependant.count
+ assert_equal 1, NotParanoid.count
+ assert_equal 0, HasOneNotParanoid.count
assert_equal @paranoid_boolean_count + 3, ParanoidBoolean.count
end
@@ -134,6 +148,8 @@ def test_non_recursive_recovery
assert_equal 0, ParanoidHasManyDependant.count
assert_equal 0, ParanoidBelongsDependant.count
assert_equal 0, ParanoidHasOneDependant.count
+ assert_equal 1, NotParanoid.count
+ assert_equal 0, HasOneNotParanoid.count
assert_equal @paranoid_boolean_count, ParanoidBoolean.count
end
View
@@ -15,6 +15,8 @@ def setup_db
t.datetime :deleted_at
t.integer :paranoid_belongs_dependant_id
+ t.integer :not_paranoid_id
+
t.timestamps
end
@@ -29,6 +31,16 @@ 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
end
@@ -69,6 +81,11 @@ class ParanoidTime < ActiveRecord::Base
has_many :paranoid_has_many_dependants, :dependent => :destroy
has_many :paranoid_booleans, :dependent => :destroy
+ has_many :not_paranoids, :dependent => :destroy
+
+ has_one :has_one_not_paranoid, :dependent => :destroy
+
+ belongs_to :not_paranoid, :dependent => :destroy
end
class ParanoidBoolean < ActiveRecord::Base
@@ -81,6 +98,9 @@ class ParanoidBoolean < ActiveRecord::Base
class NotParanoid < ActiveRecord::Base
end
+class HasOneNotParanoid < ActiveRecord::Base
+end
+
class ParanoidHasManyDependant < ActiveRecord::Base
acts_as_paranoid
belongs_to :paranoid_time

0 comments on commit 5713eb4

Please sign in to comment.