Skip to content

Commit

Permalink
Merge branch 'release-1.9.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dchandekstark committed Apr 9, 2021
2 parents cae2aca + 4220c1e commit 24cc925
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 35 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby

on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]

jobs:
test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7']

steps:
- uses: actions/checkout@v2
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rspec ./spec/unit/
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ desc "Run all specs in spec directory"
RSpec::Core::RakeTask.new(:spec)

desc "Run the ci build (no integration tests)"
task :ci do
system "rspec . -t ~deprecated -t ~integration"
RSpec::Core::RakeTask.new(:ci) do |t|
t.rspec_opts = "--tag '~deprecated' --tag '~ezid'"
end

desc "Run tests of deprecated functionality"
task :deprecated do
system "rspec . -t deprecated"
RSpec::Core::RakeTask.new(:deprecated) do |t|
t.rspec_opts = "--tag deprecated"
end

desc "Run the integration tests"
task :integration do
system "rspec . -t integration"
RSpec::Core::RakeTask.new(:integration) do |t|
t.rspec_opts = "--tag 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.8.0
1.9.0
2 changes: 1 addition & 1 deletion ezid-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "hashie", "~> 3.4", ">= 3.4.3"
spec.add_dependency "nokogiri"

spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "bundler"
spec.add_development_dependency "byebug"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec", "~> 3.4"
Expand Down
2 changes: 2 additions & 0 deletions lib/ezid/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ class IdentifierNotFoundError < Error; end
class NotAllowedError < Error; end

class DeletionError < Error; end

class UnexpectedResponseError < Error; end
end
31 changes: 22 additions & 9 deletions lib/ezid/requests/request.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require "delegate"
require "uri"
require "net/http"
require "forwardable"
require 'delegate'
require 'uri'
require 'net/http'
require 'forwardable'
require 'date'

require_relative "../responses/response"
require_relative '../responses/response'

module Ezid
#
Expand Down Expand Up @@ -31,7 +32,7 @@ def execute(client, *args)
end

def short_name
name.split("::").last.sub("Request", "")
name.split('::').last.sub('Request', '')
end
end

Expand All @@ -42,13 +43,24 @@ def short_name
def initialize(client, *args)
@client = client
super build_request
set_content_type("text/plain", charset: "UTF-8")
set_content_type('text/plain', charset: 'UTF-8')
end

# Executes the request and returns the response
# @return [Ezid::Response] the response
def execute
response_class.new(get_response_for_request)
retries = 0
begin
response_class.new(get_response_for_request)
rescue Net::HTTPServerException, UnexpectedResponseError => e
if retries < 2
sleep 15
retries += 1
retry
else
raise
end
end
end

# The request URI
Expand Down Expand Up @@ -91,6 +103,7 @@ def handle_response(http_response)

def get_response_for_request
connection.start do |conn|
self['Accept'] = 'text/plain'
add_authentication if authentication_required?
add_metadata if has_metadata?
conn.request(__getobj__)
Expand All @@ -113,7 +126,7 @@ def build_uri
# Adds authentication data to the request
def add_authentication
if session.open?
self["Cookie"] = session.cookie
self['Cookie'] = session.cookie
else
basic_auth(user, password)
end
Expand Down
13 changes: 13 additions & 0 deletions lib/ezid/responses/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ class Response < SimpleDelegator
# Error response status
ERROR = "error".freeze

def initialize(http_response)
super

unless __getobj__.code =~ /2\d\d/
raise Error, "HTTP response error: %s %s" %
[ __getobj__.code, __getobj__.message ]
end

unless status_line =~ /^(#{SUCCESS}|#{ERROR}): /
raise UnexpectedResponseError, __getobj__.body
end
end

# The response status -- "success" or "error"
# @return [String] the status
def status
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/batch_download_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
require 'tempfile'

module Ezid
RSpec.describe BatchDownload, integration: true do
RSpec.describe BatchDownload, ezid: true do

subject do
a_week_ago = (Time.now - (7*24*60*60)).to_i
described_class.new(:anvl, compression: "zip", permanence: "test", status: "public", createdAfter: a_week_ago)
end

specify {
expect(subject.download_url).to match(/\Ahttp:\/\/ezid\.cdlib\.org\/download\/\w+\.zip\z/)
expect(subject.url).to match(/\Ahttp:\/\/ezid\.cdlib\.org\/download\/\w+\.zip\z/)
expect(subject.download_url).to match(/\Ahttps:\/\/ezid\.cdlib\.org\/download\/\w+\.zip\z/)
expect(subject.url).to match(/\Ahttps:\/\/ezid\.cdlib\.org\/download\/\w+\.zip\z/)
Dir.mktmpdir do |tmpdir|
expect(subject.file(path: tmpdir))
.to match(/\A#{tmpdir}\/\w+\.zip\z/)
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, integration: true do
RSpec.describe Client, ezid: true do

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

before {
@identifier = described_class.mint(TEST_ARK_SHOULDER, target: "http://example.com")
Expand Down Expand Up @@ -38,7 +38,8 @@ module Ezid
end
describe "delete" do
subject { described_class.mint(TEST_ARK_SHOULDER, status: "reserved") }
it "deletes the identifier" do
# Getting 400 Bad Request response - DCS 3/22/21
xit "deletes the identifier" do
subject.delete
expect(subject).to be_deleted
expect { described_class.find(subject.id) }.to raise_error(IdentifierNotFoundError)
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration

require "byebug"

require "rspec/its"

require "ezid/test_helper"
Expand Down
38 changes: 35 additions & 3 deletions spec/unit/client_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module Ezid
RSpec.describe Client do

let(:http_response) { double }

before do
allow(http_response).to receive(:value) { nil }
allow(http_response).to receive(:code) { '200' }
end

describe "initialization without a block" do
let(:http_response) { double }
it "should not login" do
expect_any_instance_of(described_class).not_to receive(:login)
described_class.new
Expand Down Expand Up @@ -151,9 +159,33 @@ module Ezid
end

describe "error handling" do
let(:http_response) { double(body: "error: bad request - no such identifier") }
it "should raise an exception" do
expect { subject.get_identifier_metadata("invalid") }.to raise_error(Error)
let(:stub_response) { GetIdentifierMetadataResponse.new(http_response) }
before do
allow(GetIdentifierMetadataRequest).to receive(:execute).with(subject, "invalid") { stub_response }
end

describe "HTTP error response" do
before do
allow(http_response).to receive(:code) { '500' }
allow(http_response).to receive(:message) { 'Internal Server Error' }
end
it "should raise an exception" do
expect { subject.get_identifier_metadata("invalid") }.to raise_error(Error)
end
end

describe "EZID API error response" do
let(:http_response) { double(body: "error: bad request - no such identifier") }
it "should raise an exception" do
expect { subject.get_identifier_metadata("invalid") }.to raise_error(Error)
end
end

describe "Unexpected response" do
let(:http_response) { double(body: "<html>\n<head><title>Ouch!</title></head>\n<body>Help!</body>\n</html>") }
it "should raise an exception" do
expect { subject.get_identifier_metadata("invalid") }.to raise_error(UnexpectedResponseError)
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/unit/metadata_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'time'

module Ezid
RSpec.describe Metadata do
describe "initializer" do
Expand Down

0 comments on commit 24cc925

Please sign in to comment.