From 0a88273c6c981d78e15a67382980a376d3d010b0 Mon Sep 17 00:00:00 2001 From: David Chandek-Stark Date: Thu, 3 Mar 2016 17:04:50 -0500 Subject: [PATCH] Version 1.4.2 Addresses backward compatibility issues in the initializer of `Ezid::Identifier` which were introduced in v1.4.0. --- Rakefile | 12 ++++++++++- VERSION | 2 +- lib/ezid/identifier.rb | 21 +++++++++++++----- lib/ezid/proxy_identifier.rb | 2 +- spec/integration/client_spec.rb | 2 +- spec/integration/identifier_spec.rb | 2 +- spec/unit/identifier_spec.rb | 32 +++++++++++++++++++++------- spec/unit/proxy_identifier_spec.rb | 33 ++++++++++++++--------------- 8 files changed, 71 insertions(+), 35 deletions(-) diff --git a/Rakefile b/Rakefile index 7cab52c..629e25b 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/VERSION b/VERSION index 347f583..9df886c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.1 +1.4.2 diff --git a/lib/ezid/identifier.rb b/lib/ezid/identifier.rb index ddaf4c0..e65d669 100644 --- a/lib/ezid/identifier.rb +++ b/lib/ezid/identifier.rb @@ -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 diff --git a/lib/ezid/proxy_identifier.rb b/lib/ezid/proxy_identifier.rb index 0786b0e..de61629 100644 --- a/lib/ezid/proxy_identifier.rb +++ b/lib/ezid/proxy_identifier.rb @@ -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 diff --git a/spec/integration/client_spec.rb b/spec/integration/client_spec.rb index cd2d70e..a9761b2 100644 --- a/spec/integration/client_spec.rb +++ b/spec/integration/client_spec.rb @@ -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 diff --git a/spec/integration/identifier_spec.rb b/spec/integration/identifier_spec.rb index 7d3a8c0..9234299 100644 --- a/spec/integration/identifier_spec.rb +++ b/spec/integration/identifier_spec.rb @@ -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") diff --git a/spec/unit/identifier_spec.rb b/spec/unit/identifier_spec.rb index da8a0a6..5299bf6 100644 --- a/spec/unit/identifier_spec.rb +++ b/spec/unit/identifier_spec.rb @@ -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 @@ -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 } @@ -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 @@ -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" } @@ -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 diff --git a/spec/unit/proxy_identifier_spec.rb b/spec/unit/proxy_identifier_spec.rb index 33706cd..2ffc0c1 100644 --- a/spec/unit/proxy_identifier_spec.rb +++ b/spec/unit/proxy_identifier_spec.rb @@ -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