Commit 26b9f4f7 by Ryan Bigg

Merge pull request #69 from fullcirclegroup/class-level-restore

Add Model#restore(id)
parents 95f6a5d6 4ff0fdad
......@@ -13,6 +13,14 @@ module Paranoia
def with_deleted
all.tap { |x| x.default_scoped = false }
end
def restore(id)
if id.is_a?(Array)
id.map { |one_id| restore(one_id) }
else
only_deleted.find(id).restore!
end
end
end
def destroy
......
......@@ -71,7 +71,7 @@ class ParanoiaTest < Test::Unit::TestCase
assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count
end
def test_scoping_behavior_for_paranoid_models
ParanoidModel.unscoped.delete_all
parent1 = ParentModel.create
......@@ -204,6 +204,33 @@ class ParanoiaTest < Test::Unit::TestCase
refute ParanoidModel.unscoped.exists?(model.id)
end
def test_multiple_restore
a = ParanoidModel.new
a.save
a_id = a.id
a.destroy
b = ParanoidModel.new
b.save
b_id = b.id
b.destroy
c = ParanoidModel.new
c.save
c_id = c.id
c.destroy
ParanoidModel.restore([a_id, c_id])
a.reload
b.reload
c.reload
refute a.destroyed?
assert b.destroyed?
refute c.destroyed?
end
private
def get_featureful_model
FeaturefulModel.new(:name => "not empty")
......
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