-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing support for ARK validation by extending the Ark Class (#84)
* Implementing support for ARK validation by extending the `Ark` Class; Ensuring that WebMock is enabled but does not conflict wit h test suites which request data from the EZID API endpoint * Increasing the test coverage for the `User` Model
- Loading branch information
1 parent
bfb3269
commit 727c8ca
Showing
11 changed files
with
306 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
require "rails_helper" | ||
|
||
RSpec.describe Ark, type: :model do | ||
describe ".valid?" do | ||
let(:id) { "id" } | ||
|
||
context "when the ARK references a non-existent EZID" do | ||
before do | ||
stub_request(:get, "https://ezid.cdlib.org/id/#{id}").to_return(status: 400, body: "error: bad request - invalid identifier") | ||
|
||
# This is a work-around for WebMock | ||
allow(Ezid::Identifier).to receive(:find).and_raise(Net::HTTPServerException, '400 "Bad Request"') | ||
end | ||
|
||
it "returns false" do | ||
expect(described_class.valid?(id)).to be false | ||
end | ||
end | ||
|
||
context "when the ARK references an existing EZID" do | ||
let(:response_body) do | ||
%( | ||
success: ark:/99999/fk4cz3dh0 | ||
_created: 1300812337 | ||
_updated: 1300913550 | ||
_target: http://www.gutenberg.org/ebooks/7178 | ||
_profile: erc | ||
erc.who: Proust, Marcel | ||
erc.what: Remembrance of Things Past | ||
erc.when: 1922 | ||
) | ||
end | ||
let(:identifier) { instance_double(Ezid::Identifier) } | ||
|
||
before do | ||
stub_request(:get, "https://ezid.cdlib.org/id/#{id}").to_return(status: 200, body: response_body) | ||
# This is a work-around for WebMock | ||
allow(Ezid::Identifier).to receive(:find).and_return(identifier) | ||
end | ||
|
||
it "returns true" do | ||
expect(described_class.valid?(id)).to be true | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.