From 313e26d962a0ce3931c266c16f3cb5b61dd44fb0 Mon Sep 17 00:00:00 2001 From: Carolyn Cole Date: Wed, 25 Nov 2015 09:36:17 -0500 Subject: [PATCH] Allowing access to the gone? method from outside the object --- lib/active_fedora/persistence.rb | 18 ++++++++------ spec/integration/gone_spec.rb | 41 ++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 spec/integration/gone_spec.rb diff --git a/lib/active_fedora/persistence.rb b/lib/active_fedora/persistence.rb index 75497650f..d5777bc3c 100644 --- a/lib/active_fedora/persistence.rb +++ b/lib/active_fedora/persistence.rb @@ -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" diff --git a/spec/integration/gone_spec.rb b/spec/integration/gone_spec.rb new file mode 100644 index 000000000..2e1001267 --- /dev/null +++ b/spec/integration/gone_spec.rb @@ -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