active_fedora_relsint 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 059d025a9c1151a15355876f60ff87e808520d33
4
- data.tar.gz: 08de94e141d50b1c3e8dd3a827ed2acd67cb10e8
3
+ metadata.gz: 804d1e107e01115222d2c938924909f60dea4481
4
+ data.tar.gz: 441b7e2f98637ce3c5cba3db80739a20ac8f591a
5
5
  SHA512:
6
- metadata.gz: 2b029a74aa68d006905dd9273b576e2d70e782d32a7425f1a4e6038a46030fa4b2ee582792950aad9c2c91fb1f7459d563fef788ecc4138e7b064f3a41138050
7
- data.tar.gz: ae3de7a0bbdfae56084318a101e927e090854526ea540cd90cf18d658d0fea41513ecb567ffbc9343268c71354684736b32be032d5168b0b554e511142eb6709
6
+ metadata.gz: 03c43dde8f0d13d0ab3528aac58223d313eb5c91c379f3a6fe18b2d58442bcf0e0dac1d48715dea9134afb291c204d02024981427e8fa7da37d0c92b4cee4f4b
7
+ data.tar.gz: 6f685ed9e328162b071980cf078e32f89318ba949d39ded9c0ec4025e4e0356441394ba64bf10e6494144cd4668aa57fd715311200096a1f190e6681ab339a77
@@ -2,6 +2,7 @@
2
2
  module ActiveFedora
3
3
  module RelsInt
4
4
  class Datastream < ActiveFedora::Datastream
5
+ XSD_INT_BITLENGTH = 31
5
6
  class_attribute :profile_solr_name
6
7
  attr_accessor :relationships_loaded
7
8
 
@@ -38,7 +39,20 @@ module ActiveFedora
38
39
  elsif object.is_a? RDF::Resource
39
40
  object
40
41
  elsif literal
41
- RDF::Literal.new(object)
42
+ result = RDF::Literal.new(object)
43
+ case # invalid datatypes for FCRepo 3
44
+ when result.datatype.eql?(RDF::XSD.integer)
45
+ result.datatype = (signed_bit_length(result.object) > XSD_INT_BITLENGTH ? RDF::XSD.long : RDF::XSD.int)
46
+ when result.datatype.eql?(RDF::XSD.decimal)
47
+ result.datatype = RDF::XSD.double
48
+ when result.datatype.eql?(RDF::XSD.boolean)
49
+ result.datatype = nil
50
+ when result.datatype.eql?(RDF::XSD.date)
51
+ result = RDF::Literal.new(object.to_datetime)
52
+ when result.datatype.eql?(RDF::XSD.time)
53
+ result = RDF::Literal.new(object.to_datetime)
54
+ end
55
+ result
42
56
  else
43
57
  RDF::URI.new(object.to_s)
44
58
  end
@@ -149,6 +163,14 @@ module ActiveFedora
149
163
  @resource = resource
150
164
  end
151
165
  end
166
+ private
167
+ def signed_bit_length(num)
168
+ if num.respond_to? :bit_length
169
+ num.bit_length
170
+ else # in MRI 1.9.x, we need to implement the two complement bitlength
171
+ Math.log2(num < 0 ? num.abs : num+1).ceil
172
+ end
173
+ end
152
174
  end
153
175
  end
154
176
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveFedora
2
2
  module RelsInt
3
- VERSION = '0.4.0'
3
+ VERSION = '0.4.1'
4
4
  end
5
5
  end
@@ -1,126 +1,133 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::RelsInt, type: :unit do
4
- before :all do
5
- class Foo < ActiveFedora::Base
6
- include ActiveFedora::RelsInt
7
- end
8
- end
9
-
10
- after :all do
11
- Object.send(:remove_const, :Foo) # cleanup
4
+ it do
5
+ is_expected.to be
6
+ expect(defined? ActiveFedora::RelsInt::Datastream).to be
12
7
  end
13
-
14
- describe "modules" do
15
- it "should exist" do
16
- expect(defined? ActiveFedora::RelsInt).to be_truthy
17
- expect(defined? ActiveFedora::RelsInt::Datastream).to be_truthy
8
+ context "is included in a subclass of ActiveFedora::Base" do
9
+ let(:af_model) do
10
+ af_model = Class.new(ActiveFedora::Base)
11
+ af_model.class_eval do
12
+ include ActiveFedora::RelsInt
13
+ end
14
+ af_model
15
+ end
16
+ it "should add the appropriate ds_spec and accessor methods when mixed in" do
17
+ expect(af_model.ds_specs.keys).to include( 'RELS-INT')
18
+ expect(af_model.ds_specs['RELS-INT'][:type]).to be(ActiveFedora::RelsInt::Datastream)
18
19
  end
19
- end
20
-
21
- it "should add the appropriate ds_spec and accessor methods when mixed in" do
22
- expect(Foo.ds_specs.keys).to include( 'RELS-INT')
23
- expect(Foo.ds_specs['RELS-INT'][:type]).to be(ActiveFedora::RelsInt::Datastream)
24
- end
25
-
26
- it "should serialize to appropriate RDF-XML on a new object" do
27
- blank_relsint = fixture('rels_int_blank.xml').read
28
- inner = double("DigitalObject")
29
- allow(inner).to receive(:new_record?).and_return(true)
30
- allow(inner).to receive(:pid).and_return("test:relsint")
31
- repo = double("Repository")
32
- allow(inner).to receive(:repository).and_return(repo)
33
- test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
34
- expect(Nokogiri::XML.parse(test_obj.content)).to be_equivalent_to Nokogiri::XML.parse(blank_relsint)
35
- end
36
-
37
- it "should serialize to appropriate RDF-XML when added to an existing obect" do
38
- blank_relsint = fixture('rels_int_blank.xml').read
39
- inner = double("DigitalObject")
40
- allow(inner).to receive(:new_record?).and_return(false)
41
- allow(inner).to receive(:pid).and_return("test:relsint")
42
- repo = double("Repository")
43
- # new datastream, no profile
44
- expect(repo).to receive(:datastream_profile).with(inner.pid,"RELS-INT",nil, nil).and_return('')
45
- allow(inner).to receive(:repository).and_return(repo)
46
- test_obj = ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
47
- expect(Nokogiri::XML.parse(test_obj.content)).to be_equivalent_to Nokogiri::XML.parse(blank_relsint)
48
20
  end
49
21
 
50
22
  describe ActiveFedora::RelsInt::Datastream do
51
- before :each do
52
- @test_relsint = fixture('rels_int_test.xml').read
53
- @inner = double("DigitalObject")
54
- allow(@inner).to receive(:new_record?).and_return(false)
55
- allow(@inner).to receive(:pid).and_return("test:relsint")
56
- allow(@inner).to receive(:internal_uri).and_return("info:fedora/test:relsint")
23
+ let(:pid) { "test:relsint" }
24
+ let(:inner) do
25
+ inner = double("DigitalObject")
26
+ allow(inner).to receive(:pid).and_return(pid)
27
+ allow(inner).to receive(:internal_uri).and_return("info:fedora/test:relsint")
28
+ allow(inner).to receive(:repository).and_return(repo)
29
+ inner
30
+ end
31
+ let(:repo) do
57
32
  repo = double("Repository")
33
+ allow(repo).to receive(:datastream_dissemination).with(:pid=>pid,:dsid=>"RELS-INT").and_return(test_relsint)
34
+ repo
35
+ end
36
+ let(:test_relsint) { fixture('rels_int_test.xml').read }
37
+ let(:profile) do
58
38
  profile_xml = fixture('rels_int_profile.xml').read
59
39
  profile = Rubydora::ProfileParser.parse_datastream_profile(profile_xml)
60
- expect(repo).to receive(:datastream_profile).with(@inner.pid,"RELS-INT",nil, nil).and_return(profile)
61
- allow(repo).to receive(:datastream_dissemination).with(:pid=>@inner.pid,:dsid=>"RELS-INT").and_return(@test_relsint)
62
- allow(@inner).to receive(:repository).and_return(repo)
40
+ profile
41
+ end
42
+ let(:datastream) do
43
+ ActiveFedora::RelsInt::Datastream.new(inner,"RELS-INT")
44
+ end
45
+ before do
46
+ allow(inner).to receive(:new_record?).and_return(false)
47
+ allow(repo).to receive(:datastream_profile).with(pid,"RELS-INT",nil, nil).and_return(profile)
48
+ end
49
+ context "on a new object" do
50
+ before do
51
+ allow(inner).to receive(:new_record?).and_return(true)
52
+ end
53
+ it "should serialize to appropriate RDF-XML" do
54
+ blank_relsint = fixture('rels_int_blank.xml').read
55
+ expect(Nokogiri::XML.parse(datastream.content)).to be_equivalent_to Nokogiri::XML.parse(blank_relsint)
56
+ end
63
57
  end
58
+ context "is a new datastream on an existing object" do
59
+ before do
60
+ # new datastream, no profile
61
+ allow(repo).to receive(:datastream_profile).with(pid,"RELS-INT",nil, nil).and_return('')
62
+ end
63
+ it "should serialize to appropriate RDF-XML" do
64
+ blank_relsint = fixture('rels_int_blank.xml').read
65
+ expect(Nokogiri::XML.parse(datastream.content)).to be_equivalent_to Nokogiri::XML.parse(blank_relsint)
66
+ end
67
+ end
68
+
64
69
  it "should load relationships from foxml into the appropriate graphs" do
65
- test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
66
- expect(test_obj.changed?).to be(false)
67
- dc = ActiveFedora::Datastream.new(@inner,"DC")
68
- triples = test_obj.relationships(dc,:is_metadata_for)
70
+ expect(datastream.changed?).to be(false)
71
+ dc = ActiveFedora::Datastream.new(inner,"DC")
72
+ triples = datastream.relationships(dc,:is_metadata_for)
69
73
  e = ['info:fedora/test:relsint/DC','info:fedora/fedora-system:def/relations-external#isMetadataFor','info:fedora/test:relsint/RELS-INT'].
70
74
  map {|x| RDF::URI.new(x)}
71
75
  f = ['info:fedora/test:relsint/DC','info:fedora/fedora-system:def/relations-external#isMetadataFor','info:fedora/test:relsint/RELS-EXT']
72
76
  .map {|x| RDF::URI.new(x)}
73
77
  expect(triples).to eq([RDF::Statement.new(*e),RDF::Statement.new(*f)])
74
- expect(Nokogiri::XML.parse(test_obj.content)).to be_equivalent_to Nokogiri::XML.parse(@test_relsint)
78
+ expect(Nokogiri::XML.parse(datastream.content)).to be_equivalent_to Nokogiri::XML.parse(test_relsint)
75
79
  end
76
80
  it "should load relationships into appropriate graphs when assigned content" do
77
- #test_relsint = fixture('rels_int_test.xml').read
78
- #inner = double("DigitalObject")
79
- #inner.stub(:pid).and_return("test:relsint")
80
- #inner.stub(:internal_uri).and_return("info:fedora/test:relsint")
81
- test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
82
- test_obj.content=@test_relsint
83
- expect(test_obj.changed?).to be(true)
84
- dc = ActiveFedora::Datastream.new(@inner,"DC")
85
- triples = test_obj.relationships(dc,:is_metadata_for)
81
+ datastream.content=test_relsint
82
+ expect(datastream.changed?).to be(true)
83
+ dc = ActiveFedora::Datastream.new(inner,"DC")
84
+ triples = datastream.relationships(dc,:is_metadata_for)
86
85
  e = ['info:fedora/test:relsint/DC','info:fedora/fedora-system:def/relations-external#isMetadataFor','info:fedora/test:relsint/RELS-INT']
87
86
  .map {|x| RDF::URI.new(x)}
88
87
  f = ['info:fedora/test:relsint/DC','info:fedora/fedora-system:def/relations-external#isMetadataFor','info:fedora/test:relsint/RELS-EXT']
89
88
  .map {|x| RDF::URI.new(x)}
90
89
  expect(triples).to eq([RDF::Statement.new(*e),RDF::Statement.new(*f)])
91
- end
90
+ end
92
91
  it "should propagate relationship changes to the appropriate graph in RELS-INT" do
93
- #test_relsint = fixture('rels_int_test.xml').read
94
- #inner = double("DigitalObject")
95
- #inner.stub(:pid).and_return("test:relsint")
96
- #inner.stub(:internal_uri).and_return("info:fedora/test:relsint")
97
- test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
98
- dc = ActiveFedora::Datastream.new(@inner,"DC")
99
- rels_ext = ActiveFedora::Datastream.new(@inner,"RELS-EXT")
100
- expect(test_obj.to_resource(test_obj)).to eql(RDF::URI.new("info:fedora/#{@inner.pid}/#{test_obj.dsid}"))
101
- test_obj.add_relationship(dc,:is_metadata_for, test_obj)
102
- test_obj.add_relationship(dc,:is_metadata_for, rels_ext)
103
- test_obj.add_relationship(rels_ext,:asserts, "FOO", true)
104
- test_obj.add_relationship(test_obj,:asserts, "BAR", true)
105
- test_obj.serialize!
106
- expect(Nokogiri::XML.parse(test_obj.content)).to be_equivalent_to Nokogiri::XML.parse(@test_relsint)
92
+ dc = ActiveFedora::Datastream.new(inner,"DC")
93
+ rels_ext = ActiveFedora::Datastream.new(inner,"RELS-EXT")
94
+ expect(datastream.to_resource(datastream)).to eql(RDF::URI.new("info:fedora/#{inner.pid}/#{datastream.dsid}"))
95
+ datastream.add_relationship(dc,:is_metadata_for, datastream)
96
+ datastream.add_relationship(dc,:is_metadata_for, rels_ext)
97
+ datastream.add_relationship(rels_ext,:asserts, "FOO", true)
98
+ datastream.add_relationship(datastream,:asserts, "BAR", true)
99
+ datastream.serialize!
100
+ expect(Nokogiri::XML.parse(datastream.content)).to be_equivalent_to Nokogiri::XML.parse(test_relsint)
107
101
  end
108
102
  it "should clear matching relationships selectively" do
109
- test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
110
- test_obj.content=@test_relsint
111
- rels_ext = ActiveFedora::Datastream.new(@inner,"RELS-EXT")
103
+ datastream.content=test_relsint
104
+ rels_ext = ActiveFedora::Datastream.new(inner,"RELS-EXT")
112
105
  test_pred = 'http://projecthydra.org/ns/relations#asserts'
113
- expect(test_obj.relationships(rels_ext,:asserts)).to_not be_empty
114
- test_obj.clear_relationship('info:fedora/test:relsint/RELS-EXT',:asserts)
115
- expect(test_obj.relationships(rels_ext,:asserts)).to be_empty
116
- expect(test_obj.relationships(test_obj,:asserts)).to_not be_empty
106
+ expect(datastream.relationships(rels_ext,:asserts)).to_not be_empty
107
+ datastream.clear_relationship('info:fedora/test:relsint/RELS-EXT',:asserts)
108
+ expect(datastream.relationships(rels_ext,:asserts)).to be_empty
109
+ expect(datastream.relationships(datastream,:asserts)).to_not be_empty
117
110
  end
118
111
  it "should run to_solr" do
119
- test_obj = ActiveFedora::RelsInt::Datastream.new(@inner,"RELS-INT")
120
- test_obj.content=@test_relsint
121
- expect(test_obj.changed?).to be(true)
122
- expect{test_obj.to_solr}.to_not raise_error
112
+ datastream.content=test_relsint
113
+ expect(datastream.changed?).to be(true)
114
+ expect{datastream.to_solr}.to_not raise_error
115
+ end
116
+ describe "#to_resource" do
117
+ # FCRepo 3.x only supports RDF::XSD.int, RDF::XSD.long, RDF::XSD.float, RDF::XSD.double,
118
+ # and RDF::XSD.date_time but RDF uses RDF::XSD.integer, RDF::XSD.boolean
119
+ {
120
+ 0 => RDF::XSD.int, 32767 => RDF::XSD.int, -32768 => RDF::XSD.int,
121
+ 2147483647 => RDF::XSD.int, -2147483648 => RDF::XSD.int,
122
+ 2147483648 => RDF::XSD.long, -2147483649 => RDF::XSD.long,
123
+ true => nil, false => nil,
124
+ BigDecimal('2.5') => RDF::XSD.double, 2.5.to_f => RDF::XSD.double,
125
+ Time.new => RDF::XSD.date_time, Date.new => RDF::XSD.date_time, DateTime.new => RDF::XSD.date_time
126
+ }.each do |value, datatype|
127
+ it "should assign implicit datatypes to #{value.class.name} literals such as #{value} valid for FCRepo 3" do
128
+ expect(datastream.to_resource(value,true).datatype).to eql(datatype)
129
+ end
130
+ end
123
131
  end
124
132
  end
125
-
126
133
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_fedora_relsint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Armintor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-26 00:00:00.000000000 Z
11
+ date: 2015-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active-fedora
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
211
  version: '0'
212
212
  requirements: []
213
213
  rubyforge_project:
214
- rubygems_version: 2.4.6
214
+ rubygems_version: 2.2.2
215
215
  signing_key:
216
216
  specification_version: 4
217
217
  summary: ActiveFedora library supporting RELS-INT datastreams