Skip to content

Commit

Permalink
Merge pull request #66 from duke-libraries/hotfix-1.4.2
Browse files Browse the repository at this point in the history
Version 1.4.2
  • Loading branch information
dchandekstark committed Mar 3, 2016
2 parents faa1ff3 + 0a88273 commit ac81745
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 35 deletions.
12 changes: 11 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ RSpec::Core::RakeTask.new(:spec)

desc "Run the ci build (no integration tests)"
task :ci do
system "rspec ./spec/unit/"
system "rspec . -t ~deprecated -t ~integration"
end

desc "Run tests of deprecated functionality"
task :deprecated do
system "rspec . -t deprecated"
end

desc "Run the integration tests"
task :integration do
system "rspec . -t integration"
end

task default: :spec
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.4.2
21 changes: 16 additions & 5 deletions lib/ezid/identifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,29 @@ def find(id)

def initialize(*args)
raise ArgumentError, "`new` receives 0-2 arguments." if args.size > 2
data = args.last.is_a?(Hash) ? args.pop : nil
options = args.last.is_a?(Hash) ? args.pop : nil
@id = args.first
apply_default_metadata
if data
if shoulder = data.delete(:shoulder)
if options
if id = options.delete(:id)
warn "[DEPRECATION] The `:id` hash option is deprecated and will raise an exception in 2.0. The id should be passed as the first argument to `new` or set explicitly using the attribute writer. (called by #{caller.first})"
if @id
raise ArgumentError,
"`id' specified in both positional argument and (deprecated) hash option."
end
@id = id
end
if shoulder = options.delete(:shoulder)
warn "[DEPRECATION] The `:shoulder` hash option is deprecated and will raise an exception in 2.0. Use `Ezid::Identifier.mint(shoulder, metadata)` to mint an identifier. (called by #{caller.first})"
@shoulder = shoulder
end
if anvl = data.delete(:metadata)
if client = options.delete(:client)
warn "[DEPRECATION] The `:client` hash option is deprecated and ignored. It will raise an exception in 2.0. See the README for details on configuring `Ezid::Client`."
end
if anvl = options.delete(:metadata)
update_metadata(anvl)
end
update_metadata(data)
update_metadata(options)
end
yield self if block_given?
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ezid/proxy_identifier.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Ezid
class ProxyIdentifier

warn "[DEPRECATION] `Ezid::ProxyIdentifier` is deprecated and will be removed in v2.0. Use `Ezid::Identifier` instead."
warn "[DEPRECATION] `Ezid::ProxyIdentifier` is deprecated and will be removed in v2.0. Use `Ezid::Identifier` instead. (called from #{caller.first})"

attr_reader :id
attr_accessor :__real
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "time"

module Ezid
RSpec.describe Client do
RSpec.describe Client, integration: true do

shared_examples "an EZID client" do |client|
it "should mint and modify" do
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/identifier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Ezid
RSpec.describe Identifier do
RSpec.describe Identifier, integration: true do

before {
@identifier = described_class.mint(TEST_ARK_SHOULDER, target: "http://example.com")
Expand Down
32 changes: 24 additions & 8 deletions spec/unit/identifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ module Ezid
described_class.create("id")
end
end
describe "with a hash metadata arg" do
describe "with a hash metadata arg", deprecated: true do
it "mints a new Identifier" do
skip "DEPRECATED"
expect(described_class).to receive(:mint).with(nil, profile: "dc", target: "http://example.com")
described_class.create(profile: "dc", target: "http://example.com")
end
end
describe "with no args" do
describe "with no args", deprecated: true do
it "mints a new Identifier" do
skip "DEPRECATED"
expect(described_class).to receive(:mint).with(nil, nil)
described_class.create
end
Expand Down Expand Up @@ -113,11 +111,29 @@ module Ezid
its(:metadata) { is_expected.to eq("_profile"=>"dc", "_target"=>"http://example.com", "_status"=>"reserved", "_export"=>"no") }
end
end
describe "deprecated hash options", deprecated: true do
describe "id" do
subject { described_class.new(id: "id") }
its(:id) { is_expected.to eq("id") }
specify {
expect { described_class.new("id", id: "id") }.to raise_error(ArgumentError)
}
end
describe "shoulder" do
subject { described_class.new(shoulder: "shoulder") }
its(:shoulder) { is_expected.to eq("shoulder") }
end
describe "client" do
let(:client) { double }
subject { described_class.new(client: client) }
its(:client) { is_expected.to_not eq(client) }
end
end
end

describe "#update" do
let(:metadata) { {"status" => "unavailable"} }
subject { described_class.new(id: "id") }
subject { described_class.new("id") }
it "updates the metadata and saves" do
expect(subject).to receive(:update_metadata).with(metadata)
expect(subject).to receive(:save) { double }
Expand Down Expand Up @@ -223,7 +239,7 @@ module Ezid
end
end
context "when identifier is not reserved" do
subject { described_class.new(id: "id", status: Status::PUBLIC) }
subject { described_class.new("id", status: Status::PUBLIC) }
it "raises an exception" do
expect { subject.delete }.to raise_error(Error)
end
Expand Down Expand Up @@ -302,7 +318,7 @@ module Ezid
end

describe "status-changing methods" do
subject { described_class.new(id: "id", status: status) }
subject { described_class.new("id", status: status) }
describe "#unavailable!" do
context "when the status is \"unavailable\"" do
let(:status) { "#{Status::UNAVAILABLE} | whatever" }
Expand Down Expand Up @@ -359,7 +375,7 @@ module Ezid
end
end
describe "#public!" do
subject { described_class.new(id: "id", status: Status::UNAVAILABLE) }
subject { described_class.new("id", status: Status::UNAVAILABLE) }
it "changes the status" do
expect { subject.public! }.to change(subject, :status).from(Status::UNAVAILABLE).to(Status::PUBLIC)
end
Expand Down
33 changes: 16 additions & 17 deletions spec/unit/proxy_identifier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
require 'ezid/proxy_identifier'

module Ezid
RSpec.describe ProxyIdentifier do

describe "initialization" do
it "should not load the real identifier" do
expect(Identifier).not_to receive(:find)
described_class.new("ark:/99999/fk4fn19h88")
RSpec.describe "proxy identifier", deprecated: true do
require 'ezid/proxy_identifier'
describe ProxyIdentifier do
describe "initialization" do
it "should not load the real identifier" do
expect(Identifier).not_to receive(:find)
described_class.new("ark:/99999/fk4fn19h88")
end
end
end

describe "lazy loading" do
subject { described_class.new(id) }
describe "lazy loading" do
subject { described_class.new(id) }

let(:id) { "ark:/99999/fk4fn19h88" }
let(:real) { double(id: id, target: "http://ezid.cdlib.org/id/#{id}") }
let(:id) { "ark:/99999/fk4fn19h88" }
let(:real) { double(id: id, target: "http://ezid.cdlib.org/id/#{id}") }

it "should load the real identifier when calling a missing method" do
expect(Identifier).to receive(:find).with(id) { real }
expect(subject.target).to eq(real.target)
it "should load the real identifier when calling a missing method" do
expect(Identifier).to receive(:find).with(id) { real }
expect(subject.target).to eq(real.target)
end
end
end

end
end

0 comments on commit ac81745

Please sign in to comment.