active-fedora 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 3.0.1
2
+
3
+ HYDRA-654 -- Fixed reification using has_model as the class instead of active_fedora_model
4
+
1
5
  3.0.0
2
6
 
3
7
  added belongs_to and has_many model relationships
@@ -292,6 +292,7 @@ module ActiveFedora
292
292
  class PredicateMappingsNotFoundError < RuntimeError; end # :nodoc:
293
293
  class UnknownAttributeError < NoMethodError; end; # :nodoc:
294
294
  class ActiveFedoraConfigurationException < Exception; end # :nodoc:
295
+ class AssociationTypeMismatch < RuntimeError; end # :nodoc:
295
296
 
296
297
  end
297
298
 
@@ -21,6 +21,7 @@ module ActiveFedora
21
21
  #set this Datastream's content
22
22
  def content=(content)
23
23
  self.blob = content
24
+ self.dirty = true
24
25
  end
25
26
 
26
27
  def self.delete(parent_pid, dsid)
@@ -14,7 +14,8 @@ class ActiveFedora::NokogiriDatastream < ActiveFedora::Datastream
14
14
  alias_method(:om_term_values, :term_values) unless method_defined?(:om_term_values)
15
15
  alias_method(:om_update_values, :update_values) unless method_defined?(:om_update_values)
16
16
 
17
- attr_accessor :ng_xml, :internal_solr_doc
17
+ attr_accessor :internal_solr_doc
18
+ attr_reader :ng_xml
18
19
 
19
20
  #constructor, calls up to ActiveFedora::Datastream's constructor
20
21
  def initialize(attrs=nil)
@@ -43,22 +44,22 @@ class ActiveFedora::NokogiriDatastream < ActiveFedora::Datastream
43
44
  Nokogiri::XML::Document.parse("<xml/>")
44
45
  end
45
46
 
46
- # class << self
47
- # from_xml_original = self.instance_method(:from_xml)
48
- #
49
- # define_method(:from_xml, xml, tmpl=self.new) do
50
- # from_xml_original.bind(self).call(xml, tmpl)
51
- # tmpl.send(:dirty=, false)
52
- # end
53
- #
54
- # # def from_xml_custom(xml, tmpl=self.new)
55
- # # from_xml_original(xml, tmpl)
56
- # # tmpl.send(:dirty=, false)
57
- # # end
58
- # #
59
- # # alias_method :from_xml_original, :from_xml
60
- # # alias_method :from_xml, :from_xml_custom
61
- # end
47
+ def ng_xml=(new_xml)
48
+ case new_xml
49
+ when Nokogiri::XML::Document, Nokogiri::XML::Element, Nokogiri::XML::Node
50
+ @ng_xml = new_xml
51
+ when String
52
+ @ng_xml = Nokogiri::XML::Document.parse(new_xml)
53
+ else
54
+ raise TypeError, "You passed a #{new_xml.class} into the ng_xml of the #{self.dsid} datastream. NokogiriDatastream.ng_xml= only accepts Nokogiri::XML::Document, Nokogiri::XML::Element, Nokogiri::XML::Node, or raw XML (String) as inputs."
55
+ end
56
+ self.dirty = true
57
+ end
58
+
59
+ def content=(content)
60
+ super
61
+ self.ng_xml = Nokogiri::XML::Document.parse(content)
62
+ end
62
63
 
63
64
 
64
65
  def to_xml(xml = self.ng_xml)
@@ -32,12 +32,7 @@ module ActiveFedora
32
32
  end
33
33
  results = []
34
34
  solr_result.hits.each do |hit|
35
- model_value = hit[solr_name("active_fedora_model", :symbol)].first
36
- if model_value.include?("::")
37
- classname = eval(model_value)
38
- else
39
- classname = Kernel.const_get(model_value)
40
- end
35
+ classname = class_from_solr_document(hit)
41
36
  if opts[:load_from_solr]
42
37
  results << classname.load_instance_from_solr(hit[SOLR_DOCUMENT_ID])
43
38
  else
@@ -46,6 +41,22 @@ module ActiveFedora
46
41
  end
47
42
  return results
48
43
  end
44
+
45
+ def self.class_from_solr_document(hit)
46
+ model_value = hit[solr_name("has_model", :symbol)].first
47
+ if match_data = /info:fedora\/afmodel:(.+)$/.match(model_value)
48
+ model_value = match_data[1]
49
+ model_value.gsub!('_', '::')
50
+ else
51
+ raise "has_model assertion incorrectly formatted: #{model_value}"
52
+ end
53
+
54
+ if model_value.include?("::")
55
+ eval(model_value)
56
+ else
57
+ Kernel.const_get(model_value)
58
+ end
59
+ end
49
60
 
50
61
  # Construct a solr query for a list of pids
51
62
  # This is used to get a solr response based on the list of pids in an object's RELS-EXT relationhsips
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -26,7 +26,6 @@ describe ActiveFedora do
26
26
  it "should use config_options[:environment] if set" do
27
27
  ActiveFedora.expects(:config_options).at_least_once.returns(:environment=>"ballyhoo")
28
28
  ActiveFedora.environment.should eql("ballyhoo")
29
- ENV['environment']='test'
30
29
  end
31
30
 
32
31
  it "should use Rails.env if no config_options and Rails.env is set" do
@@ -60,6 +60,17 @@ describe ActiveFedora::Datastream do
60
60
  end
61
61
  end
62
62
 
63
+ describe '.content=' do
64
+ it "should update the content and ng_xml, marking the datastream as dirty" do
65
+ sample_xml = "<foo><xmlelement/></foo>"
66
+ @test_datastream.should_not be_dirty
67
+ @test_datastream.blob.should_not be_equivalent_to(sample_xml)
68
+ @test_datastream.content = sample_xml
69
+ @test_datastream.should be_dirty
70
+ @test_datastream.blob.should be_equivalent_to(sample_xml)
71
+ end
72
+ end
73
+
63
74
  describe ".dirty?" do
64
75
  it "should return the value of the @dirty attribute" do
65
76
  @test_datastream.dirty.should equal(@test_datastream.dirty?)
@@ -10,7 +10,7 @@ describe ActiveFedora::NokogiriDatastream do
10
10
  :empty_field => {:values => {}}
11
11
  }
12
12
  @sample_xml = XmlSimple.xml_in("<fields><coverage>coverage1</coverage><coverage>coverage2</coverage><creation_date>fake-date</creation_date><mydate>fake-date</mydate><publisher>publisher1</publisher></fields>")
13
-
13
+ @sample_raw_xml = "<foo><xmlelement/></foo>"
14
14
  @solr_doc = {"id"=>"hydrange_article1","name_role_roleTerm_t"=>["creator","submitter","teacher"],"name_0_role_t"=>"\r\ncreator\r\nsubmitter\r\n","name_1_role_t"=>"\r\n teacher \r\n","name_0_role_0_roleTerm_t"=>"creator","name_0_role_1_roleTerm_t"=>"submitter","name_1_role_0_roleTerm_t"=>["teacher"]}
15
15
  end
16
16
 
@@ -35,8 +35,8 @@ describe ActiveFedora::NokogiriDatastream do
35
35
  test_ds1.ng_xml.to_xml.should == "<?xml version=\"1.0\"?>\n<xml>\n <foo/>\n</xml>\n"
36
36
  end
37
37
  it "should initialize from #xml_template if no xml is provided" do
38
- ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("fake template")
39
- ActiveFedora::NokogiriDatastream.new.ng_xml.should == "fake template"
38
+ ActiveFedora::NokogiriDatastream.expects(:xml_template).returns("<fake template/>")
39
+ ActiveFedora::NokogiriDatastream.new.ng_xml.should be_equivalent_to("<fake template/>")
40
40
  end
41
41
  end
42
42
 
@@ -234,6 +234,32 @@ describe ActiveFedora::NokogiriDatastream do
234
234
  end
235
235
  end
236
236
 
237
+ describe '.content=' do
238
+ it "should update the content and ng_xml, marking the datastream as dirty" do
239
+ @test_ds.should_not be_dirty
240
+ @test_ds.blob.should_not be_equivalent_to(@sample_raw_xml)
241
+ @test_ds.ng_xml.to_xml.should_not be_equivalent_to(@sample_raw_xml)
242
+ @test_ds.content = @sample_raw_xml
243
+ @test_ds.should be_dirty
244
+ @test_ds.blob.should be_equivalent_to(@sample_raw_xml)
245
+ @test_ds.ng_xml.to_xml.should be_equivalent_to(@sample_raw_xml)
246
+ end
247
+ end
248
+
249
+ describe 'ng_xml=' do
250
+ it "should parse raw xml for you" do
251
+ @test_ds.ng_xml.to_xml.should_not be_equivalent_to(@sample_raw_xml)
252
+ @test_ds.ng_xml = @sample_raw_xml
253
+ @test_ds.ng_xml.class.should == Nokogiri::XML::Document
254
+ @test_ds.ng_xml.to_xml.should be_equivalent_to(@sample_raw_xml)
255
+ end
256
+ it "should mark the datastream as dirty" do
257
+ @test_ds.should_not be_dirty
258
+ @test_ds.ng_xml = @sample_raw_xml
259
+ @test_ds.should be_dirty
260
+ end
261
+ end
262
+
237
263
  describe '.to_xml' do
238
264
  it "should provide .to_xml" do
239
265
  @test_ds.should respond_to(:to_xml)
@@ -25,9 +25,9 @@ describe ActiveFedora::SemanticNode do
25
25
  before(:all) do
26
26
  @pid = "test:sample_pid"
27
27
  @uri = "info:fedora/#{@pid}"
28
- @sample_solr_hits = [{"id"=>"_PID1_", "active_fedora_model_s"=>["AudioRecord"]},
29
- {"id"=>"_PID2_", "active_fedora_model_s"=>["AudioRecord"]},
30
- {"id"=>"_PID3_", "active_fedora_model_s"=>["AudioRecord"]}]
28
+ @sample_solr_hits = [{"id"=>"_PID1_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
29
+ {"id"=>"_PID2_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
30
+ {"id"=>"_PID3_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]}]
31
31
  end
32
32
 
33
33
  before(:each) do
@@ -347,7 +347,11 @@ describe ActiveFedora::SemanticNode do
347
347
  local_node.expects(:outbound_relationships).returns({:is_member_of => ["my:_PID1_", "my:_PID2_", "my:_PID3_"]}).times(2)
348
348
  mock_repo = mock("repo")
349
349
  solr_result = mock("solr result", :is_a? => true)
350
- solr_result.expects(:hits).returns([{"id"=> "my:_PID1_", "active_fedora_model_s" => ["SpecNode"]}, {"id"=> "my:_PID2_", "active_fedora_model_s" => ["SpecNode"]}, {"id"=> "my:_PID3_", "active_fedora_model_s" => ["SpecNode"]}])
350
+ solr_result.expects(:hits).returns(
351
+ [{"id"=> "my:_PID1_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
352
+ {"id"=> "my:_PID2_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]},
353
+ {"id"=> "my:_PID3_", "has_model_s"=>["info:fedora/afmodel:SpecNode"]}])
354
+
351
355
  ActiveFedora::SolrService.instance.conn.expects(:query).with("id:my\\:_PID1_ OR id:my\\:_PID2_ OR id:my\\:_PID3_").returns(solr_result)
352
356
  mock_repo.expects(:find_model).with("my:_PID1_", SpecNode).returns("AR1")
353
357
  mock_repo.expects(:find_model).with("my:_PID2_", SpecNode).returns("AR2")
@@ -47,9 +47,9 @@ describe ActiveFedora::SolrService do
47
47
 
48
48
  describe "#reify_solr_results" do
49
49
  before(:each) do
50
- @sample_solr_hits = [{"id"=>"my:_PID1_", "active_fedora_model_s"=>["AudioRecord"]},
51
- {"id"=>"my:_PID2_", "active_fedora_model_s"=>["AudioRecord"]},
52
- {"id"=>"my:_PID3_", "active_fedora_model_s"=>["AudioRecord"]}]
50
+ @sample_solr_hits = [{"id"=>"my:_PID1_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
51
+ {"id"=>"my:_PID2_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]},
52
+ {"id"=>"my:_PID3_", "has_model_s"=>["info:fedora/afmodel:AudioRecord"]}]
53
53
  end
54
54
  it "should only take Solr::Response::Standard objects as input" do
55
55
  mocko = mock("input", :is_a? => false)
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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 0
10
- version: 3.0.0
9
+ - 1
10
+ version: 3.0.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-09-02 00:00:00 -05:00
19
+ date: 2011-09-08 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency