active-fedora 1.1.13 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/README.textile +8 -1
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/active-fedora.gemspec +17 -13
- data/lib/active_fedora.rb +2 -2
- data/lib/active_fedora/base.rb +295 -10
- data/lib/active_fedora/metadata_datastream.rb +10 -3
- data/lib/active_fedora/metadata_datastream_helper.rb +23 -7
- data/lib/active_fedora/model.rb +104 -2
- data/lib/active_fedora/nokogiri_datastream.rb +23 -18
- data/lib/active_fedora/qualified_dublin_core_datastream.rb +1 -0
- data/lib/active_fedora/rels_ext_datastream.rb +22 -1
- data/lib/active_fedora/semantic_node.rb +293 -8
- data/lib/active_fedora/solr_service.rb +21 -36
- data/lib/fedora/connection.rb +7 -3
- data/lib/hydra/sample_mods_datastream.rb +57 -94
- data/spec/integration/base_find_by_fields_spec.rb +215 -0
- data/spec/integration/base_spec.rb +756 -1
- data/spec/integration/metadata_datastream_helper_spec.rb +103 -0
- data/spec/integration/model_spec.rb +10 -9
- data/spec/integration/rels_ext_datastream_spec.rb +85 -0
- data/spec/integration/semantic_node_spec.rb +1 -2
- data/spec/integration/solr_service_spec.rb +36 -0
- data/spec/unit/base_file_management_spec.rb +0 -1
- data/spec/unit/base_named_datastream_spec.rb +580 -0
- data/spec/unit/base_spec.rb +98 -7
- data/spec/unit/nokogiri_datastream_spec.rb +29 -145
- data/spec/unit/semantic_node_spec.rb +479 -2
- metadata +39 -23
- data/README.rdoc +0 -17
- data/lib/active_fedora/solr_mapper.rb +0 -21
- data/spec/unit/solr_mapper_spec.rb +0 -31
@@ -0,0 +1,103 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "../spec_helper" )
|
2
|
+
|
3
|
+
require 'active_fedora'
|
4
|
+
require "rexml/document"
|
5
|
+
require 'ftools'
|
6
|
+
|
7
|
+
class MockMetaHelperSolr < ActiveFedora::Base
|
8
|
+
has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
|
9
|
+
m.field "holding_id", :string
|
10
|
+
end
|
11
|
+
|
12
|
+
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
|
13
|
+
m.field "created", :date, :xml_node => "created"
|
14
|
+
m.field "language", :string, :xml_node => "language"
|
15
|
+
m.field "creator", :string, :xml_node => "creator"
|
16
|
+
# Created remaining fields
|
17
|
+
m.field "geography", :string, :xml_node => "geography"
|
18
|
+
m.field "title", :string, :xml_node => "title"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe ActiveFedora::MetadataDatastreamHelper do
|
23
|
+
|
24
|
+
before(:each) do
|
25
|
+
@test_object = ActiveFedora::Base.new
|
26
|
+
@test_object.save
|
27
|
+
end
|
28
|
+
|
29
|
+
after(:each) do
|
30
|
+
begin
|
31
|
+
@test_object.delete
|
32
|
+
rescue
|
33
|
+
end
|
34
|
+
begin
|
35
|
+
@test_object2.delete
|
36
|
+
rescue
|
37
|
+
end
|
38
|
+
begin
|
39
|
+
@test_object3.delete
|
40
|
+
rescue
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#from_solr' do
|
45
|
+
it 'should return an object with the appropriate metadata fields filled in' do
|
46
|
+
@test_object = MockMetaHelperSolr.new
|
47
|
+
@test_object.new_object = true
|
48
|
+
attributes = {"holding_id"=>{0=>"Holding 1"},
|
49
|
+
"language"=>{0=>"Italian"},
|
50
|
+
"creator"=>{0=>"Linguist, A."},
|
51
|
+
"geography"=>{0=>"Italy"},
|
52
|
+
"title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
|
53
|
+
@test_object.update_indexed_attributes(attributes)
|
54
|
+
@test_object.save
|
55
|
+
|
56
|
+
@test_object2 = MockMetaHelperSolr.new
|
57
|
+
@test_object2.new_object = true
|
58
|
+
attributes = {"holding_id"=>{0=>"Holding 2"},
|
59
|
+
"language"=>{0=>"Spanish;Latin"},
|
60
|
+
"creator"=>{0=>"Linguist, A."},
|
61
|
+
"geography"=>{0=>"Spain"},
|
62
|
+
"title"=>{0=>"A study of the evolution of Spanish from Latin"}}
|
63
|
+
@test_object2.update_indexed_attributes(attributes)
|
64
|
+
@test_object2.save
|
65
|
+
|
66
|
+
@test_object3 = MockMetaHelperSolr.new
|
67
|
+
@test_object3.new_object = true
|
68
|
+
attributes = {"holding_id"=>{0=>"Holding 3"},
|
69
|
+
"language"=>{0=>"Spanish;Latin"},
|
70
|
+
"creator"=>{0=>"Linguist, A."},
|
71
|
+
"geography"=>{0=>"Spain"},
|
72
|
+
"title"=>{0=>"An obscure look into early nomadic tribes of Spain"}}
|
73
|
+
@test_object3.update_indexed_attributes(attributes)
|
74
|
+
@test_object3.save
|
75
|
+
|
76
|
+
#from_solr gets called indirectly
|
77
|
+
test_from_solr_object = MockMetaHelperSolr.load_instance_from_solr(@test_object.pid)
|
78
|
+
test_from_solr_object2 = MockMetaHelperSolr.load_instance_from_solr(@test_object2.pid)
|
79
|
+
test_from_solr_object3 = MockMetaHelperSolr.load_instance_from_solr(@test_object3.pid)
|
80
|
+
|
81
|
+
test_from_solr_object.fields[:language][:values].should == ["Italian"]
|
82
|
+
test_from_solr_object.fields[:creator][:values].should == ["Linguist, A."]
|
83
|
+
test_from_solr_object.fields[:geography][:values].should == ["Italy"]
|
84
|
+
test_from_solr_object.fields[:title][:values].should == ["Italian and Spanish: A Comparison of Common Phrases"]
|
85
|
+
test_from_solr_object.fields[:holding_id][:values].should == ["Holding 1"]
|
86
|
+
|
87
|
+
test_from_solr_object2.fields[:language][:values].should == ["Spanish;Latin"]
|
88
|
+
test_from_solr_object2.fields[:creator][:values].should == ["Linguist, A."]
|
89
|
+
test_from_solr_object2.fields[:geography][:values].should == ["Spain"]
|
90
|
+
test_from_solr_object2.fields[:title][:values].should == ["A study of the evolution of Spanish from Latin"]
|
91
|
+
test_from_solr_object2.fields[:holding_id][:values].should == ["Holding 2"]
|
92
|
+
|
93
|
+
test_from_solr_object3.fields[:language][:values].should == ["Spanish;Latin"]
|
94
|
+
test_from_solr_object3.fields[:creator][:values].should == ["Linguist, A."]
|
95
|
+
test_from_solr_object3.fields[:geography][:values].should == ["Spain"]
|
96
|
+
test_from_solr_object3.fields[:title][:values].should == ["An obscure look into early nomadic tribes of Spain"]
|
97
|
+
test_from_solr_object3.fields[:holding_id][:values].should == ["Holding 3"]
|
98
|
+
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
@@ -13,30 +13,31 @@ describe ActiveFedora::Model do
|
|
13
13
|
|
14
14
|
|
15
15
|
before(:each) do
|
16
|
-
module
|
16
|
+
module ModelIntegrationSpec
|
17
17
|
|
18
18
|
class Basic < ActiveFedora::Base
|
19
|
-
|
19
|
+
include ActiveFedora::Model
|
20
20
|
end
|
21
21
|
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
|
+
@test_instance = ModelIntegrationSpec::Basic.new
|
24
25
|
@test_instance.save
|
25
26
|
|
26
27
|
end
|
27
28
|
|
28
29
|
after(:each) do
|
29
30
|
@test_instance.delete
|
30
|
-
Object.send(:remove_const, :
|
31
|
+
Object.send(:remove_const, :ModelIntegrationSpec)
|
31
32
|
end
|
32
33
|
|
33
34
|
describe '#find' do
|
34
35
|
it "should return an array of instances of the calling Class" do
|
35
36
|
pending
|
36
|
-
result =
|
37
|
+
result = ModelIntegrationSpec::Basic.find(:all)
|
37
38
|
result.should be_instance_of(Array)
|
38
39
|
result.each do |obj|
|
39
|
-
obj.class.should ==
|
40
|
+
obj.class.should == ModelIntegrationSpec::Basic
|
40
41
|
end
|
41
42
|
end
|
42
43
|
end
|
@@ -44,9 +45,9 @@ describe ActiveFedora::Model do
|
|
44
45
|
describe '#find_model' do
|
45
46
|
|
46
47
|
it "should return an object of the given Model whose inner object is nil" do
|
47
|
-
#result =
|
48
|
-
result = Fedora::Repository.instance.find_model(@test_instance.pid,
|
49
|
-
result.class.should ==
|
48
|
+
#result = ModelIntegrationSpec::Basic.find_model(@test_instance.pid, ModelIntegrationSpec::Basic)
|
49
|
+
result = Fedora::Repository.instance.find_model(@test_instance.pid, ModelIntegrationSpec::Basic)
|
50
|
+
result.class.should == ModelIntegrationSpec::Basic
|
50
51
|
result.inner_object.new_object?.should be_false
|
51
52
|
end
|
52
53
|
end
|
@@ -4,6 +4,13 @@ require 'active_fedora'
|
|
4
4
|
require "rexml/document"
|
5
5
|
require 'ftools'
|
6
6
|
|
7
|
+
class MockAFRelsSolr < ActiveFedora::Base
|
8
|
+
has_relationship "testing", :has_part, :type=>MockAFRelsSolr
|
9
|
+
has_relationship "testing2", :has_member, :type=>MockAFRelsSolr
|
10
|
+
has_relationship "testing_inbound", :has_part, :type=>MockAFRelsSolr, :inbound=>true
|
11
|
+
has_relationship "testing_inbound2", :has_member, :type=>MockAFRelsSolr, :inbound=>true
|
12
|
+
end
|
13
|
+
|
7
14
|
describe ActiveFedora::RelsExtDatastream do
|
8
15
|
|
9
16
|
before(:all) do
|
@@ -29,7 +36,26 @@ describe ActiveFedora::RelsExtDatastream do
|
|
29
36
|
end
|
30
37
|
|
31
38
|
after(:each) do
|
39
|
+
begin
|
32
40
|
@test_object.delete
|
41
|
+
rescue
|
42
|
+
end
|
43
|
+
begin
|
44
|
+
@test_object2.delete
|
45
|
+
rescue
|
46
|
+
end
|
47
|
+
begin
|
48
|
+
@test_object3.delete
|
49
|
+
rescue
|
50
|
+
end
|
51
|
+
begin
|
52
|
+
@test_object4.delete
|
53
|
+
rescue
|
54
|
+
end
|
55
|
+
begin
|
56
|
+
@test_object5.delete
|
57
|
+
rescue
|
58
|
+
end
|
33
59
|
end
|
34
60
|
|
35
61
|
|
@@ -64,4 +90,63 @@ describe ActiveFedora::RelsExtDatastream do
|
|
64
90
|
@test_object.relationships[:self].should have_key(:is_member_of)
|
65
91
|
ActiveFedora::Base.load_instance(@test_object.pid).relationships.should == @test_object.relationships
|
66
92
|
end
|
93
|
+
|
94
|
+
describe '#from_solr' do
|
95
|
+
|
96
|
+
it "should respond_to from_solr" do
|
97
|
+
@test_datastream.respond_to?(:from_solr).should be_true
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should populate the relationships hash based on data in solr only for any possible fedora predicates' do
|
101
|
+
@test_object2 = MockAFRelsSolr.new
|
102
|
+
@test_object2.new_object = true
|
103
|
+
@test_object2.save
|
104
|
+
@test_object3 = MockAFRelsSolr.new
|
105
|
+
@test_object3.new_object = true
|
106
|
+
@test_object3.save
|
107
|
+
@test_object4 = MockAFRelsSolr.new
|
108
|
+
@test_object4.new_object = true
|
109
|
+
@test_object4.save
|
110
|
+
@test_object5 = MockAFRelsSolr.new
|
111
|
+
@test_object5.new_object = true
|
112
|
+
@test_object5.save
|
113
|
+
#append to named relationship 'testing'
|
114
|
+
@test_object2.testing_append(@test_object3)
|
115
|
+
@test_object2.testing2_append(@test_object4)
|
116
|
+
@test_object5.testing_append(@test_object2)
|
117
|
+
@test_object5.testing2_append(@test_object3)
|
118
|
+
@test_object2.save
|
119
|
+
@test_object5.save
|
120
|
+
r2 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object2)
|
121
|
+
r3 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object3)
|
122
|
+
r4 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object4)
|
123
|
+
r5 = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>@test_object5)
|
124
|
+
model_rel = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>:dummy, :object=>ActiveFedora::ContentModel.pid_from_ruby_class(MockAFRelsSolr))
|
125
|
+
#check inbound correct, testing goes to :has_part and testing2 goes to :has_member
|
126
|
+
#get solr doc for @test_object2
|
127
|
+
solr_doc = MockAFRelsSolr.find_by_solr(@test_object2.pid).hits.first
|
128
|
+
test_from_solr_object2 = MockAFRelsSolr.new
|
129
|
+
test_from_solr_object2.rels_ext.from_solr(solr_doc)
|
130
|
+
solr_doc = MockAFRelsSolr.find_by_solr(@test_object3.pid).hits.first
|
131
|
+
test_from_solr_object3 = MockAFRelsSolr.new
|
132
|
+
test_from_solr_object3.rels_ext.from_solr(solr_doc)
|
133
|
+
solr_doc = MockAFRelsSolr.find_by_solr(@test_object4.pid).hits.first
|
134
|
+
test_from_solr_object4 = MockAFRelsSolr.new
|
135
|
+
test_from_solr_object4.rels_ext.from_solr(solr_doc)
|
136
|
+
solr_doc = MockAFRelsSolr.find_by_solr(@test_object5.pid).hits.first
|
137
|
+
test_from_solr_object5 = MockAFRelsSolr.new
|
138
|
+
test_from_solr_object5.rels_ext.from_solr(solr_doc)
|
139
|
+
|
140
|
+
test_from_solr_object2.relationships.should == {:self=>{:has_part=>[r3.object],:has_member=>[r4.object],:has_model=>[model_rel.object]}}
|
141
|
+
test_from_solr_object2.named_relationships.should == {:self=>{"testing"=>[r3.object],"testing2"=>[r4.object]}}
|
142
|
+
test_from_solr_object3.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
|
143
|
+
test_from_solr_object3.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
|
144
|
+
test_from_solr_object4.relationships.should == {:self=>{:has_model=>[model_rel.object]}}
|
145
|
+
test_from_solr_object4.named_relationships.should == {:self=>{"testing"=>[],"testing2"=>[]}}
|
146
|
+
test_from_solr_object5.relationships.should == {:self=>{:has_model=>[model_rel.object],
|
147
|
+
:has_part=>[r2.object],
|
148
|
+
:has_member=>[r3.object]}}
|
149
|
+
test_from_solr_object5.named_relationships.should == {:self=>{"testing"=>[r2.object],"testing2"=>[r3.object]}}
|
150
|
+
end
|
151
|
+
end
|
67
152
|
end
|
@@ -6,9 +6,27 @@ describe ActiveFedora::SolrService do
|
|
6
6
|
describe "#reify_solr_results" do
|
7
7
|
before(:all) do
|
8
8
|
class FooObject < ActiveFedora::Base
|
9
|
+
has_metadata :name => "properties", :type => ActiveFedora::MetadataDatastream do |m|
|
10
|
+
m.field "holding_id", :string
|
11
|
+
end
|
12
|
+
|
13
|
+
has_metadata :name => "descMetadata", :type => ActiveFedora::QualifiedDublinCoreDatastream do |m|
|
14
|
+
m.field "created", :date, :xml_node => "created"
|
15
|
+
m.field "language", :string, :xml_node => "language"
|
16
|
+
m.field "creator", :string, :xml_node => "creator"
|
17
|
+
# Created remaining fields
|
18
|
+
m.field "geography", :string, :xml_node => "geography"
|
19
|
+
m.field "title", :string, :xml_node => "title"
|
20
|
+
end
|
9
21
|
end
|
10
22
|
@test_object = ActiveFedora::Base.new
|
11
23
|
@foo_object = FooObject.new
|
24
|
+
attributes = {"holding_id"=>{0=>"Holding 1"},
|
25
|
+
"language"=>{0=>"Italian"},
|
26
|
+
"creator"=>{0=>"Linguist, A."},
|
27
|
+
"geography"=>{0=>"Italy"},
|
28
|
+
"title"=>{0=>"Italian and Spanish: A Comparison of Common Phrases"}}
|
29
|
+
@foo_object.update_indexed_attributes(attributes)
|
12
30
|
@test_object.save
|
13
31
|
@foo_object.save
|
14
32
|
end
|
@@ -26,5 +44,23 @@ describe ActiveFedora::SolrService do
|
|
26
44
|
end
|
27
45
|
end
|
28
46
|
|
47
|
+
it 'should load objects from solr data if a :load_from_solr option is passed in' do
|
48
|
+
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
49
|
+
solr_result = ActiveFedora::SolrService.instance.conn.query(query)
|
50
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
51
|
+
result.length.should == 2
|
52
|
+
result.each do |r|
|
53
|
+
(r.class == ActiveFedora::Base || r.class == FooObject).should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should call load_instance_from_solr if :load_from_solr option passed in' do
|
58
|
+
query = "id\:#{ActiveFedora::SolrService.escape_uri_for_query(@test_object.pid)} OR id\:#{ActiveFedora::SolrService.escape_uri_for_query(@foo_object.pid)}"
|
59
|
+
solr_result = ActiveFedora::SolrService.instance.conn.query(query)
|
60
|
+
ActiveFedora::Base.expects(:load_instance_from_solr).times(1)
|
61
|
+
FooObject.expects(:load_instance_from_solr).times(1)
|
62
|
+
result = ActiveFedora::SolrService.reify_solr_results(solr_result,{:load_from_solr=>true})
|
63
|
+
end
|
64
|
+
|
29
65
|
end
|
30
66
|
end
|
@@ -0,0 +1,580 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require "active_fedora"
|
3
|
+
|
4
|
+
# Some tentative extensions to ActiveFedora::Base
|
5
|
+
|
6
|
+
describe ActiveFedora::Base do
|
7
|
+
|
8
|
+
def increment_pid
|
9
|
+
@@last_pid += 1
|
10
|
+
end
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
14
|
+
@test_object = ActiveFedora::Base.new
|
15
|
+
@test_object.new_object = true
|
16
|
+
end
|
17
|
+
|
18
|
+
after(:each) do
|
19
|
+
begin
|
20
|
+
@test_object.delete
|
21
|
+
rescue
|
22
|
+
end
|
23
|
+
|
24
|
+
begin
|
25
|
+
@test_object2.delete
|
26
|
+
rescue
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
@test_object3.delete
|
31
|
+
rescue
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should provide #datastream_names' do
|
36
|
+
@test_object.should respond_to(:datastream_names)
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#datastream_names' do
|
40
|
+
class MockDatastreamNames < ActiveFedora::Base
|
41
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
42
|
+
has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return an array of datastream names defined by has_datastream' do
|
46
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
47
|
+
@test_object2 = MockDatastreamNames.new
|
48
|
+
@test_object2.datastream_names.should == ["thumbnail","EAD"]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should provide #add_named_datastream' do
|
53
|
+
@test_object.should respond_to(:add_named_datastream)
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#add_named_datastream' do
|
57
|
+
class MockAddNamedDatastream < ActiveFedora::Base
|
58
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
59
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
60
|
+
has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
|
61
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should add a named datastream to a fedora object' do
|
65
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
66
|
+
@test_object2 = MockAddNamedDatastream.new
|
67
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
68
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
69
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
70
|
+
f.stubs(:content_type).returns("image/jpeg")
|
71
|
+
#check cannot add a datastream with name that does not exist
|
72
|
+
had_exception = false
|
73
|
+
begin
|
74
|
+
@test_object2.add_named_datastream("thumb",{:content_type=>"image/jpeg",:blob=>f})
|
75
|
+
rescue
|
76
|
+
had_exception = true
|
77
|
+
end
|
78
|
+
raise "Did not raise exception with datastream name that does not exist" unless had_exception
|
79
|
+
#check that either blob or file opt must be set
|
80
|
+
had_exception = false
|
81
|
+
begin
|
82
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg"})
|
83
|
+
rescue
|
84
|
+
had_exception = true
|
85
|
+
end
|
86
|
+
raise "Did not raise exception with blob not set" unless had_exception
|
87
|
+
|
88
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f})
|
89
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:file=>f})
|
90
|
+
#check dslabel set from either opt[label] or opt[blob].original_file_name
|
91
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2, :label=>"my_image"})
|
92
|
+
@test_object2.high.first.attributes[:dsLabel].should == "my_image"
|
93
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
94
|
+
@test_object2.high.first.attributes[:dsLabel].should == "dino.jpg"
|
95
|
+
#check opt[content_type] must be set or opt[blob] responds to content_type, already checking if content_type option set above
|
96
|
+
f.expects(:content_type).returns("image/jpeg")
|
97
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f})
|
98
|
+
had_exception = false
|
99
|
+
begin
|
100
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f2})
|
101
|
+
rescue
|
102
|
+
had_exception = true
|
103
|
+
end
|
104
|
+
raise "Did not raise exception if content_type not set" unless had_exception
|
105
|
+
#check mimetype and content type must match if mimetype is specified (if not specified can be anything)
|
106
|
+
f.stubs(:content_type).returns("image/tiff")
|
107
|
+
had_exception = false
|
108
|
+
begin
|
109
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f})
|
110
|
+
rescue
|
111
|
+
had_exception = true
|
112
|
+
end
|
113
|
+
raise "Did not raise exception on content type and mime type mismatch" unless had_exception
|
114
|
+
|
115
|
+
#check for if any mime type allowed
|
116
|
+
@test_object2.add_named_datastream("anymime",{:file=>f})
|
117
|
+
#check datastream created is of type ActiveFedora::Datastream
|
118
|
+
@test_object2.anymime.first.class.should == ActiveFedora::Datastream
|
119
|
+
#if dsid supplied check that conforms to prefix
|
120
|
+
f.stubs(:content_type).returns("image/jpeg")
|
121
|
+
had_exception = false
|
122
|
+
begin
|
123
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f,:dsid=>"DS1"})
|
124
|
+
rescue
|
125
|
+
had_exception = true
|
126
|
+
end
|
127
|
+
raise "Did not raise exception with dsid that does not conform to prefix" unless had_exception
|
128
|
+
#if prefix not set check uses name in CAPS and dsid uses prefix
|
129
|
+
@test_object2.high.first.attributes[:prefix].should == "HIGH"
|
130
|
+
@test_object2.high.first.dsid.match(/HIGH[0-9]/)
|
131
|
+
#check datastreams added with other right properties
|
132
|
+
@test_object2.high.first.attributes[:controlGroup].should == "M"
|
133
|
+
@test_object2.high.first.attributes[:type].should == "ActiveFedora::Datastream"
|
134
|
+
|
135
|
+
#check external datastream
|
136
|
+
@test_object2.add_named_datastream("external",{:dsLocation=>"http://myreasource.com"})
|
137
|
+
#check dslocation goes to dslabel
|
138
|
+
@test_object2.external.first.attributes[:dsLabel].should == "http://myreasource.com"
|
139
|
+
#check datastreams added to fedora (may want to stub this at first)
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should provide #add_named_file_datastream' do
|
145
|
+
@test_object.should respond_to(:add_named_file_datastream)
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#add_named_file_datastream' do
|
149
|
+
class MockAddNamedFileDatastream < ActiveFedora::Base
|
150
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
151
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
152
|
+
has_datastream :name=>"anymime", :type=>ActiveFedora::Datastream, :controlGroup=>'M'
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should add a datastream as controlGroup M with blob set to file' do
|
156
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
157
|
+
@test_object2 = MockAddNamedFileDatastream.new
|
158
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
159
|
+
#these normally supplied in multi-part post request
|
160
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
161
|
+
f.stubs(:content_type).returns("image/jpeg")
|
162
|
+
@test_object2.add_named_file_datastream("thumbnail",f)
|
163
|
+
@test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
164
|
+
:prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
165
|
+
:pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should provide #update_named_datastream' do
|
171
|
+
@test_object.should respond_to(:update_named_datastream)
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '#update_named_datastream' do
|
175
|
+
class MockUpdateNamedDatastream < ActiveFedora::Base
|
176
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should update a datastream and not increment the dsid' do
|
180
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
181
|
+
@test_object2 = MockUpdateNamedDatastream.new
|
182
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
183
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
184
|
+
f.stubs(:content_type).returns("image/jpeg")
|
185
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
186
|
+
f2.stubs(:content_type).returns("image/jpeg")
|
187
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
188
|
+
#check raise exception if dsid not supplied
|
189
|
+
@test_object2.add_named_datastream("thumbnail",{:file=>f})
|
190
|
+
had_exception = false
|
191
|
+
begin
|
192
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f})
|
193
|
+
rescue
|
194
|
+
had_exception = true
|
195
|
+
end
|
196
|
+
raise "Failed to raise exception if dsid not supplied" unless had_exception
|
197
|
+
#raise exception if dsid does not exist
|
198
|
+
had_exception = false
|
199
|
+
begin
|
200
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f,:dsid=>"THUMB100"})
|
201
|
+
rescue
|
202
|
+
had_exception = true
|
203
|
+
end
|
204
|
+
raise "Failed to raise exception if dsid does not exist" unless had_exception
|
205
|
+
#check datastream is updated in place without new dsid
|
206
|
+
@test_object2.thumbnail.size.should == 1
|
207
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
208
|
+
@test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
209
|
+
:content_type=>"image/jpeg",
|
210
|
+
:prefix=>"THUMB", :mimeType=>"image/jpeg",
|
211
|
+
:controlGroup=>"M", :dsid=>"THUMB1",
|
212
|
+
:pid=>@test_object2.pid, :dsID=>"THUMB1",
|
213
|
+
:name=>"thumbnail", :dsLabel=>"minivan.jpg"}
|
214
|
+
@test_object2.thumbnail.first.blob.should == f
|
215
|
+
@test_object2.update_named_datastream("thumbnail",{:file=>f2,:dsid=>"THUMB1"})
|
216
|
+
@test_object2.thumbnail.size.should == 1
|
217
|
+
@test_object2.thumbnail_ids == ["THUMB1"]
|
218
|
+
@test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
219
|
+
:content_type=>"image/jpeg",
|
220
|
+
:prefix=>"THUMB", :mimeType=>"image/jpeg",
|
221
|
+
:controlGroup=>"M", :dsid=>"THUMB1",
|
222
|
+
:pid=>@test_object2.pid, :dsID=>"THUMB1",
|
223
|
+
:name=>"thumbnail", :dsLabel=>"dino.jpg"}
|
224
|
+
@test_object2.thumbnail.first.blob.should == f2
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should provide #create_datastream' do
|
229
|
+
@test_object.should respond_to(:create_datastream)
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#create_datastream' do
|
233
|
+
it 'should create a datastream object using the type of object supplied in the string (does reflection)' do
|
234
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
235
|
+
f.stubs(:content_type).returns("image/jpeg")
|
236
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
237
|
+
ds = @test_object.create_datastream("ActiveFedora::Datastream",{:blob=>f})
|
238
|
+
ds.class.should == ActiveFedora::Datastream
|
239
|
+
ds.blob.should == f
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'should provide #is_named_datastream?' do
|
244
|
+
@test_object.should respond_to(:is_named_datastream?)
|
245
|
+
end
|
246
|
+
|
247
|
+
describe '#is_named_datastream?' do
|
248
|
+
class MockIsNamedDatastream < ActiveFedora::Base
|
249
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should return true if a named datastream exists in model' do
|
253
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
254
|
+
@test_object2 = MockIsNamedDatastream.new
|
255
|
+
@test_object2.is_named_datastream?("thumbnail").should == true
|
256
|
+
@test_object2.is_named_datastream?("thumb").should == false
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
it 'should provide #named_datastreams' do
|
261
|
+
@test_object.should respond_to(:named_datastreams)
|
262
|
+
end
|
263
|
+
|
264
|
+
describe '#named_datastreams' do
|
265
|
+
class MockNamedDatastreams < ActiveFedora::Base
|
266
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
267
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
268
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'should return a hash of datastream names to arrays of datastreams' do
|
272
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
273
|
+
@test_object2 = MockNamedDatastreams.new
|
274
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
|
275
|
+
f.stubs(:content_type).returns("image/jpeg")
|
276
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
277
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
278
|
+
f2.stubs(:content_type).returns("image/jpeg")
|
279
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
280
|
+
@test_object2.thumbnail_file_append(f)
|
281
|
+
@test_object2.high_file_append(f2)
|
282
|
+
@test_object2.external_append({:dsLocation=>"http://myresource.com"})
|
283
|
+
datastreams = @test_object2.named_datastreams
|
284
|
+
datastreams.keys.include?("thumbnail").should == true
|
285
|
+
datastreams.keys.include?("external").should == true
|
286
|
+
datastreams.keys.include?("high").should == true
|
287
|
+
datastreams.keys.size.should == 3
|
288
|
+
datastreams["thumbnail"].size.should == 1
|
289
|
+
datastreams["thumbnail"].first.class.should == ActiveFedora::Datastream
|
290
|
+
datastreams["thumbnail"].first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
291
|
+
:content_type=>"image/jpeg",
|
292
|
+
:prefix=>"THUMB",
|
293
|
+
:mimeType=>"image/jpeg",
|
294
|
+
:controlGroup=>"M",
|
295
|
+
:dsid=>"THUMB1",
|
296
|
+
:pid=>@test_object2.pid,
|
297
|
+
:dsID=>"THUMB1",
|
298
|
+
:name=>"thumbnail", :dsLabel=>"minivan.jpg"}
|
299
|
+
datastreams["thumbnail"].first.blob.should == f
|
300
|
+
datastreams["external"].size.should == 1
|
301
|
+
datastreams["external"].first.class.should == ActiveFedora::Datastream
|
302
|
+
datastreams["external"].first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
303
|
+
:prefix=>"EXTERNAL",
|
304
|
+
:controlGroup=>"E",
|
305
|
+
:dsid=>"EXTERNAL1",
|
306
|
+
:pid=>@test_object2.pid,
|
307
|
+
:dsID=>"EXTERNAL1",
|
308
|
+
:dsLocation=>"http://myresource.com",
|
309
|
+
:name=>"external", :dsLabel=>"http://myresource.com"}
|
310
|
+
datastreams["external"].first.blob.should == nil
|
311
|
+
datastreams["high"].size.should == 1
|
312
|
+
datastreams["high"].first.class.should == ActiveFedora::Datastream
|
313
|
+
datastreams["high"].first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
314
|
+
:content_type=>"image/jpeg",
|
315
|
+
:prefix=>"HIGH",
|
316
|
+
:mimeType=>"image/jpeg",
|
317
|
+
:controlGroup=>"M",
|
318
|
+
:dsid=>"HIGH1",
|
319
|
+
:pid=>@test_object2.pid,
|
320
|
+
:dsID=>"HIGH1",
|
321
|
+
:name=>"high", :dsLabel=>"dino.jpg"}
|
322
|
+
datastreams["high"].first.blob.should == f2
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'should provide #named_datastreams_attributes' do
|
327
|
+
@test_object.should respond_to(:named_datastreams_attributes)
|
328
|
+
end
|
329
|
+
|
330
|
+
describe '#named_datastreams_attributes' do
|
331
|
+
class MockNamedDatastreamsAttributes < ActiveFedora::Base
|
332
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
333
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
334
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should return a hash of datastream names to hash of dsid to attribute hashes' do
|
338
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
339
|
+
@test_object2 = MockNamedDatastreamsAttributes.new
|
340
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
|
341
|
+
f.stubs(:content_type).returns("image/jpeg")
|
342
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
343
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
344
|
+
f2.stubs(:content_type).returns("image/jpeg")
|
345
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
346
|
+
@test_object2.thumbnail_file_append(f)
|
347
|
+
@test_object2.high_file_append(f2)
|
348
|
+
@test_object2.external_append({:dsLocation=>"http://myresource.com"})
|
349
|
+
datastreams_attr = @test_object2.named_datastreams_attributes
|
350
|
+
datastreams_attr.keys.include?("thumbnail").should == true
|
351
|
+
datastreams_attr.keys.include?("external").should == true
|
352
|
+
datastreams_attr.keys.include?("high").should == true
|
353
|
+
datastreams_attr.keys.size.should == 3
|
354
|
+
datastreams_attr["thumbnail"].size.should == 1
|
355
|
+
datastreams_attr["thumbnail"]["THUMB1"].should == {:type=>"ActiveFedora::Datastream",
|
356
|
+
:content_type=>"image/jpeg",
|
357
|
+
:prefix=>"THUMB",
|
358
|
+
:mimeType=>"image/jpeg",
|
359
|
+
:controlGroup=>"M",
|
360
|
+
:dsid=>"THUMB1",
|
361
|
+
:pid=>@test_object2.pid,
|
362
|
+
:dsID=>"THUMB1",
|
363
|
+
:name=>"thumbnail", :dsLabel=>"minivan.jpg"}
|
364
|
+
datastreams_attr["external"].size.should == 1
|
365
|
+
datastreams_attr["external"]["EXTERNAL1"].should == {:type=>"ActiveFedora::Datastream",
|
366
|
+
:prefix=>"EXTERNAL",
|
367
|
+
:controlGroup=>"E",
|
368
|
+
:dsid=>"EXTERNAL1",
|
369
|
+
:pid=>@test_object2.pid,
|
370
|
+
:dsID=>"EXTERNAL1",
|
371
|
+
:dsLocation=>"http://myresource.com",
|
372
|
+
:name=>"external", :dsLabel=>"http://myresource.com"}
|
373
|
+
datastreams_attr["high"].size.should == 1
|
374
|
+
datastreams_attr["high"]["HIGH1"].should == {:type=>"ActiveFedora::Datastream",
|
375
|
+
:content_type=>"image/jpeg",
|
376
|
+
:prefix=>"HIGH",
|
377
|
+
:mimeType=>"image/jpeg",
|
378
|
+
:controlGroup=>"M",
|
379
|
+
:dsid=>"HIGH1",
|
380
|
+
:pid=>@test_object2.pid,
|
381
|
+
:dsID=>"HIGH1",
|
382
|
+
:name=>"high", :dsLabel=>"dino.jpg"}
|
383
|
+
end
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should provide #named_datastreams_ids' do
|
387
|
+
@test_object.should respond_to(:named_datastreams_ids)
|
388
|
+
end
|
389
|
+
|
390
|
+
describe '#named_datastreams_ids' do
|
391
|
+
class MockNamedDatastreamsIds < ActiveFedora::Base
|
392
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
393
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
394
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
395
|
+
end
|
396
|
+
|
397
|
+
it 'should provide a hash of datastreams names to array of datastream ids' do
|
398
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
399
|
+
@test_object2 = MockNamedDatastreamsIds.new
|
400
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
|
401
|
+
f.stubs(:content_type).returns("image/jpeg")
|
402
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
403
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
404
|
+
f2.stubs(:content_type).returns("image/jpeg")
|
405
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
406
|
+
@test_object2.thumbnail_file_append(f)
|
407
|
+
@test_object2.high_file_append(f2)
|
408
|
+
@test_object2.external_append({:dsLocation=>"http://myresource.com"})
|
409
|
+
@test_object2.named_datastreams_ids.should == {"thumbnail"=>["THUMB1"],"high"=>["HIGH1"],"external"=>["EXTERNAL1"]}
|
410
|
+
end
|
411
|
+
end
|
412
|
+
|
413
|
+
it 'should provide #datastreams_attributes' do
|
414
|
+
@test_object.should respond_to(:datastreams_attributes)
|
415
|
+
end
|
416
|
+
|
417
|
+
describe '#datastreams_attributes' do
|
418
|
+
class MockDatastreamsAttributes < ActiveFedora::Base
|
419
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
420
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
421
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'should return a hash of datastream ids to an attribute hash' do
|
425
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
426
|
+
@test_object2 = MockDatastreamsAttributes.new
|
427
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg" ))
|
428
|
+
f.stubs(:content_type).returns("image/jpeg")
|
429
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
430
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
431
|
+
f2.stubs(:content_type).returns("image/jpeg")
|
432
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
433
|
+
@test_object2.thumbnail_file_append(f)
|
434
|
+
@test_object2.high_file_append(f2)
|
435
|
+
@test_object2.external_append({:dsLocation=>"http://myresource.com"})
|
436
|
+
datastreams_attr = @test_object2.datastreams_attributes
|
437
|
+
datastreams_attr.should == {"THUMB1"=>{:type=>"ActiveFedora::Datastream",
|
438
|
+
:content_type=>"image/jpeg",
|
439
|
+
:prefix=>"THUMB",
|
440
|
+
:mimeType=>"image/jpeg",
|
441
|
+
:controlGroup=>"M",
|
442
|
+
:dsid=>"THUMB1",
|
443
|
+
:pid=>@test_object2.pid,
|
444
|
+
:dsID=>"THUMB1",
|
445
|
+
:name=>"thumbnail", :dsLabel=>"minivan.jpg"},
|
446
|
+
"EXTERNAL1"=>{:type=>"ActiveFedora::Datastream",
|
447
|
+
:prefix=>"EXTERNAL",
|
448
|
+
:controlGroup=>"E",
|
449
|
+
:dsid=>"EXTERNAL1",
|
450
|
+
:pid=>@test_object2.pid,
|
451
|
+
:dsID=>"EXTERNAL1",
|
452
|
+
:dsLocation=>"http://myresource.com",
|
453
|
+
:name=>"external", :dsLabel=>"http://myresource.com"},
|
454
|
+
"HIGH1"=>{:type=>"ActiveFedora::Datastream",
|
455
|
+
:content_type=>"image/jpeg",
|
456
|
+
:prefix=>"HIGH",
|
457
|
+
:mimeType=>"image/jpeg",
|
458
|
+
:controlGroup=>"M",
|
459
|
+
:dsid=>"HIGH1",
|
460
|
+
:pid=>@test_object2.pid,
|
461
|
+
:dsID=>"HIGH1",
|
462
|
+
:name=>"high", :dsLabel=>"dino.jpg"}}
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
#
|
467
|
+
# Class level methods
|
468
|
+
#
|
469
|
+
describe '#named_datastreams_desc' do
|
470
|
+
|
471
|
+
class MockNamedDatastreamsDesc < ActiveFedora::Base
|
472
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
473
|
+
end
|
474
|
+
|
475
|
+
it 'should intialize a value to an empty hash and then not modify afterward' do
|
476
|
+
@test_object.named_datastreams_desc.should == {}
|
477
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
478
|
+
@test_object2 = MockNamedDatastreamsDesc.new
|
479
|
+
@test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
|
480
|
+
:type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
|
481
|
+
:controlGroup=>'M'}}
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
describe '#create_named_datastream_finders' do
|
486
|
+
class MockCreateNamedDatastreamFinder < ActiveFedora::Base
|
487
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
488
|
+
has_datastream :name=>"high", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
489
|
+
end
|
490
|
+
|
491
|
+
it 'should create helper methods to get named datastreams or dsids' do
|
492
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
493
|
+
@test_object2 = MockCreateNamedDatastreamFinder.new
|
494
|
+
@test_object2.should respond_to(:thumbnail)
|
495
|
+
@test_object2.should respond_to(:thumbnail_ids)
|
496
|
+
@test_object2.should respond_to(:high)
|
497
|
+
@test_object2.should respond_to(:high_ids)
|
498
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
499
|
+
f2 = File.new(File.join( File.dirname(__FILE__), "../fixtures/dino.jpg" ))
|
500
|
+
f2.stubs(:original_filename).returns("dino.jpg")
|
501
|
+
f.stubs(:content_type).returns("image/jpeg")
|
502
|
+
@test_object2.add_named_datastream("thumbnail",{:content_type=>"image/jpeg",:blob=>f, :label=>"testDS"})
|
503
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
504
|
+
@test_object2.add_named_datastream("high",{:content_type=>"image/jpeg",:blob=>f2})
|
505
|
+
@test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
506
|
+
:prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
507
|
+
:pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"testDS", :name=>"thumbnail", :label=>"testDS"}
|
508
|
+
@test_object2.thumbnail_ids.should == ["THUMB1"]
|
509
|
+
@test_object2.high_ids.include?("HIGH1") == true
|
510
|
+
@test_object2.high_ids.include?("HIGH2") == true
|
511
|
+
@test_object2.high_ids.size.should == 2
|
512
|
+
#just check returning datastream object at this point
|
513
|
+
@test_object2.high.first.class.should == ActiveFedora::Datastream
|
514
|
+
end
|
515
|
+
end
|
516
|
+
|
517
|
+
describe '#create_named_datastream_update_methods' do
|
518
|
+
class MockCreateNamedDatastreamUpdateMethods < ActiveFedora::Base
|
519
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
520
|
+
has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
521
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
522
|
+
end
|
523
|
+
|
524
|
+
it 'should create append method for each has_datastream entry' do
|
525
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
526
|
+
@test_object2 = MockCreateNamedDatastreamUpdateMethods.new
|
527
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
528
|
+
@test_object3 = MockCreateNamedDatastreamUpdateMethods.new
|
529
|
+
@test_object2.should respond_to(:thumbnail_append)
|
530
|
+
@test_object2.should respond_to(:ead_append)
|
531
|
+
f = File.new(File.join( File.dirname(__FILE__), "../fixtures/minivan.jpg"))
|
532
|
+
f.stubs(:content_type).returns("image/jpeg")
|
533
|
+
f.stubs(:original_filename).returns("minivan.jpg")
|
534
|
+
@test_object2.thumbnail_file_append(f)
|
535
|
+
@test_object2.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
536
|
+
:prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
537
|
+
:pid=>@test_object2.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
|
538
|
+
@test_object3.thumbnail_append({:file=>f})
|
539
|
+
@test_object3.thumbnail.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
540
|
+
:prefix=>"THUMB", :content_type=>"image/jpeg", :dsid=>"THUMB1", :dsID=>"THUMB1",
|
541
|
+
:pid=>@test_object3.pid, :mimeType=>"image/jpeg", :controlGroup=>"M", :dsLabel=>"minivan.jpg", :name=>"thumbnail"}
|
542
|
+
@test_object3.external_append({:dsLocation=>"http://myresource.com"})
|
543
|
+
@test_object3.external.first.attributes.should == {:type=>"ActiveFedora::Datastream",
|
544
|
+
:prefix=>"EXTERNAL", :dsid=>"EXTERNAL1", :dsID=>"EXTERNAL1",
|
545
|
+
:pid=>@test_object3.pid, :controlGroup=>"E", :dsLabel=>"http://myresource.com", :dsLocation=>"http://myresource.com", :name=>"external"}
|
546
|
+
end
|
547
|
+
end
|
548
|
+
|
549
|
+
describe '#has_datastream' do
|
550
|
+
class MockHasDatastream < ActiveFedora::Base
|
551
|
+
has_datastream :name=>"thumbnail",:prefix => "THUMB", :type=>ActiveFedora::Datastream, :mimeType=>"image/jpeg", :controlGroup=>'M'
|
552
|
+
has_datastream :name=>"EAD", :type=>ActiveFedora::Datastream, :mimeType=>"application/xml", :controlGroup=>'M'
|
553
|
+
has_datastream :name=>"external", :type=>ActiveFedora::Datastream, :controlGroup=>'E'
|
554
|
+
end
|
555
|
+
|
556
|
+
it 'should cache a definition of named datastream and create helper methods to add/remove/access them' do
|
557
|
+
Fedora::Repository.instance.stubs(:nextid).returns(increment_pid)
|
558
|
+
@test_object2 = MockHasDatastream.new
|
559
|
+
#prefix should default to name in caps if not specified in has_datastream call
|
560
|
+
@test_object2.named_datastreams_desc.should == {"thumbnail"=>{:name=>"thumbnail",:prefix => "THUMB",
|
561
|
+
:type=>"ActiveFedora::Datastream", :mimeType=>"image/jpeg",
|
562
|
+
:controlGroup=>'M'},
|
563
|
+
"EAD"=> {:name=>"EAD", :prefix=>"EAD",
|
564
|
+
:type=>"ActiveFedora::Datastream", :mimeType=>"application/xml",
|
565
|
+
:controlGroup=>'M' },
|
566
|
+
"external"=> {:name=>"external", :prefix=>"EXTERNAL",
|
567
|
+
:type=>"ActiveFedora::Datastream", :controlGroup=>'E' }}
|
568
|
+
@test_object2.should respond_to(:thumbnail_append)
|
569
|
+
@test_object2.should respond_to(:thumbnail_file_append)
|
570
|
+
@test_object2.should respond_to(:thumbnail)
|
571
|
+
@test_object2.should respond_to(:thumbnail_ids)
|
572
|
+
@test_object2.should respond_to(:ead_append)
|
573
|
+
@test_object2.should respond_to(:ead_file_append)
|
574
|
+
@test_object2.should respond_to(:EAD)
|
575
|
+
@test_object2.should respond_to(:EAD_ids)
|
576
|
+
@test_object2.should respond_to(:external)
|
577
|
+
@test_object2.should respond_to(:external_ids)
|
578
|
+
end
|
579
|
+
end
|
580
|
+
end
|