Commit 2b0db84f by Washington Luiz Committed by John Hawthorn

Rename Paranoia#destroyed? to Paranoia#paranoia_destroyed?

There was a change in ActiveRecord#update_columns on latest rails
so now it checks for `destroyed?` instead of `persisted?`. Paranoia
can't override `destoyed?` like this anymore otherwise
`update_columns` will always raise:

        ActiveRecord::ActiveRecordError: cannot update a destroyed record

see https://github.com/rails/rails/commit/0f99aa615e11c50cc64b567f54cf64f59108c5e5
parent 7866b73d
...@@ -71,7 +71,7 @@ module Paranoia ...@@ -71,7 +71,7 @@ module Paranoia
# when they shouldn't # when they shouldn't
if ActiveRecord::VERSION::STRING >= "4.1" if ActiveRecord::VERSION::STRING >= "4.1"
def destroy! def destroy!
destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed) paranoia_destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed)
end end
end end
...@@ -98,10 +98,10 @@ module Paranoia ...@@ -98,10 +98,10 @@ module Paranoia
end end
alias :restore :restore! alias :restore :restore!
def destroyed? def paranoia_destroyed?
send(paranoia_column) != paranoia_sentinel_value send(paranoia_column) != paranoia_sentinel_value
end end
alias :deleted? :destroyed? alias :deleted? :paranoia_destroyed?
private private
......
...@@ -136,6 +136,13 @@ class ParanoiaTest < test_framework ...@@ -136,6 +136,13 @@ class ParanoiaTest < test_framework
assert_equal 1, model.class.unscoped.count assert_equal 1, model.class.unscoped.count
end end
def test_update_columns_on_paranoia_destroyed
record = ParentModel.create
record.destroy
assert record.update_columns deleted_at: Time.now
end
def test_scoping_behavior_for_paranoid_models def test_scoping_behavior_for_paranoid_models
parent1 = ParentModel.create parent1 = ParentModel.create
parent2 = ParentModel.create parent2 = ParentModel.create
...@@ -160,7 +167,7 @@ class ParanoiaTest < test_framework ...@@ -160,7 +167,7 @@ class ParanoiaTest < test_framework
model.destroy model.destroy
assert_equal false, model.destroyed_at.nil? assert_equal false, model.destroyed_at.nil?
assert model.destroyed? assert model.paranoia_destroyed?
assert_equal 0, model.class.count assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count assert_equal 1, model.class.unscoped.count
...@@ -181,7 +188,7 @@ class ParanoiaTest < test_framework ...@@ -181,7 +188,7 @@ class ParanoiaTest < test_framework
model.destroy model.destroy
assert DateTime.new(0) != model.deleted_at assert DateTime.new(0) != model.deleted_at
assert model.destroyed? assert model.paranoia_destroyed?
assert_equal 0, model.class.count assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count assert_equal 1, model.class.unscoped.count
...@@ -290,13 +297,13 @@ class ParanoiaTest < test_framework ...@@ -290,13 +297,13 @@ class ParanoiaTest < test_framework
id = model.id id = model.id
model.destroy model.destroy
assert model.destroyed? assert model.paranoia_destroyed?
model = ParanoidModel.only_deleted.find(id) model = ParanoidModel.only_deleted.find(id)
model.restore! model.restore!
model.reload model.reload
assert_equal false, model.destroyed? assert_equal false, model.paranoia_destroyed?
end end
def test_restore_on_object_return_self def test_restore_on_object_return_self
...@@ -336,7 +343,7 @@ class ParanoiaTest < test_framework ...@@ -336,7 +343,7 @@ class ParanoiaTest < test_framework
id = model.id id = model.id
model.destroy model.destroy
assert model.destroyed? assert model.paranoia_destroyed?
model = CallbackModel.only_deleted.find(id) model = CallbackModel.only_deleted.find(id)
model.restore! model.restore!
...@@ -417,9 +424,9 @@ class ParanoiaTest < test_framework ...@@ -417,9 +424,9 @@ class ParanoiaTest < test_framework
b.reload b.reload
c.reload c.reload
refute a.destroyed? refute a.paranoia_destroyed?
assert b.destroyed? assert b.paranoia_destroyed?
refute c.destroyed? refute c.paranoia_destroyed?
end end
def test_restore_with_associations def test_restore_with_associations
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment