active-fedora 6.0.0.pre5 → 6.0.0.pre6

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.
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency("mediashelf-loggable")
26
26
  s.add_dependency("rubydora", '~>1.2')
27
27
  s.add_dependency("rdf")
28
- s.add_dependency("rdf-rdfxml", '~>0.3.8')
28
+ s.add_dependency("rdf-rdfxml", '~>1.0.0')
29
29
  s.add_dependency("deprecation")
30
30
  s.add_development_dependency("yard")
31
31
  s.add_development_dependency("RedCloth") # for RDoc formatting
@@ -4,7 +4,11 @@ module ActiveFedora
4
4
  def initialize(graph, subject)
5
5
  @graph = graph
6
6
  @subject = subject
7
+ first = graph.query([subject, RDF.first, nil]).first
8
+ graph.insert([subject, RDF.first, RDF.nil]) unless first
9
+ graph.insert([subject, RDF.rest, RDF.nil])
7
10
  end
11
+
8
12
  def first
9
13
  self[0]
10
14
  end
@@ -13,8 +17,22 @@ module ActiveFedora
13
17
  idx == 0 ? head.value : tail[idx-1]
14
18
  end
15
19
 
20
+ def []=(idx, value)
21
+ idx == 0 ? head.value=value : tail_or_create(idx-1).value=value
22
+ end
23
+
16
24
  def size
17
- tail ? tail.size + 1 : 0
25
+ if tail
26
+ tail.size + 1
27
+ elsif graph.query([subject, RDF.first, RDF.nil]).first
28
+ 0
29
+ else
30
+ 1
31
+ end
32
+ end
33
+
34
+ def inspect
35
+ "[ #{value ? value.inspect : 'nil'}, #{tail.inspect}]"
18
36
  end
19
37
 
20
38
  def value
@@ -27,14 +45,38 @@ module ActiveFedora
27
45
  v
28
46
  end
29
47
 
48
+ def value=(obj)
49
+ graph.delete([subject, RDF.first, RDF.nil])
50
+ if obj.respond_to? :rdf_subject
51
+ graph.insert([subject, RDF.first, obj.rdf_subject]) # an ActiveFedora::RdfObject
52
+ else
53
+ graph.insert([subject, RDF.first, obj])
54
+ end
55
+ end
56
+
30
57
  def head
31
58
  @head ||= self.class.new(graph, subject)
32
59
  end
33
60
 
34
61
  def tail
35
62
  rest = graph.query([subject, RDF.rest, nil]).first
36
- return unless rest
63
+ return if rest.object == RDF.nil
37
64
  self.class.new(graph, rest.object)
38
65
  end
66
+
67
+ def tail_or_create(idx)
68
+ rest = graph.query([subject, RDF.rest, nil]).first
69
+ obj = if rest.object != RDF.nil
70
+ self.class.new(graph, rest.object)
71
+ else
72
+ #add a tail
73
+ graph.delete([subject, RDF.rest, RDF.nil])
74
+ tail = RDF::Node.new
75
+ graph.insert([subject, RDF.rest, tail])
76
+ self.class.new(graph, tail)
77
+ end
78
+
79
+ idx == 0 ? obj : obj.tail_or_create(idx-1)
80
+ end
39
81
  end
40
82
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveFedora
2
- VERSION = "6.0.0.pre5"
2
+ VERSION = "6.0.0.pre6"
3
3
  end
@@ -38,70 +38,134 @@ describe ActiveFedora::RdfList do
38
38
  Object.send(:remove_const, :MADS)
39
39
  end
40
40
 
41
- subject do
42
- subject = DemoList.new(stub('inner object', :pid=>'foo', :new? =>true), 'descMetadata')
43
- subject.content =<<END
44
- <rdf:RDF
45
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
46
-
47
- <mads:ComplexSubject rdf:about="info:fedora/foo">
48
- <mads:elementList rdf:parseType="Collection">
49
- <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
50
- <mads:TopicElement>
51
- <mads:elementValue>Relations with Mexican Americans</mads:elementValue>
52
- </mads:TopicElement>
53
- <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"/>
54
- <mads:TemporalElement>
55
- <mads:elementValue>20th century</mads:elementValue>
56
- </mads:TemporalElement>
57
- </mads:elementList>
58
- </mads:ComplexSubject>
59
- </rdf:RDF>
41
+ describe "a new list" do
42
+ let (:ds) { DemoList.new(stub('inner object', :pid=>'foo', :new? =>true), 'descMetadata')}
43
+ subject { ds.elementList.build}
44
+
45
+ it "should insert at the end" do
46
+ subject.should be_kind_of DemoList::List
47
+ subject.size.should == 0
48
+ subject[1] = DemoList::List::TopicElement.new(subject.graph)
49
+ subject.size.should == 2
50
+ end
51
+
52
+ it "should insert at the head" do
53
+ subject.should be_kind_of DemoList::List
54
+ subject.size.should == 0
55
+ subject[0] = DemoList::List::TopicElement.new(subject.graph)
56
+ subject.size.should == 1
57
+ end
58
+
59
+ describe "that has 4 elements" do
60
+ before do
61
+ subject[3] = DemoList::List::TopicElement.new(subject.graph)
62
+ subject.size.should == 4
63
+ end
64
+ it "should insert in the middle" do
65
+ subject[1] = DemoList::List::TopicElement.new(subject.graph)
66
+ subject.size.should == 4
67
+ end
68
+ end
69
+
70
+ describe "return updated xml" do
71
+ it "should be built" do
72
+ subject[0] = RDF::URI.new "http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"
73
+ subject[1] = DemoList::List::TopicElement.new(ds.graph)
74
+ subject[1].elementValue = "Relations with Mexican Americans"
75
+ subject[2] = RDF::URI.new "http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"
76
+ subject[3] = DemoList::List::TemporalElement.new(ds.graph)
77
+ subject[3].elementValue = "20th century"
78
+ expected_xml =<<END
79
+ <rdf:RDF
80
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
81
+
82
+ <rdf:Description rdf:about="info:fedora/foo">
83
+ <mads:elementList rdf:parseType="Collection">
84
+ <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
85
+ <mads:TopicElement>
86
+ <mads:elementValue>Relations with Mexican Americans</mads:elementValue>
87
+ </mads:TopicElement>
88
+ <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"/>
89
+ <mads:TemporalElement>
90
+ <mads:elementValue>20th century</mads:elementValue>
91
+ </mads:TemporalElement>
92
+ </mads:elementList>
93
+ </rdf:Description>
94
+ </rdf:RDF>
60
95
  END
96
+ ds.content.should be_equivalent_to expected_xml
97
+ end
98
+ end
61
99
 
62
- subject
63
- end
64
- it "should have a subject" do
65
- subject.rdf_subject.to_s.should == "info:fedora/foo"
66
- end
67
- it "should have fields" do
68
- list = subject.elementList.first
69
- list.first.should == "http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"
70
- list[1].should be_kind_of DemoList::List::TopicElement
71
- list[1].elementValue.should == ["Relations with Mexican Americans"]
72
- list[2].should == "http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"
73
- list[3].should be_kind_of DemoList::List::TemporalElement
74
- list[3].elementValue.should == ["20th century"]
75
- end
76
100
 
77
- it "should have size" do
78
- list = subject.elementList.first
79
- list.size.should == 4
80
101
  end
81
102
 
82
- it "should update fields" do
83
- list = subject.elementList.first
84
- list[3].elementValue = ["1900s"]
85
- expected_xml =<<END
86
- <rdf:RDF
87
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
88
-
89
- <mads:ComplexSubject rdf:about="info:fedora/foo">
90
- <mads:elementList rdf:parseType="Collection">
91
- <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
92
- <mads:TopicElement>
93
- <mads:elementValue>Relations with Mexican Americans</mads:elementValue>
94
- </mads:TopicElement>
95
- <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"/>
96
- <mads:TemporalElement>
97
- <mads:elementValue>1900s</mads:elementValue>
98
- </mads:TemporalElement>
99
- </mads:elementList>
100
- </mads:ComplexSubject>
101
- </rdf:RDF>
103
+ describe "a list with content" do
104
+ subject do
105
+ subject = DemoList.new(stub('inner object', :pid=>'foo', :new? =>true), 'descMetadata')
106
+ subject.content =<<END
107
+ <rdf:RDF
108
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
109
+
110
+ <mads:ComplexSubject rdf:about="info:fedora/foo">
111
+ <mads:elementList rdf:parseType="Collection">
112
+ <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
113
+ <mads:TopicElement>
114
+ <mads:elementValue>Relations with Mexican Americans</mads:elementValue>
115
+ </mads:TopicElement>
116
+ <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"/>
117
+ <mads:TemporalElement>
118
+ <mads:elementValue>20th century</mads:elementValue>
119
+ </mads:TemporalElement>
120
+ </mads:elementList>
121
+ </mads:ComplexSubject>
122
+ </rdf:RDF>
123
+ END
124
+
125
+ subject
126
+ end
127
+ it "should have a subject" do
128
+ subject.rdf_subject.to_s.should == "info:fedora/foo"
129
+ end
130
+ it "should have fields" do
131
+ list = subject.elementList.first
132
+ list.first.should == "http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"
133
+ list[1].should be_kind_of DemoList::List::TopicElement
134
+ list[1].elementValue.should == ["Relations with Mexican Americans"]
135
+ list[2].should == "http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"
136
+ list[3].should be_kind_of DemoList::List::TemporalElement
137
+ list[3].elementValue.should == ["20th century"]
138
+ end
139
+
140
+ it "should have size" do
141
+ list = subject.elementList.first
142
+ list.size.should == 4
143
+ end
144
+
145
+ it "should update fields" do
146
+ list = subject.elementList.first
147
+ list[3].elementValue = ["1900s"]
148
+ expected_xml =<<END
149
+ <rdf:RDF
150
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:mads="http://www.loc.gov/mads/rdf/v1#">
151
+
152
+ <mads:ComplexSubject rdf:about="info:fedora/foo">
153
+ <mads:elementList rdf:parseType="Collection">
154
+ <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX6"/>
155
+ <mads:TopicElement>
156
+ <mads:elementValue>Relations with Mexican Americans</mads:elementValue>
157
+ </mads:TopicElement>
158
+ <rdf:Description rdf:about="http://library.ucsd.edu/ark:/20775/bbXXXXXXX4"/>
159
+ <mads:TemporalElement>
160
+ <mads:elementValue>1900s</mads:elementValue>
161
+ </mads:TemporalElement>
162
+ </mads:elementList>
163
+ </mads:ComplexSubject>
164
+ </rdf:RDF>
102
165
 
103
166
  END
104
- subject.content.should be_equivalent_to expected_xml
167
+ subject.content.should be_equivalent_to expected_xml
168
+ end
105
169
  end
106
170
  end
107
171
 
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: 6.0.0.pre5
4
+ version: 6.0.0.pre6
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: 2013-01-26 00:00:00.000000000 Z
14
+ date: 2013-01-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rsolr
@@ -180,7 +180,7 @@ dependencies:
180
180
  requirements:
181
181
  - - ~>
182
182
  - !ruby/object:Gem::Version
183
- version: 0.3.8
183
+ version: 1.0.0
184
184
  type: :runtime
185
185
  prerelease: false
186
186
  version_requirements: !ruby/object:Gem::Requirement
@@ -188,7 +188,7 @@ dependencies:
188
188
  requirements:
189
189
  - - ~>
190
190
  - !ruby/object:Gem::Version
191
- version: 0.3.8
191
+ version: 1.0.0
192
192
  - !ruby/object:Gem::Dependency
193
193
  name: deprecation
194
194
  requirement: !ruby/object:Gem::Requirement