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
# when they shouldn't
if ActiveRecord::VERSION::STRING >= "4.1"
def destroy!
destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed)
paranoia_destroyed? ? super : destroy || raise(ActiveRecord::RecordNotDestroyed)
end
end
......@@ -98,10 +98,10 @@ module Paranoia
end
alias :restore :restore!
def destroyed?
def paranoia_destroyed?
send(paranoia_column) != paranoia_sentinel_value
end
alias :deleted? :destroyed?
alias :deleted? :paranoia_destroyed?
private
......
......@@ -136,6 +136,13 @@ class ParanoiaTest < test_framework
assert_equal 1, model.class.unscoped.count
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
parent1 = ParentModel.create
parent2 = ParentModel.create
......@@ -160,7 +167,7 @@ class ParanoiaTest < test_framework
model.destroy
assert_equal false, model.destroyed_at.nil?
assert model.destroyed?
assert model.paranoia_destroyed?
assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count
......@@ -181,7 +188,7 @@ class ParanoiaTest < test_framework
model.destroy
assert DateTime.new(0) != model.deleted_at
assert model.destroyed?
assert model.paranoia_destroyed?
assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count
......@@ -290,13 +297,13 @@ class ParanoiaTest < test_framework
id = model.id
model.destroy
assert model.destroyed?
assert model.paranoia_destroyed?
model = ParanoidModel.only_deleted.find(id)
model.restore!
model.reload
assert_equal false, model.destroyed?
assert_equal false, model.paranoia_destroyed?
end
def test_restore_on_object_return_self
......@@ -336,7 +343,7 @@ class ParanoiaTest < test_framework
id = model.id
model.destroy
assert model.destroyed?
assert model.paranoia_destroyed?
model = CallbackModel.only_deleted.find(id)
model.restore!
......@@ -417,9 +424,9 @@ class ParanoiaTest < test_framework
b.reload
c.reload
refute a.destroyed?
assert b.destroyed?
refute c.destroyed?
refute a.paranoia_destroyed?
assert b.paranoia_destroyed?
refute c.paranoia_destroyed?
end
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