From 09cf82e8b640519ad5b913b5354f0b577d61d50d Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Tue, 5 May 2015 14:45:24 -0500 Subject: [PATCH] Initial implementation of PCDM::File. Fixes #19 --- Gemfile | 3 ++- lib/hydra/pcdm/models/file.rb | 16 +++++--------- spec/hydra/pcdm/models/file_spec.rb | 33 +++++++++++++++-------------- spec/spec_helper.rb | 6 ++++++ 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index 3677b0e8..eea1cb07 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,7 @@ source 'https://rubygems.org' -gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation', branch: 'master' +gem 'activefedora-aggregation', github: 'projecthydra-labs/activefedora-aggregation' +gem 'active-fedora', github: 'projecthydra/active_fedora' # Specify your gem's dependencies in hydra-pcdm.gemspec gemspec diff --git a/lib/hydra/pcdm/models/file.rb b/lib/hydra/pcdm/models/file.rb index c09dca7a..ba3c557a 100644 --- a/lib/hydra/pcdm/models/file.rb +++ b/lib/hydra/pcdm/models/file.rb @@ -1,16 +1,10 @@ module Hydra::PCDM class File < ActiveFedora::File - type RDFVocabularies::PCDMTerms.File # TODO switch to using generated vocabulary when ready - - # behavior: - # 1) PCDM::File can NOT aggregate anything - # 2) PCDM::File can NOT contain PCDM::File - # 3) PCDM::File can have technical metadata about one uploaded binary file - # TODO: add code to enforce behavior rules - - # TODO: The only expected additional behavior for PCDM::File beyond ActiveFedora::File is the expression - # of additional technical metadata + include ActiveFedora::WithMetadata + metadata do + configure type: RDFVocabularies::PCDMTerms.File + property :label, predicate: ::RDF::RDFS.label + end end end - diff --git a/spec/hydra/pcdm/models/file_spec.rb b/spec/hydra/pcdm/models/file_spec.rb index e096f457..1009fadc 100644 --- a/spec/hydra/pcdm/models/file_spec.rb +++ b/spec/hydra/pcdm/models/file_spec.rb @@ -1,24 +1,25 @@ require 'spec_helper' -describe 'Hydra::PCDM::File' do +describe Hydra::PCDM::File do - # subject { Hydra::PCDM::Object.new } - - # There isn't a #members method on Hydra::PCDM::File, so no need to test what can and can't be aggregated. - # 1) Hydra::PCDM::File can NOT aggregate anything - - # There isn't a #contains method on Hydra::PCDM::File, so no need to test if Hydra::PCDM::File can contain Hydra::PCDM::File - # 2) Hydra::PCDM::File can NOT contain Hydra::PCDM::File - - # TODO: What method is used to set metadata in a Hydra::PCDM::File - describe '#METHOD_NAME' do - xit 'should be able to add metadata about an uploaded file' do - # 3) Hydra::PCDM::File can set/hold technical metadata for an uploaded file - - # TODO Write test + let(:file) { Hydra::PCDM::File.new } + let(:reloaded) { Hydra::PCDM::File.new(file.uri) } + describe "when saving" do + it "sets an RDF type" 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] end - end + describe "#label" do + it "saves a label" do + file.content = 'stuff' + file.label = 'foo' + expect(file.label).to eq ['foo'] + expect(file.save).to be true + expect(reloaded.label).to eq ['foo'] + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 57c6792d..488abc4e 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,6 +12,12 @@ Dir['./spec/support/**/*.rb'].each { |f| require f } +# require 'http_logger' +# HttpLogger.logger = Logger.new(STDOUT) +# HttpLogger.ignore = [/localhost:8983\/solr/] +# HttpLogger.colorize = false +# HttpLogger.log_headers = true + RSpec.configure do |config| config.color = true config.tty = true