active-fedora 5.0.0.rc4 → 5.0.0.rc5

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module ActiveFedora
7
7
  attr_accessor :last_modified, :fields
8
8
  before_create :add_mime_type, :add_ds_location, :validate_content_present
9
9
 
10
- def initialize(digital_object, dsid, options={})
10
+ def initialize(digital_object=nil, dsid=nil, options={})
11
11
  ## When you use the versions feature of rubydora (0.5.x), you need to have a 3 argument constructor
12
12
  self.fields={}
13
13
  super
@@ -43,6 +43,12 @@ module ActiveFedora
43
43
  changed?
44
44
  end
45
45
 
46
+ # @abstract Override this in your concrete datastream class.
47
+ # @return [boolean] does this datastream contain metadata (not file data)
48
+ def metadata?
49
+ false
50
+ end
51
+
46
52
  # Deprecated
47
53
  def dirty
48
54
  changed?
@@ -77,7 +83,6 @@ module ActiveFedora
77
83
  return create if new?
78
84
  repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid })
79
85
  reset_profile_attributes
80
- #Datastream.new(digital_object, dsid)
81
86
  self
82
87
  end
83
88
  end
@@ -22,9 +22,9 @@ module ActiveFedora
22
22
  def serialize_datastreams
23
23
  datastreams.each {|k, ds| ds.serialize! }
24
24
  self.metadata_is_dirty = datastreams.any? do |k,ds|
25
- ds.changed? && (ds.kind_of?(ActiveFedora::NokogiriDatastream) || ds.instance_of?(ActiveFedora::RelsExtDatastream) || ds.kind_of?(ActiveFedora::RDFDatastream))
25
+ ds.changed? && ds.metadata?
26
26
  end
27
- true
27
+ true
28
28
  end
29
29
 
30
30
  # Adds the disseminator location to the datastream after the pid has been established
@@ -106,7 +106,7 @@ module ActiveFedora
106
106
  def metadata_streams
107
107
  results = []
108
108
  datastreams.each_value do |ds|
109
- if ds.kind_of?(ActiveFedora::RDFDatastream) || ds.kind_of?(ActiveFedora::NokogiriDatastream)
109
+ if ds.metadata? && !ds.kind_of?(ActiveFedora::RelsExtDatastream)
110
110
  results << ds
111
111
  end
112
112
  end
@@ -24,7 +24,7 @@ module ActiveFedora
24
24
  # @param [ActiveFedora::NokogiriDatastream] tmpl the Datastream object that you are building @default a new instance of this class
25
25
  # Careful! If you call this from a constructor, be sure to provide something 'ie. self' as the @tmpl. Otherwise, you will get an infinite loop!
26
26
  def self.from_xml(xml, tmpl=nil)
27
- tmpl = self.new(nil, nil) if tmpl.nil? ## This path is used only for unit testing (e.g. MarpaDCDatastream.from_xml(fixture("data.xml")) )
27
+ tmpl = self.new if tmpl.nil? ## This path is used only for unit testing (e.g. MarpaDCDatastream.from_xml(fixture("data.xml")) )
28
28
 
29
29
  if !xml.present?
30
30
  tmpl.ng_xml = self.xml_template
@@ -78,6 +78,12 @@ module ActiveFedora
78
78
  def ng_xml_changed?
79
79
  changed_attributes.has_key? 'ng_xml'
80
80
  end
81
+
82
+ # Indicates that this datastream has metadata content.
83
+ # @return true
84
+ def metadata?
85
+ true
86
+ end
81
87
 
82
88
  def content=(content)
83
89
  super
@@ -8,12 +8,12 @@ module ActiveFedora
8
8
  # If it's a new object, set the conformsTo relationship for Fedora CMA
9
9
  if new_object?
10
10
  result = create
11
- update_index if ENABLE_SOLR_UPDATES
11
+ update_index if create_needs_index?
12
12
  else
13
13
  result = update
14
- update_index if @metadata_is_dirty == true && ENABLE_SOLR_UPDATES
14
+ update_index if update_needs_index?
15
15
  end
16
- @metadata_is_dirty = false
16
+ self.metadata_is_dirty = false
17
17
  return result
18
18
  end
19
19
 
@@ -82,6 +82,19 @@ module ActiveFedora
82
82
  end
83
83
  end
84
84
 
85
+ protected
86
+
87
+ # Determines whether a create operation cause a solr index of this object.
88
+ # Override this if you need different behavior
89
+ def create_needs_index?
90
+ ENABLE_SOLR_UPDATES
91
+ end
92
+
93
+ # Determines whether an update operation cause a solr index of this object.
94
+ # Override this if you need different behavior
95
+ def update_needs_index?
96
+ @metadata_is_dirty && ENABLE_SOLR_UPDATES
97
+ end
85
98
 
86
99
  private
87
100
 
@@ -29,8 +29,8 @@ module ActiveFedora
29
29
 
30
30
  #Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist
31
31
  #when this method returns. Each term is marked as a multivalue string.
32
- def initialize(digital_object, dsid )
33
- super(digital_object, dsid)
32
+ def initialize(digital_object=nil, dsid=nil, options={})
33
+ super
34
34
  DCTERMS.each do |el|
35
35
  field el, :string, :multiple=>true
36
36
  end
@@ -157,6 +157,10 @@ module ActiveFedora
157
157
  graph.dirty
158
158
  end
159
159
 
160
+ def metadata?
161
+ true
162
+ end
163
+
160
164
  def save
161
165
  super
162
166
  graph.dirty = false
@@ -263,6 +267,7 @@ module ActiveFedora
263
267
  graph.delete(predicate)
264
268
  args = [args] unless args.respond_to? :each
265
269
  args.each do |arg|
270
+ arg = arg.to_s if arg.kind_of? RDF::Literal
266
271
  graph.add(predicate, arg, true) unless arg.empty?
267
272
  end
268
273
  graph.dirty = true
@@ -17,6 +17,10 @@ module ActiveFedora
17
17
  model.relationships_are_dirty or super
18
18
  end
19
19
 
20
+ def metadata?
21
+ true
22
+ end
23
+
20
24
  def serialize!
21
25
  self.content = to_rels_ext() if model.relationships_are_dirty
22
26
  model.relationships_are_dirty = false
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "5.0.0.rc4"
2
+ VERSION = "5.0.0.rc5"
3
3
  end
@@ -5,36 +5,6 @@ describe ActiveFedora::Base do
5
5
  before(:each) do
6
6
  @test_object = ActiveFedora::Base.new
7
7
  end
8
-
9
-
10
- describe ".metadata_streams" do
11
- #TODO move to datastreams_spec
12
- it "should return all of the datastreams from the object that are kinds of SimpleDatastreams " do
13
- mock_mds1 = mock("metadata ds1")
14
- mock_mds2 = mock("metadata ds2")
15
- mock_fds = mock("file ds")
16
- mock_fds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
17
- mock_ngds = mock("nokogiri ds")
18
- mock_ngds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
19
- mock_ngds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
20
-
21
-
22
- [mock_mds1,mock_mds2].each do |ds|
23
- ds.expects(:kind_of?).with(ActiveFedora::RDFDatastream).returns(false)
24
- ds.expects(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(true)
25
- end
26
- mock_fds.stubs(:kind_of?).with(ActiveFedora::NokogiriDatastream).returns(false)
27
-
28
- @test_object.expects(:datastreams).returns({:foo => mock_mds1, :bar => mock_mds2, :baz => mock_fds, :bork=>mock_ngds})
29
-
30
- result = @test_object.metadata_streams
31
- result.length.should == 3
32
- result.should include(mock_mds1)
33
- result.should include(mock_mds2)
34
- result.should include(mock_ngds)
35
- end
36
- end
37
-
38
8
 
39
9
  describe ".update_index" do
40
10
  before do
@@ -8,10 +8,11 @@ describe ActiveFedora::Datastream do
8
8
  before(:each) do
9
9
  @test_object = ActiveFedora::Base.new
10
10
  @test_datastream = ActiveFedora::Datastream.new(@test_object.inner_object, 'abcd')
11
- #:pid=>@test_object.pid, :dsid=>'abcd', :blob=>StringIO.new("hi there"))
12
11
  @test_datastream.content = "hi there"
13
12
  end
14
13
 
14
+ its(:metadata?) { should be_false}
15
+
15
16
  it "should escape dots in to_param" do
16
17
  @test_datastream.stubs(:dsid).returns('foo.bar')
17
18
  @test_datastream.to_param.should == 'foo%2ebar'
@@ -94,10 +95,10 @@ describe ActiveFedora::Datastream do
94
95
  end
95
96
 
96
97
  it "should have mimeType accessors" do
97
- ds1 = ActiveFedora::Datastream.new(nil, nil)#:mime_type=>"text/foo")
98
+ ds1 = ActiveFedora::Datastream.new
98
99
  ds1.mimeType = "text/foo"
99
100
  ds1.mimeType.should == "text/foo"
100
- ds2 = ActiveFedora::Datastream.new(nil, nil)#:mime_type=>"text/bar")
101
+ ds2 = ActiveFedora::Datastream.new
101
102
  ds2.mimeType = "text/bar"
102
103
  ds2.mimeType.should == "text/bar"
103
104
  end
@@ -9,6 +9,29 @@ describe ActiveFedora::Datastreams do
9
9
  ActiveFedora::Base.respond_to?(:has_metadata).should be_true
10
10
  end
11
11
 
12
+ describe ".metadata_streams" do
13
+ it "should return all of the datastreams from the object that are kinds of SimpleDatastreams " do
14
+ mock_mds1 = mock("metadata ds1")
15
+ mock_mds2 = mock("metadata ds2")
16
+ mock_fds = mock("file ds")
17
+ mock_fds.expects(:metadata?).returns(false)
18
+ mock_ngds = mock("nokogiri ds")
19
+ mock_ngds.expects(:metadata?).returns(true)
20
+
21
+ [mock_mds1,mock_mds2].each do |ds|
22
+ ds.expects(:metadata?).returns(true)
23
+ end
24
+
25
+ @test_object.expects(:datastreams).returns({:foo => mock_mds1, :bar => mock_mds2, :baz => mock_fds, :bork=>mock_ngds})
26
+
27
+ result = @test_object.metadata_streams
28
+ result.length.should == 3
29
+ result.should include(mock_mds1)
30
+ result.should include(mock_mds2)
31
+ result.should include(mock_ngds)
32
+ end
33
+ end
34
+
12
35
  describe "datastream_from_spec" do
13
36
  it "should accept versionable" do
14
37
  ds = @test_object.datastream_from_spec({:type=>ActiveFedora::Datastream, :versionable=>false}, 'test')
@@ -25,6 +25,8 @@ describe ActiveFedora::NokogiriDatastream do
25
25
  after(:each) do
26
26
  end
27
27
 
28
+ its(:metadata?) { should be_true}
29
+
28
30
  it "should include the Solrizer::XML::TerminologyBasedSolrizer for .to_solr support" do
29
31
  ActiveFedora::NokogiriDatastream.included_modules.should include(Solrizer::XML::TerminologyBasedSolrizer)
30
32
  end
@@ -41,7 +43,7 @@ describe ActiveFedora::NokogiriDatastream do
41
43
  end
42
44
  it "should initialize from #xml_template if no xml is provided" do
43
45
  ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
44
- n = ActiveFedora::NokogiriDatastream.new(nil, nil)
46
+ n = ActiveFedora::NokogiriDatastream.new
45
47
  n.ensure_xml_loaded
46
48
  n.ng_xml.should be_equivalent_to("<fake template/>")
47
49
  end
@@ -54,7 +56,7 @@ describe ActiveFedora::NokogiriDatastream do
54
56
  end
55
57
 
56
58
  describe "an instance" do
57
- subject { ActiveFedora::NokogiriDatastream.new(nil, nil) }
59
+ subject { ActiveFedora::NokogiriDatastream.new }
58
60
  it{ should.respond_to? :to_solr }
59
61
  its(:to_solr) {should == { }}
60
62
  end
@@ -159,7 +161,7 @@ describe ActiveFedora::NokogiriDatastream do
159
161
  describe '#from_xml' do
160
162
  it "should work when a template datastream is passed in" do
161
163
  mods_xml = Nokogiri::XML::Document.parse( fixture(File.join("mods_articles", "hydrangea_article1.xml")) )
162
- tmpl = Hydra::ModsArticleDatastream.new(nil, nil)
164
+ tmpl = Hydra::ModsArticleDatastream.new
163
165
  Hydra::ModsArticleDatastream.from_xml(mods_xml,tmpl).ng_xml.root.to_xml.should == mods_xml.root.to_xml
164
166
  tmpl.dirty?.should be_false
165
167
  end
@@ -263,7 +265,7 @@ describe ActiveFedora::NokogiriDatastream do
263
265
 
264
266
  describe '.get_values_from_solr' do
265
267
  before(:each) do
266
- @mods_ds = ActiveFedora::NokogiriDatastream.new(nil, nil)
268
+ @mods_ds = ActiveFedora::NokogiriDatastream.new
267
269
  @mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
268
270
  end
269
271
 
@@ -319,7 +321,7 @@ describe ActiveFedora::NokogiriDatastream do
319
321
 
320
322
  describe '.update_values' do
321
323
  before(:each) do
322
- @mods_ds = ActiveFedora::NokogiriDatastream.new(nil, nil)
324
+ @mods_ds = ActiveFedora::NokogiriDatastream.new
323
325
  @mods_ds.content= fixture(File.join("mods_articles","hydrangea_article1.xml")).read
324
326
  end
325
327
 
@@ -341,7 +343,7 @@ describe ActiveFedora::NokogiriDatastream do
341
343
  end
342
344
 
343
345
  it "should set @dirty to true" do
344
- mods_ds = Hydra::ModsArticleDatastream.new(nil, nil)
346
+ mods_ds = Hydra::ModsArticleDatastream.new
345
347
  mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
346
348
  mods_ds.update_values([{":person"=>"0"}, "role", "text"]=>{"0"=>"role1", "1"=>"role2", "2"=>"role3"})
347
349
  mods_ds.dirty?.should be_true
@@ -351,7 +353,7 @@ describe ActiveFedora::NokogiriDatastream do
351
353
  describe '.term_values' do
352
354
 
353
355
  before(:each) do
354
- @mods_ds = ActiveFedora::NokogiriDatastream.new(nil, nil)
356
+ @mods_ds = ActiveFedora::NokogiriDatastream.new
355
357
  @mods_ds.content=fixture(File.join("mods_articles","hydrangea_article1.xml")).read
356
358
  end
357
359
 
@@ -9,6 +9,7 @@ describe ActiveFedora::NtriplesRDFDatastream do
9
9
  map.created(:in => RDF::DC)
10
10
  map.title(:in => RDF::DC)
11
11
  map.publisher(:in => RDF::DC)
12
+ map.creator(:in => RDF::DC)
12
13
  map.based_near(:in => RDF::FOAF)
13
14
  map.related_url(:to => "seeAlso", :in => RDF::RDFS)
14
15
  end
@@ -59,6 +60,10 @@ describe ActiveFedora::NtriplesRDFDatastream do
59
60
  @subject.publisher = "St. Martin's Press"
60
61
  @subject.publisher.should == ["St. Martin's Press"]
61
62
  end
63
+ it "should set rdf literal fields" do
64
+ @subject.creator = RDF.Literal("Geoff Ryman")
65
+ @subject.creator.should == ["Geoff Ryman"]
66
+ end
62
67
  it "should append fields" do
63
68
  @subject.publisher << "St. Martin's Press"
64
69
  @subject.publisher.should == ["Penn State", "St. Martin's Press"]
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::Persistence do
4
+ before :all do
5
+ class SpecNode
6
+ include ActiveFedora::Persistence
7
+ end
8
+ end
9
+ after :all do
10
+ Object.send(:remove_const, :SpecNode)
11
+ end
12
+
13
+ subject { SpecNode.new }
14
+
15
+ describe "#create_needs_index?" do
16
+ it "should be true" do
17
+ subject.send(:create_needs_index?).should be_true
18
+ end
19
+ end
20
+
21
+ describe "#update_needs_index?" do
22
+ describe "when metadata is dirty" do
23
+ before do
24
+ subject.send(:metadata_is_dirty=, true)
25
+ end
26
+ it "should be true" do
27
+ subject.send(:update_needs_index?).should be_true
28
+ end
29
+ end
30
+
31
+ describe "when metadata is not dirty" do
32
+ it "should be false" do
33
+ subject.send(:update_needs_index?).should be_false
34
+ end
35
+ end
36
+ end
37
+
38
+
39
+ end
@@ -56,7 +56,7 @@ describe ActiveFedora::QualifiedDublinCoreDatastream do
56
56
  it "should parse dcterms and dcelements from xml" do
57
57
  doc = Nokogiri::XML::Document.parse(File.open( File.dirname(__FILE__)+'/../fixtures/changeme155.xml') )
58
58
  stream = doc.xpath('//foxml:datastream[@ID=\'dublin_core\']/foxml:datastreamVersion/foxml:xmlContent/dc')
59
- ds = ActiveFedora::QualifiedDublinCoreDatastream.new(nil, nil)
59
+ ds = ActiveFedora::QualifiedDublinCoreDatastream.new
60
60
  n = ActiveFedora::QualifiedDublinCoreDatastream.from_xml(stream.to_xml, ds)
61
61
  n.spatial.should == ["Boston [7013445]", "Dorchester [7013575]", "Roxbury [7015002]"]
62
62
  n.title.should == ["Oral history with Frances Addelson, 1997 November 14"]
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::RDFDatastream do
4
+ its(:metadata?) { should be_true}
5
+ end
@@ -22,6 +22,8 @@ describe ActiveFedora::RelsExtDatastream do
22
22
  @test_ds = ActiveFedora::RelsExtDatastream.new(mock_inner, "RELS-EXT")
23
23
  end
24
24
 
25
+ its(:metadata?) { should be_true}
26
+
25
27
  describe "#save" do
26
28
  before do
27
29
  @mock_repo.expects(:add_datastream).with(:pid => 'test:sample_pid', :dsid => 'RELS-EXT', :versionable => true, :content => 'fake xml', :controlGroup => 'M', :dsState => 'A', :mimeType=>'application/rdf+xml')
@@ -139,7 +141,7 @@ describe ActiveFedora::RelsExtDatastream do
139
141
  </rdf:RDF>
140
142
  EOS
141
143
  model = ActiveFedora::Base.new
142
- new_ds = ActiveFedora::RelsExtDatastream.new(nil, nil)
144
+ new_ds = ActiveFedora::RelsExtDatastream.new
143
145
  new_ds.model = model
144
146
  lambda { ActiveFedora::RelsExtDatastream.from_xml(xml, new_ds) }.should_not raise_exception
145
147
  new_ds.to_rels_ext.should =~ /missing:hasOtherRelationship/
@@ -155,7 +157,7 @@ describe ActiveFedora::RelsExtDatastream do
155
157
  </rdf:Description>
156
158
  </rdf:RDF>"
157
159
  model = ActiveFedora::Base.new
158
- new_ds = ActiveFedora::RelsExtDatastream.new(nil, nil)
160
+ new_ds = ActiveFedora::RelsExtDatastream.new
159
161
  new_ds.model = model
160
162
  ActiveFedora::RelsExtDatastream.from_xml(xml, new_ds)
161
163
  new_ext = new_ds.to_rels_ext()
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc4
4
+ version: 5.0.0.rc5
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-11-28 00:00:00.000000000 Z
14
+ date: 2012-11-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rsolr
@@ -502,9 +502,11 @@ files:
502
502
  - spec/unit/model_spec.rb
503
503
  - spec/unit/nokogiri_datastream_spec.rb
504
504
  - spec/unit/ntriples_datastream_spec.rb
505
+ - spec/unit/persistence_spec.rb
505
506
  - spec/unit/predicates_spec.rb
506
507
  - spec/unit/property_spec.rb
507
508
  - spec/unit/qualified_dublin_core_datastream_spec.rb
509
+ - spec/unit/rdf_datastream_spec.rb
508
510
  - spec/unit/rdf_xml_writer_spec.rb
509
511
  - spec/unit/rdfxml_rdf_datastream_spec.rb
510
512
  - spec/unit/relationship_graph_spec.rb
@@ -653,9 +655,11 @@ test_files:
653
655
  - spec/unit/model_spec.rb
654
656
  - spec/unit/nokogiri_datastream_spec.rb
655
657
  - spec/unit/ntriples_datastream_spec.rb
658
+ - spec/unit/persistence_spec.rb
656
659
  - spec/unit/predicates_spec.rb
657
660
  - spec/unit/property_spec.rb
658
661
  - spec/unit/qualified_dublin_core_datastream_spec.rb
662
+ - spec/unit/rdf_datastream_spec.rb
659
663
  - spec/unit/rdf_xml_writer_spec.rb
660
664
  - spec/unit/rdfxml_rdf_datastream_spec.rb
661
665
  - spec/unit/relationship_graph_spec.rb