Skip to content

Commit

Permalink
Merge pull request #955 from psu-stewardship/gone
Browse files Browse the repository at this point in the history
Allowing access to the gone? method from outside the object
  • Loading branch information
awead committed Nov 25, 2015
2 parents a555b1e + 313e26d commit 7d9a187
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/active_fedora/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ def eradicate(uri)
gone?(uri) ? delete_tombstone(uri) : false
end

private
# Allows the user to find out if an id has been used in the system and then been deleted
# @param uri id in fedora that may or may not have been deleted
def gone?(uri)
ActiveFedora::Base.find(uri)
false
rescue Ldp::Gone
true
rescue ActiveFedora::ObjectNotFoundError
false
end

def gone?(uri)
ActiveFedora::Base.find(uri)
false
rescue Ldp::Gone
true
end
private

def delete_tombstone(uri)
tombstone = ActiveFedora::Base.id_to_uri(uri) + "/fcr:tombstone"
Expand Down
41 changes: 41 additions & 0 deletions spec/integration/gone_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

describe ActiveFedora::Base do
before(:all) do
class ResurrectionModel < ActiveFedora::Base
after_destroy :eradicate
end
end

after(:all) do
Object.send(:remove_const, :ResurrectionModel)
end

context "when an object is has already been deleted" do
let(:ghost) do
obj = described_class.create
obj.destroy
obj.id
end
it "is gone" do
expect(described_class.gone?(ghost)).to be true
end
end

context "when the id has never been used" do
let(:id) { "abc123" }
it "is not gone" do
expect(described_class.gone?(id)).to be false
end
end

context "when the id is in use" do
let(:active) do
obj = described_class.create
obj.id
end
it "is not gone" do
expect(described_class.gone?(active)).to be false
end
end
end

0 comments on commit 7d9a187

Please sign in to comment.