active-fedora 6.7.8 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +938 -0
- data/.travis.yml +5 -6
- data/Gemfile +3 -1
- data/Rakefile +7 -5
- data/active-fedora.gemspec +7 -8
- data/lib/active_fedora/om_datastream.rb +1 -0
- data/lib/active_fedora/rdf_xml_writer.rb +31 -62
- data/lib/active_fedora/version.rb +1 -1
- data/spec/config_helper.rb +14 -14
- data/spec/integration/associations_spec.rb +232 -232
- data/spec/integration/attributes_spec.rb +11 -12
- data/spec/integration/auditable_spec.rb +10 -10
- data/spec/integration/base_spec.rb +163 -163
- data/spec/integration/bug_spec.rb +7 -7
- data/spec/integration/complex_rdf_datastream_spec.rb +88 -88
- data/spec/integration/datastream_collections_spec.rb +69 -69
- data/spec/integration/datastream_spec.rb +43 -43
- data/spec/integration/datastreams_spec.rb +63 -63
- data/spec/integration/delegating_spec.rb +14 -14
- data/spec/integration/delete_all_spec.rb +38 -42
- data/spec/integration/fedora_solr_sync_spec.rb +5 -5
- data/spec/integration/full_featured_model_spec.rb +101 -101
- data/spec/integration/has_many_associations_spec.rb +24 -24
- data/spec/integration/model_spec.rb +30 -30
- data/spec/integration/nested_attribute_spec.rb +41 -41
- data/spec/integration/ntriples_datastream_spec.rb +107 -107
- data/spec/integration/om_datastream_spec.rb +67 -67
- data/spec/integration/persistence_spec.rb +6 -6
- data/spec/integration/rdf_nested_attributes_spec.rb +56 -56
- data/spec/integration/relation_delegation_spec.rb +24 -26
- data/spec/integration/rels_ext_datastream_spec.rb +20 -20
- data/spec/integration/scoped_query_spec.rb +40 -41
- data/spec/integration/solr_instance_loader_spec.rb +4 -4
- data/spec/integration/solr_service_spec.rb +46 -46
- data/spec/rails3_test_app/config/application.rb +1 -1
- data/spec/rails3_test_app/config/environments/development.rb +0 -1
- data/spec/rails3_test_app/config/environments/production.rb +1 -1
- data/spec/rails3_test_app/spec/spec_helper.rb +3 -3
- data/spec/rails3_test_app/spec/unit/rails_3_init.rb +4 -4
- data/spec/samples/hydra-mods_article_datastream.rb +334 -334
- data/spec/samples/hydra-rights_metadata_datastream.rb +57 -57
- data/spec/samples/marpa-dc_datastream.rb +17 -17
- data/spec/samples/models/audio_record.rb +16 -16
- data/spec/samples/models/image.rb +2 -2
- data/spec/samples/models/mods_article.rb +5 -5
- data/spec/samples/models/oral_history.rb +18 -18
- data/spec/samples/models/seminar.rb +24 -24
- data/spec/samples/models/seminar_audio_file.rb +17 -17
- data/spec/samples/oral_history_sample_model.rb +21 -21
- data/spec/samples/special_thing.rb +14 -14
- data/spec/spec_helper.rb +7 -11
- data/spec/support/an_active_model.rb +2 -2
- data/spec/support/mock_fedora.rb +16 -17
- data/spec/unit/active_fedora_spec.rb +58 -58
- data/spec/unit/association_proxy_spec.rb +5 -7
- data/spec/unit/base_active_model_spec.rb +25 -26
- data/spec/unit/base_cma_spec.rb +5 -5
- data/spec/unit/base_datastream_management_spec.rb +27 -27
- data/spec/unit/base_delegate_spec.rb +80 -82
- data/spec/unit/base_delegate_to_spec.rb +37 -39
- data/spec/unit/base_extra_spec.rb +48 -48
- data/spec/unit/base_spec.rb +300 -300
- data/spec/unit/callback_spec.rb +19 -19
- data/spec/unit/code_configurator_spec.rb +17 -17
- data/spec/unit/config_spec.rb +16 -8
- data/spec/unit/content_model_spec.rb +60 -60
- data/spec/unit/datastream_collections_spec.rb +229 -229
- data/spec/unit/datastream_spec.rb +57 -54
- data/spec/unit/datastreams_spec.rb +77 -77
- data/spec/unit/file_configurator_spec.rb +217 -217
- data/spec/unit/has_and_belongs_to_many_collection_spec.rb +26 -26
- data/spec/unit/has_many_collection_spec.rb +9 -9
- data/spec/unit/inheritance_spec.rb +12 -13
- data/spec/unit/model_spec.rb +41 -51
- data/spec/unit/nom_datastream_spec.rb +15 -15
- data/spec/unit/ntriples_datastream_spec.rb +112 -112
- data/spec/unit/om_datastream_spec.rb +233 -227
- data/spec/unit/persistence_spec.rb +6 -6
- data/spec/unit/predicates_spec.rb +73 -73
- data/spec/unit/property_spec.rb +9 -17
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +33 -33
- data/spec/unit/query_spec.rb +188 -217
- data/spec/unit/rdf_datastream_spec.rb +28 -21
- data/spec/unit/rdf_list_nested_attributes_spec.rb +34 -34
- data/spec/unit/rdf_list_spec.rb +80 -104
- data/spec/unit/rdf_node_spec.rb +7 -7
- data/spec/unit/rdf_xml_writer_spec.rb +10 -10
- data/spec/unit/rdfxml_rdf_datastream_spec.rb +27 -27
- data/spec/unit/relationship_graph_spec.rb +51 -51
- data/spec/unit/rels_ext_datastream_spec.rb +75 -69
- data/spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/have_predicate_matcher_spec.rb +15 -15
- data/spec/unit/rspec_matchers/match_fedora_datastream_matcher_spec.rb +12 -12
- data/spec/unit/rubydora_connection_spec.rb +5 -5
- data/spec/unit/semantic_node_spec.rb +59 -59
- data/spec/unit/serializers_spec.rb +4 -4
- data/spec/unit/service_definitions_spec.rb +26 -26
- data/spec/unit/simple_datastream_spec.rb +17 -17
- data/spec/unit/solr_config_options_spec.rb +27 -28
- data/spec/unit/solr_digital_object_spec.rb +21 -21
- data/spec/unit/solr_service_spec.rb +81 -81
- data/spec/unit/unsaved_digital_object_spec.rb +20 -20
- data/spec/unit/validations_spec.rb +21 -21
- metadata +70 -58
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'delegating attributes' do
|
4
4
|
before :all do
|
5
5
|
class TitledObject < ActiveFedora::Base
|
6
6
|
has_metadata 'foo', type: ActiveFedora::SimpleDatastream do |m|
|
7
|
-
m.field
|
7
|
+
m.field 'title', :string
|
8
8
|
end
|
9
9
|
has_attributes :title, datastream: 'foo', multiple: false
|
10
10
|
end
|
@@ -13,21 +13,20 @@ describe "delegating attributes" do
|
|
13
13
|
Object.send(:remove_const, :TitledObject)
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe 'save' do
|
17
17
|
subject do
|
18
|
-
obj = TitledObject.create
|
19
|
-
obj.title =
|
18
|
+
obj = TitledObject.create
|
19
|
+
obj.title = 'Hydra for Dummies'
|
20
20
|
obj.save
|
21
21
|
obj
|
22
22
|
end
|
23
|
-
it
|
24
|
-
subject.previous_changes.
|
25
|
-
subject.previous_changes.keys.
|
23
|
+
it 'should keep a list of changes after a successful save' do
|
24
|
+
expect(subject.previous_changes).not_to be_empty
|
25
|
+
expect(subject.previous_changes.keys).to include('title')
|
26
26
|
end
|
27
|
-
it
|
28
|
-
subject.title_changed
|
29
|
-
subject.changes.
|
27
|
+
it 'should clean out changes' do
|
28
|
+
expect(subject.title_changed?).to be_falsey
|
29
|
+
expect(subject.changes).to be_empty
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
@@ -12,18 +12,18 @@ describe ActiveFedora::Auditable do
|
|
12
12
|
after(:all) do
|
13
13
|
@test_object.delete
|
14
14
|
end
|
15
|
-
it
|
16
|
-
@test_object.audit_trail.records.length.
|
15
|
+
it 'should have the correct number of audit records' do
|
16
|
+
expect(@test_object.audit_trail.records.length).to eq(1)
|
17
17
|
end
|
18
|
-
it
|
18
|
+
it 'should return all the data from each audit record' do
|
19
19
|
record = @test_object.audit_trail.records.last
|
20
|
-
record.id.
|
21
|
-
record.process_type.
|
22
|
-
record.action.
|
23
|
-
record.component_id.
|
24
|
-
record.responsibility.
|
20
|
+
expect(record.id).to eq('AUDREC1')
|
21
|
+
expect(record.process_type).to eq('Fedora API-M')
|
22
|
+
expect(record.action).to eq('addDatastream')
|
23
|
+
expect(record.component_id).to eq('RELS-EXT')
|
24
|
+
expect(record.responsibility).to eq('fedoraAdmin')
|
25
25
|
expect(DateTime.parse(record.date)).to eq DateTime.parse(@test_object.modified_date)
|
26
|
-
record.justification.
|
26
|
+
expect(record.justification).to eq('')
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
end
|
@@ -1,73 +1,73 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe 'A base object with metadata' do
|
4
4
|
before :all do
|
5
5
|
class MockAFBaseRelationship < ActiveFedora::Base
|
6
|
-
has_metadata :name=>'foo', :type=>Hydra::ModsArticleDatastream
|
6
|
+
has_metadata :name => 'foo', :type => Hydra::ModsArticleDatastream
|
7
7
|
end
|
8
8
|
end
|
9
9
|
after :all do
|
10
10
|
Object.send(:remove_const, :MockAFBaseRelationship)
|
11
11
|
end
|
12
|
-
describe
|
12
|
+
describe 'a new document' do
|
13
13
|
before do
|
14
14
|
@obj = MockAFBaseRelationship.new
|
15
15
|
|
16
|
-
@obj.foo.person =
|
16
|
+
@obj.foo.person = 'bob'
|
17
17
|
@obj.save
|
18
18
|
end
|
19
|
-
it
|
20
|
-
obj = ActiveFedora::Base.find(@obj.pid, :cast=>true)
|
21
|
-
obj.foo.
|
22
|
-
obj.foo.person.
|
19
|
+
it 'should save the datastream.' do
|
20
|
+
obj = ActiveFedora::Base.find(@obj.pid, :cast => true)
|
21
|
+
expect(obj.foo).not_to be_new
|
22
|
+
expect(obj.foo.person).to eq(['bob'])
|
23
23
|
person_field = ActiveFedora::SolrService.solr_name('person', type: :string)
|
24
|
-
ActiveFedora::SolrService.query("{!raw f=id}#{@obj.pid}", :fl=>"id #{person_field}").first.
|
24
|
+
expect(ActiveFedora::SolrService.query("{!raw f=id}#{@obj.pid}", :fl => "id #{person_field}").first).to eq({'id' => @obj.pid, person_field => ['bob']})
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
describe
|
29
|
-
it
|
28
|
+
describe 'setting object state' do
|
29
|
+
it 'should store it' do
|
30
30
|
obj = MockAFBaseRelationship.create
|
31
|
-
obj.state='D'
|
31
|
+
obj.state = 'D'
|
32
32
|
obj.save!
|
33
33
|
obj.reload
|
34
|
-
obj.state.
|
34
|
+
expect(obj.state).to eq('D')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
38
|
+
describe 'that already exists in the repo' do
|
39
39
|
before do
|
40
40
|
@release = MockAFBaseRelationship.create()
|
41
41
|
@release.add_relationship(:is_governed_by, 'info:fedora/test:catalog-fixture')
|
42
42
|
@release.add_relationship(:is_part_of, 'info:fedora/test:777')
|
43
|
-
@release.foo.person =
|
43
|
+
@release.foo.person = 'test foo content'
|
44
44
|
@release.save
|
45
45
|
end
|
46
|
-
describe
|
46
|
+
describe 'and has been changed' do
|
47
47
|
before do
|
48
48
|
@release.foo.person = 'frank'
|
49
49
|
@release.save!
|
50
50
|
end
|
51
|
-
it
|
52
|
-
MockAFBaseRelationship.find(@release.pid).foo.person.
|
51
|
+
it 'should save the datastream.' do
|
52
|
+
expect(MockAFBaseRelationship.find(@release.pid).foo.person).to eq(['frank'])
|
53
53
|
person_field = ActiveFedora::SolrService.solr_name('person', type: :string)
|
54
|
-
ActiveFedora::SolrService.query("id:#{@release.pid.gsub(":", "\\:")}", :fl=>"id #{person_field}").first.
|
54
|
+
expect(ActiveFedora::SolrService.query("id:#{@release.pid.gsub(":", "\\:")}", :fl => "id #{person_field}").first).to eq({'id' => @release.pid, person_field => ['frank']})
|
55
55
|
end
|
56
56
|
end
|
57
|
-
describe
|
57
|
+
describe 'clone_into a new object' do
|
58
58
|
before do
|
59
59
|
begin
|
60
60
|
new_object = MockAFBaseRelationship.find('test:999')
|
61
61
|
new_object.delete
|
62
62
|
rescue ActiveFedora::ObjectNotFoundError
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
new_object = MockAFBaseRelationship.create(:pid => 'test:999')
|
66
66
|
@release.clone_into(new_object)
|
67
67
|
@new_object = MockAFBaseRelationship.find('test:999')
|
68
68
|
end
|
69
|
-
it
|
70
|
-
@new_object.rels_ext.content.
|
69
|
+
it 'should have all the assertions' do
|
70
|
+
expect(@new_object.rels_ext.content).to be_equivalent_to '<rdf:RDF xmlns:ns1="info:fedora/fedora-system:def/model#" xmlns:ns2="info:fedora/fedora-system:def/relations-external#" xmlns:ns0="http://projecthydra.org/ns/relations#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
71
71
|
<rdf:Description rdf:about="info:fedora/test:999">
|
72
72
|
<ns0:isGovernedBy rdf:resource="info:fedora/test:catalog-fixture"/>
|
73
73
|
<ns1:hasModel rdf:resource="info:fedora/afmodel:MockAFBaseRelationship"/>
|
@@ -76,18 +76,18 @@ describe "A base object with metadata" do
|
|
76
76
|
</rdf:Description>
|
77
77
|
</rdf:RDF>'
|
78
78
|
end
|
79
|
-
it
|
80
|
-
@new_object.datastreams.keys.
|
81
|
-
@new_object.foo.content.
|
79
|
+
it 'should have the other datastreams too' do
|
80
|
+
expect(@new_object.datastreams.keys).to include 'foo'
|
81
|
+
expect(@new_object.foo.content).to be_equivalent_to @release.foo.content
|
82
82
|
end
|
83
83
|
end
|
84
|
-
describe
|
84
|
+
describe 'clone' do
|
85
85
|
before do
|
86
86
|
@new_object = @release.clone
|
87
87
|
end
|
88
|
-
it
|
89
|
-
@new_object.rels_ext.content.
|
90
|
-
<rdf:Description rdf:about="info:fedora/'+ @new_object.pid+'">
|
88
|
+
it 'should have all the assertions' do
|
89
|
+
expect(@new_object.rels_ext.content).to be_equivalent_to '<rdf:RDF xmlns:ns1="info:fedora/fedora-system:def/model#" xmlns:ns2="info:fedora/fedora-system:def/relations-external#" xmlns:ns0="http://projecthydra.org/ns/relations#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
90
|
+
<rdf:Description rdf:about="info:fedora/' + @new_object.pid + '">
|
91
91
|
<ns0:isGovernedBy rdf:resource="info:fedora/test:catalog-fixture"/>
|
92
92
|
<ns1:hasModel rdf:resource="info:fedora/afmodel:MockAFBaseRelationship"/>
|
93
93
|
<ns2:isPartOf rdf:resource="info:fedora/test:777"/>
|
@@ -95,9 +95,9 @@ describe "A base object with metadata" do
|
|
95
95
|
</rdf:Description>
|
96
96
|
</rdf:RDF>'
|
97
97
|
end
|
98
|
-
it
|
99
|
-
@new_object.datastreams.keys.
|
100
|
-
@new_object.foo.content.
|
98
|
+
it 'should have the other datastreams too' do
|
99
|
+
expect(@new_object.datastreams.keys).to include 'foo'
|
100
|
+
expect(@new_object.foo.content).to be_equivalent_to @release.foo.content
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
@@ -115,12 +115,12 @@ describe "A base object with metadata" do
|
|
115
115
|
end
|
116
116
|
it 'should requery Fedora' do
|
117
117
|
@object.reload
|
118
|
-
@object.foo.person.
|
118
|
+
expect(@object.foo.person).to eq(['dave'])
|
119
119
|
end
|
120
120
|
it 'should raise an error if not persisted' do
|
121
121
|
@object = MockAFBaseRelationship.new
|
122
122
|
# You will want this stub or else it will be really chatty in your STDERR
|
123
|
-
@object.inner_object.logger.
|
123
|
+
allow(@object.inner_object.logger).to receive(:error)
|
124
124
|
expect {
|
125
125
|
@object.reload
|
126
126
|
}.to raise_error(ActiveFedora::ObjectNotFoundError)
|
@@ -128,26 +128,26 @@ describe "A base object with metadata" do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
-
describe
|
131
|
+
describe 'Datastreams synched together' do
|
132
132
|
before do
|
133
133
|
class DSTest < ActiveFedora::Base
|
134
134
|
def load_datastreams
|
135
135
|
super
|
136
136
|
unless self.datastreams.keys.include? 'test_ds'
|
137
|
-
add_file_datastream(
|
137
|
+
add_file_datastream('XXX', :dsid => 'test_ds', :mimeType => 'text/html')
|
138
138
|
end
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
142
|
-
it
|
142
|
+
it 'Should update datastream' do
|
143
143
|
@nc = DSTest.new
|
144
144
|
@nc.save
|
145
|
-
@nc.test_ds.content.
|
145
|
+
expect(@nc.test_ds.content).to eq('XXX')
|
146
146
|
ds = @nc.datastreams['test_ds']
|
147
|
-
ds.content =
|
147
|
+
ds.content = 'Foobar'
|
148
148
|
@nc.save
|
149
|
-
DSTest.find(@nc.pid).datastreams['test_ds'].content.
|
150
|
-
DSTest.find(@nc.pid).test_ds.content.
|
149
|
+
expect(DSTest.find(@nc.pid).datastreams['test_ds'].content).to eq('Foobar')
|
150
|
+
expect(DSTest.find(@nc.pid).test_ds.content).to eq('Foobar')
|
151
151
|
end
|
152
152
|
|
153
153
|
end
|
@@ -161,21 +161,21 @@ describe ActiveFedora::Base do
|
|
161
161
|
end
|
162
162
|
|
163
163
|
class MockAFBaseFromSolr < ActiveFedora::Base
|
164
|
-
has_metadata :name =>
|
165
|
-
m.field
|
164
|
+
has_metadata :name => 'properties', :type => ActiveFedora::SimpleDatastream do |m|
|
165
|
+
m.field 'holding_id', :string
|
166
166
|
end
|
167
|
-
|
168
|
-
has_metadata :name =>
|
169
|
-
m.field
|
170
|
-
m.field
|
171
|
-
m.field
|
167
|
+
|
168
|
+
has_metadata :name => 'descMetadata', :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
|
169
|
+
m.field 'created', :date, :xml_node => 'created'
|
170
|
+
m.field 'language', :string, :xml_node => 'language'
|
171
|
+
m.field 'creator', :string, :xml_node => 'creator'
|
172
172
|
# Created remaining fields
|
173
|
-
m.field
|
174
|
-
m.field
|
173
|
+
m.field 'geography', :string, :xml_node => 'geography'
|
174
|
+
m.field 'title', :string, :xml_node => 'title'
|
175
175
|
end
|
176
176
|
end
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
before(:all) do
|
180
180
|
ActiveFedora::SolrService.register(ActiveFedora.solr_config[:url])
|
181
181
|
end
|
@@ -183,12 +183,12 @@ describe ActiveFedora::Base do
|
|
183
183
|
after :all do
|
184
184
|
Object.send(:remove_const, :MockAFBaseRelationship)
|
185
185
|
end
|
186
|
-
|
186
|
+
|
187
187
|
before(:each) do
|
188
188
|
@test_object = ActiveFedora::Base.new
|
189
189
|
@test_object.save
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
after(:each) do
|
193
193
|
begin
|
194
194
|
@test_object.delete
|
@@ -211,15 +211,15 @@ describe ActiveFedora::Base do
|
|
211
211
|
rescue
|
212
212
|
end
|
213
213
|
end
|
214
|
-
|
215
|
-
describe
|
216
|
-
it
|
217
|
-
@test_object.
|
218
|
-
@test_object.pid.
|
214
|
+
|
215
|
+
describe '.initialize' do
|
216
|
+
it 'calling constructor should create a new Fedora Object' do
|
217
|
+
expect(@test_object.errors.size).to eq(0)
|
218
|
+
expect(@test_object.pid).not_to be_nil
|
219
219
|
end
|
220
220
|
end
|
221
|
-
|
222
|
-
describe
|
221
|
+
|
222
|
+
describe '#save' do
|
223
223
|
before(:each) do
|
224
224
|
@test_object2 = ActiveFedora::Base.new
|
225
225
|
end
|
@@ -227,167 +227,167 @@ describe ActiveFedora::Base do
|
|
227
227
|
after(:each) do
|
228
228
|
@test_object2.delete
|
229
229
|
end
|
230
|
-
|
231
|
-
it
|
232
|
-
@test_object2 = ActiveFedora::Base.new({:namespace=>
|
230
|
+
|
231
|
+
it 'passing namespace to constructor with no pid should generate a pid with the supplied namespace' do
|
232
|
+
@test_object2 = ActiveFedora::Base.new({:namespace => 'randomNamespace'})
|
233
233
|
# will be nil if match failed, otherwise will equal pid
|
234
234
|
@test_object2.save
|
235
|
-
@test_object2.pid.match('randomNamespace:\d+').to_a.first.
|
235
|
+
expect(@test_object2.pid.match('randomNamespace:\d+').to_a.first).to eq(@test_object2.pid)
|
236
236
|
end
|
237
237
|
|
238
|
-
it
|
238
|
+
it 'should set the CMA hasModel relationship in the Rels-EXT' do
|
239
239
|
@test_object2.save
|
240
|
-
rexml = REXML::Document.new(@test_object2.datastreams[
|
240
|
+
rexml = REXML::Document.new(@test_object2.datastreams['RELS-EXT'].content)
|
241
241
|
# Purpose: confirm that the isMemberOf entries exist and have real RDF in them
|
242
|
-
rexml.root.elements[
|
242
|
+
expect(rexml.root.elements['rdf:Description/ns0:hasModel'].attributes['rdf:resource']).to eq('info:fedora/afmodel:ActiveFedora_Base')
|
243
243
|
end
|
244
|
-
it
|
244
|
+
it 'should merge attributes from fedora into attributes hash' do
|
245
245
|
@test_object2.save
|
246
246
|
inner_object = @test_object2.inner_object
|
247
|
-
inner_object.pid.
|
248
|
-
inner_object.
|
247
|
+
expect(inner_object.pid).to eq(@test_object2.pid)
|
248
|
+
expect(inner_object).to respond_to(:lastModifiedDate)
|
249
249
|
end
|
250
250
|
end
|
251
|
-
|
252
|
-
describe
|
253
|
-
it
|
251
|
+
|
252
|
+
describe '.datastreams' do
|
253
|
+
it 'should return a Hash of datastreams from fedora' do
|
254
254
|
datastreams = @test_object.datastreams
|
255
|
-
datastreams.
|
256
|
-
datastreams.each_value do |ds|
|
257
|
-
ds.
|
255
|
+
expect(datastreams).to be_a_kind_of(ActiveFedora::DatastreamHash)
|
256
|
+
datastreams.each_value do |ds|
|
257
|
+
expect(ds).to be_a_kind_of(ActiveFedora::Datastream)
|
258
258
|
end
|
259
|
-
@test_object.datastreams[
|
260
|
-
datastreams[
|
261
|
-
datastreams[
|
259
|
+
expect(@test_object.datastreams['DC']).to be_an_instance_of(ActiveFedora::Datastream)
|
260
|
+
expect(datastreams['DC']).not_to be_nil
|
261
|
+
expect(datastreams['DC']).to be_an_instance_of(ActiveFedora::Datastream)
|
262
262
|
end
|
263
|
-
it
|
263
|
+
it 'should initialize the datastream pointers with @new_object=false' do
|
264
264
|
datastreams = @test_object.datastreams
|
265
|
-
datastreams.each_value do |ds|
|
266
|
-
ds.
|
265
|
+
datastreams.each_value do |ds|
|
266
|
+
expect(ds).not_to be_new
|
267
267
|
end
|
268
268
|
end
|
269
269
|
end
|
270
|
-
|
271
|
-
describe
|
272
|
-
it
|
273
|
-
mds1 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object,
|
274
|
-
mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(@test_object.inner_object,
|
275
|
-
fds = ActiveFedora::Datastream.new(@test_object.inner_object,
|
270
|
+
|
271
|
+
describe '.metadata_streams' do
|
272
|
+
it 'should return all of the datastreams from the object that are kinds of OmDatastream ' do
|
273
|
+
mds1 = ActiveFedora::SimpleDatastream.new(@test_object.inner_object, 'md1')
|
274
|
+
mds2 = ActiveFedora::QualifiedDublinCoreDatastream.new(@test_object.inner_object, 'qdc')
|
275
|
+
fds = ActiveFedora::Datastream.new(@test_object.inner_object, 'fds')
|
276
276
|
@test_object.add_datastream(mds1)
|
277
277
|
@test_object.add_datastream(mds2)
|
278
|
-
@test_object.add_datastream(fds)
|
279
|
-
|
278
|
+
@test_object.add_datastream(fds)
|
279
|
+
|
280
280
|
result = @test_object.metadata_streams
|
281
|
-
result.length.
|
282
|
-
result.
|
283
|
-
result.
|
281
|
+
expect(result.length).to eq(2)
|
282
|
+
expect(result).to include(mds1)
|
283
|
+
expect(result).to include(mds2)
|
284
284
|
end
|
285
285
|
end
|
286
|
-
|
286
|
+
|
287
287
|
describe '.rels_ext' do
|
288
|
-
it
|
289
|
-
@test_object.rels_ext.
|
288
|
+
it 'should retrieve RelsExtDatastream object via rels_ext method' do
|
289
|
+
expect(@test_object.rels_ext).to be_instance_of(ActiveFedora::RelsExtDatastream)
|
290
290
|
end
|
291
|
-
|
291
|
+
|
292
292
|
it 'should create the RELS-EXT datastream if it doesnt exist' do
|
293
293
|
test_object = ActiveFedora::Base.new
|
294
|
-
#test_object.datastreams["RELS-EXT"].should == nil
|
294
|
+
# test_object.datastreams["RELS-EXT"].should == nil
|
295
295
|
test_object.rels_ext
|
296
|
-
test_object.datastreams[
|
297
|
-
test_object.datastreams[
|
296
|
+
expect(test_object.datastreams['RELS-EXT']).not_to be_nil
|
297
|
+
expect(test_object.datastreams['RELS-EXT'].class).to eq(ActiveFedora::RelsExtDatastream)
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
301
301
|
describe '.add_relationship' do
|
302
|
-
it
|
303
|
-
@test_object.add_relationship(:is_member_of,
|
304
|
-
@test_object.add_relationship(:is_member_of,
|
305
|
-
@test_object.add_relationship(:conforms_to,
|
302
|
+
it 'should update the RELS-EXT datastream and relationships should end up in Fedora when the object is saved' do
|
303
|
+
@test_object.add_relationship(:is_member_of, 'info:fedora/demo:5')
|
304
|
+
@test_object.add_relationship(:is_member_of, 'info:fedora/demo:10')
|
305
|
+
@test_object.add_relationship(:conforms_to, 'info:fedora/afmodel:OralHistory')
|
306
306
|
@test_object.save
|
307
|
-
rexml = REXML::Document.new(@test_object.datastreams[
|
307
|
+
rexml = REXML::Document.new(@test_object.datastreams['RELS-EXT'].content)
|
308
308
|
# Purpose: confirm that the isMemberOf entries exist and have real RDF in them
|
309
|
-
rexml.root.attributes[
|
310
|
-
rexml.root.elements["rdf:Description/ns1:isMemberOf[@rdf:resource='info:fedora/demo:5']"].
|
311
|
-
rexml.root.elements["rdf:Description/ns1:isMemberOf[@rdf:resource='info:fedora/demo:10']"].
|
309
|
+
expect(rexml.root.attributes['xmlns:ns1']).to eq('info:fedora/fedora-system:def/relations-external#')
|
310
|
+
expect(rexml.root.elements["rdf:Description/ns1:isMemberOf[@rdf:resource='info:fedora/demo:5']"]).not_to be_nil
|
311
|
+
expect(rexml.root.elements["rdf:Description/ns1:isMemberOf[@rdf:resource='info:fedora/demo:10']"]).not_to be_nil
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
315
315
|
describe '.add_file_datastream' do
|
316
316
|
|
317
|
-
it
|
318
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
317
|
+
it 'should set the correct mimeType if :mime_type, :mimeType, or :content_type passed in and path does not contain correct extension' do
|
318
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/dino_jpg_no_file_ext' ))
|
319
319
|
@test_object.add_file_datastream(f)
|
320
320
|
@test_object.save
|
321
321
|
test_obj = ActiveFedora::Base.find(@test_object.pid)
|
322
322
|
#check case where nothing passed in does not have correct mime type
|
323
|
-
test_obj.datastreams[
|
323
|
+
expect(test_obj.datastreams['DS1'].mimeType).to eq('application/octet-stream')
|
324
324
|
@test_object2 = ActiveFedora::Base.new
|
325
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
326
|
-
@test_object2.add_file_datastream(f,{:mimeType=>
|
325
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/dino_jpg_no_file_ext' ))
|
326
|
+
@test_object2.add_file_datastream(f, {:mimeType => 'image/jpeg'})
|
327
327
|
@test_object2.save
|
328
328
|
test_obj = ActiveFedora::Base.find(@test_object2.pid)
|
329
|
-
test_obj.datastreams[
|
329
|
+
expect(test_obj.datastreams['DS1'].mimeType).to eq('image/jpeg')
|
330
330
|
@test_object3 = ActiveFedora::Base.new
|
331
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
332
|
-
@test_object3.add_file_datastream(f,{:mime_type=>
|
331
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/dino_jpg_no_file_ext' ))
|
332
|
+
@test_object3.add_file_datastream(f, {:mime_type => 'image/jpeg'})
|
333
333
|
@test_object3.save
|
334
334
|
test_obj = ActiveFedora::Base.find(@test_object3.pid)
|
335
|
-
test_obj.datastreams[
|
335
|
+
expect(test_obj.datastreams['DS1'].mimeType).to eq('image/jpeg')
|
336
336
|
@test_object4 = ActiveFedora::Base.new
|
337
|
-
f = File.new(File.join( File.dirname(__FILE__),
|
338
|
-
@test_object4.add_file_datastream(f,{:content_type=>
|
337
|
+
f = File.new(File.join( File.dirname(__FILE__), '../fixtures/dino_jpg_no_file_ext' ))
|
338
|
+
@test_object4.add_file_datastream(f, {:content_type => 'image/jpeg'})
|
339
339
|
@test_object4.save
|
340
340
|
test_obj = ActiveFedora::Base.find(@test_object4.pid)
|
341
|
-
test_obj.datastreams[
|
341
|
+
expect(test_obj.datastreams['DS1'].mimeType).to eq('image/jpeg')
|
342
342
|
end
|
343
343
|
end
|
344
|
-
|
344
|
+
|
345
345
|
describe '.add_datastream' do
|
346
|
-
|
347
|
-
it
|
346
|
+
|
347
|
+
it 'should be able to add datastreams' do
|
348
348
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
349
|
-
@test_object.add_datastream(ds).
|
349
|
+
expect(@test_object.add_datastream(ds)).to be_truthy
|
350
350
|
end
|
351
|
-
|
352
|
-
it
|
353
|
-
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
351
|
+
|
352
|
+
it 'adding and saving should add the datastream to the datastreams array' do
|
353
|
+
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
354
354
|
ds.content = fixture('dino.jpg').read
|
355
|
-
@test_object.datastreams.
|
355
|
+
expect(@test_object.datastreams).not_to have_key('DS1')
|
356
356
|
@test_object.add_datastream(ds)
|
357
357
|
ds.save
|
358
|
-
@test_object.datastreams.
|
358
|
+
expect(@test_object.datastreams).to have_key('DS1')
|
359
359
|
end
|
360
|
-
|
360
|
+
|
361
361
|
end
|
362
|
-
|
363
|
-
it
|
362
|
+
|
363
|
+
it 'should retrieve blobs that match the saved blobs' do
|
364
364
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'DS1')
|
365
|
-
ds.content =
|
365
|
+
ds.content = 'foo'
|
366
366
|
new_ds = ds.save
|
367
367
|
@test_object.add_datastream(new_ds)
|
368
|
-
@test_object.class.find(@test_object.pid).datastreams[
|
368
|
+
expect(@test_object.class.find(@test_object.pid).datastreams['DS1'].content).to eq(new_ds.content)
|
369
369
|
end
|
370
|
-
|
371
|
-
describe
|
372
|
-
it
|
373
|
-
@test_object.create_date.
|
370
|
+
|
371
|
+
describe '.create_date' do
|
372
|
+
it 'should return W3C date' do
|
373
|
+
expect(@test_object.create_date).not_to be_nil
|
374
374
|
end
|
375
375
|
end
|
376
|
-
|
377
|
-
describe
|
378
|
-
it
|
379
|
-
@test_object.modified_date.
|
380
|
-
end
|
376
|
+
|
377
|
+
describe '.modified_date' do
|
378
|
+
it 'should return nil before saving and a W3C date after saving' do
|
379
|
+
expect(@test_object.modified_date).not_to be_nil
|
380
|
+
end
|
381
381
|
end
|
382
|
-
|
383
|
-
describe
|
384
|
-
|
385
|
-
it
|
382
|
+
|
383
|
+
describe 'delete' do
|
384
|
+
|
385
|
+
it 'should delete the object from Fedora and Solr' do
|
386
386
|
@test_object.save
|
387
|
-
ActiveFedora::Base.find_with_conditions(:id
|
387
|
+
expect(ActiveFedora::Base.find_with_conditions(:id => @test_object.pid).first['id']).to eq(@test_object.pid)
|
388
388
|
pid = @test_object.pid # store so we can access it after deletion
|
389
389
|
@test_object.delete
|
390
|
-
ActiveFedora::Base.find_with_conditions(:id=>pid).
|
390
|
+
expect(ActiveFedora::Base.find_with_conditions(:id => pid)).to be_empty
|
391
391
|
end
|
392
392
|
end
|
393
393
|
|
@@ -395,7 +395,7 @@ describe ActiveFedora::Base do
|
|
395
395
|
it 'should remove a relationship from an object after a save' do
|
396
396
|
@test_object2 = ActiveFedora::Base.new
|
397
397
|
@test_object2.save
|
398
|
-
@test_object.add_relationship(:has_part
|
398
|
+
@test_object.add_relationship(:has_part, @test_object2)
|
399
399
|
@test_object.save
|
400
400
|
@pid = @test_object.pid
|
401
401
|
begin
|
@@ -404,28 +404,28 @@ describe ActiveFedora::Base do
|
|
404
404
|
puts "#{e.message}\n#{e.backtrace}"
|
405
405
|
raise e
|
406
406
|
end
|
407
|
-
@test_object.object_relations[:has_part].
|
408
|
-
@test_object.remove_relationship(:has_part
|
407
|
+
expect(@test_object.object_relations[:has_part]).to include @test_object2.internal_uri
|
408
|
+
@test_object.remove_relationship(:has_part, @test_object2)
|
409
409
|
@test_object.save
|
410
410
|
@test_object = ActiveFedora::Base.find(@pid)
|
411
|
-
@test_object.object_relations[:has_part].
|
411
|
+
expect(@test_object.object_relations[:has_part]).to be_empty
|
412
412
|
end
|
413
413
|
end
|
414
414
|
|
415
|
-
|
416
|
-
describe
|
417
|
-
it
|
415
|
+
|
416
|
+
describe '#exists?' do
|
417
|
+
it 'should return true for objects that exist' do
|
418
418
|
@obj = ActiveFedora::Base.create
|
419
|
-
ActiveFedora::Base.exists?(@obj.pid).
|
419
|
+
expect(ActiveFedora::Base.exists?(@obj.pid)).to be_truthy
|
420
420
|
end
|
421
421
|
it "should return false for objects that don't exist" do
|
422
|
-
ActiveFedora::Base.exists?('test:missing_object').
|
422
|
+
expect(ActiveFedora::Base.exists?('test:missing_object')).to be_falsey
|
423
423
|
end
|
424
|
-
it
|
425
|
-
ActiveFedora::Base.exists?(nil).
|
424
|
+
it 'should return false for nil' do
|
425
|
+
expect(ActiveFedora::Base.exists?(nil)).to be_falsey
|
426
426
|
end
|
427
|
-
it
|
428
|
-
ActiveFedora::Base.exists?('').
|
427
|
+
it 'should return false for empty' do
|
428
|
+
expect(ActiveFedora::Base.exists?('')).to be_falsey
|
429
429
|
end
|
430
430
|
end
|
431
431
|
end
|