Skip to content

Commit

Permalink
RdfDatastream#deserialize should always return an RDF::Graph. Fixes #471
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 16, 2014
1 parent 2d21c13 commit c9adc7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/active_fedora/rdf/rdf_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def deserialize(data=nil)
end

# Because datastream_content can return nil, we should check that here.
return repository if data.nil?
return RDF::Graph.new if data.nil?

data.force_encoding('utf-8')
RDF::Graph.new << RDF::Reader.for(serialization_format).new(data)
Expand Down
24 changes: 19 additions & 5 deletions spec/unit/rdf_datastream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,27 @@ class MyObj < ActiveFedora::Base
end

describe "deserialize" do
it "should be able to handle non-utf-8 characters" do
let(:ds) { ActiveFedora::NtriplesRDFDatastream.new }
subject { ds.deserialize(data) }

context "with non-utf-8 characters" do
# see https://github.com/ruby-rdf/rdf/issues/142
ds = ActiveFedora::NtriplesRDFDatastream.new
data = "<info:fedora/scholarsphere:qv33rx50r> <http://purl.org/dc/terms/description> \"\\n\xE2\x80\x99 \" .\n".force_encoding('ASCII-8BIT')
let(:data) { "<info:fedora/scholarsphere:qv33rx50r> <http://purl.org/dc/terms/description> \"\\n\xE2\x80\x99 \" .\n".force_encoding('ASCII-8BIT') }

it "should be able to handle non-utf-8 characters" do
expect(subject.dump(:ntriples)).to eq "<info:fedora/scholarsphere:qv33rx50r> <http://purl.org/dc/terms/description> \"\\n’ \" .\n"
end
end

result = ds.deserialize(data)
result.dump(:ntriples).should == "<info:fedora/scholarsphere:qv33rx50r> <http://purl.org/dc/terms/description> \"\\n’ \" .\n"
context "when the object is saved and has no content in the datastream" do
let(:data) { nil }
before do
allow(ds).to receive(:new?).and_return(false);
allow(ds).to receive(:datastream_content).and_return(nil);
end
it "should return an empty graph" do
expect(subject).to be_kind_of RDF::Graph
end
end
end

Expand Down

0 comments on commit c9adc7e

Please sign in to comment.