Skip to content

Commit

Permalink
Merge pull request #50 from duke-libraries/47-unavailable
Browse files Browse the repository at this point in the history
Sets expectations for `Identifier#unavailable!` when status is already u...
  • Loading branch information
dchandekstark committed Apr 23, 2015
2 parents dc39a90 + 8db3055 commit edb0626
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/ezid/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ def deletable?
# @param reason [String] an optional reason
# @return [String] the new status
def unavailable!(reason = nil)
raise Error, "Cannot make a reserved identifier unavailable." if persisted? && reserved?
if persisted? && reserved?
raise Error, "Cannot make a reserved identifier unavailable."
end
if unavailable? and reason.nil?
return
end
value = UNAVAILABLE
if reason
value += " | #{reason}"
Expand Down
34 changes: 29 additions & 5 deletions spec/unit/identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,33 @@ module Ezid
end

describe "status-changing methods" do
subject { described_class.new(id: "id", status: status) }
describe "#unavailable!" do
context "when the identifier is reserved" do
subject { described_class.new(id: "id", status: Identifier::RESERVED) }
context "when the status is \"unavailable\"" do
let(:status) { "#{Identifier::UNAVAILABLE} | whatever" }
context "and no reason is given" do
it "should log a warning" do
pending "https://github.com/duke-libraries/ezid-client/issues/46"
expect(subject.logger).to receive(:warn)
subject.unavailable!
end
it "should not change the status" do
expect { subject.unavailable! }.not_to change(subject, :status)
end
end
context "and a reason is given" do
it "should log a warning" do
pending "https://github.com/duke-libraries/ezid-client/issues/46"
expect(subject.logger).to receive(:warn)
subject.unavailable!("because")
end
it "should change the status" do
expect { subject.unavailable!("because") }.to change(subject, :status).from(status).to("#{Identifier::UNAVAILABLE} | because")
end
end
end
context "when the status is \"reserved\"" do
let(:status) { Identifier::RESERVED }
context "and persisted" do
before { allow(subject).to receive(:persisted?) { true } }
it "should raise an exception" do
Expand All @@ -232,13 +256,13 @@ module Ezid
end
context "and not persisted" do
before { allow(subject).to receive(:persisted?) { false } }
it "should changed the status" do
it "should change the status" do
expect { subject.unavailable! }.to change(subject, :status).from(Identifier::RESERVED).to(Identifier::UNAVAILABLE)
end
end
end
context "when the identifier is public" do
subject { described_class.new(id: "id", status: Identifier::PUBLIC) }
context "when the status is \"public\"" do
let(:status) { Identifier::PUBLIC }
context "and no reason is given" do
it "should change the status" do
expect { subject.unavailable! }.to change(subject, :status).from(Identifier::PUBLIC).to(Identifier::UNAVAILABLE)
Expand Down

0 comments on commit edb0626

Please sign in to comment.