Skip to content

Commit

Permalink
implements Hydra::PCDM::VersionedFile
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingzumwalt committed Jun 23, 2015
1 parent e19f056 commit 4b824d9
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
1 change: 1 addition & 0 deletions lib/hydra/pcdm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module PCDM
autoload :Collection, 'hydra/pcdm/models/collection'
autoload :Object, 'hydra/pcdm/models/object'
autoload :File, 'hydra/pcdm/models/file'
autoload :VersionedFile, 'hydra/pcdm/models/versioned_file'

# behavior concerns
autoload :CollectionBehavior, 'hydra/pcdm/models/concerns/collection_behavior'
Expand Down
22 changes: 22 additions & 0 deletions lib/hydra/pcdm/models/versioned_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Hydra::PCDM
class VersionedFile < Hydra::PCDM::File
has_many_versions

# This stuff wasn't inheriting from Hydra::PCDM::File, so repeating it here.
metadata do
configure type: RDFVocabularies::PCDMTerms.File
property :label, predicate: ::RDF::RDFS.label

property :file_name, predicate: EBUCoreVocabularies::EBUCoreTerms.filename
property :file_size, predicate: EBUCoreVocabularies::EBUCoreTerms.fileSize
property :date_created, predicate: EBUCoreVocabularies::EBUCoreTerms.dateCreated
property :has_mime_type, predicate: EBUCoreVocabularies::EBUCoreTerms.hasMimeType
property :date_modified, predicate: EBUCoreVocabularies::EBUCoreTerms.dateModified
property :byte_order, predicate: SweetjplVocabularies::SweetjplTerms.byteOrder

# This is a server-managed predicate which means Fedora does not let us change it.
property :file_hash, predicate: RDF::Vocab::PREMIS.hasMessageDigest
end

end
end
26 changes: 13 additions & 13 deletions spec/hydra/pcdm/models/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@
let(:reloaded) { Hydra::PCDM::File.new(file.uri) }

describe "when saving" do
it "sets an RDF type" do
before do
file.content = 'stuff'
expect(file.save).to be true
expect(reloaded.metadata_node.query(predicate: RDF.type, object: RDFVocabularies::PCDMTerms.File).map(&:object)).to eq [RDFVocabularies::PCDMTerms.File]
file.save
end
subject { reloaded }
# it { is_expected.to be_persisted } # This check isn't currently supported by ActiveFedora
it "sets an RDF type" do
expect(subject.metadata_node.query(predicate: RDF.type, object: RDFVocabularies::PCDMTerms.File).map(&:object)).to eq [RDFVocabularies::PCDMTerms.File]
end
end

describe "#label" do
it "saves a label" do
before do
file.content = 'stuff'
file.label = 'foo'
end
it "saves a label" do
expect(file.label).to eq ['foo']
expect(file.save).to be true
expect(reloaded.label).to eq ['foo']
Expand All @@ -28,13 +34,15 @@
let(:date_modified) { Date.parse "Sat, 09 May 2015 09:00:00 -0400 (EDT)" }
let(:content) { "hello world" }
let(:file) { Hydra::PCDM::File.new.tap { |ds| ds.content = content } }
it "saves technical metadata" do
before do
file.file_name = "picture.jpg"
file.file_size = content.length.to_s
file.date_created = date_created
file.has_mime_type = "application/jpg"
file.date_modified = date_modified
file.byte_order = "little-endian"
end
it "saves technical metadata" do
expect(file.save).to be true
expect(reloaded.file_name).to eq ["picture.jpg"]
expect(reloaded.file_size).to eq [content.length.to_s]
Expand All @@ -43,14 +51,6 @@
expect(reloaded.date_modified).to eq [date_modified]
expect(reloaded.byte_order).to eq ["little-endian"]
end

it "does not save server managed properties" do
# Currently we can't write this property because Fedora
# complains that it's a server managed property. This test
# is mostly to document this situation.
file.file_hash = "the-hash"
expect{file.save}.to raise_error(Ldp::BadRequest)
end
end

end
60 changes: 60 additions & 0 deletions spec/hydra/pcdm/models/versioned_file_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'spec_helper'

describe Hydra::PCDM::File do

let(:file) { Hydra::PCDM::VersionedFile.new }
let(:reloaded) { Hydra::PCDM::VersionedFile.new(file.uri) }

it "has_many_versions" do
expect(file.class).to be_versionable
end

describe "when saving" do
before do
file.content = 'stuff'
file.save
end
subject { reloaded }
# it { is_expected.to be_persisted } # This check isn't currently supported by ActiveFedora
it "sets the PCDMTerms.File RDF type" do
expect(reloaded.metadata_node.query(predicate: RDF.type, object: RDFVocabularies::PCDMTerms.File).map(&:object)).to eq [RDFVocabularies::PCDMTerms.File]
end
end

describe "#label" do
before do
file.content = 'stuff'
file.label = 'foo'
end
it "saves a label" do
expect(file.label).to eq ['foo']
expect(file.save).to be true
expect(reloaded.label).to eq ['foo']
end
end

describe "technical metadata" do
let(:date_created) { Date.parse "Fri, 08 May 2015 08:00:00 -0400 (EDT)" }
let(:date_modified) { Date.parse "Sat, 09 May 2015 09:00:00 -0400 (EDT)" }
let(:content) { "hello world" }
let(:file) { Hydra::PCDM::File.new.tap { |ds| ds.content = content } }
before do
file.file_name = "picture.jpg"
file.file_size = content.length.to_s
file.date_created = date_created
file.has_mime_type = "application/jpg"
file.date_modified = date_modified
file.byte_order = "little-endian"
end
it "saves technical metadata" do
expect(file.save).to be true
expect(reloaded.file_name).to eq ["picture.jpg"]
expect(reloaded.file_size).to eq [content.length.to_s]
expect(reloaded.has_mime_type).to eq ["application/jpg"]
expect(reloaded.date_created).to eq [date_created]
expect(reloaded.date_modified).to eq [date_modified]
expect(reloaded.byte_order).to eq ["little-endian"]
end
end

end

0 comments on commit 4b824d9

Please sign in to comment.