Skip to content

Commit

Permalink
Allow the FixityService to accept an RDF::URI
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Jun 30, 2015
1 parent dd23591 commit a216b07
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
34 changes: 17 additions & 17 deletions lib/active_fedora/fixity_service.rb
Expand Up @@ -4,10 +4,10 @@ class FixityService

attr_accessor :target, :response

# Accepts an Fedora resource such as File.ldp_resource.subject
# @param [String, RDF::URI] target url for a Fedora resource
def initialize target
raise ArgumentError, 'You must provide a uri' unless target
@target = target
@target = target.to_s
end

# Executes a fixity check on Fedora and saves the Faraday::Response.
Expand All @@ -23,23 +23,23 @@ def status

private

def get_fixity_response_from_fedora
uri = target + "/fcr:fixity"
ActiveFedora.fedora.connection.get(encoded_url(uri))
end

def fixity_graph
::RDF::Graph.new << ::RDF::Reader.for(:ttl).new(response.body)
end
def get_fixity_response_from_fedora
uri = target + "/fcr:fixity"
ActiveFedora.fedora.connection.get(encoded_url(uri))
end

# See https://jira.duraspace.org/browse/FCREPO-1247
def encoded_url uri
if uri.match("fcr:versions")
uri.gsub(/fcr:versions/,"fcr%3aversions")
else
uri
def fixity_graph
::RDF::Graph.new << ::RDF::Reader.for(:ttl).new(response.body)
end
end

# See https://jira.duraspace.org/browse/FCREPO-1247
# @param [String] uri
def encoded_url uri
if uri.match("fcr:versions")
uri.gsub(/fcr:versions/,"fcr%3aversions")
else
uri
end
end
end
end
34 changes: 23 additions & 11 deletions spec/unit/fixity_service_spec.rb
Expand Up @@ -2,32 +2,44 @@

describe ActiveFedora::FixityService do

subject { ActiveFedora::FixityService.new("http://path/to/resource") }
let(:service) { described_class.new(uri) }
let(:uri) { RDF::URI("http://path/to/resource") }

it { is_expected.to respond_to(:target) }
it { is_expected.to respond_to(:response) }
describe "the instance" do
subject { described_class.new(uri) }
it { is_expected.to respond_to(:response) }
end

describe "initialize" do
context "with a string" do
let(:uri) { 'http://path/to/resource' }
subject { service.target }
it { is_expected.to eq 'http://path/to/resource' }
end

context "with an RDF::URI" do
subject { service.target }
it { is_expected.to eq 'http://path/to/resource' }
end
end

describe "#check" do
before do
expect(subject).to receive(:get_fixity_response_from_fedora).and_return(response)
allow(service).to receive(:get_fixity_response_from_fedora).and_return(response)
end
subject { service.check }
context "with a passing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://fedora.info/definitions/v4/repository#status> "SUCCESS"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
specify "returns true" do
expect(subject.check).to be true
end

it { is_expected.to be true }
end

context "with a failing result" do
let(:response) do
instance_double("Response", body: '<subject> <http://fedora.info/definitions/v4/repository#status> "BAD_CHECKSUM"^^<http://www.w3.org/2001/XMLSchema#string> .')
end
specify "returns false" do
expect(subject.check).to be false
end
it { is_expected.to be false }
end
end

Expand Down

0 comments on commit a216b07

Please sign in to comment.