active-fedora 13.1.2 → 13.1.3
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/.github_changelog_generator +2 -0
- data/CHANGELOG.md +3362 -0
- data/CONTRIBUTING.md +23 -1
- data/README.md +4 -0
- data/active-fedora.gemspec +14 -13
- data/lib/active_fedora/version.rb +1 -1
- metadata +104 -206
- data/spec/config_helper.rb +0 -17
- data/spec/fixtures/dino.jpg +0 -0
- data/spec/fixtures/dino_jpg_no_file_ext +0 -0
- data/spec/fixtures/minivan.jpg +0 -0
- data/spec/fixtures/rails_root/config/fake_fedora.yml +0 -7
- data/spec/fixtures/rails_root/config/fedora.yml +0 -12
- data/spec/fixtures/rails_root/config/solr.yml +0 -15
- data/spec/fixtures/rails_root/config/solr_mappings.yml +0 -16
- data/spec/fixtures/rails_root/config/solr_mappings_af_0.1.yml +0 -9
- data/spec/fixtures/rails_root/config/solr_mappings_bl_2.4.yml +0 -17
- data/spec/integration/associations/rdf_spec.rb +0 -61
- data/spec/integration/associations_spec.rb +0 -680
- data/spec/integration/attached_files_spec.rb +0 -146
- data/spec/integration/attributes_spec.rb +0 -73
- data/spec/integration/autosave_association_spec.rb +0 -24
- data/spec/integration/base_spec.rb +0 -184
- data/spec/integration/basic_contains_association_spec.rb +0 -121
- data/spec/integration/belongs_to_association_spec.rb +0 -260
- data/spec/integration/caching_spec.rb +0 -59
- data/spec/integration/clean_connection_spec.rb +0 -21
- data/spec/integration/collection_association_spec.rb +0 -166
- data/spec/integration/date_time_properties_spec.rb +0 -41
- data/spec/integration/delete_all_spec.rb +0 -64
- data/spec/integration/direct_container_spec.rb +0 -250
- data/spec/integration/directly_contains_one_association_spec.rb +0 -96
- data/spec/integration/eradicate_spec.rb +0 -52
- data/spec/integration/fedora_solr_sync_spec.rb +0 -30
- data/spec/integration/file_fixity_spec.rb +0 -36
- data/spec/integration/file_spec.rb +0 -221
- data/spec/integration/generators/fedora_generator_spec.rb +0 -26
- data/spec/integration/generators/solr_generator_spec.rb +0 -23
- data/spec/integration/gone_spec.rb +0 -41
- data/spec/integration/has_and_belongs_to_many_associations_spec.rb +0 -414
- data/spec/integration/has_many_associations_spec.rb +0 -436
- data/spec/integration/has_subresource_spec.rb +0 -34
- data/spec/integration/indexing/descendant_fetcher_spec.rb +0 -64
- data/spec/integration/indexing_spec.rb +0 -110
- data/spec/integration/indirect_container_spec.rb +0 -290
- data/spec/integration/json_serialization_spec.rb +0 -32
- data/spec/integration/marshal_spec.rb +0 -39
- data/spec/integration/nested_attribute_spec.rb +0 -177
- data/spec/integration/nested_hash_resources_spec.rb +0 -43
- data/spec/integration/persistence_spec.rb +0 -37
- data/spec/integration/query_result_builder_spec.rb +0 -37
- data/spec/integration/rdf_nested_attributes_spec.rb +0 -85
- data/spec/integration/relation_delegation_spec.rb +0 -52
- data/spec/integration/relation_spec.rb +0 -117
- data/spec/integration/scoped_query_spec.rb +0 -134
- data/spec/integration/scoping_spec.rb +0 -48
- data/spec/integration/solr_hit_spec.rb +0 -32
- data/spec/integration/versionable_spec.rb +0 -256
- data/spec/integration/with_metadata_spec.rb +0 -111
- data/spec/lib/active_fedora/null_logger_spec.rb +0 -10
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -5
- data/spec/spec_helper.rb +0 -106
- data/spec/support/an_active_model.rb +0 -29
- data/spec/unit/active_fedora/indexing/inserter_spec.rb +0 -35
- data/spec/unit/active_fedora_spec.rb +0 -118
- data/spec/unit/aggregation/list_source_spec.rb +0 -134
- data/spec/unit/aggregation/ordered_reader_spec.rb +0 -43
- data/spec/unit/association_hash_spec.rb +0 -64
- data/spec/unit/attached_files_spec.rb +0 -218
- data/spec/unit/attributes_spec.rb +0 -146
- data/spec/unit/base_active_model_spec.rb +0 -28
- data/spec/unit/base_cma_spec.rb +0 -15
- data/spec/unit/base_extra_spec.rb +0 -33
- data/spec/unit/base_spec.rb +0 -328
- data/spec/unit/builder/has_and_belongs_to_many_spec.rb +0 -8
- data/spec/unit/callback_spec.rb +0 -65
- data/spec/unit/change_set_spec.rb +0 -60
- data/spec/unit/checksum_spec.rb +0 -25
- data/spec/unit/code_configurator_spec.rb +0 -41
- data/spec/unit/collection_proxy_spec.rb +0 -25
- data/spec/unit/config_spec.rb +0 -18
- data/spec/unit/core/fedora_id_translator_spec.rb +0 -29
- data/spec/unit/core/fedora_uri_translator_spec.rb +0 -19
- data/spec/unit/core/logger_spec.rb +0 -18
- data/spec/unit/core_spec.rb +0 -242
- data/spec/unit/default_model_mapper_spec.rb +0 -39
- data/spec/unit/fedora_spec.rb +0 -31
- data/spec/unit/file/streaming_spec.rb +0 -33
- data/spec/unit/file_configurator_spec.rb +0 -295
- data/spec/unit/file_io_spec.rb +0 -137
- data/spec/unit/file_path_builder_spec.rb +0 -18
- data/spec/unit/file_spec.rb +0 -489
- data/spec/unit/files_hash_spec.rb +0 -52
- data/spec/unit/filter_spec.rb +0 -133
- data/spec/unit/finder_methods_spec.rb +0 -154
- data/spec/unit/fixity_service_spec.rb +0 -128
- data/spec/unit/forbidden_attributes_protection_spec.rb +0 -50
- data/spec/unit/has_and_belongs_to_many_association_spec.rb +0 -125
- data/spec/unit/has_many_association_spec.rb +0 -131
- data/spec/unit/indexers/global_indexer_spec.rb +0 -41
- data/spec/unit/indexing/map/index_object_spec.rb +0 -25
- data/spec/unit/indexing/map_spec.rb +0 -27
- data/spec/unit/indexing_service_spec.rb +0 -28
- data/spec/unit/indexing_spec.rb +0 -86
- data/spec/unit/inheritance_spec.rb +0 -60
- data/spec/unit/ldp_resource_spec.rb +0 -15
- data/spec/unit/loadable_from_json_spec.rb +0 -40
- data/spec/unit/logger_spec.rb +0 -19
- data/spec/unit/model_classifier_spec.rb +0 -49
- data/spec/unit/ordered_spec.rb +0 -367
- data/spec/unit/orders/list_node_spec.rb +0 -151
- data/spec/unit/orders/ordered_list_spec.rb +0 -335
- data/spec/unit/orders/reflection_spec.rb +0 -22
- data/spec/unit/pathing_spec.rb +0 -35
- data/spec/unit/persistence_spec.rb +0 -115
- data/spec/unit/property_predicate_spec.rb +0 -35
- data/spec/unit/property_spec.rb +0 -25
- data/spec/unit/query_result_builder_spec.rb +0 -31
- data/spec/unit/query_spec.rb +0 -307
- data/spec/unit/querying_spec.rb +0 -24
- data/spec/unit/rdf/indexing_service_spec.rb +0 -114
- data/spec/unit/rdf_vocab_spec.rb +0 -30
- data/spec/unit/readonly_spec.rb +0 -24
- data/spec/unit/reflection_spec.rb +0 -42
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +0 -37
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +0 -38
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +0 -38
- data/spec/unit/schema_indexing_strategy_spec.rb +0 -68
- data/spec/unit/scoping_spec.rb +0 -67
- data/spec/unit/serializers_spec.rb +0 -19
- data/spec/unit/solr_config_options_spec.rb +0 -57
- data/spec/unit/solr_hit_spec.rb +0 -57
- data/spec/unit/solr_query_builder_spec.rb +0 -18
- data/spec/unit/solr_service_spec.rb +0 -165
- data/spec/unit/sparql_insert_spec.rb +0 -31
- data/spec/unit/validations_spec.rb +0 -92
- data/spec/unit/with_metadata/default_metadata_class_factory_spec.rb +0 -29
- data/spec/unit/with_metadata/metadata_node_spec.rb +0 -69
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::FilePathBuilder do
|
|
4
|
-
describe ".build" do
|
|
5
|
-
subject { described_class.build(parent, nil, 'FOO') }
|
|
6
|
-
let(:parent) { ActiveFedora::Base.new(id: '1234') }
|
|
7
|
-
|
|
8
|
-
it { is_expected.to eq 'FOO1' }
|
|
9
|
-
|
|
10
|
-
context "when some datastreams exist" do
|
|
11
|
-
before do
|
|
12
|
-
allow(parent).to receive(:attached_files).and_return('FOO56' => instance_double(ActiveFedora::File))
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it { is_expected.to eq 'FOO57' }
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
data/spec/unit/file_spec.rb
DELETED
|
@@ -1,489 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe ActiveFedora::File do
|
|
4
|
-
subject(:af_file) { described_class.new }
|
|
5
|
-
|
|
6
|
-
it { is_expected.not_to be_metadata }
|
|
7
|
-
|
|
8
|
-
describe "#save!" do
|
|
9
|
-
context "when updating metadata" do
|
|
10
|
-
before do
|
|
11
|
-
af_file.content = 'foo'
|
|
12
|
-
af_file.save!
|
|
13
|
-
af_file.mime_type = 'application/pdf'
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "Updates metadata" do
|
|
17
|
-
expect(af_file.metadata).to receive(:save)
|
|
18
|
-
af_file.save!
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
describe "#behaves_like_io?" do
|
|
24
|
-
subject { af_file.send(:behaves_like_io?, object) }
|
|
25
|
-
|
|
26
|
-
context "with a File" do
|
|
27
|
-
let(:object) { File.new __FILE__ }
|
|
28
|
-
it { is_expected.to be true }
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
context "with a Tempfile" do
|
|
32
|
-
after { object.close; object.unlink }
|
|
33
|
-
let(:object) { Tempfile.new('foo') }
|
|
34
|
-
it { is_expected.to be true }
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context "with a StringIO" do
|
|
38
|
-
let(:object) { StringIO.new('foo') }
|
|
39
|
-
it { is_expected.to be true }
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
describe "#uri" do
|
|
44
|
-
subject(:uri) { af_file.uri }
|
|
45
|
-
|
|
46
|
-
context "when the file is in an ldp:BasicContainer" do
|
|
47
|
-
let(:parent) { ActiveFedora::Base.new(id: '1234') }
|
|
48
|
-
|
|
49
|
-
context "and it's initialized with the URI" do
|
|
50
|
-
let(:af_file) { described_class.new(parent.uri + "/FOO1") }
|
|
51
|
-
it "works" do
|
|
52
|
-
expect(uri.to_s).to eq "#{ActiveFedora.fedora.base_uri}/1234/FOO1"
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
context "and it's initialized with an ID" do
|
|
57
|
-
let(:af_file) { described_class.new(parent.id + "/FOO1") }
|
|
58
|
-
it "works" do
|
|
59
|
-
expect(uri.to_s).to eq "#{ActiveFedora.fedora.base_uri}/1234/FOO1"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
context "when the file doesn't have a uri" do
|
|
65
|
-
it { is_expected.to eq ::RDF::URI(nil) }
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
context "content" do
|
|
70
|
-
let(:mock_conn) do
|
|
71
|
-
Faraday.new do |builder|
|
|
72
|
-
builder.adapter :test, conn_stubs do |_stub|
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
let(:mock_client) do
|
|
78
|
-
Ldp::Client.new mock_conn
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
let(:conn_stubs) do
|
|
82
|
-
Faraday::Adapter::Test::Stubs.new do |stub|
|
|
83
|
-
stub.head(path) { [200, { 'Content-Length' => '9999' }] }
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
let(:path) { '/fedora/rest/test/1234/abcd' }
|
|
88
|
-
|
|
89
|
-
let(:ldp_source) { Ldp::Resource.new(mock_client, path) }
|
|
90
|
-
|
|
91
|
-
before do
|
|
92
|
-
allow(af_file).to receive(:ldp_source).and_return(ldp_source)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
describe '#persisted_size' do
|
|
96
|
-
it 'loads the file size attribute from the fedora repository' do
|
|
97
|
-
expect(af_file.size).to eq 9999
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it 'returns nil without making a head request to Ldp::Resource::BinarySource if it is a new record' do
|
|
101
|
-
allow(af_file).to receive(:new_record?).and_return(true)
|
|
102
|
-
expect(af_file.ldp_source).not_to receive(:head)
|
|
103
|
-
expect(af_file.persisted_size).to eq nil
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
describe '#dirty_size' do
|
|
108
|
-
context 'when content has changed from what is currently persisted' do
|
|
109
|
-
context 'and has been set to something that has a #size method (i.e. string or File)' do
|
|
110
|
-
it 'returns the size of the dirty content' do
|
|
111
|
-
dirty_content = instance_double(::File)
|
|
112
|
-
allow(dirty_content).to receive(:size) { 8_675_309 }
|
|
113
|
-
af_file.content = dirty_content
|
|
114
|
-
expect(af_file.size).to eq dirty_content.size
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context 'when content has not changed from what is currently persisted' do
|
|
120
|
-
it 'returns nil, indicating that the content is not "dirty", but its not necessarily 0 either.' do
|
|
121
|
-
expect(af_file.dirty_size).to be_nil
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
describe '#size' do
|
|
127
|
-
context 'when content has not changed' do
|
|
128
|
-
it 'returns the value of .persisted_size' do
|
|
129
|
-
expect(af_file.size).to eq af_file.persisted_size
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
context 'when content has changed' do
|
|
134
|
-
it 'returns the value of .dirty_size' do
|
|
135
|
-
af_file.content = "i have changed!"
|
|
136
|
-
expect(af_file.size).to eq af_file.dirty_size
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it 'returns nil when #persisted_size and #dirty_size return nil' do
|
|
141
|
-
allow(af_file).to receive(:persisted_size) { nil }
|
|
142
|
-
allow(af_file).to receive(:dirty_size) { nil }
|
|
143
|
-
expect(af_file.size).to be_nil
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
describe ".empty?" do
|
|
148
|
-
it "does not be empty" do
|
|
149
|
-
expect(af_file.empty?).to be false
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
describe ".has_content?" do
|
|
154
|
-
context "when there's content" do
|
|
155
|
-
before do
|
|
156
|
-
allow(af_file).to receive(:size).and_return(10)
|
|
157
|
-
end
|
|
158
|
-
it "returns true" do
|
|
159
|
-
expect(af_file.has_content?).to be true
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
|
|
163
|
-
context "when size is nil" do
|
|
164
|
-
before do
|
|
165
|
-
allow(af_file).to receive(:size).and_return(nil)
|
|
166
|
-
end
|
|
167
|
-
it "does not have content" do
|
|
168
|
-
expect(af_file).to_not have_content
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
context "when content is zero" do
|
|
173
|
-
before do
|
|
174
|
-
allow(af_file).to receive(:size).and_return(0)
|
|
175
|
-
end
|
|
176
|
-
it "returns false" do
|
|
177
|
-
expect(af_file.has_content?).to be false
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
context "when the file has local content" do
|
|
184
|
-
before do
|
|
185
|
-
af_file.uri = "http://localhost:8983/fedora/rest/test/1234/abcd"
|
|
186
|
-
af_file.content = "hi there"
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
describe "#inspect" do
|
|
190
|
-
subject { af_file.inspect }
|
|
191
|
-
it { is_expected.to eq "#<ActiveFedora::File uri=\"http://localhost:8983/fedora/rest/test/1234/abcd\" >" }
|
|
192
|
-
end
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
context 'when file is new and content behaves like io' do
|
|
196
|
-
let(:file_content) { "hello world" }
|
|
197
|
-
|
|
198
|
-
before do
|
|
199
|
-
af_file.uri = "http://localhost:8983/fedora/rest/test/1234/abcd"
|
|
200
|
-
af_file.content = StringIO.new(file_content)
|
|
201
|
-
allow(af_file).to receive(:new_record?).and_return(true)
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
describe "#content" do
|
|
205
|
-
it 'can be re-read' do
|
|
206
|
-
expect(af_file.content.read).to eq file_content
|
|
207
|
-
expect(af_file.content.read).to eq file_content
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
describe "#mime_type" do
|
|
213
|
-
let(:parent) { ActiveFedora::Base.create }
|
|
214
|
-
before do
|
|
215
|
-
parent.add_file('banana', path: 'apple', mime_type: 'video/webm')
|
|
216
|
-
parent.save!
|
|
217
|
-
end
|
|
218
|
-
it "persists" do
|
|
219
|
-
expect(parent.reload.apple.mime_type).to eq "video/webm"
|
|
220
|
-
end
|
|
221
|
-
it "can be updated" do
|
|
222
|
-
parent.reload
|
|
223
|
-
parent.apple.mime_type = "text/awesome"
|
|
224
|
-
expect(parent.apple.mime_type).to eq "text/awesome"
|
|
225
|
-
parent.save
|
|
226
|
-
|
|
227
|
-
expect(parent.reload.apple.mime_type).to eq "text/awesome"
|
|
228
|
-
end
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
context "original_name" do
|
|
232
|
-
subject { af_file.original_name }
|
|
233
|
-
|
|
234
|
-
context "on a new file" do
|
|
235
|
-
context "that has a name set locally" do
|
|
236
|
-
before { af_file.original_name = "my_image.png" }
|
|
237
|
-
it { is_expected.to eq "my_image.png" }
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
context "that doesn't have a name set locally" do
|
|
241
|
-
it { is_expected.to be_nil }
|
|
242
|
-
end
|
|
243
|
-
end
|
|
244
|
-
|
|
245
|
-
context "when it's saved" do
|
|
246
|
-
let(:parent) { ActiveFedora::Base.create }
|
|
247
|
-
before do
|
|
248
|
-
parent.add_file('one1two2threfour', path: 'abcd', mime_type: 'video/webm', original_name: 'my image.png')
|
|
249
|
-
parent.save!
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
it "has original_name" do
|
|
253
|
-
expect(parent.reload.abcd.original_name).to eq 'my image.png'
|
|
254
|
-
end
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
context "with special characters" do
|
|
258
|
-
let(:parent) { ActiveFedora::Base.create }
|
|
259
|
-
before do
|
|
260
|
-
parent.add_file('one1two2threfour', path: 'abcd', mime_type: 'video/webm', original_name: 'my "image".png')
|
|
261
|
-
parent.save!
|
|
262
|
-
end
|
|
263
|
-
it "saves OK and preserve name" do
|
|
264
|
-
expect(parent.reload.abcd.original_name).to eq 'my "image".png'
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
context "digest" do
|
|
270
|
-
subject(:digest) { af_file.digest }
|
|
271
|
-
|
|
272
|
-
context "on a new file" do
|
|
273
|
-
it { is_expected.to be_empty }
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
context "when it's saved" do
|
|
277
|
-
let(:parent) { ActiveFedora::Base.create }
|
|
278
|
-
before do
|
|
279
|
-
parent.add_file('one1two2threfour', path: 'abcd', mime_type: 'video/webm')
|
|
280
|
-
parent.save!
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
it "has digest" do
|
|
284
|
-
expect(parent.reload.abcd.digest.first).to be_kind_of RDF::URI
|
|
285
|
-
end
|
|
286
|
-
end
|
|
287
|
-
context "with pre-4.3.0 predicate" do
|
|
288
|
-
before do
|
|
289
|
-
predicate = ::RDF::URI("http://fedora.info/definitions/v4/repository#digest")
|
|
290
|
-
object = RDF::URI.new("urn:sha1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15")
|
|
291
|
-
graph = ActiveTriples::Resource.new
|
|
292
|
-
graph << RDF::Statement.new(af_file.uri, predicate, object)
|
|
293
|
-
allow(af_file).to receive_message_chain(:metadata, :ldp_source, :graph).and_return(graph)
|
|
294
|
-
end
|
|
295
|
-
it "falls back on fedora:digest if premis:hasMessageDigest is not present" do
|
|
296
|
-
expect(digest.first).to be_kind_of RDF::URI
|
|
297
|
-
end
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
describe "#checksum" do
|
|
302
|
-
let(:digest) { RDF::URI.new("urn:sha1:f1d2d2f924e986ac86fdf7b36c94bcdf32beec15") }
|
|
303
|
-
before do
|
|
304
|
-
allow(af_file).to receive(:digest) { [digest] }
|
|
305
|
-
end
|
|
306
|
-
its(:checksum) { is_expected.to be_a(ActiveFedora::Checksum) }
|
|
307
|
-
it "has the right value" do
|
|
308
|
-
expect(af_file.checksum.value).to eq("f1d2d2f924e986ac86fdf7b36c94bcdf32beec15")
|
|
309
|
-
end
|
|
310
|
-
it "has the right algorithm" do
|
|
311
|
-
expect(af_file.checksum.algorithm).to eq("SHA1")
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
describe "#save" do
|
|
316
|
-
let(:file) { described_class.new }
|
|
317
|
-
context "when there is nothing to save" do
|
|
318
|
-
it "does not write" do
|
|
319
|
-
expect(file.ldp_source).not_to receive(:create)
|
|
320
|
-
expect(file.save).to be false
|
|
321
|
-
end
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
describe "#create_date" do
|
|
326
|
-
subject { af_file.create_date }
|
|
327
|
-
describe "when new record" do
|
|
328
|
-
it { is_expected.to be_nil }
|
|
329
|
-
end
|
|
330
|
-
describe "when persisted" do
|
|
331
|
-
before do
|
|
332
|
-
af_file.content = "foo"
|
|
333
|
-
af_file.save!
|
|
334
|
-
end
|
|
335
|
-
it { is_expected.to be_a(DateTime) }
|
|
336
|
-
end
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
describe "#modified_date" do
|
|
340
|
-
subject { af_file.modified_date }
|
|
341
|
-
describe "when new record" do
|
|
342
|
-
it { is_expected.to be_nil }
|
|
343
|
-
end
|
|
344
|
-
describe "when persisted" do
|
|
345
|
-
before do
|
|
346
|
-
af_file.content = "foo"
|
|
347
|
-
af_file.save!
|
|
348
|
-
end
|
|
349
|
-
it { is_expected.to be_a(DateTime) }
|
|
350
|
-
end
|
|
351
|
-
end
|
|
352
|
-
|
|
353
|
-
describe "callbacks" do
|
|
354
|
-
before do
|
|
355
|
-
class MyFile < ActiveFedora::File
|
|
356
|
-
after_initialize :a_init
|
|
357
|
-
before_create :b_create
|
|
358
|
-
after_create :a_create
|
|
359
|
-
before_update :b_update
|
|
360
|
-
after_update :a_update
|
|
361
|
-
before_save :b_save
|
|
362
|
-
after_save :a_save
|
|
363
|
-
before_destroy :b_destroy
|
|
364
|
-
after_destroy :a_destroy
|
|
365
|
-
|
|
366
|
-
def a_init; end
|
|
367
|
-
|
|
368
|
-
def b_create; end
|
|
369
|
-
|
|
370
|
-
def a_create; end
|
|
371
|
-
|
|
372
|
-
def b_save; end
|
|
373
|
-
|
|
374
|
-
def a_save; end
|
|
375
|
-
|
|
376
|
-
def b_destroy; end
|
|
377
|
-
|
|
378
|
-
def a_destroy; end
|
|
379
|
-
|
|
380
|
-
def b_update; end
|
|
381
|
-
|
|
382
|
-
def a_update; end
|
|
383
|
-
end
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
after do
|
|
387
|
-
Object.send(:remove_const, :MyFile)
|
|
388
|
-
end
|
|
389
|
-
|
|
390
|
-
subject(:my_file) { MyFile.new }
|
|
391
|
-
|
|
392
|
-
describe "initialize" do
|
|
393
|
-
specify {
|
|
394
|
-
expect_any_instance_of(MyFile).to receive(:a_init)
|
|
395
|
-
MyFile.new
|
|
396
|
-
}
|
|
397
|
-
end
|
|
398
|
-
|
|
399
|
-
describe "create" do
|
|
400
|
-
describe "when content is not nil" do
|
|
401
|
-
specify {
|
|
402
|
-
expect(my_file).to receive(:b_create).once
|
|
403
|
-
expect(my_file).to receive(:a_create).once
|
|
404
|
-
expect(my_file).to receive(:b_save).once
|
|
405
|
-
expect(my_file).to receive(:a_save).once
|
|
406
|
-
my_file.content = "foo"
|
|
407
|
-
my_file.save
|
|
408
|
-
}
|
|
409
|
-
end
|
|
410
|
-
describe "when content is nil" do
|
|
411
|
-
specify {
|
|
412
|
-
expect(my_file).to receive(:b_create).once
|
|
413
|
-
expect(my_file).not_to receive(:a_create)
|
|
414
|
-
expect(my_file).to receive(:b_save).once
|
|
415
|
-
expect(my_file).not_to receive(:a_save)
|
|
416
|
-
my_file.save
|
|
417
|
-
}
|
|
418
|
-
end
|
|
419
|
-
end
|
|
420
|
-
|
|
421
|
-
describe "update" do
|
|
422
|
-
describe "when content has changed" do
|
|
423
|
-
specify {
|
|
424
|
-
my_file.content = "foo"
|
|
425
|
-
my_file.save
|
|
426
|
-
expect(my_file).to receive(:b_save).once
|
|
427
|
-
expect(my_file).to receive(:a_save).once
|
|
428
|
-
expect(my_file).to receive(:b_update).once
|
|
429
|
-
expect(my_file).to receive(:a_update).once
|
|
430
|
-
my_file.content = "bar"
|
|
431
|
-
my_file.save
|
|
432
|
-
}
|
|
433
|
-
end
|
|
434
|
-
describe "when content has not changed" do
|
|
435
|
-
specify {
|
|
436
|
-
my_file.content = "foo"
|
|
437
|
-
my_file.save
|
|
438
|
-
expect(my_file).to receive(:b_save).once
|
|
439
|
-
expect(my_file).to receive(:a_save)
|
|
440
|
-
expect(my_file).to receive(:b_update).once
|
|
441
|
-
expect(my_file).to receive(:a_update)
|
|
442
|
-
my_file.save
|
|
443
|
-
}
|
|
444
|
-
end
|
|
445
|
-
end
|
|
446
|
-
|
|
447
|
-
describe "destroy" do
|
|
448
|
-
specify {
|
|
449
|
-
my_file.content = "foo"
|
|
450
|
-
my_file.save
|
|
451
|
-
expect(my_file).to receive(:b_destroy).once
|
|
452
|
-
expect(my_file).to receive(:a_destroy).once
|
|
453
|
-
my_file.destroy
|
|
454
|
-
}
|
|
455
|
-
end
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
describe "#new" do
|
|
459
|
-
let(:file2) do
|
|
460
|
-
described_class.new do |file|
|
|
461
|
-
file.content = "My Content"
|
|
462
|
-
file.save!
|
|
463
|
-
end
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
context "when uri is passed to new" do
|
|
467
|
-
subject { described_class.new(file2.uri).content }
|
|
468
|
-
|
|
469
|
-
it { is_expected.to eq "My Content" }
|
|
470
|
-
end
|
|
471
|
-
|
|
472
|
-
context "when id is passed to new" do
|
|
473
|
-
subject { described_class.new(file2.id).content }
|
|
474
|
-
|
|
475
|
-
it { is_expected.to eq "My Content" }
|
|
476
|
-
end
|
|
477
|
-
|
|
478
|
-
context "when object responding to .uri is passed to new" do
|
|
479
|
-
subject { described_class.new(file2).content }
|
|
480
|
-
it { is_expected.to eq "My Content" }
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
context "when Array passed to new" do
|
|
484
|
-
it "raises an expection" do
|
|
485
|
-
expect { described_class.new([]) }.to raise_error(RuntimeError)
|
|
486
|
-
end
|
|
487
|
-
end
|
|
488
|
-
end
|
|
489
|
-
end
|