hydra-works 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +72 -0
- data/Gemfile +5 -4
- data/README.md +17 -11
- data/Rakefile +18 -8
- data/config/solrconfig.xml +223 -0
- data/hydra-works.gemspec +15 -15
- data/lib/hydra/works.rb +28 -17
- data/lib/hydra/works/errors/full_text_extraction_error.rb +5 -0
- data/lib/hydra/works/models/concerns/block_child_objects.rb +12 -6
- data/lib/hydra/works/models/concerns/collection_behavior.rb +44 -6
- data/lib/hydra/works/models/concerns/generic_file/contained_files.rb +3 -3
- data/lib/hydra/works/models/concerns/generic_file/derivatives.rb +2 -4
- data/lib/hydra/works/models/concerns/generic_file/mime_types.rb +1 -3
- data/lib/hydra/works/models/concerns/generic_file/versioned_content.rb +4 -6
- data/lib/hydra/works/models/concerns/generic_file/virus_check.rb +13 -14
- data/lib/hydra/works/models/concerns/generic_file_behavior.rb +13 -3
- data/lib/hydra/works/models/concerns/generic_work_behavior.rb +34 -9
- data/lib/hydra/works/models/generic_file.rb +0 -3
- data/lib/hydra/works/services/generic_file/add_file_to_generic_file.rb +14 -16
- data/lib/hydra/works/services/generic_file/full_text_extraction_service.rb +57 -0
- data/lib/hydra/works/services/generic_file/generate_thumbnail.rb +13 -0
- data/lib/hydra/works/services/generic_file/persist_derivative.rb +3 -5
- data/lib/hydra/works/services/generic_file/{upload_file.rb → upload_file_to_generic_file.rb} +1 -3
- data/lib/hydra/works/version.rb +1 -1
- data/lib/hydra/works/vocab/works_terms.rb +9 -9
- data/lib/tasks/hydra-works_tasks.rake +80 -0
- data/lib/tasks/jetty.rake +15 -0
- data/spec/hydra/works/models/collection_spec.rb +258 -246
- data/spec/hydra/works/models/concerns/block_child_objects_spec.rb +6 -8
- data/spec/hydra/works/models/concerns/generic_file/contained_files_spec.rb +40 -48
- data/spec/hydra/works/models/concerns/generic_file/mime_types_spec.rb +16 -18
- data/spec/hydra/works/models/concerns/generic_file/versioned_content_spec.rb +11 -11
- data/spec/hydra/works/models/concerns/generic_file/virus_check_spec.rb +11 -8
- data/spec/hydra/works/models/concerns/generic_file_behavior_spec.rb +1 -1
- data/spec/hydra/works/models/generic_file_spec.rb +87 -85
- data/spec/hydra/works/models/generic_work_spec.rb +167 -169
- data/spec/hydra/works/services/full_text_extraction_service_spec.rb +89 -0
- data/spec/hydra/works/services/generic_file/add_file_to_generic_file_spec.rb +36 -38
- data/spec/hydra/works/services/generic_file/generate/thumbnail_spec.rb +10 -12
- data/spec/hydra/works/services/generic_file/upload_file_spec.rb +39 -42
- data/spec/hydra/works/services/persist_derivatives_spec.rb +2 -3
- data/spec/hydra/works_spec.rb +57 -61
- data/spec/spec_helper.rb +2 -4
- metadata +23 -15
- data/lib/hydra/works/services/generic_file/generate/thumbnail.rb +0 -18
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hydra::Works::FullTextExtractionService do
|
4
|
+
let(:generic_file) { Hydra::Works::GenericFile::Base.new }
|
5
|
+
|
6
|
+
describe 'integration test' do
|
7
|
+
before do
|
8
|
+
Hydra::Works::UploadFileToGenericFile.call(generic_file, File.open(File.join(fixture_path, 'sample-file.pdf')))
|
9
|
+
end
|
10
|
+
subject { described_class.run(generic_file) }
|
11
|
+
it 'extracts fulltext and stores the results' do
|
12
|
+
expect(subject).to include('This is some original content')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "run" do
|
17
|
+
let(:generic_file) { double(id: '123') }
|
18
|
+
subject { described_class.run(generic_file) }
|
19
|
+
|
20
|
+
context "when it is successful" do
|
21
|
+
before do
|
22
|
+
allow_any_instance_of(described_class).to receive(:fetch).and_return('{"":"one two three"}')
|
23
|
+
end
|
24
|
+
it { is_expected.to eq 'one two three' }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "when solr raises an error" do
|
28
|
+
before do
|
29
|
+
allow_any_instance_of(described_class).to receive(:fetch).and_raise(Hydra::Works::FullTextExtractionError.new, "Solr failed")
|
30
|
+
end
|
31
|
+
it "raises an error" do
|
32
|
+
expect { subject }.to raise_error Hydra::Works::FullTextExtractionError, 'Solr failed'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "network error" do
|
37
|
+
before do
|
38
|
+
allow_any_instance_of(described_class).to receive(:fetch).and_raise(Errno::ECONNRESET)
|
39
|
+
end
|
40
|
+
it "raises an error" do
|
41
|
+
expect { subject }.to raise_error Hydra::Works::FullTextExtractionError, 'Error extracting content from 123: #<Errno::ECONNRESET: Connection reset by peer>'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "fetch" do
|
47
|
+
let(:generic_file) { double('generic file', id: '123', original_file: original) }
|
48
|
+
let(:original) { double(content: content, size: 13, mime_type: 'text/plain') }
|
49
|
+
let(:service) { described_class.new(generic_file) }
|
50
|
+
subject { service.fetch }
|
51
|
+
let(:request) { double }
|
52
|
+
let(:response_body) { 'returned by Solr' }
|
53
|
+
let(:resp) { double(code: '200', body: response_body) }
|
54
|
+
let(:uri) { URI('http://example.com:99/solr/update') }
|
55
|
+
let(:content) { 'file contents' }
|
56
|
+
|
57
|
+
before do
|
58
|
+
allow(service).to receive(:uri).and_return(URI('http://example.com:99/solr/update'))
|
59
|
+
allow(Net::HTTP).to receive(:new).with('example.com', 99).and_return(request)
|
60
|
+
end
|
61
|
+
|
62
|
+
context "that is successful" do
|
63
|
+
let(:resp) { double(code: '200', body: response_body) }
|
64
|
+
it "calls the extraction service" do
|
65
|
+
expect(request).to receive(:post).with('http://example.com:99/solr/update', content, "Content-Type" => "text/plain;charset=utf-8", "Content-Length" => "13").and_return(resp)
|
66
|
+
expect(subject).to eq response_body
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "that fails" do
|
71
|
+
let(:resp) { double(code: '500', body: response_body) }
|
72
|
+
it "raises an error" do
|
73
|
+
expect(request).to receive(:post).with('http://example.com:99/solr/update', content, "Content-Type" => "text/plain;charset=utf-8", "Content-Length" => "13").and_return(resp)
|
74
|
+
expect { subject }.to raise_error Hydra::Works::FullTextExtractionError, "Solr Extract service was unsuccessful. 'http://example.com:99/solr/update' returned code 500 for 123\nreturned by Solr"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "uri" do
|
80
|
+
let(:generic_file) { double }
|
81
|
+
let(:service) { described_class.new(generic_file) }
|
82
|
+
subject { service.uri }
|
83
|
+
|
84
|
+
it "points at the extraction service" do
|
85
|
+
expect(subject).to be_kind_of URI
|
86
|
+
expect(subject.to_s).to end_with '/update/extract?extractOnly=true&wt=json&extractFormat=text'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -1,110 +1,108 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::Works::AddFileToGenericFile do
|
4
|
-
|
5
4
|
let(:generic_file) { Hydra::Works::GenericFile::Base.new }
|
6
|
-
let(:filename) {
|
7
|
-
let(:filename2) {
|
8
|
-
let(:original_name) {
|
5
|
+
let(:filename) { 'sample-file.pdf' }
|
6
|
+
let(:filename2) { 'updated-file.txt' }
|
7
|
+
let(:original_name) { 'original-name.pdf' }
|
9
8
|
let(:file) { File.open(File.join(fixture_path, filename)) }
|
10
9
|
let(:file2) { File.open(File.join(fixture_path, filename2)) }
|
11
|
-
let(:type) { ::RDF::URI(
|
10
|
+
let(:type) { ::RDF::URI('http://pcdm.org/use#ExtractedText') }
|
12
11
|
let(:update_existing) { true }
|
13
|
-
let(:mime_type) {
|
12
|
+
let(:mime_type) { 'application/pdf' }
|
14
13
|
|
15
|
-
context
|
16
|
-
let(:generic_file)
|
17
|
-
it
|
14
|
+
context 'when generic_file is not persisted' do
|
15
|
+
let(:generic_file) { Hydra::Works::GenericFile::Base.new }
|
16
|
+
it 'saves generic_file' do
|
18
17
|
described_class.call(generic_file, file, type)
|
19
18
|
expect(generic_file.persisted?).to be true
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
context
|
22
|
+
context 'when generic_file is not valid' do
|
24
23
|
before do
|
25
24
|
generic_file.save
|
26
25
|
allow(generic_file).to receive(:valid?).and_return(false)
|
27
26
|
end
|
28
|
-
it
|
29
|
-
expect(
|
27
|
+
it 'returns false' do
|
28
|
+
expect(described_class.call(generic_file, file, type)).to be false
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
context
|
32
|
+
context 'file responds to :mime_type and :original_name' do
|
34
33
|
before do
|
35
|
-
allow(file).to
|
36
|
-
allow(file).to
|
34
|
+
allow(file).to receive(:mime_type).and_return(mime_type)
|
35
|
+
allow(file).to receive(:original_name).and_return(original_name)
|
37
36
|
described_class.call(generic_file, file, type)
|
38
37
|
end
|
39
38
|
subject { generic_file.filter_files_by_type(type).first }
|
40
|
-
it
|
39
|
+
it 'uses the mime_type and original_name methods' do
|
41
40
|
expect(subject.mime_type).to eq(mime_type)
|
42
41
|
expect(subject.original_name).to eq(original_name)
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
46
|
-
context
|
47
|
-
it
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
context 'file responds to :path but not to :mime_type nor :original_name' do
|
46
|
+
it 'defaults to Hydra::PCDM for mimetype and ::File for basename.' do
|
47
|
+
expect(Hydra::PCDM::GetMimeTypeForFile).to receive(:call).with(file.path)
|
48
|
+
expect(::File).to receive(:basename).with(file.path)
|
49
|
+
described_class.call(generic_file, file, type)
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
it
|
53
|
+
it 'adds the given file and applies the specified type to it' do
|
55
54
|
described_class.call(generic_file, file, type, update_existing: update_existing)
|
56
|
-
expect(generic_file.filter_files_by_type(type).first.content).to start_with(
|
55
|
+
expect(generic_file.filter_files_by_type(type).first.content).to start_with('%PDF-1.3')
|
57
56
|
end
|
58
57
|
|
59
|
-
context
|
58
|
+
context 'when :type is the name of an association' do
|
60
59
|
let(:type) { :extracted_text }
|
61
60
|
before do
|
62
61
|
described_class.call(generic_file, file, type)
|
63
62
|
end
|
64
63
|
it "builds and uses the association's target" do
|
65
|
-
expect(generic_file.extracted_text.content).to start_with(
|
64
|
+
expect(generic_file.extracted_text.content).to start_with('%PDF-1.3')
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
|
-
context
|
68
|
+
context 'when :versioning => true' do
|
70
69
|
let(:type) { :original_file }
|
71
70
|
let(:versioning) { true }
|
72
71
|
subject { generic_file }
|
73
|
-
it
|
72
|
+
it 'updates the file and creates a version' do
|
74
73
|
described_class.call(generic_file, file, type, versioning: versioning)
|
75
74
|
expect(subject.original_file.versions.all.count).to eq(1)
|
76
|
-
expect(subject.original_file.content).to start_with(
|
75
|
+
expect(subject.original_file.content).to start_with('%PDF-1.3')
|
77
76
|
end
|
78
|
-
context
|
77
|
+
context 'and there are already versions' do
|
79
78
|
before do
|
80
79
|
described_class.call(generic_file, file, type, versioning: versioning)
|
81
80
|
described_class.call(generic_file, file2, type, versioning: versioning)
|
82
81
|
end
|
83
|
-
it
|
82
|
+
it 'adds to the version history' do
|
84
83
|
expect(subject.original_file.versions.all.count).to eq(2)
|
85
84
|
expect(subject.original_file.content).to eq("some updated content\n")
|
86
85
|
end
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
|
-
context
|
89
|
+
context 'when :versioning => false' do
|
91
90
|
let(:type) { :original_file }
|
92
91
|
let(:versioning) { false }
|
93
92
|
before do
|
94
93
|
described_class.call(generic_file, file, type, versioning: versioning)
|
95
94
|
end
|
96
|
-
subject
|
97
|
-
it
|
95
|
+
subject { generic_file }
|
96
|
+
it 'skips creating versions' do
|
98
97
|
expect(subject.original_file.versions.all.count).to eq(0)
|
99
|
-
expect(subject.original_file.content).to start_with(
|
98
|
+
expect(subject.original_file.content).to start_with('%PDF-1.3')
|
100
99
|
end
|
101
100
|
end
|
102
101
|
|
103
|
-
context
|
102
|
+
context 'type_to_uri' do
|
104
103
|
subject { Hydra::Works::AddFileToGenericFile::Updater.allocate }
|
105
|
-
it
|
106
|
-
expect(subject.send(:type_to_uri,
|
104
|
+
it 'converts URI strings to RDF::URI' do
|
105
|
+
expect(subject.send(:type_to_uri, 'http://example.com/CustomURI')).to eq(::RDF::URI('http://example.com/CustomURI'))
|
107
106
|
end
|
108
107
|
end
|
109
|
-
|
110
108
|
end
|
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::Works::GenerateThumbnail do
|
4
|
-
|
5
|
-
|
6
|
-
let(:
|
7
|
-
|
8
|
-
|
9
|
-
expect(lambda{ described_class.call(object) }).to raise_error(ArgumentError, error_message)
|
4
|
+
context 'when the object has no original file' do
|
5
|
+
let(:error_message) { 'object has no content at original_file from which to generate a thumbnail' }
|
6
|
+
let(:object) { double('object', original_file: nil) }
|
7
|
+
it 'raises an error' do
|
8
|
+
expect(-> { described_class.call(object) }).to raise_error(ArgumentError, error_message)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
|
-
context
|
14
|
-
let(:error_message) {
|
15
|
-
let(:object) { double(
|
16
|
-
it
|
17
|
-
expect(
|
12
|
+
context 'when the object has no content at specified location' do
|
13
|
+
let(:error_message) { 'object has no content at my_location from which to generate a thumbnail' }
|
14
|
+
let(:object) { double('object', my_location: nil) }
|
15
|
+
it 'raises an error' do
|
16
|
+
expect(-> { described_class.call(object, content: :my_location) }).to raise_error(ArgumentError, error_message)
|
18
17
|
end
|
19
18
|
end
|
20
|
-
|
21
19
|
end
|
@@ -1,64 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::Works::UploadFileToGenericFile do
|
4
|
-
|
5
4
|
let(:generic_work) { Hydra::Works::GenericWork::Base.new }
|
6
5
|
let(:generic_file) { Hydra::Works::GenericFile::Base.new }
|
7
|
-
let(:file) { File.open(File.join(fixture_path,
|
8
|
-
let(:updated_file) { File.open(File.join(fixture_path,
|
9
|
-
let(:mime_type) {
|
10
|
-
let(:original_name) {
|
11
|
-
let(:updated_mime_type) {
|
12
|
-
let(:updated_name) {
|
6
|
+
let(:file) { File.open(File.join(fixture_path, 'sample-file.pdf')) }
|
7
|
+
let(:updated_file) { File.open(File.join(fixture_path, 'updated-file.txt')) }
|
8
|
+
let(:mime_type) { 'application/pdf' }
|
9
|
+
let(:original_name) { 'my_original.pdf' }
|
10
|
+
let(:updated_mime_type) { 'text/plain' }
|
11
|
+
let(:updated_name) { 'my_updated.txt' }
|
13
12
|
let(:additional_services) { [Hydra::Works::GenerateThumbnail] }
|
14
13
|
|
15
|
-
context
|
16
|
-
it
|
17
|
-
expect(Hydra::Works::AddFileToGenericFile).to receive(:call).with(generic_file, file, :original_file, update_existing: true, versioning: true
|
18
|
-
described_class.call(generic_file, file
|
14
|
+
context 'when you provide mime_type and original_name, etc' do
|
15
|
+
it 'uses the provided values' do
|
16
|
+
expect(Hydra::Works::AddFileToGenericFile).to receive(:call).with(generic_file, file, :original_file, update_existing: true, versioning: true)
|
17
|
+
described_class.call(generic_file, file)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
|
22
21
|
# Duplicate test from add_file_spec
|
23
|
-
context
|
24
|
-
let(:error_message) {
|
25
|
-
it
|
26
|
-
expect(
|
22
|
+
context 'without a proper generic file' do
|
23
|
+
let(:error_message) { 'supplied object must be a generic file' }
|
24
|
+
it 'raises an error' do
|
25
|
+
expect(-> { described_class.call(generic_work, file) }).to raise_error(ArgumentError, error_message)
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
29
|
# Duplicate test from add_file_spec
|
31
|
-
context
|
32
|
-
let(:error_message) {
|
33
|
-
it
|
34
|
-
expect(
|
30
|
+
context 'without file that responds to read.' do
|
31
|
+
let(:error_message) { 'supplied file must respond to read' }
|
32
|
+
it 'raises an error' do
|
33
|
+
expect(-> { described_class.call(generic_file, ['this does not respond to read.']) }).to raise_error(ArgumentError, error_message)
|
35
34
|
end
|
36
35
|
end
|
37
36
|
|
38
|
-
context
|
39
|
-
before do
|
40
|
-
allow(file).to
|
41
|
-
allow(file).to
|
42
|
-
described_class.call(generic_file, file, additional_services: additional_services)
|
37
|
+
context 'with an empty generic file' do
|
38
|
+
before do
|
39
|
+
allow(file).to receive(:mime_type).and_return(mime_type)
|
40
|
+
allow(file).to receive(:original_name).and_return(original_name)
|
41
|
+
described_class.call(generic_file, file, additional_services: additional_services)
|
43
42
|
end
|
44
43
|
|
45
|
-
describe
|
44
|
+
describe 'the uploaded file' do
|
46
45
|
subject { generic_file.original_file }
|
47
|
-
it
|
48
|
-
expect(subject.content).to start_with(
|
46
|
+
it 'has content' do
|
47
|
+
expect(subject.content).to start_with('%PDF-1.3')
|
49
48
|
end
|
50
|
-
it
|
49
|
+
it 'has a mime type' do
|
51
50
|
expect(subject.mime_type).to eql mime_type
|
52
51
|
end
|
53
|
-
it
|
52
|
+
it 'has a name' do
|
54
53
|
expect(subject.original_name).to eql original_name
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
57
|
describe "the generic file's generated files" do
|
59
58
|
subject { generic_file }
|
60
|
-
it
|
61
|
-
expect(subject.original_file.content).to start_with(
|
59
|
+
it 'has content and generated files' do
|
60
|
+
expect(subject.original_file.content).to start_with('%PDF-1.3')
|
62
61
|
expect(subject.original_file.mime_type).to eql mime_type
|
63
62
|
expect(subject.original_file.original_name).to eql original_name
|
64
63
|
expect(subject.thumbnail.content).not_to be_nil
|
@@ -66,34 +65,32 @@ describe Hydra::Works::UploadFileToGenericFile do
|
|
66
65
|
end
|
67
66
|
end
|
68
67
|
|
69
|
-
context
|
68
|
+
context 'when updating an existing file' do
|
70
69
|
let(:additional_services) { [] }
|
71
70
|
|
72
71
|
before do
|
73
|
-
allow(file).to
|
74
|
-
allow(file).to
|
75
|
-
allow(updated_file).to
|
76
|
-
allow(updated_file).to
|
72
|
+
allow(file).to receive(:mime_type).and_return(mime_type)
|
73
|
+
allow(file).to receive(:original_name).and_return(original_name)
|
74
|
+
allow(updated_file).to receive(:mime_type).and_return(updated_mime_type)
|
75
|
+
allow(updated_file).to receive(:original_name).and_return(updated_name)
|
77
76
|
|
78
77
|
described_class.call(generic_file, file, additional_services: additional_services)
|
79
78
|
described_class.call(generic_file, updated_file, additional_services: additional_services, update_existing: true)
|
80
79
|
end
|
81
80
|
|
82
|
-
describe
|
81
|
+
describe 'the new file' do
|
83
82
|
subject { generic_file.original_file }
|
84
|
-
it
|
83
|
+
it 'has updated content' do
|
85
84
|
updated_file.rewind
|
86
85
|
expect(subject.content).to eql updated_file.read
|
87
86
|
end
|
88
|
-
it
|
87
|
+
it 'has an updated name' do
|
89
88
|
expect(subject.original_name).to eql updated_name
|
90
89
|
end
|
91
|
-
it
|
90
|
+
it 'has a updated mime type' do
|
92
91
|
expect(subject.mime_type).to eql updated_mime_type
|
93
92
|
expect(subject.versions.all.count).to eql 2
|
94
93
|
end
|
95
94
|
end
|
96
95
|
end
|
97
|
-
|
98
96
|
end
|
99
|
-
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::Works::PersistDerivative do
|
4
|
-
|
5
4
|
describe 'thumbnail generation' do
|
6
5
|
before do
|
7
6
|
file = File.open(File.join(fixture_path, file_name), 'r')
|
@@ -37,7 +36,7 @@ describe Hydra::Works::PersistDerivative do
|
|
37
36
|
|
38
37
|
it 'uses PersistDerivative service to generate a thumbnail derivative' do
|
39
38
|
generic_file.create_derivatives
|
40
|
-
expect(Hydra::Derivatives.output_file_service).to eq(
|
39
|
+
expect(Hydra::Derivatives.output_file_service).to eq(described_class)
|
41
40
|
expect(generic_file.thumbnail).to have_content
|
42
41
|
expect(generic_file.thumbnail.mime_type).to eq('image/jpeg')
|
43
42
|
end
|
@@ -90,4 +89,4 @@ describe Hydra::Works::PersistDerivative do
|
|
90
89
|
end
|
91
90
|
end
|
92
91
|
end
|
93
|
-
end
|
92
|
+
end
|
data/spec/hydra/works_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Hydra::Works do
|
4
|
-
|
5
4
|
let(:works_coll) { Hydra::Works::Collection.new }
|
6
5
|
let(:works_gwork) { Hydra::Works::GenericWork::Base.new }
|
7
6
|
let(:works_gfile) { Hydra::Works::GenericFile::Base.new }
|
@@ -11,139 +10,136 @@ describe Hydra::Works do
|
|
11
10
|
let(:pcdm_file) { Hydra::PCDM::File.new }
|
12
11
|
|
13
12
|
describe 'Validations' do
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
expect( works_coll.works_collection? ).to be true
|
13
|
+
describe '#works_collection?' do
|
14
|
+
it 'returns true for a works collection' do
|
15
|
+
expect(works_coll.works_collection?).to be true
|
18
16
|
end
|
19
17
|
|
20
|
-
it
|
21
|
-
expect(
|
18
|
+
it 'returns false for a works generic work' do
|
19
|
+
expect(works_gwork.works_collection?).to be false
|
22
20
|
end
|
23
21
|
|
24
|
-
it
|
25
|
-
expect(
|
22
|
+
it 'returns false for a works generic file' do
|
23
|
+
expect(works_gfile.works_collection?).to be false
|
26
24
|
end
|
27
25
|
|
28
|
-
it
|
26
|
+
it 'returns that method is not available for pcdm a collection' do
|
29
27
|
expect(pcdm_coll).not_to respond_to(:works_collection?)
|
30
28
|
end
|
31
29
|
|
32
|
-
it
|
30
|
+
it 'returns that method is not available for a pcdm object' do
|
33
31
|
expect(pcdm_obj).not_to respond_to(:works_collection?)
|
34
32
|
end
|
35
33
|
|
36
|
-
it
|
34
|
+
it 'returns that method is not available for a pcdm file' do
|
37
35
|
expect(pcdm_file).not_to respond_to(:works_collection?)
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
41
|
-
describe
|
42
|
-
it
|
43
|
-
expect(
|
39
|
+
describe '#works_generic_work?' do
|
40
|
+
it 'returns false for a works collection' do
|
41
|
+
expect(works_coll.works_generic_work?).to be false
|
44
42
|
end
|
45
43
|
|
46
|
-
it
|
47
|
-
expect(
|
44
|
+
it 'returns true for a works generic work' do
|
45
|
+
expect(works_gwork.works_generic_work?).to be true
|
48
46
|
end
|
49
47
|
|
50
|
-
it
|
51
|
-
expect(
|
48
|
+
it 'returns false for a works generic file' do
|
49
|
+
expect(works_gfile.works_generic_work?).to be false
|
52
50
|
end
|
53
51
|
|
54
|
-
it
|
52
|
+
it 'returns that method is not available for a pcdm collection' do
|
55
53
|
expect(pcdm_coll).not_to respond_to(:works_generic_work?)
|
56
54
|
end
|
57
55
|
|
58
|
-
it
|
56
|
+
it 'returns that method is not available for a pcdm object' do
|
59
57
|
expect(pcdm_obj).not_to respond_to(:works_generic_work?)
|
60
58
|
end
|
61
59
|
|
62
|
-
it
|
60
|
+
it 'returns that method is not available for a pcdm file' do
|
63
61
|
expect(pcdm_file).not_to respond_to(:works_generic_work?)
|
64
62
|
end
|
65
63
|
end
|
66
64
|
|
67
|
-
describe
|
68
|
-
it
|
69
|
-
expect(
|
65
|
+
describe '#works_generic_file?' do
|
66
|
+
it 'returns false for a works collection' do
|
67
|
+
expect(works_coll.works_generic_file?).to be false
|
70
68
|
end
|
71
69
|
|
72
|
-
it
|
73
|
-
expect(
|
70
|
+
it 'returns false for a works generic work' do
|
71
|
+
expect(works_gwork.works_generic_file?).to be false
|
74
72
|
end
|
75
73
|
|
76
|
-
it
|
77
|
-
expect(
|
74
|
+
it 'returns true for a works generic file' do
|
75
|
+
expect(works_gfile.works_generic_file?).to be true
|
78
76
|
end
|
79
77
|
|
80
|
-
it
|
78
|
+
it 'returns that method is not available for a pcdm collection' do
|
81
79
|
expect(pcdm_coll).not_to respond_to(:works_generic_file?)
|
82
80
|
end
|
83
81
|
|
84
|
-
it
|
82
|
+
it 'returns that method is not available for a pcdm object' do
|
85
83
|
expect(pcdm_obj).not_to respond_to(:works_generic_file?)
|
86
84
|
end
|
87
85
|
|
88
|
-
it
|
86
|
+
it 'returns that method is not available for a pcdm file' do
|
89
87
|
expect(pcdm_file).not_to respond_to(:works_generic_file?)
|
90
88
|
end
|
91
89
|
end
|
92
90
|
end
|
93
91
|
|
94
|
-
describe
|
95
|
-
describe
|
96
|
-
it
|
97
|
-
expect(
|
92
|
+
describe 'Hydra::PCDM' do
|
93
|
+
describe '#collection?' do
|
94
|
+
it 'returns true for a works collection' do
|
95
|
+
expect(Hydra::PCDM.collection? works_coll).to be true
|
98
96
|
end
|
99
97
|
|
100
|
-
it
|
101
|
-
expect(
|
98
|
+
it 'returns false for a works generic work' do
|
99
|
+
expect(Hydra::PCDM.collection? works_gwork).to be false
|
102
100
|
end
|
103
101
|
|
104
|
-
it
|
105
|
-
expect(
|
102
|
+
it 'returns false for a works generic file' do
|
103
|
+
expect(Hydra::PCDM.collection? works_gfile).to be false
|
106
104
|
end
|
107
105
|
|
108
|
-
it
|
109
|
-
expect(
|
106
|
+
it 'returns true for a pcdm collection' do
|
107
|
+
expect(Hydra::PCDM.collection? pcdm_coll).to be true
|
110
108
|
end
|
111
109
|
|
112
|
-
it
|
113
|
-
expect(
|
110
|
+
it 'returns false for a pcdm object' do
|
111
|
+
expect(Hydra::PCDM.collection? pcdm_obj).to be false
|
114
112
|
end
|
115
113
|
|
116
|
-
it
|
117
|
-
expect(
|
114
|
+
it 'returns false for a pcdm file' do
|
115
|
+
expect(Hydra::PCDM.collection? pcdm_file).to be false
|
118
116
|
end
|
119
117
|
end
|
120
118
|
|
121
|
-
describe
|
122
|
-
it
|
123
|
-
expect(
|
119
|
+
describe '#object?' do
|
120
|
+
it 'returns false for a works collection' do
|
121
|
+
expect(Hydra::PCDM.object? works_coll).to be false
|
124
122
|
end
|
125
123
|
|
126
|
-
it
|
127
|
-
expect(
|
124
|
+
it 'returns true for a works generic work' do
|
125
|
+
expect(Hydra::PCDM.object? works_gwork).to be true
|
128
126
|
end
|
129
127
|
|
130
|
-
it
|
131
|
-
expect(
|
128
|
+
it 'returns true for a works generic file' do
|
129
|
+
expect(Hydra::PCDM.object? works_gfile).to be true
|
132
130
|
end
|
133
131
|
|
134
|
-
it
|
135
|
-
expect(
|
132
|
+
it 'returns false for a pcdm collection' do
|
133
|
+
expect(Hydra::PCDM.object? pcdm_coll).to be false
|
136
134
|
end
|
137
135
|
|
138
|
-
it
|
139
|
-
expect(
|
136
|
+
it 'returns true for a pcdm object' do
|
137
|
+
expect(Hydra::PCDM.object? pcdm_obj).to be true
|
140
138
|
end
|
141
139
|
|
142
|
-
it
|
143
|
-
expect(
|
140
|
+
it 'returns false for a pcdm file' do
|
141
|
+
expect(Hydra::PCDM.object? pcdm_file).to be false
|
144
142
|
end
|
145
143
|
end
|
146
|
-
|
147
144
|
end
|
148
|
-
|
149
145
|
end
|