active-fedora 3.1.6 → 3.2.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +22 -22
- data/History.txt +9 -3
- data/active-fedora.gemspec +3 -3
- data/config/predicate_mappings.yml +1 -0
- data/config/service_mappings.yml +9 -0
- data/lib/active_fedora.rb +7 -1
- data/lib/active_fedora/base.rb +84 -30
- data/lib/active_fedora/datastream.rb +4 -1
- data/lib/active_fedora/datastream_collections.rb +304 -293
- data/lib/active_fedora/metadata_datastream.rb +2 -24
- data/lib/active_fedora/metadata_datastream_helper.rb +32 -5
- data/lib/active_fedora/named_relationships.rb +95 -0
- data/lib/active_fedora/nested_attributes.rb +1 -1
- data/lib/active_fedora/predicates.rb +76 -0
- data/lib/active_fedora/reflection.rb +9 -1
- data/lib/active_fedora/relationship.rb +1 -0
- data/lib/active_fedora/relationship_graph.rb +152 -0
- data/lib/active_fedora/relationships_helper.rb +32 -41
- data/lib/active_fedora/rels_ext_datastream.rb +3 -10
- data/lib/active_fedora/semantic_node.rb +47 -203
- data/lib/active_fedora/service_definitions.rb +89 -0
- data/lib/active_fedora/unsaved_digital_object.rb +40 -0
- data/lib/active_fedora/version.rb +1 -1
- data/spec/integration/base_spec.rb +106 -309
- data/spec/integration/datastream_collections_spec.rb +135 -0
- data/spec/integration/rels_ext_datastream_spec.rb +14 -35
- data/spec/integration/semantic_node_spec.rb +6 -10
- data/spec/unit/base_datastream_management_spec.rb +0 -3
- data/spec/unit/base_extra_spec.rb +5 -9
- data/spec/unit/base_spec.rb +103 -57
- data/spec/unit/{base_named_datastream_spec.rb → datastream_collections_spec.rb} +107 -150
- data/spec/unit/metadata_datastream_spec.rb +0 -1
- data/spec/unit/nokogiri_datastream_spec.rb +0 -1
- data/spec/unit/predicates_spec.rb +64 -0
- data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -7
- data/spec/unit/relationship_graph_spec.rb +95 -0
- data/spec/unit/relationship_spec.rb +4 -4
- data/spec/unit/relationships_helper_spec.rb +43 -104
- data/spec/unit/rels_ext_datastream_spec.rb +6 -6
- data/spec/unit/semantic_node_spec.rb +27 -116
- data/spec/unit/service_definitions_spec.rb +52 -0
- data/spec/unit/solr_config_options_spec.rb +1 -1
- metadata +35 -17
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveFedora::DatastreamCollections do
|
4
|
+
before(:all) do
|
5
|
+
ActiveSupport::Deprecation.expects(:warn).with("Deprecation: DatastreamCollections will not be included by default in the next version. To use has_datastream add 'include ActiveFedora::DatastreamCollections' to your model")
|
6
|
+
class MockAFBaseDatastream < ActiveFedora::Base
|
7
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
8
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Named datastream specs
|
14
|
+
#
|
15
|
+
describe '#add_named_datastream' do
|
16
|
+
it 'should add a datastream with the given name to the object in fedora' do
|
17
|
+
@test_object2 = MockAFBaseDatastream.new
|
18
|
+
# @test_object2.new_object = true
|
19
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
20
|
+
f2 = File.open(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ), 'rb')
|
21
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
22
|
+
f.stubs(:content_type).returns("image/jpeg")
|
23
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
|
24
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
25
|
+
ds = @test_object2.thumbnail.first
|
26
|
+
ds2 = @test_object2.high.first
|
27
|
+
@test_object2.save
|
28
|
+
@test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
|
29
|
+
@test_object2.named_datastreams.keys.size.should == 2
|
30
|
+
@test_object2.named_datastreams.keys.include?("thumbnail").should == true
|
31
|
+
@test_object2.named_datastreams.keys.include?("high").should == true
|
32
|
+
@test_object2.named_datastreams["thumbnail"].size.should == 1
|
33
|
+
@test_object2.named_datastreams["high"].size.should == 1
|
34
|
+
t2_thumb1 = @test_object2.named_datastreams["thumbnail"].first
|
35
|
+
t2_thumb1.dsid.should == ds.dsid
|
36
|
+
t2_thumb1.mimeType.should == ds.mimeType
|
37
|
+
t2_thumb1.pid.should == ds.pid
|
38
|
+
t2_thumb1.dsLabel.should == ds.dsLabel
|
39
|
+
t2_thumb1.controlGroup.should == ds.controlGroup
|
40
|
+
t2_high1 = @test_object2.named_datastreams["high"].first
|
41
|
+
t2_high1.dsid.should == ds2.dsid
|
42
|
+
t2_high1.mimeType.should == ds2.mimeType
|
43
|
+
t2_high1.pid.should == ds2.pid
|
44
|
+
t2_high1.dsLabel.should == ds2.dsLabel
|
45
|
+
t2_high1.controlGroup.should == ds2.controlGroup
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#add_named_file_datastream' do
|
50
|
+
it 'should add a file datastream with the given name to the object in fedora' do
|
51
|
+
@test_object2 = MockAFBaseDatastream.new
|
52
|
+
# @test_object2.new_object = true
|
53
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
54
|
+
f.stubs(:content_type).returns("image/jpeg")
|
55
|
+
@test_object2.add_named_file_datastream("thumbnail",f)
|
56
|
+
ds = @test_object2.thumbnail.first
|
57
|
+
@test_object2.save
|
58
|
+
@test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
|
59
|
+
@test_object2.named_datastreams["thumbnail"].size.should == 1
|
60
|
+
t2_thumb1 = @test_object2.named_datastreams["thumbnail"].first
|
61
|
+
t2_thumb1.dsid.should == "THUMB1"
|
62
|
+
t2_thumb1.mimeType.should == "image/jpeg"
|
63
|
+
t2_thumb1.pid.should == @test_object2.pid
|
64
|
+
t2_thumb1.dsLabel.should == "minivan.jpg"
|
65
|
+
t2_thumb1.controlGroup.should == "M"
|
66
|
+
|
67
|
+
# .attributes.should == {"label"=>ds.label,"dsid"=>ds.dsid,
|
68
|
+
# "mimeType"=>ds.attributes[:mimeType],
|
69
|
+
# :controlGroup=>ds.attributes[:controlGroup],
|
70
|
+
# :pid=>ds.pid, :dsID=>ds.dsid, :dsLabel=>ds.attributes[:dsLabel]}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#update_named_datastream' do
|
75
|
+
it 'should update a named datastream to have a new file' do
|
76
|
+
@test_object2 = MockAFBaseDatastream.new
|
77
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
78
|
+
minivan = f.read
|
79
|
+
f.rewind
|
80
|
+
f2 = File.open(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ), 'rb')
|
81
|
+
dino = f2.read
|
82
|
+
f2.rewind
|
83
|
+
f.stubs(:content_type).returns("image/jpeg")
|
84
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
85
|
+
f2.stubs(:content_type).returns("image/jpeg")
|
86
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
87
|
+
#check raise exception if dsid not supplied
|
88
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f})
|
89
|
+
@test_object2.save
|
90
|
+
@test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
|
91
|
+
|
92
|
+
@test_object2.thumbnail.size.should == 1
|
93
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
94
|
+
ds = @test_object2.thumbnail.first
|
95
|
+
ds.dsid.should == "THUMB1"
|
96
|
+
ds.mimeType.should == "image/jpeg"
|
97
|
+
ds.pid.should == @test_object2.pid
|
98
|
+
ds.dsLabel.should == "minivan.jpg"
|
99
|
+
ds.controlGroup.should == "M"
|
100
|
+
|
101
|
+
ds.content.should == minivan
|
102
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
|
103
|
+
@test_object2.save
|
104
|
+
@test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
|
105
|
+
@test_object2.thumbnail.size.should == 1
|
106
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
107
|
+
ds2 = @test_object2.thumbnail.first
|
108
|
+
ds2.dsid.should == "THUMB1"
|
109
|
+
ds2.mimeType.should == "image/jpeg"
|
110
|
+
ds2.pid.should == @test_object2.pid
|
111
|
+
ds2.dsLabel.should == "dino.jpg"
|
112
|
+
ds2.controlGroup.should == "M"
|
113
|
+
(ds2.content == dino).should be_true
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#named_datastreams_ids' do
|
118
|
+
it 'should return a hash of datastream name to an array of dsids' do
|
119
|
+
@test_object2 = MockAFBaseDatastream.new
|
120
|
+
# @test_object2.new_object = true
|
121
|
+
f = File.open(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"), 'rb')
|
122
|
+
f2 = File.open(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ), 'rb')
|
123
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
124
|
+
f.stubs(:content_type).returns("image/jpeg")
|
125
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
|
126
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f2})
|
127
|
+
@test_object2.save
|
128
|
+
@test_object2 = MockAFBaseDatastream.load_instance(@test_object2.pid)
|
129
|
+
@test_object2.named_datastreams_ids.should == {"high"=>[], "thumbnail"=>["THUMB1", "THUMB2"]}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
end
|
@@ -31,8 +31,6 @@ describe ActiveFedora::RelsExtDatastream do
|
|
31
31
|
@test_datastream = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
32
32
|
@test_datastream.model = @test_object
|
33
33
|
@test_object.save
|
34
|
-
@test_relationships = [ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:5"),
|
35
|
-
ActiveFedora::Relationship.new(:subject => :self, :predicate => :is_member_of, :object => "info:fedora/demo:10")]
|
36
34
|
end
|
37
35
|
|
38
36
|
after(:each) do
|
@@ -63,9 +61,8 @@ describe ActiveFedora::RelsExtDatastream do
|
|
63
61
|
|
64
62
|
it "should generate new rdf/xml as the datastream content" do
|
65
63
|
@test_object.add_datastream(@test_datastream)
|
66
|
-
@
|
67
|
-
|
68
|
-
end
|
64
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
65
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
69
66
|
rexml1 = REXML::Document.new(@test_datastream.to_rels_ext())
|
70
67
|
@test_datastream.serialize!
|
71
68
|
rexml2 = REXML::Document.new(@test_object.datastreams["RELS-EXT"].content)
|
@@ -76,7 +73,7 @@ describe ActiveFedora::RelsExtDatastream do
|
|
76
73
|
|
77
74
|
it "should load relationships from fedora into parent object" do
|
78
75
|
class SpecNode; include ActiveFedora::SemanticNode; end
|
79
|
-
|
76
|
+
ActiveFedora::Predicates.predicate_mappings[ActiveFedora::Predicates.default_predicate_namespace].each_key do |p|
|
80
77
|
@test_object.add_relationship(p, "info:fedora/demo:#{rand(100)}")
|
81
78
|
end
|
82
79
|
@test_object.save
|
@@ -113,11 +110,7 @@ describe ActiveFedora::RelsExtDatastream do
|
|
113
110
|
@test_object5.testing2_append(@test_object3)
|
114
111
|
@test_object2.save
|
115
112
|
@test_object5.save
|
116
|
-
|
117
|
-
r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
|
118
|
-
r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object4)
|
119
|
-
r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
|
120
|
-
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFRelsSolr))
|
113
|
+
model_rel = ActiveFedora::ContentModel.pid_from_ruby_class(MockAFRelsSolr)
|
121
114
|
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
122
115
|
#get solr doc for @test_object2
|
123
116
|
solr_doc = MockAFRelsSolr.find_by_solr(@test_object2.pid).hits.first
|
@@ -133,35 +126,21 @@ describe ActiveFedora::RelsExtDatastream do
|
|
133
126
|
test_from_solr_object5 = MockAFRelsSolr.new
|
134
127
|
test_from_solr_object5.rels_ext.from_solr(solr_doc)
|
135
128
|
|
136
|
-
|
137
|
-
test_from_solr_object2.
|
138
|
-
|
139
|
-
test_from_solr_object2.relationships.has_statement?(stmt).should be_true
|
140
|
-
stmt = test_from_solr_object2.build_statement(test_from_solr_object2.internal_uri, :has_model, model_rel.object)
|
141
|
-
test_from_solr_object2.relationships.has_statement?(stmt).should be_true
|
129
|
+
test_from_solr_object2.object_relations[:has_part].should include @test_object3.internal_uri
|
130
|
+
test_from_solr_object2.object_relations[:has_member].should include @test_object4.internal_uri
|
131
|
+
test_from_solr_object2.object_relations[:has_model].should include model_rel
|
142
132
|
|
143
|
-
|
144
|
-
|
145
|
-
#test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
|
146
|
-
stmt = test_from_solr_object3.build_statement(test_from_solr_object3.internal_uri, :has_model, model_rel.object)
|
147
|
-
test_from_solr_object3.relationships.has_statement?(stmt).should be_true
|
133
|
+
test_from_solr_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object3.internal_uri],"testing2"=>[@test_object4.internal_uri], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[@test_object3.internal_uri]}}
|
134
|
+
test_from_solr_object3.object_relations[:has_model].should include model_rel
|
148
135
|
test_from_solr_object3.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
|
149
|
-
|
150
|
-
stmt = test_from_solr_object4.build_statement(test_from_solr_object4.internal_uri, :has_model, model_rel.object)
|
151
|
-
test_from_solr_object4.relationships.has_statement?(stmt).should be_true
|
136
|
+
test_from_solr_object4.object_relations[:has_model].should include model_rel
|
152
137
|
test_from_solr_object4.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
|
153
138
|
|
154
|
-
|
155
|
-
test_from_solr_object5.
|
156
|
-
|
157
|
-
test_from_solr_object5.relationships.has_statement?(stmt).should be_true
|
158
|
-
stmt = test_from_solr_object5.build_statement(test_from_solr_object5.internal_uri, :has_member, r3.object)
|
159
|
-
test_from_solr_object5.relationships.has_statement?(stmt).should be_true
|
139
|
+
test_from_solr_object5.object_relations[:has_model].should include model_rel
|
140
|
+
test_from_solr_object5.object_relations[:has_part].should include @test_object2.internal_uri
|
141
|
+
test_from_solr_object5.object_relations[:has_member].should include @test_object3.internal_uri
|
160
142
|
|
161
|
-
|
162
|
-
# :has_part=>[r2.object],
|
163
|
-
# :has_member=>[r3.object]}}
|
164
|
-
test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[r3.object], "collection_members"=>[], "part_of"=>[], "testing"=>[r2.object], "parts_outbound"=>[r2.object]}}
|
143
|
+
test_from_solr_object5.relationships_by_name.should == {:self=>{"testing2"=>[@test_object3.internal_uri], "collection_members"=>[], "part_of"=>[], "testing"=>[@test_object2.internal_uri], "parts_outbound"=>[@test_object2.internal_uri]}}
|
165
144
|
end
|
166
145
|
end
|
167
146
|
end
|
@@ -150,9 +150,8 @@ describe ActiveFedora::SemanticNode do
|
|
150
150
|
it "should create useable finders" do
|
151
151
|
spec_node = SNSpecNode.new
|
152
152
|
spec_node.collection_members.should == []
|
153
|
-
rel = ActiveFedora::Relationship.new(:subject => :self, :predicate => :has_collection_member, :object => @test_object.pid)
|
154
153
|
|
155
|
-
spec_node.add_relationship(
|
154
|
+
spec_node.add_relationship(:has_collection_member, @test_object.pid)
|
156
155
|
collection_members = spec_node.collection_members
|
157
156
|
collection_members.length.should == 1
|
158
157
|
collection_members.first.pid.should == @test_object.pid
|
@@ -449,16 +448,13 @@ describe ActiveFedora::SemanticNode do
|
|
449
448
|
|
450
449
|
it 'should automatically update the relationships_by_name if relationships has changed (no refresh of relationships_by_name hash unless relationships hash has changed' do
|
451
450
|
@test_object2 = MockSemNamedRelationships.new
|
452
|
-
|
453
|
-
@test_object2.add_relationship(r.predicate, r.object)
|
451
|
+
@test_object2.add_relationship(:has_model, ActiveFedora::ContentModel.pid_from_ruby_class(MockSemNamedRelationships))
|
454
452
|
#should return expected named relationships
|
455
453
|
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"testing2"=>[], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[]}}
|
456
|
-
|
457
|
-
@test_object2.
|
458
|
-
@test_object2.
|
459
|
-
|
460
|
-
@test_object2.add_relationship(r4.predicate, r4.object)
|
461
|
-
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[r3.object]}}
|
454
|
+
@test_object2.add_relationship(:has_part, @test_object.internal_uri)
|
455
|
+
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[@test_object.internal_uri]}}
|
456
|
+
@test_object2.add_relationship(:has_member, "3", true)
|
457
|
+
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>["3"], "collection_members"=>[], "part_of"=>[], "parts_outbound"=>[@test_object.internal_uri]}}
|
462
458
|
end
|
463
459
|
end
|
464
460
|
end
|
@@ -3,9 +3,6 @@ require 'spec_helper'
|
|
3
3
|
describe ActiveFedora::Base do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
stub_get('__nextid__')
|
7
|
-
ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
|
8
|
-
Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
9
6
|
@test_object = ActiveFedora::Base.new
|
10
7
|
end
|
11
8
|
|
@@ -6,9 +6,9 @@ require 'active_fedora/metadata_datastream'
|
|
6
6
|
describe ActiveFedora::Base do
|
7
7
|
|
8
8
|
before(:each) do
|
9
|
-
stub_get('__nextid__')
|
10
|
-
ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
|
11
|
-
Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
9
|
+
# stub_get('__nextid__')
|
10
|
+
# ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("__nextid__")
|
11
|
+
# Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
|
12
12
|
@test_object = ActiveFedora::Base.new
|
13
13
|
end
|
14
14
|
|
@@ -100,12 +100,8 @@ describe ActiveFedora::Base do
|
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should delete object from repository and index" do
|
103
|
-
|
104
|
-
|
105
|
-
#@test_object.inner_object.stubs(:delete)
|
106
|
-
mock_repository = mock('repo')
|
107
|
-
@test_object.inner_object.expects(:repository).returns(mock_repository)
|
108
|
-
mock_repository.expects :purge_object
|
103
|
+
ActiveFedora::SolrService.instance.conn.expects(:delete).with("__DO_NOT_USE__")
|
104
|
+
@test_object.inner_object.stubs(:delete)
|
109
105
|
@test_object.expects(:inbound_relationships).returns({})
|
110
106
|
@test_object.delete
|
111
107
|
end
|
data/spec/unit/base_spec.rb
CHANGED
@@ -17,6 +17,8 @@ class FooHistory < ActiveFedora::Base
|
|
17
17
|
m.field "fubar", :text
|
18
18
|
end
|
19
19
|
end
|
20
|
+
class FooAdaptation < ActiveFedora::Base
|
21
|
+
end
|
20
22
|
|
21
23
|
@@last_pid = 0
|
22
24
|
|
@@ -33,7 +35,6 @@ describe ActiveFedora::Base do
|
|
33
35
|
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(@this_pid)
|
34
36
|
|
35
37
|
@test_object = ActiveFedora::Base.new
|
36
|
-
@test_history = FooHistory.new
|
37
38
|
end
|
38
39
|
|
39
40
|
after(:each) do
|
@@ -47,14 +48,9 @@ describe ActiveFedora::Base do
|
|
47
48
|
describe '#new' do
|
48
49
|
it "should create a new inner object" do
|
49
50
|
Rubydora::DigitalObject.any_instance.expects(:save).never
|
50
|
-
|
51
|
-
@mock_client.stubs(:[]).with("objects/test%3A1/datastreams?format=xml").returns(@getter)
|
52
|
-
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
53
|
-
@mock_client.stubs(:[]).with {|params| /objects\/test%3A1\/datastreams\/#{dsid}/.match(params)}.returns(@getter)
|
54
|
-
# @mock_client.stubs(:[]).with {|params| /objects\/test%3A1\/datastreams\/#{dsid}\/content/.match(params)}.returns(stub(:post=>'test:1'))
|
55
|
-
end
|
51
|
+
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
56
52
|
|
57
|
-
result = ActiveFedora::Base.new(:pid
|
53
|
+
result = ActiveFedora::Base.new(:pid=>@this_pid)
|
58
54
|
result.inner_object.should be_kind_of(Rubydora::DigitalObject)
|
59
55
|
end
|
60
56
|
|
@@ -62,7 +58,7 @@ describe ActiveFedora::Base do
|
|
62
58
|
# for doing AFObject.new(params[:foo]) when nothing is in params[:foo]
|
63
59
|
Rubydora::DigitalObject.any_instance.expects(:save).never
|
64
60
|
result = ActiveFedora::Base.new(nil)
|
65
|
-
result.inner_object.should be_kind_of(
|
61
|
+
result.inner_object.should be_kind_of(ActiveFedora::UnsavedDigitalObject)
|
66
62
|
end
|
67
63
|
|
68
64
|
end
|
@@ -241,6 +237,9 @@ describe ActiveFedora::Base do
|
|
241
237
|
|
242
238
|
|
243
239
|
describe ".datastreams" do
|
240
|
+
before do
|
241
|
+
@test_history = FooHistory.new
|
242
|
+
end
|
244
243
|
it "should create dynamic accessors" do
|
245
244
|
@test_history.withText.should == @test_history.datastreams['withText']
|
246
245
|
end
|
@@ -320,7 +319,7 @@ describe ActiveFedora::Base do
|
|
320
319
|
describe '#add_relationship' do
|
321
320
|
it 'should call #add_relationship on the rels_ext datastream' do
|
322
321
|
@test_object.add_relationship("predicate", "info:fedora/object")
|
323
|
-
pred =
|
322
|
+
pred = ActiveFedora::Predicates.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
|
324
323
|
@test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
|
325
324
|
end
|
326
325
|
|
@@ -328,11 +327,8 @@ describe ActiveFedora::Base do
|
|
328
327
|
mock_ds = mock("Rels-Ext")
|
329
328
|
mock_ds.expects(:dirty=).with(true).times(2)
|
330
329
|
@test_object.datastreams["RELS-EXT"] = mock_ds
|
331
|
-
|
332
|
-
|
333
|
-
test_relationships.each do |rel|
|
334
|
-
@test_object.add_relationship(rel.predicate, rel.object)
|
335
|
-
end
|
330
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:5")
|
331
|
+
@test_object.add_relationship(:is_member_of, "info:fedora/demo:10")
|
336
332
|
end
|
337
333
|
|
338
334
|
it 'should add a relationship to an object only if it does not exist already' do
|
@@ -342,7 +338,6 @@ describe ActiveFedora::Base do
|
|
342
338
|
|
343
339
|
@test_object3 = ActiveFedora::Base.new
|
344
340
|
@test_object.add_relationship(:has_part,@test_object3)
|
345
|
-
r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
|
346
341
|
@test_object.ids_for_outbound(:has_part).should == [@test_object3.pid]
|
347
342
|
#try adding again and make sure not there twice
|
348
343
|
@test_object.add_relationship(:has_part,@test_object3)
|
@@ -364,11 +359,11 @@ describe ActiveFedora::Base do
|
|
364
359
|
next_pid = increment_pid.to_s
|
365
360
|
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
366
361
|
stub_get(next_pid)
|
367
|
-
@test_object3 = ActiveFedora::Base.new
|
362
|
+
@test_object3 = ActiveFedora::Base.new(:pid=>next_pid)
|
368
363
|
next_pid = increment_pid.to_s
|
369
364
|
ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns(next_pid)
|
370
365
|
stub_get(next_pid)
|
371
|
-
@test_object4 = ActiveFedora::Base.new
|
366
|
+
@test_object4 = ActiveFedora::Base.new(:pid=>next_pid)
|
372
367
|
@test_object.add_relationship(:has_part,@test_object3)
|
373
368
|
@test_object.add_relationship(:has_part,@test_object4)
|
374
369
|
#check both are there
|
@@ -426,8 +421,8 @@ describe ActiveFedora::Base do
|
|
426
421
|
end
|
427
422
|
|
428
423
|
it "should call .save on any datastreams that are dirty" do
|
429
|
-
stub_ingest(@
|
430
|
-
stub_add_ds(@
|
424
|
+
stub_ingest(@this_pid)
|
425
|
+
stub_add_ds(@this_pid, ['withText2', 'withText', 'RELS-EXT'])
|
431
426
|
to = FooHistory.new
|
432
427
|
to.expects(:update_index)
|
433
428
|
|
@@ -438,8 +433,8 @@ describe ActiveFedora::Base do
|
|
438
433
|
to.save
|
439
434
|
end
|
440
435
|
it "should call .save on any datastreams that are new" do
|
441
|
-
stub_ingest(@
|
442
|
-
stub_add_ds(@
|
436
|
+
stub_ingest(@this_pid)
|
437
|
+
stub_add_ds(@this_pid, ['RELS-EXT'])
|
443
438
|
ds = ActiveFedora::Datastream.new(@test_object.inner_object, 'ds_to_add')
|
444
439
|
ds.content = "DS CONTENT"
|
445
440
|
@test_object.add_datastream(ds)
|
@@ -450,7 +445,7 @@ describe ActiveFedora::Base do
|
|
450
445
|
@test_object.save
|
451
446
|
end
|
452
447
|
it "should not call .save on any datastreams that are not dirty" do
|
453
|
-
stub_ingest(@
|
448
|
+
stub_ingest(@this_pid)
|
454
449
|
@test_object = FooHistory.new
|
455
450
|
@test_object.expects(:update_index)
|
456
451
|
@test_object.expects(:refresh)
|
@@ -465,9 +460,8 @@ describe ActiveFedora::Base do
|
|
465
460
|
@test_object.save
|
466
461
|
end
|
467
462
|
it "should update solr index with all metadata if any MetadataDatastreams have changed" do
|
468
|
-
|
469
|
-
|
470
|
-
stub_add_ds(@test_object.pid, ['ds1', 'RELS-EXT'])
|
463
|
+
stub_ingest(@this_pid)
|
464
|
+
stub_add_ds(@this_pid, ['ds1', 'RELS-EXT'])
|
471
465
|
|
472
466
|
dirty_ds = ActiveFedora::MetadataDatastream.new(@test_object.inner_object, 'ds1')
|
473
467
|
rels_ds = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
@@ -495,20 +489,20 @@ describe ActiveFedora::Base do
|
|
495
489
|
@test_object.save
|
496
490
|
end
|
497
491
|
it "should update solr index if relationships have changed" do
|
498
|
-
|
499
|
-
@test_object.inner_object.expects(:repository).returns(@mock_repo).at_least_once
|
500
|
-
@test_object.inner_object.expects(:new?).returns(true).twice
|
492
|
+
stub_ingest(@this_pid)
|
501
493
|
|
502
494
|
rels_ext = ActiveFedora::RelsExtDatastream.new(@test_object.inner_object, 'RELS-EXT')
|
503
495
|
rels_ext.model = @test_object
|
504
|
-
rels_ext.expects(:changed?).returns(true).twice
|
496
|
+
rels_ext.expects(:changed?).returns(true).twice
|
505
497
|
rels_ext.expects(:save).returns(true)
|
506
498
|
rels_ext.expects(:serialize!)
|
507
|
-
clean_ds = mock("ds2")
|
499
|
+
clean_ds = mock("ds2", :digital_object=)
|
508
500
|
clean_ds.stubs(:dirty? => false, :changed? => false, :new? => false)
|
509
501
|
clean_ds.expects(:serialize!)
|
510
|
-
@test_object.
|
511
|
-
@test_object.
|
502
|
+
@test_object.datastreams["RELS-EXT"] = rels_ext
|
503
|
+
@test_object.datastreams[:clean_ds] = clean_ds
|
504
|
+
# @test_object.inner_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
|
505
|
+
# @test_object.stubs(:datastreams).returns({"RELS-EXT" => rels_ext, :clean_ds => clean_ds})
|
512
506
|
@test_object.instance_variable_set(:@new_object, false)
|
513
507
|
@test_object.expects(:refresh)
|
514
508
|
@test_object.expects(:update_index)
|
@@ -517,6 +511,24 @@ describe ActiveFedora::Base do
|
|
517
511
|
end
|
518
512
|
end
|
519
513
|
|
514
|
+
describe "#create_datastream" do
|
515
|
+
it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
|
516
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
517
|
+
f.stubs(:content_type).returns("image/jpeg")
|
518
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
519
|
+
ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>f})
|
520
|
+
ds.class.should == ActiveFedora::Datastream
|
521
|
+
ds.dsLabel.should == "minivan.jpg"
|
522
|
+
ds.mimeType.should == "image/jpeg"
|
523
|
+
end
|
524
|
+
it 'should create a datastream object from a string' do
|
525
|
+
ds = @test_object.create_datastream("ActiveFedora::Datastream", 'NAME', {:blob=>"My file data"})
|
526
|
+
ds.class.should == ActiveFedora::Datastream
|
527
|
+
ds.dsLabel.should == nil
|
528
|
+
ds.mimeType.should == "application/octet-stream"
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
520
532
|
describe ".add_file_datastream" do
|
521
533
|
before do
|
522
534
|
@mock_file = mock('file')
|
@@ -541,6 +553,47 @@ describe ActiveFedora::Base do
|
|
541
553
|
end
|
542
554
|
end
|
543
555
|
|
556
|
+
describe ".adapt_to" do
|
557
|
+
before(:each) do
|
558
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams?format=xml").returns(@getter)
|
559
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/MY_DSID?format=xml").returns(@getter)
|
560
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/RELS-EXT/content").returns(@getter)
|
561
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/MY_DSID/content").returns("XXX")
|
562
|
+
#Update record
|
563
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99").returns(stub('post', :post=>'monkey:99'))
|
564
|
+
#Update datastream
|
565
|
+
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
566
|
+
@mock_client.stubs(:[]).with {|params| /objects\/monkey%3A99\/datastreams\/#{dsid}/.match(params)}.returns(stub('post', :post=>'monkey:99', :get=>''))
|
567
|
+
end
|
568
|
+
@mock_file = mock('file')
|
569
|
+
end
|
570
|
+
it "should return an adapted object of the requested type" do
|
571
|
+
@test_object = FooHistory.new(:pid=>"monkey:99")
|
572
|
+
@test_object.adapt_to(FooAdaptation).class.should == FooAdaptation
|
573
|
+
end
|
574
|
+
it "should not make an additional call to fedora to create the adapted object" do
|
575
|
+
@mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams?format=xml").returns(@getter).once
|
576
|
+
@test_object = FooHistory.new(:pid=>"monkey:99")
|
577
|
+
adapted = @test_object.adapt_to(FooAdaptation)
|
578
|
+
end
|
579
|
+
it "should propagate new datastreams to the adapted object" do
|
580
|
+
@test_object = FooHistory.new(:pid=>"monkey:99")
|
581
|
+
@test_object.add_file_datastream("XXX", :dsid=>'MY_DSID')
|
582
|
+
adapted = @test_object.adapt_to(FooAdaptation)
|
583
|
+
adapted.datastreams.keys.should include 'MY_DSID'
|
584
|
+
adapted.datastreams['MY_DSID'].content.should == "XXX"
|
585
|
+
adapted.datastreams['MY_DSID'].changed?.should be_true
|
586
|
+
end
|
587
|
+
it "should propagate modified datastreams to the adapted object" do
|
588
|
+
@test_object = FooHistory.new(:pid=>"monkey:99")
|
589
|
+
@test_object.datastreams['someData'].content="YYY"
|
590
|
+
adapted = @test_object.adapt_to(FooAdaptation)
|
591
|
+
adapted.datastreams.keys.should include 'someData'
|
592
|
+
adapted.datastreams['someData'].content.should == "YYY"
|
593
|
+
adapted.datastreams['someData'].changed?.should be_true
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
544
597
|
describe ".to_xml" do
|
545
598
|
it "should provide .to_xml" do
|
546
599
|
@test_object.should respond_to(:to_xml)
|
@@ -594,7 +647,9 @@ describe ActiveFedora::Base do
|
|
594
647
|
end
|
595
648
|
|
596
649
|
it "should add self.class as the :active_fedora_model" do
|
597
|
-
|
650
|
+
stub_get(@this_pid)
|
651
|
+
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
652
|
+
@test_history = FooHistory.new(:pid=>@this_pid)
|
598
653
|
solr_doc = @test_history.to_solr
|
599
654
|
solr_doc["active_fedora_model_s"].should eql("FooHistory")
|
600
655
|
end
|
@@ -664,16 +719,10 @@ describe ActiveFedora::Base do
|
|
664
719
|
end
|
665
720
|
end
|
666
721
|
|
667
|
-
it "should
|
722
|
+
it "should not save or get an pid on init" do
|
668
723
|
Rubydora::DigitalObject.any_instance.expects(:save).never
|
669
|
-
ActiveFedora::RubydoraConnection.instance.
|
670
|
-
@mock_client.stubs(:[]).with("objects/mooshoo%3A24/datastreams?format=xml").returns(@getter)
|
671
|
-
['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
|
672
|
-
@mock_client.stubs(:[]).with {|params| /objects\/mooshoo%3A24\/datastreams\/#{dsid}/.match(params)}.returns(@getter)
|
673
|
-
end
|
724
|
+
ActiveFedora::RubydoraConnection.instance.expects(:nextid).never
|
674
725
|
f = FooHistory.new
|
675
|
-
f.pid.should_not be_nil
|
676
|
-
f.pid.should == 'mooshoo:24'
|
677
726
|
end
|
678
727
|
it "should not clobber a pid if i'm creating!" do
|
679
728
|
@mock_client.stubs(:[]).with("objects/numbnuts%3A1/datastreams?format=xml").returns(@getter)
|
@@ -746,10 +795,9 @@ describe ActiveFedora::Base do
|
|
746
795
|
end
|
747
796
|
it "should take a :datastreams argument" do
|
748
797
|
att= {"fubar"=>{"-1"=>"mork", "0"=>"york", "1"=>"mangle"}}
|
749
|
-
|
750
|
-
['
|
751
|
-
|
752
|
-
end
|
798
|
+
stub_get(@this_pid)
|
799
|
+
stub_get_content(@this_pid, ['RELS-EXT', 'someData', 'withText2', 'withText'])
|
800
|
+
m = FooHistory.new(:pid=>@this_pid)
|
753
801
|
m.update_indexed_attributes(att, :datastreams=>"withText")
|
754
802
|
m.should_not be_nil
|
755
803
|
m.datastreams['someData'].fubar_values.should == []
|
@@ -804,9 +852,8 @@ describe ActiveFedora::Base do
|
|
804
852
|
#should return expected named relationships
|
805
853
|
@test_object2.relationships_by_name
|
806
854
|
@test_object2.relationships_by_name.should == {:self=>{"testing2"=>[], "collection_members"=>[], "part_of"=>[], "testing"=>[], "parts_outbound"=>[]}}
|
807
|
-
r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:dummy,:object=>@test_object})
|
808
855
|
@test_object2.add_relationship_by_name("testing",@test_object)
|
809
|
-
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[
|
856
|
+
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"testing2"=>[],"part_of"=>[], "parts_outbound"=>[@test_object.internal_uri], "collection_members"=>[]}}
|
810
857
|
end
|
811
858
|
end
|
812
859
|
|
@@ -825,13 +872,12 @@ describe ActiveFedora::Base do
|
|
825
872
|
@test_object2.should respond_to(:testing_append)
|
826
873
|
@test_object2.should respond_to(:testing_remove)
|
827
874
|
#test executing each one to make sure code added is correct
|
828
|
-
|
829
|
-
@test_object.add_relationship(
|
830
|
-
@test_object2.add_relationship(
|
875
|
+
model_pid = ActiveFedora::ContentModel.pid_from_ruby_class(ActiveFedora::Base)
|
876
|
+
@test_object.add_relationship(:has_model,model_pid)
|
877
|
+
@test_object2.add_relationship(:has_model,model_pid)
|
831
878
|
@test_object2.testing_append(@test_object)
|
832
879
|
#create relationship to access generate_uri method for an object
|
833
|
-
|
834
|
-
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[r.object],"collection_members"=>[], "part_of"=>[r.object], "parts_outbound"=>[]}}
|
880
|
+
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[@test_object.internal_uri],"collection_members"=>[], "part_of"=>[@test_object.internal_uri], "parts_outbound"=>[]}}
|
835
881
|
@test_object2.testing_remove(@test_object)
|
836
882
|
@test_object2.relationships_by_name.should == {:self=>{"testing"=>[],"collection_members"=>[], "part_of"=>[], "parts_outbound"=>[]}}
|
837
883
|
end
|
@@ -841,10 +887,10 @@ describe ActiveFedora::Base do
|
|
841
887
|
it "should serialize the relationships into a Hash" do
|
842
888
|
graph = RDF::Graph.new
|
843
889
|
subject = RDF::URI.new "info:fedora/test:sample_pid"
|
844
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::
|
845
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::
|
846
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::
|
847
|
-
graph.insert RDF::Statement.new(subject, ActiveFedora::
|
890
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_member_of), RDF::URI.new('info:fedora/demo:10'))
|
891
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:is_part_of), RDF::URI.new('info:fedora/demo:11'))
|
892
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:has_part), RDF::URI.new('info:fedora/demo:12'))
|
893
|
+
graph.insert RDF::Statement.new(subject, ActiveFedora::Predicates.find_graph_predicate(:conforms_to), "AnInterface")
|
848
894
|
|
849
895
|
@test_object.expects(:relationships).returns(graph)
|
850
896
|
solr_doc = @test_object.solrize_relationships
|