active-fedora 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active-fedora (3.1.0)
4
+ active-fedora (3.1.1)
5
5
  activeresource (~> 3.0.0)
6
6
  activesupport (~> 3.0.0)
7
7
  equivalent-xml
@@ -34,7 +34,9 @@ module ActiveFedora
34
34
  include SemanticNode
35
35
  class_inheritable_accessor :ds_specs, :class_named_datastreams_desc
36
36
  self.class_named_datastreams_desc = {}
37
- self.ds_specs = {'RELS-EXT'=> [ActiveFedora::RelsExtDatastream, "", nil]}#, 'DC'=> [ActiveFedora::Datastream, "", nil]}
37
+
38
+ self.ds_specs = {'RELS-EXT'=> {:type=> ActiveFedora::RelsExtDatastream, :label=>"", :block=>nil}}
39
+
38
40
  attr_accessor :named_datastreams_desc
39
41
 
40
42
 
@@ -97,7 +99,7 @@ module ActiveFedora
97
99
  end
98
100
 
99
101
  def self.datastream_class_for_name(dsid)
100
- ds_specs[dsid] ? ds_specs[dsid].first : ActiveFedora::Datastream
102
+ ds_specs[dsid] ? ds_specs[dsid][:type] : ActiveFedora::Datastream
101
103
  end
102
104
 
103
105
  #This method is used to specify the details of a datastream.
@@ -105,8 +107,7 @@ module ActiveFedora
105
107
  #execute the block, but stores it at the class level, to be executed
106
108
  #by any future instantiations.
107
109
  def self.has_metadata(args, &block)
108
- #@ds_specs ||= Hash.new
109
- ds_specs[args[:name]]= [args[:type], args.fetch(:label,""), block]
110
+ ds_specs[args[:name]]= {:type => args[:type], :label => args.fetch(:label,""), :control_group => args.fetch(:control_group,"X"), :disseminator => args.fetch(:disseminator,""), :url => args.fetch(:url,""),:block => block}
110
111
  end
111
112
 
112
113
  def method_missing(name, *args)
@@ -127,6 +128,7 @@ module ActiveFedora
127
128
  #Saves a Base object, and any dirty datastreams, then updates
128
129
  #the Solr index for this object.
129
130
  def save
131
+
130
132
  # If it's a new object, set the conformsTo relationship for Fedora CMA
131
133
  if new_object?
132
134
  result = create
@@ -199,20 +201,17 @@ module ActiveFedora
199
201
  ds_spec = self.class.ds_specs[dsid]
200
202
  datastreams[dsid] = datastream
201
203
  if (ds_spec)
202
- klass = ds_spec.first
204
+ klass = ds_spec[:type]
203
205
  datastreams[dsid].model = self if klass == RelsExtDatastream
204
206
 
205
- if ds_spec.last.class == Proc
206
- ds_spec.last.call(datastreams[dsid])
207
+ if ds_spec[:block].class == Proc
208
+ ds_spec[:block].call(datastreams[dsid])
207
209
  end
208
- # if klass.respond_to? :from_xml
209
- # ### TODO, this is loading eagerly, we could load it as needed
210
- # klass.from_xml(datastreams[dsid].content, datastreams[dsid])
211
- # end
212
210
  end
213
211
  end
214
212
  end
215
213
 
214
+
216
215
  # Adds datastream to the object. Saves the datastream to fedora upon adding.
217
216
  # If datastream does not have a DSID, a unique DSID is generated
218
217
  # :prefix option will set the prefix on auto-generated DSID
@@ -994,23 +993,46 @@ module ActiveFedora
994
993
  private
995
994
  def configure_defined_datastreams
996
995
  if self.class.ds_specs
997
- self.class.ds_specs.each do |name,ar|
996
+ self.class.ds_specs.each do |name,ds_config|
998
997
  if self.datastreams.has_key?(name)
999
998
  #attributes = self.datastreams[name].attributes
1000
999
  else
1001
- ds = ar.first.new(inner_object, name)
1002
- ds.model = self if ar.first == RelsExtDatastream
1003
- ds.dsLabel = ar[1] if ar[1].present?
1000
+ ds = ds_config[:type].new(inner_object, name)
1001
+ ds.model = self if ds_config[:type] == RelsExtDatastream
1002
+ ds.dsLabel = ds_config[:label] if ds_config[:label].present?
1003
+ ds.controlGroup = ds_config[:control_group]
1004
1004
  # If you called has_metadata with a block, pass the block into the Datastream class
1005
- if ar.last.class == Proc
1006
- ar.last.call(ds)
1005
+ if ds_config[:block].class == Proc
1006
+ ds_config[:block].call(ds)
1007
1007
  end
1008
- #ds.attributes = attributes.merge(ds.attributes)
1008
+ additional_attributes_for_external_and_redirect_control_groups(ds, ds_config)
1009
1009
  self.add_datastream(ds)
1010
1010
  end
1011
1011
  end
1012
1012
  end
1013
1013
  end
1014
+
1015
+
1016
+ # This method provides validation of proper options for control_group 'E' and 'R' and builds an attribute hash to be merged back into ds.attributes prior to saving
1017
+ #
1018
+ # @param [Object] ds The datastream
1019
+ # @param [Object] ds_config hash of options which may contain :disseminator and :url
1020
+ def additional_attributes_for_external_and_redirect_control_groups(ds,ds_config)
1021
+ if ds.controlGroup=='E'
1022
+ raise "Must supply either :disseminator or :url if you specify :control_group => 'E'" if (ds_config[:disseminator].empty? && ds_config[:url].empty?)
1023
+ if !ds_config[:disseminator].empty?
1024
+ ds.dsLocation= "#{RubydoraConnection.instance.options[:url]}/objects/#{pid}/methods/#{ds_config[:disseminator]}"
1025
+ elsif !ds_config[:url].empty?
1026
+ ds.dsLocation= ds_config[:url]
1027
+ end
1028
+ elsif ds.controlGroup=='R'
1029
+ raise "Must supply a :url if you specify :control_group => 'R'" if (ds_config[:url].empty?)
1030
+ ds.dsLocation= ds_config[:url]
1031
+ end
1032
+ end
1033
+
1034
+
1035
+
1014
1036
 
1015
1037
  # Deals with preparing new object to be saved to Fedora, then pushes it and its datastreams into Fedora.
1016
1038
  def create
@@ -13,7 +13,7 @@ module ActiveFedora
13
13
  end
14
14
 
15
15
  def self.pid_from_ruby_class(klass,attrs={})
16
- sanitized_class_name = klass.name.gsub(/(::)/, '_')
16
+
17
17
  unless klass.respond_to? :pid_suffix
18
18
  pid_suffix = attrs.has_key?(:pid_suffix) ? attrs[:pid_suffix] : CMODEL_PID_SUFFIX
19
19
  else
@@ -24,7 +24,12 @@ module ActiveFedora
24
24
  else
25
25
  namespace = klass.pid_namespace
26
26
  end
27
- return "info:fedora/#{namespace}:#{sanitized_class_name}#{pid_suffix}"
27
+ return "info:fedora/#{namespace}:#{sanitized_class_name(klass)}#{pid_suffix}"
28
+ end
29
+
30
+ ###Override this, if you prefer your class names serialized some other way
31
+ def self.sanitized_class_name(klass)
32
+ klass.name.gsub(/(::)/, '_')
28
33
  end
29
34
 
30
35
  def self.models_asserted_by(obj)
@@ -41,11 +46,17 @@ module ActiveFedora
41
46
  end
42
47
 
43
48
  if models_array.empty?
44
- models_array = [ActiveFedora::Base]
49
+ models_array = [default_model(obj)]
45
50
  end
46
51
 
47
52
  return models_array
48
53
  end
54
+
55
+ ### Returns a ruby class to use if no other class could be find to instantiate
56
+ ### Override this method if you need something other than the default strategy
57
+ def self.default_model(obj)
58
+ ActiveFedora::Base
59
+ end
49
60
 
50
61
  # Returns a ruby class corresponding to the given uri if one can be found.
51
62
  # Returns false if no corresponding class can be found.
@@ -9,25 +9,6 @@ module ActiveFedora
9
9
  obj
10
10
  end
11
11
 
12
- # def datastreams
13
- # @datastreams ||= begin
14
- # h = Hash.new { |h,k| h[k] = datastream_object_for(k) }
15
-
16
- # begin
17
- # datastreams_xml = repository.datastreams(:pid => pid)
18
- # datastreams_xml.gsub! '<objectDatastreams', '<objectDatastreams xmlns="http://www.fedora.info/definitions/1/0/access/"' unless datastreams_xml =~ /xmlns=/
19
- # doc = Nokogiri::XML(datastreams_xml)
20
- # doc.xpath('//access:datastream', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).each do |ds|
21
- # h[ds['dsid']] = datastream_object_for ds['dsid']
22
- # end
23
- # rescue RestClient::ResourceNotFound
24
- # end
25
-
26
- # h
27
- # end
28
- # end
29
-
30
-
31
12
  def datastream_object_for dsid
32
13
  klass = original_class.datastream_class_for_name(dsid)
33
14
  klass.new self, dsid
@@ -33,7 +33,7 @@ module ActiveFedora
33
33
  literal = statement.object.kind_of?(RDF::Literal)
34
34
  predicate = self.short_predicate(statement.predicate)
35
35
  object = literal ? statement.object.value : statement.object.to_str
36
- tmpl.model.add_relationship(predicate, object)
36
+ tmpl.model.add_relationship(predicate, object, literal)
37
37
  end
38
38
  end
39
39
  tmpl.model.relationships_are_dirty = false
@@ -19,40 +19,29 @@ module ActiveFedora
19
19
  # Add a relationship to the Object.
20
20
  # @param predicate
21
21
  # @param object Either a string URI or an object that is a kind of ActiveFedora::Base
22
- def add_relationship(predicate, obj, literal=false)
23
- unless relationship_exists?(internal_uri, predicate, obj)
24
- register_triple(internal_uri, predicate, obj)
25
- #need to call here to indicate update of named_relationships
22
+ def add_relationship(predicate, target, literal=false)
23
+ stmt = build_statement(internal_uri, predicate, target, literal)
24
+ unless relationships.has_statement? stmt
25
+ relationships.insert stmt
26
26
  @relationships_are_dirty = true
27
27
  rels_ext.dirty = true
28
28
  end
29
29
  end
30
30
 
31
- # Add a RDF triple to the relationship graph
32
- # @param pid a string represending the pid of the subject
33
- # @param predicate a predicate symbol
34
- # @param target an object to store
35
- def register_triple(pid, predicate, target)
36
- self.relationships_are_dirty = true
37
- relationships.insert build_statement(pid, predicate, target)
38
-
39
- # register_subject(subject)
40
- # register_predicate(subject, predicate)
41
- # relationships[subject][predicate] << object
42
- end
43
-
44
31
  # Create an RDF statement
45
32
  # @param uri a string represending the subject
46
33
  # @param predicate a predicate symbol
47
34
  # @param target an object to store
48
- def build_statement(uri, predicate, target)
35
+ def build_statement(uri, predicate, target, literal=nil)
49
36
  raise "Not allowed anymore" if uri == :self
50
37
  target = target.internal_uri if target.respond_to? :internal_uri
51
38
  subject = RDF::URI.new(uri) #TODO cache
52
- begin
53
- literal = URI.parse(target).scheme.nil?
54
- rescue URI::InvalidURIError
55
- literal = false
39
+ if literal.nil?
40
+ begin
41
+ literal = URI.parse(target).scheme.nil?
42
+ rescue URI::InvalidURIError
43
+ literal = false
44
+ end
56
45
  end
57
46
  raise ArgumentError, "Invalid target \"#{target}\". Must have namespace." unless literal || /^info/.match(target)
58
47
  object = literal ? RDF::Literal.new(target) : RDF::URI.new(target)
@@ -88,18 +77,6 @@ module ActiveFedora
88
77
  self.class.vocabularies[xmlns][rel_predicate]
89
78
  end
90
79
 
91
- # def register_subject(subject)
92
- # if !relationships.has_key?(subject)
93
- # relationships[subject] = {}
94
- # end
95
- # end
96
-
97
- # def register_predicate(subject, predicate)
98
- # register_subject(subject)
99
- # if !relationships[subject].has_key?(predicate)
100
- # relationships[subject][predicate] = []
101
- # end
102
- # end
103
80
 
104
81
  # ** EXPERIMENTAL **
105
82
  #
@@ -112,15 +89,6 @@ module ActiveFedora
112
89
  rels_ext.dirty = true
113
90
  end
114
91
 
115
-
116
-
117
- # ** EXPERIMENTAL **
118
- #
119
- # Returns true if a relationship exists for the given subject, predicate, and object triple
120
- def relationship_exists?(subject, predicate, object)
121
- relationships.has_statement? build_statement(subject, predicate, object)
122
- end
123
-
124
92
  def inbound_relationships(response_format=:uri)
125
93
  rel_values = {}
126
94
  inbound_relationship_predicates.each_pair do |name,predicate|
@@ -147,14 +115,22 @@ module ActiveFedora
147
115
  relationships.statements
148
116
  end
149
117
 
150
- def relationships
118
+ # If no arguments are supplied, return the whole RDF::Graph.
119
+ # if a predicate is supplied as a parameter, then it returns the result of quering the graph with that predicate
120
+ def relationships(*args)
151
121
  unless @subject
152
122
  raise "Must have internal_uri" unless internal_uri
153
123
  @subject = RDF::URI.new(internal_uri)
154
124
  end
155
125
  @relationships ||= RDF::Graph.new
156
126
  load_relationships if !relationships_loaded
157
- @relationships
127
+
128
+ return @relationships if args.empty?
129
+ rels = @relationships.query(:predicate => find_graph_predicate(args.first))
130
+ results = []
131
+ rels.each_object {|o| results << o.to_s }
132
+ results
133
+
158
134
  end
159
135
 
160
136
  def load_relationships
@@ -201,8 +177,8 @@ module ActiveFedora
201
177
  def ids_for_outbound(predicate)
202
178
  id_array = []
203
179
  res = relationships.query(:predicate => find_graph_predicate(predicate))
204
- res.each_object do |o|
205
- id_array << o.to_s.gsub("info:fedora/", "")
180
+ relationships(predicate).each do |o|
181
+ id_array << o.gsub("info:fedora/", "")
206
182
  end
207
183
  id_array
208
184
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
@@ -6,20 +6,23 @@ def mock_client
6
6
  @mock_client
7
7
  end
8
8
 
9
- def stub_get(pid, record_exists=false)
9
+ def stub_get(pid, datastreams=nil, record_exists=false)
10
10
  pid.gsub!(/:/, '%3A')
11
11
  mock_client.stubs(:[]).with("objects/#{pid}?format=xml").returns(stub('get getter', :get=>'foobar')) if record_exists
12
12
  # @mock_client.expects(:[]).with("objects/#{pid}?format=xml").raises(RestClient::ResourceNotFound) unless record_exists
13
13
  mock_client.stubs(:[]).with("objects/#{pid}/datastreams?format=xml").returns(@getter)
14
- ['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
14
+ datastreams ||= ['someData', 'withText', 'withText2', 'RELS-EXT']
15
+ datastreams.each do |dsid|
15
16
  mock_client.stubs(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").returns(@getter)
16
17
  end
17
18
  end
18
19
  def stub_ingest(pid)
19
- mock_client.stubs(:[]).with("objects/#{pid || 'new'}").returns(stub("ingester", :post=>pid))
20
+ n = pid.gsub(/:/, '%3A')
21
+ mock_client.stubs(:[]).with("objects/#{n || 'new'}").returns(stub("ingester", :post=>pid))
20
22
  end
21
23
 
22
24
  def stub_add_ds(pid, dsids)
25
+ pid.gsub!(/:/, '%3A')
23
26
  dsids.each do |dsid|
24
27
  client = mock_client.stubs(:[]).with do |params|
25
28
  /objects\/#{pid}\/datastreams\/#{dsid}/.match(params)
@@ -106,30 +106,132 @@ describe ActiveFedora::Base do
106
106
  end
107
107
 
108
108
  describe "has_metadata" do
109
- before :each do
110
- @mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams?format=xml").returns(@getter)
111
- @mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/RELS-EXT/content").returns(@getter)
109
+ describe "creates datastreams" do
110
+ before :each do
111
+ @mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams?format=xml").returns(@getter)
112
+ @mock_client.stubs(:[]).with("objects/monkey%3A99/datastreams/RELS-EXT/content").returns(@getter)
113
+
114
+ #Update record
115
+ @mock_client.stubs(:[]).with("objects/monkey%3A99").returns(stub('post', :post=>'monkey:99'))
116
+ #Update datastream
117
+ ['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
118
+ @mock_client.stubs(:[]).with {|params| /objects\/monkey%3A99\/datastreams\/#{dsid}/.match(params)}.returns(stub('post', :post=>'monkey:99', :get=>''))
119
+ end
120
+
121
+ @n = FooHistory.new(:pid=>"monkey:99")
122
+ @n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
123
+ @n.expects(:update_index)
124
+ @n.save
125
+ end
112
126
 
113
- #Update record
114
- @mock_client.stubs(:[]).with("objects/monkey%3A99").returns(stub('post', :post=>'monkey:99'))
115
- #Update datastream
116
- ['someData', 'withText', 'withText2', 'RELS-EXT'].each do |dsid|
117
- @mock_client.stubs(:[]).with {|params| /objects\/monkey%3A99\/datastreams\/#{dsid}/.match(params)}.returns(stub('post', :post=>'monkey:99', :get=>''))
127
+ it "should create specified datastreams with specified fields" do
128
+ @n.datastreams["someData"].should_not be_nil
129
+ @n.datastreams["someData"].fubar_values='bar'
130
+ @n.datastreams["someData"].fubar_values.should == ['bar']
131
+ @n.datastreams["withText2"].dsLabel.should == "withLabel"
118
132
  end
133
+ end
134
+
135
+
136
+ it "should create specified datastreams with appropriate control group" do
137
+ stub_ingest('monkey:99')
138
+ stub_add_ds('monkey:99', ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
139
+ stub_get('monkey:99', ['RELS-EXT', 'DC', 'rightsMetadata', 'properties', 'descMetadata', 'UKETD_DC'])
140
+ class UketdObject < ActiveFedora::Base
141
+ has_metadata :name => "rightsMetadata", :label=>"Rights metadata", :type => ActiveFedora::NokogiriDatastream
142
+
143
+ # Uses the Hydra MODS Article profile for tracking most of the descriptive metadata
144
+ # TODO: define terminology for ETD
145
+ has_metadata :name => "descMetadata", :label=>"MODS metadata", :control_group=>"M", :type => ActiveFedora::NokogiriDatastream
146
+
147
+ has_metadata :name => "UKETD_DC", :label=>"UKETD_DC metadata", :control_group => "E", :disseminator=>"hull-sDef:uketdObject/getUKETDMetadata", :type => ActiveFedora::NokogiriDatastream
119
148
 
120
- @n = FooHistory.new(:pid=>"monkey:99")
121
- @n.datastreams['RELS-EXT'].expects(:changed?).returns(true).at_least_once
122
- @n.expects(:update_index)
149
+ has_metadata :name => "DC", :type => ActiveFedora::NokogiriDatastream, :label=>"DC admin metadata"
150
+
151
+ # A place to put extra metadata values
152
+ has_metadata :name => "properties", :label=>"Workflow properties", :type => ActiveFedora::MetadataDatastream do |m|
153
+ m.field 'collection', :string
154
+ m.field 'depositor', :string
155
+ end
156
+
157
+ end
158
+ @n = UketdObject.new(:pid=>"monkey:99")
123
159
  @n.save
160
+ @n.datastreams["DC"].controlGroup.should eql("X")
161
+ @n.datastreams["rightsMetadata"].controlGroup.should eql("X")
162
+ @n.datastreams["properties"].controlGroup.should eql("X")
163
+ @n.datastreams["descMetadata"].controlGroup.should eql("M")
164
+ @n.datastreams["UKETD_DC"].controlGroup.should eql("E")
124
165
  end
125
166
 
126
- it "should create specified datastreams with specified fields" do
127
- @n.datastreams["someData"].should_not be_nil
128
- @n.datastreams["someData"].fubar_values='bar'
129
- @n.datastreams["someData"].fubar_values.should == ['bar']
130
- @n.datastreams["withText2"].dsLabel.should == "withLabel"
167
+ context ":control_group => 'E'" do
168
+ before do
169
+ stub_ingest(@this_pid)
170
+ stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator', 'externalUrl'])
171
+ end
172
+ it "should raise an error without :disseminator or :url option" do
173
+ class MoreFooHistory < ActiveFedora::Base
174
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "E"
175
+ end
176
+ lambda { @n = MoreFooHistory.new }.should raise_exception
177
+ end
178
+
179
+ it "should allow :control_group => 'E' with a :url option" do
180
+ class MoreFooHistory < ActiveFedora::Base
181
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "E", :url => "http://exampl.com/mypic.jpg"
182
+ end
183
+ @n = MoreFooHistory.new
184
+ @n.save
185
+ end
186
+ it "should raise an error if :url is malformed" do
187
+ class MoreFooHistory < ActiveFedora::Base
188
+ has_metadata :type => ActiveFedora::NokogiriDatastream, :name=>"externalUrl", :url=>"my_rul", :control_group => "E"
189
+ end
190
+ client = mock_client.stubs(:[]).with do |params|
191
+ /objects\/#{@this_pid}\/datastreams\/externalUrl/.match(params)
192
+ end
193
+ client.raises(RuntimeError, "Error adding datastream externalUrl for object changeme:4020. See logger for details")
194
+ @n = MoreFooHistory.new
195
+ lambda {@n.save }.should raise_exception
196
+ end
131
197
  end
132
198
 
199
+ context ":control_group => 'R'" do
200
+ before do
201
+ stub_ingest(@this_pid)
202
+ stub_add_ds(@this_pid, ['RELS-EXT', 'externalDisseminator' ])
203
+ end
204
+ it "should raise an error without :url option" do
205
+ class MoreFooHistory < ActiveFedora::Base
206
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "R"
207
+ end
208
+ lambda { @n = MoreFooHistory.new }.should raise_exception
209
+ end
210
+
211
+ it "should work with a valid :url option" do
212
+ class MoreFooHistory < ActiveFedora::Base
213
+ has_metadata :type=>ActiveFedora::MetadataDatastream, :name=>"externalDisseminator",:control_group => "R", :url => "http://exampl.com/mypic.jpg"
214
+ end
215
+ @n = MoreFooHistory.new
216
+ @n.save
217
+ end
218
+ it "should not take a :disseminator option without a :url option" do
219
+ class MoreFooHistory < ActiveFedora::Base
220
+ has_metadata :type=>ActiveFedora::NokogiriDatastream, :name=>"externalDisseminator", :control_group => "R", :disseminator => "foo:s-def/hull-cModel:Foo"
221
+ end
222
+ lambda { @n = MoreFooHistory.new }.should raise_exception
223
+ end
224
+ it "should raise an error if :url is malformed" do
225
+ class MoreFooHistory < ActiveFedora::Base
226
+ has_metadata :type => ActiveFedora::NokogiriDatastream, :name=>"externalUrl", :url=>"my_rul", :control_group => "R"
227
+ end
228
+ client = mock_client.stubs(:[]).with do |params|
229
+ /objects\/#{@this_pid}\/datastreams\/externalUrl/.match(params)
230
+ end
231
+ client.raises(RuntimeError, "Error adding datastream externalUrl for object changeme:4020. See logger for details")
232
+ lambda {MoreFooHistory.new }.should raise_exception
233
+ end
234
+ end
133
235
  end
134
236
 
135
237
 
@@ -195,11 +297,9 @@ describe ActiveFedora::Base do
195
297
 
196
298
  describe '#add_relationship' do
197
299
  it 'should call #add_relationship on the rels_ext datastream' do
198
- mock_rels_ext = mock("rels-ext")
199
- mock_rels_ext.expects(:dirty=).with(true)
200
- @test_object.expects(:relationship_exists?).returns(false).once()
201
- @test_object.expects(:rels_ext).returns(mock_rels_ext).at_least_once
202
- @test_object.add_relationship("predicate", "object")
300
+ @test_object.add_relationship("predicate", "info:fedora/object")
301
+ pred = @test_object.class.vocabularies["info:fedora/fedora-system:def/relations-external#"]["predicate"]
302
+ @test_object.relationships.should have_statement(RDF::Statement.new(RDF::URI.new(@test_object.internal_uri), pred, RDF::URI.new("info:fedora/object")))
203
303
  end
204
304
 
205
305
  it "should update the RELS-EXT datastream and set the datastream as dirty when relationships are added" do
@@ -279,7 +379,7 @@ describe ActiveFedora::Base do
279
379
  stub_add_ds(@this_pid, ['RELS-EXT'])
280
380
  @test_object.persisted?.should be false
281
381
  @test_object.expects(:update_index)
282
- stub_get(@this_pid, true)
382
+ stub_get(@this_pid, nil, true)
283
383
  @test_object.save.should == true
284
384
  @test_object.persisted?.should be true
285
385
  end
@@ -418,12 +518,6 @@ describe ActiveFedora::Base do
418
518
  end
419
519
 
420
520
  describe ".to_solr" do
421
-
422
- # before(:all) do
423
- # # Revert to default mappings after running tests
424
- # ActiveFedora::SolrService.load_mappings
425
- # end
426
-
427
521
  after(:all) do
428
522
  # Revert to default mappings after running tests
429
523
  ActiveFedora::SolrService.load_mappings
@@ -443,8 +537,7 @@ describe ActiveFedora::Base do
443
537
  end
444
538
 
445
539
  it "should omit base metadata and RELS-EXT if :model_only==true" do
446
- @test_object.add_relationship(:has_part, "foo")
447
- # @test_object.expects(:modified_date).returns("mDate")
540
+ @test_object.add_relationship(:has_part, "foo", true)
448
541
  solr_doc = @test_object.to_solr(Hash.new, :model_only => true)
449
542
  solr_doc["system_create_dt"].should be_nil
450
543
  solr_doc["system_modified_dt"].should be_nil
@@ -14,7 +14,7 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
14
14
  end
15
15
 
16
16
  before(:each) do
17
- stub_get("_nextid_")
17
+ stub_get("_nextid_", ['RELS-EXT', 'sensitive_passages', 'significant_passages', 'dublin_core', 'properties'])
18
18
  Rubydora::Repository.any_instance.stubs(:client).returns(@mock_client)
19
19
  ActiveFedora::RubydoraConnection.instance.stubs(:nextid).returns("_nextid_")
20
20
  @test_ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, nil)
@@ -23,7 +23,7 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
23
23
  end
24
24
  it "from_xml should parse everything correctly" do
25
25
  #originally just tested that lcsh encoding and stuff worked, but the other stuff is worth testing
26
- stub_get("meh:leh")
26
+ stub_get("meh:leh", ['RELS-EXT', 'sensitive_passages', 'significant_passages', 'dublin_core', 'properties'])
27
27
  stub_get_content("meh:leh", ['dublin_core'])
28
28
  ActiveFedora::RubydoraConnection.instance.expects(:nextid).returns("meh:leh")
29
29
  tmpl = OralHistorySampleModel.new.datastreams['dublin_core']
@@ -91,32 +91,22 @@ describe ActiveFedora::RelsExtDatastream do
91
91
  @test_obj.ids_for_outbound("foo").should == ["foo:bar"]
92
92
  end
93
93
  it "should handle un-mapped literals" do
94
- pending
95
94
  xml = "
96
- <foxml:datastream ID=\"RELS-EXT\" STATE=\"A\" CONTROL_GROUP=\"X\" VERSIONABLE=\"true\" xmlns:foxml=\"info:fedora/fedora-system:def/foxml#\">
97
- <foxml:datastreamVersion ID=\"RELS-EXT.0\" LABEL=\"\" CREATED=\"2011-09-20T19:48:43.714Z\" MIMETYPE=\"text/xml\" SIZE=\"622\">
98
- <foxml:xmlContent>
99
- <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">
95
+ <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:oai=\"http://www.openarchives.org/OAI/2.0/\">
100
96
  <rdf:Description rdf:about=\"info:fedora/changeme:3489\">
101
97
  <hasModel xmlns=\"info:fedora/fedora-system:def/model#\" rdf:resource=\"info:fedora/afmodel:ActiveFedora_Base\"/>
102
98
  <isPartOf xmlns=\"info:fedora/fedora-system:def/relations-external#\" rdf:resource=\"info:fedora/demo:11\"/>
103
99
  <isMemberOf xmlns=\"info:fedora/fedora-system:def/relations-external#\" rdf:resource=\"info:fedora/demo:10\"/>
104
- <hasMetadata xmlns=\"info:fedora/fedora-system:def/relations-external#\">oai:hull.ac.uk:hull:2708</hasMetadata>
100
+ <oai:itemID>oai:hull.ac.uk:hull:2708</oai:itemID>
105
101
  </rdf:Description>
106
- </rdf:RDF>
107
- </foxml:xmlContent>
108
- </foxml:datastreamVersion>\n</foxml:datastream>\n"
109
- doc = Nokogiri::XML::Document.parse(xml)
110
- new_ds = ActiveFedora::RelsExtDatastream.new
111
- ActiveFedora::RelsExtDatastream.from_xml(new_ds,doc.root)
112
- new_ext = new_ds.to_rels_ext('changeme:3489')
113
- new_ext.should match "<hasMetadata xmlns=\"info:fedora/fedora-system:def/relations-external#\">oai:hull.ac.uk:hull:2708</hasMetadata>"
102
+ </rdf:RDF>"
103
+ model = ActiveFedora::Base.new
104
+ new_ds = ActiveFedora::RelsExtDatastream.new(nil, nil)
105
+ new_ds.model = model
106
+ ActiveFedora::RelsExtDatastream.from_xml(xml, new_ds)
107
+ new_ext = new_ds.to_rels_ext()
108
+ new_ext.should match "<ns0:itemID>oai:hull.ac.uk:hull:2708</ns0:itemID>"
114
109
 
115
110
  end
116
111
  end
117
-
118
-
119
-
120
- it "should treat :self and self.pid as equivalent subjects"
121
-
122
112
  end
@@ -316,8 +316,6 @@ describe ActiveFedora::SemanticNode do
316
316
  local_node.expects(:relationship_query).with("parts")
317
317
  local_node.parts_query
318
318
  end
319
-
320
- it "resulting finder should provide option of filtering results by :type"
321
319
  end
322
320
 
323
321
  describe '#create_outbound_relationship_finders' do
@@ -383,7 +381,6 @@ describe ActiveFedora::SemanticNode do
383
381
  result.should include("demo:10")
384
382
  end
385
383
 
386
- it "should provide option of filtering results by :type"
387
384
  end
388
385
 
389
386
  describe " resulting _ids finder" do
@@ -489,10 +486,15 @@ describe ActiveFedora::SemanticNode do
489
486
  end
490
487
 
491
488
  describe ".add_relationship" do
492
- it "should add relationship to the relationships hash" do
489
+ it "should add relationship to the relationships graph" do
493
490
  @node.add_relationship(@test_relationship.predicate, @test_relationship.object)
494
491
  @node.ids_for_outbound("isMemberOf").should == ['demo:9']
495
492
  end
493
+
494
+ it "should add a literal relationship to the relationships graph" do
495
+ @node.add_relationship(@test_relationship.predicate, @test_relationship.object, true)
496
+ @node.ids_for_outbound("isMemberOf").should == ['demo:9']
497
+ end
496
498
 
497
499
  it "adding relationship to an instance should not affect class-level relationships hash" do
498
500
  local_test_node1 = SpecNode.new
@@ -516,20 +518,6 @@ describe ActiveFedora::SemanticNode do
516
518
  end
517
519
 
518
520
 
519
- it "should provide a relationship setter"
520
- it "should provide a relationship getter"
521
- it "should provide a relationship deleter"
522
-
523
- describe '.register_triple' do
524
- it 'should add triples to the relationships hash' do
525
- @node.register_triple(@node.internal_uri, :is_part_of, "info:fedora/demo:10")
526
- @node.register_triple(@node.internal_uri, :is_member_of, "info:fedora/demo:11")
527
- @node.ids_for_outbound(:is_part_of).should == ['demo:10']
528
- @node.ids_for_outbound(:is_member_of).should == ['demo:11']
529
- end
530
-
531
- it "should not be a class level method"
532
- end
533
521
 
534
522
  it 'should provide #predicate_lookup that maps symbols to common RELS-EXT predicates' do
535
523
  SpecNode.should respond_to(:predicate_lookup)
@@ -570,18 +558,6 @@ describe ActiveFedora::SemanticNode do
570
558
 
571
559
  end
572
560
  end
573
-
574
- describe '#relationship_exists?' do
575
- it 'should return true if a relationship does exist' do
576
- @test_object3 = SpecNode2.new
577
- @test_object3.pid = increment_pid
578
- r = ActiveFedora::Relationship.new({:subject=>:self,:predicate=>:has_member,:object=>@test_object3})
579
- @test_object.relationship_exists?(@test_object.internal_uri,r.predicate,r.object).should == false
580
- @test_object.expects(:rels_ext).returns(stub("rels_ext", :dirty= => true))
581
- @test_object.add_relationship(r.predicate, r.object)
582
- @test_object.relationship_exists?(@test_object.internal_uri,r.predicate,r.object).should == true
583
- end
584
- end
585
561
 
586
562
  describe '#assert_kind_of' do
587
563
  it 'should raise an exception if object supplied is not the correct type' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 1
9
- - 0
10
- version: 3.1.0
9
+ - 1
10
+ version: 3.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Zumwalt
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-11-07 00:00:00 -06:00
19
+ date: 2011-11-08 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency