-
Notifications
You must be signed in to change notification settings - Fork 2
/
import_record_spec.rb
241 lines (188 loc) · 5.75 KB
/
import_record_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
require 'rails_helper'
RSpec.describe Tufts::ImportRecord do
subject(:record) { described_class.new }
let(:id) { 'IMPORT_RECORD_FAKE_ID' }
let(:title) { "President Jean Mayer speaking\n at commencement, 1987" }
shared_context 'with metadata' do
subject(:record) { described_class.new(metadata: node) }
let(:doc) { Nokogiri::XML(File.open(file_fixture('mira_xml.xml')).read) }
let(:node) do
doc.root.xpath('//xmlns:record/xmlns:metadata/xmlns:mira_import',
doc.root.namespaces).first
end
end
shared_context 'with file types' do
include_context 'with metadata'
let(:doc) { Nokogiri::XML(File.open(file_fixture('mira_xml_file_types.xml')).read) }
let(:thumbnail_record) { described_class.new(metadata: thumbnail_node) }
let(:thumbnail_node) do
doc.root.xpath('//xmlns:record/xmlns:metadata/xmlns:mira_import', doc.root.namespaces)[1]
end
end
describe '#build_object' do
it 'builds a GenericObject by default' do
expect(record.build_object).to be_a GenericObject
end
it 'can accept an id' do
expect(record.build_object(id: id)).to have_attributes(id: id)
end
it 'can defer on id' do
object = record.build_object
object.title = [title] # make object valid
expect { object.save }
.to change { object.id }
.from(nil).to(an_instance_of(String))
end
context 'with metadata' do
include_context 'with metadata'
it 'assigns metadata' do
expect(record.build_object)
.to have_attributes(title: [title],
creator: ['Unknown'],
personal_name: ['Mayer, Jean'],
corporate_name: ['Office of the President'])
end
end
end
describe '#id' do
it 'is nil by default' do
expect(record.id).to be_nil
end
context 'with metadata' do
include_context 'with metadata'
let(:doc) do
Nokogiri::XML(File.open(file_fixture('mira_export.xml')).read)
end
it 'has an id' do
expect(record.id).to eq '7s75dc36z'
end
end
end
describe '#collections' do
it 'is empty by default' do
expect(record.collections).to be_empty
end
context 'with metadata' do
include_context 'with metadata'
it 'has a collection' do
expect(record.collections).to contain_exactly(an_instance_of(String),
an_instance_of(String))
end
end
end
describe '#metadata' do
it 'is nil by default' do
expect(record.metadata).to be_nil
end
context 'with metadata' do
include_context 'with metadata'
it 'has a title' do
expect(record.title).to eq title
end
end
end
describe '#fields' do
it 'is empty' do
expect(record.fields.to_a).to be_empty
end
context 'with metadata' do
include_context 'with metadata'
it 'has metadata' do
expect(record.fields.to_a).not_to be_empty
end
it 'normalized metadata fields' do
expect(record.fields.to_a[1]).to eq([:abstract, ["Another long description with \n plenty\n of whitespace"]])
end
end
end
describe '#file' do
it 'is an empty string by default' do
expect(record.file).to eq ''
end
context 'with metadata' do
include_context 'with metadata'
it 'has a filename' do
expect(record.file).to eq 'pdf-sample.pdf'
end
end
end
describe '#visibility' do
it 'default visibility is private' do
expect(record.visibility)
.to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
end
context 'with metadata' do
include_context 'with metadata'
it 'uses specified visibility' do
expect(record.visibility)
.to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
end
end
end
describe '#transcript' do
it 'is empty by default' do
expect(record.transcript).to eq ''
end
context 'with no types' do
include_context 'with metadata'
it 'is empty' do
expect(record.transcript).to eq ''
end
end
context 'with file types' do
include_context 'with file types'
it 'has a transcript' do
expect(record.transcript).to eq '2.pdf'
end
end
end
describe '#thumbnail' do
it 'is empty by default' do
expect(record.thumbnail).to eq ''
end
context 'with no types' do
include_context 'with metadata'
it 'is empty' do
expect(record.thumbnail).to eq ''
end
end
context 'with file types' do
include_context 'with file types'
it 'has a thumbnail' do
expect(thumbnail_record.thumbnail).to eq 'fake.png'
end
end
end
describe '#representative' do
it 'is empty by default' do
expect(record.representative).to eq ''
end
context 'with no types' do
include_context 'with metadata'
it 'is empty' do
expect(record.representative).to eq ''
end
end
context 'with file types' do
include_context 'with file types'
it 'has a thumbnail' do
expect(record.representative).to eq 'pdf-sample.pdf'
end
end
end
describe '#files' do
it 'is an empty collection by default' do
expect(record.files).to be_empty
end
context 'with metadata' do
include_context 'with metadata'
it 'uses specified visibility' do
expect(record.visibility)
.to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
end
it 'has the filenames in order' do
expect(record.files).to eq ['pdf-sample.pdf', '3.pdf']
end
end
end
end