Skip to content

Commit

Permalink
Initial implementation of PCDM::File. Fixes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 5, 2015
1 parent 76f0b97 commit 09cf82e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -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
16 changes: 5 additions & 11 deletions lib/hydra/pcdm/models/file.rb
Original file line number Diff line number Diff line change
@@ -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

33 changes: 17 additions & 16 deletions spec/hydra/pcdm/models/file_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09cf82e

Please sign in to comment.