om 0.1.10 → 1.0.0
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.
- data/README.textile +27 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/om/samples/mods_article.rb +64 -0
- data/lib/om/samples.rb +2 -0
- data/lib/om/tree_node.rb +24 -0
- data/lib/om/xml/document.rb +68 -0
- data/lib/om/xml/named_term_proxy.rb +37 -0
- data/lib/om/xml/node_generator.rb +14 -0
- data/lib/om/xml/term.rb +223 -0
- data/lib/om/xml/term_value_operators.rb +182 -0
- data/lib/om/xml/term_xpath_generator.rb +224 -0
- data/lib/om/xml/terminology.rb +216 -0
- data/lib/om/xml/vocabulary.rb +17 -0
- data/lib/om/xml.rb +17 -0
- data/lib/om.rb +2 -0
- data/om.gemspec +37 -6
- data/spec/fixtures/mods_articles/hydrangea_article1.xml +0 -1
- data/spec/integration/rights_metadata_integration_example_spec.rb +27 -15
- data/spec/unit/document_spec.rb +141 -0
- data/spec/unit/generator_spec.rb +7 -1
- data/spec/unit/named_term_proxy_spec.rb +39 -0
- data/spec/unit/node_generator_spec.rb +27 -0
- data/spec/unit/properties_spec.rb +1 -1
- data/spec/unit/term_builder_spec.rb +195 -0
- data/spec/unit/term_spec.rb +180 -0
- data/spec/unit/term_value_operators_spec.rb +361 -0
- data/spec/unit/term_xpath_generator_spec.rb +111 -0
- data/spec/unit/terminology_builder_spec.rb +178 -0
- data/spec/unit/terminology_spec.rb +322 -0
- data/spec/unit/validation_spec.rb +4 -0
- metadata +40 -7
@@ -0,0 +1,322 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require "om"
|
3
|
+
|
4
|
+
describe "OM::XML::Terminology" do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@test_terminology = OM::XML::Terminology.new
|
8
|
+
|
9
|
+
# @test_name = OM::XML::Term.new("name_")
|
10
|
+
|
11
|
+
@test_name = OM::XML::Term.new(:name)
|
12
|
+
@test_child_term = OM::XML::Term.new(:namePart)
|
13
|
+
@test_name.add_child @test_child_term
|
14
|
+
@test_terminology.add_term(@test_name)
|
15
|
+
|
16
|
+
@builder_with_block = OM::XML::Terminology::Builder.new do |t|
|
17
|
+
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
|
18
|
+
|
19
|
+
t.title_info(:path=>"titleInfo") {
|
20
|
+
t.main_title(:path=>"title", :label=>"title")
|
21
|
+
t.language(:path=>{:attribute=>"lang"})
|
22
|
+
}
|
23
|
+
# t.title(:path=>"titleInfo", :default_content_path=>"title") {
|
24
|
+
# t.@language(:path=>{:attribute=>"lang"})
|
25
|
+
# }
|
26
|
+
# This is a mods:name. The underscore is purely to avoid namespace conflicts.
|
27
|
+
t.name_ {
|
28
|
+
# this is a namepart
|
29
|
+
t.namePart(:index_as=>[:searchable, :displayable, :facetable, :sortable], :required=>:true, :type=>:string, :label=>"generic name")
|
30
|
+
# affiliations are great
|
31
|
+
t.affiliation
|
32
|
+
t.displayForm
|
33
|
+
t.role(:ref=>[:role])
|
34
|
+
t.description
|
35
|
+
t.date(:path=>"namePart", :attributes=>{:type=>"date"})
|
36
|
+
t.family_name(:path=>"namePart", :attributes=>{:type=>"family"})
|
37
|
+
t.given_name(:path=>"namePart", :attributes=>{:type=>"given"}, :label=>"first name")
|
38
|
+
t.terms_of_address(:path=>"namePart", :attributes=>{:type=>"termsOfAddress"})
|
39
|
+
}
|
40
|
+
# lookup :person, :first_name
|
41
|
+
t.person(:ref=>:name, :attributes=>{:type=>"personal"})
|
42
|
+
t.conference(:ref=>:name, :attributes=>{:type=>"conference"})
|
43
|
+
|
44
|
+
t.role {
|
45
|
+
t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
|
46
|
+
t.code(:path=>"roleTerm",:attributes=>{:type=>"code"})
|
47
|
+
}
|
48
|
+
t.journal(:path=>'relatedItem', :attributes=>{:type=>"host"}) {
|
49
|
+
t.title_info
|
50
|
+
t.origin_info(:path=>"originInfo")
|
51
|
+
t.issn(:path=>"identifier", :attributes=>{:type=>"issn"})
|
52
|
+
t.issue(:ref=>[:issue])
|
53
|
+
}
|
54
|
+
t.issue(:path=>"part") {
|
55
|
+
t.volume(:path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
|
56
|
+
t.level(:path=>"detail", :attributes=>{:type=>"number"}, :default_content_path=>"number")
|
57
|
+
# t.start_page(:path=>"pages", :attributes=>{:type=>"start"})
|
58
|
+
# t.end_page(:path=>"pages", :attributes=>{:type=>"end"})
|
59
|
+
t.publication_date(:path=>"date")
|
60
|
+
t.pages(:path=>"extent", :attributes=>{:unit=>"pages"}) {
|
61
|
+
t.start
|
62
|
+
t.end
|
63
|
+
}
|
64
|
+
t.start_page(:proxy=>[:pages, :start])
|
65
|
+
t.end_page(:proxy=>[:pages, :end])
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
@test_full_terminology = @builder_with_block.build
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "basics" do
|
74
|
+
|
75
|
+
it "constructs xpath queries for finding properties" do
|
76
|
+
@test_full_terminology.retrieve_term(:name).xpath.should == '//oxns:name'
|
77
|
+
@test_full_terminology.retrieve_term(:name).xpath_relative.should == 'oxns:name'
|
78
|
+
|
79
|
+
@test_full_terminology.retrieve_term(:person).xpath.should == '//oxns:name[@type="personal"]'
|
80
|
+
@test_full_terminology.retrieve_term(:person).xpath_relative.should == 'oxns:name[@type="personal"]'
|
81
|
+
end
|
82
|
+
|
83
|
+
it "constructs templates for value-driven searches" do
|
84
|
+
@test_full_terminology.retrieve_term(:name).xpath_constrained.should == '//oxns:name[contains(., "#{constraint_value}")]'.gsub('"', '\"')
|
85
|
+
@test_full_terminology.retrieve_term(:person).xpath_constrained.should == '//oxns:name[@type="personal" and contains(., "#{constraint_value}")]'.gsub('"', '\"')
|
86
|
+
|
87
|
+
# Example of how you could use these templates:
|
88
|
+
constraint_value = "SAMPLE CONSTRAINT VALUE"
|
89
|
+
constrained_query = eval( '"' + @test_full_terminology.retrieve_term(:person).xpath_constrained + '"' )
|
90
|
+
constrained_query.should == '//oxns:name[@type="personal" and contains(., "SAMPLE CONSTRAINT VALUE")]'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "constructs xpath queries & templates for nested terms" do
|
94
|
+
name_date_term = @test_full_terminology.retrieve_term(:name, :date)
|
95
|
+
name_date_term.xpath.should == '//oxns:name/oxns:namePart[@type="date"]'
|
96
|
+
name_date_term.xpath_relative.should == 'oxns:namePart[@type="date"]'
|
97
|
+
name_date_term.xpath_constrained.should == '//oxns:name/oxns:namePart[@type="date" and contains(., "#{constraint_value}")]'.gsub('"', '\"')
|
98
|
+
# name_date_term.xpath_constrained.should == '//oxns:name[contains(oxns:namePart[@type="date"], "#{constraint_value}")]'.gsub('"', '\"')
|
99
|
+
|
100
|
+
person_date_term = @test_full_terminology.retrieve_term(:person, :date)
|
101
|
+
person_date_term.xpath.should == '//oxns:name[@type="personal"]/oxns:namePart[@type="date"]'
|
102
|
+
person_date_term.xpath_relative.should == 'oxns:namePart[@type="date"]'
|
103
|
+
person_date_term.xpath_constrained.should == '//oxns:name[@type="personal"]/oxns:namePart[@type="date" and contains(., "#{constraint_value}")]'.gsub('"', '\"')
|
104
|
+
# person_date_term.xpath_constrained.should == '//oxns:name[@type="personal" and contains(oxns:namePart[@type="date"], "#{constraint_value}")]'.gsub('"', '\"')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "supports subelements that are specified using a :ref" do
|
108
|
+
role_term = @test_full_terminology.retrieve_term(:name, :role)
|
109
|
+
role_term.xpath.should == '//oxns:name/oxns:role'
|
110
|
+
role_term.xpath_relative.should == 'oxns:role'
|
111
|
+
role_term.xpath_constrained.should == '//oxns:name/oxns:role[contains(., "#{constraint_value}")]'.gsub('"', '\"')
|
112
|
+
# role_term.xpath_constrained.should == '//oxns:name[contains(oxns:role/oxns:roleTerm, "#{constraint_value}")]'.gsub('"', '\"')
|
113
|
+
end
|
114
|
+
|
115
|
+
it "supports treating attributes as properties" do
|
116
|
+
language_term = @test_full_terminology.retrieve_term(:title_info, :language)
|
117
|
+
language_term.xpath.should == '//oxns:titleInfo/@lang'
|
118
|
+
language_term.xpath_relative.should == '@lang'
|
119
|
+
language_term.xpath_constrained.should == '//oxns:titleInfo/@lang[contains(., "#{constraint_value}")]'.gsub('"', '\"')
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should support deep nesting of properties" do
|
123
|
+
volume_term = @test_full_terminology.retrieve_term(:journal, :issue, :volume)
|
124
|
+
volume_term.xpath.should == "//oxns:relatedItem[@type=\"host\"]/oxns:part/oxns:detail[@type=\"volume\"]"
|
125
|
+
volume_term.xpath_relative.should == "oxns:detail[@type=\"volume\"]"
|
126
|
+
# volume_term.xpath_constrained.should == "//oxns:part[contains(oxns:detail[@type=\\\"volume\\\"], \\\"\#{constraint_value}\\\")]"
|
127
|
+
volume_term.xpath_constrained.should == '//oxns:relatedItem[@type="host"]/oxns:part/oxns:detail[@type="volume" and contains(oxns:number, "#{constraint_value}")]'.gsub('"', '\"')
|
128
|
+
end
|
129
|
+
|
130
|
+
it "should not overwrite default property info when adding a variant property" do
|
131
|
+
name_term = @test_full_terminology.retrieve_term(:name)
|
132
|
+
person_term = @test_full_terminology.retrieve_term(:person)
|
133
|
+
|
134
|
+
name_term.should_not equal(person_term)
|
135
|
+
name_term.xpath.should_not equal(person_term.xpath)
|
136
|
+
name_term.children.should_not equal(person_term.children)
|
137
|
+
name_term.children[:date].xpath_constrained.should_not equal(person_term.children[:date].xpath_constrained)
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#from_xml' do
|
143
|
+
it "should let you load mappings from an xml file" do
|
144
|
+
pending
|
145
|
+
vocab = OM::XML::Terminology.from_xml( fixture("sample_mappings.xml") )
|
146
|
+
vocab.should be_instance_of OM::XML::Terminology
|
147
|
+
vocab.mappers.should == {}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#to_xml' do
|
152
|
+
it "should let you serialize mappings to an xml document" do
|
153
|
+
pending
|
154
|
+
TerminologyTest.to_xml.should == ""
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe ".has_term?" do
|
159
|
+
it "should return true if the specified term does exist in the terminology" do
|
160
|
+
@test_full_terminology.has_term?(:journal,:issue,:end_page).should be_true
|
161
|
+
end
|
162
|
+
it "should support term_pointers with array indexes in them (ignoring the indexes)" do
|
163
|
+
@test_full_terminology.has_term?(:title_info, :main_title).should be_true
|
164
|
+
@test_full_terminology.has_term?({:title_info=>"0"}, :main_title).should be_true
|
165
|
+
end
|
166
|
+
it "should return false if the specified term does not exist in the terminology" do
|
167
|
+
@test_full_terminology.has_term?(:name, :date, :nonexistentTerm, :anotherTermName).should be_false
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe ".retrieve_term" do
|
172
|
+
it "should return the mapper identified by the given pointer" do
|
173
|
+
term = @test_terminology.retrieve_term(:name, :namePart)
|
174
|
+
term.should == @test_terminology.terms[:name].children[:namePart]
|
175
|
+
term.should == @test_child_term
|
176
|
+
end
|
177
|
+
it "should build complete terminologies" do
|
178
|
+
@test_full_terminology.retrieve_term(:name, :date).should be_instance_of OM::XML::Term
|
179
|
+
@test_full_terminology.retrieve_term(:name, :date).path.should == 'namePart'
|
180
|
+
@test_full_terminology.retrieve_term(:name, :date).attributes.should == {:type=>"date"}
|
181
|
+
@test_full_terminology.retrieve_term(:name, :affiliation).path.should == 'affiliation'
|
182
|
+
@test_full_terminology.retrieve_term(:name, :date).xpath.should == '//oxns:name/oxns:namePart[@type="date"]'
|
183
|
+
end
|
184
|
+
it "should support looking up variant Terms" do
|
185
|
+
@test_full_terminology.retrieve_term(:person).path.should == 'name'
|
186
|
+
@test_full_terminology.retrieve_term(:person).attributes.should == {:type=>"personal"}
|
187
|
+
@test_full_terminology.retrieve_term(:person, :affiliation).path.should == 'affiliation'
|
188
|
+
@test_full_terminology.retrieve_term(:person, :date).xpath.should == '//oxns:name[@type="personal"]/oxns:namePart[@type="date"]'
|
189
|
+
end
|
190
|
+
it "should support including root terms in pointer" do
|
191
|
+
@test_full_terminology.retrieve_term(:mods).should be_instance_of OM::XML::Term
|
192
|
+
@test_full_terminology.retrieve_term(:mods, :name, :date).should be_instance_of OM::XML::Term
|
193
|
+
@test_full_terminology.retrieve_term(:mods, :name, :date).path.should == 'namePart'
|
194
|
+
@test_full_terminology.retrieve_term(:mods, :name, :date).attributes.should == {:type=>"date"}
|
195
|
+
@test_full_terminology.retrieve_term(:mods, :name, :date).xpath.should == '//oxns:mods/oxns:name/oxns:namePart[@type="date"]'
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should raise an informative error if the desired Term doesn't exist" do
|
199
|
+
lambda { @test_full_terminology.retrieve_term(:name, :date, :nonexistentTerm, :anotherTermName) }.should raise_error(OM::XML::Terminology::BadPointerError, "You attempted to retrieve a Term using this pointer: [:name, :date, :nonexistentTerm, :anotherTermName] but no Term exists at that location. Everything is fine until \":nonexistentTerm\", which doesn't exist.")
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
describe ".term_xpath" do
|
204
|
+
it "should insert calls to xpath array lookup into parent xpaths if parents argument is provided" do
|
205
|
+
pending
|
206
|
+
# conference_mapper = TerminologyTest.retrieve_mapper(:conference)
|
207
|
+
# role_mapper = TerminologyTest.retrieve_mapper(:conference, :role)
|
208
|
+
# text_mapper = TerminologyTest.retrieve_mapper(:conference, :role, :text)
|
209
|
+
TerminologyTest.term_xpath({:conference=>0}, {:role=>1}, :text ).should == '//oxns:name[@type="conference"][1]/oxns:role[2]/oxns:roleTerm[@type="text"]'
|
210
|
+
# OM::XML::TermXpathGenerator.expects(:generate_absolute_xpath).with({conference_mapper=>0}, {role_mapper=>1}, text_mapper)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe ".xpath_for" do
|
215
|
+
|
216
|
+
it "should retrieve the generated xpath query to match your desires" do
|
217
|
+
@test_full_terminology.xpath_for(:person).should == '//oxns:name[@type="personal"]'
|
218
|
+
|
219
|
+
@test_full_terminology.xpath_for(:person, "Beethoven, Ludwig van").should == '//oxns:name[@type="personal" and contains(., "Beethoven, Ludwig van")]'
|
220
|
+
|
221
|
+
@test_full_terminology.xpath_for(:person, :date).should == '//oxns:name[@type="personal"]/oxns:namePart[@type="date"]'
|
222
|
+
|
223
|
+
@test_full_terminology.xpath_for(:person, :date, "2010").should == '//oxns:name[@type="personal"]/oxns:namePart[@type="date" and contains(., "2010")]'
|
224
|
+
end
|
225
|
+
|
226
|
+
it "should support including root terms in term pointer" do
|
227
|
+
@test_full_terminology.xpath_for(:mods, :person).should == '//oxns:mods/oxns:name[@type="personal"]'
|
228
|
+
@test_full_terminology.xpath_for(:mods, :person, "Beethoven, Ludwig van").should == '//oxns:mods/oxns:name[@type="personal" and contains(., "Beethoven, Ludwig van")]'
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should support queries with complex constraints" do
|
232
|
+
pending
|
233
|
+
@test_full_terminology.xpath_for(:person, {:date=>"2010"}).should == '//oxns:name[@type="personal" and contains(oxns:namePart[@type="date"], "2010")]'
|
234
|
+
end
|
235
|
+
|
236
|
+
it "should support queries with multiple complex constraints" do
|
237
|
+
pending
|
238
|
+
@test_full_terminology.xpath_for(:person, {:role=>"donor", :last_name=>"Rockefeller"}).should == '//oxns:name[@type="personal" and contains(oxns:role/oxns:roleTerm, "donor") and contains(oxns:namePart[@type="family"], "Rockefeller")]'
|
239
|
+
end
|
240
|
+
|
241
|
+
it "should parrot any strings back to you (in case you already have an xpath query)" do
|
242
|
+
@test_full_terminology.xpath_for('//oxns:name[@type="personal"]/oxns:namePart[@type="date"]').should == '//oxns:name[@type="personal"]/oxns:namePart[@type="date"]'
|
243
|
+
end
|
244
|
+
|
245
|
+
it "should traverse named term proxies transparently" do
|
246
|
+
proxied_xpath = @test_full_terminology.xpath_for(:journal, :issue, :pages, :start)
|
247
|
+
@test_full_terminology.xpath_for( :journal, :issue, :start_page ).should == proxied_xpath
|
248
|
+
end
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
describe ".xpath_with_indexes" do
|
253
|
+
it "should return the xpath given in the call to #accessor" do
|
254
|
+
@test_full_terminology.xpath_with_indexes( :title_info ).should == '//oxns:titleInfo'
|
255
|
+
end
|
256
|
+
it "should support xpath queries as argument" do
|
257
|
+
@test_full_terminology.xpath_with_indexes('//oxns:name[@type="personal"][1]/oxns:namePart').should == '//oxns:name[@type="personal"][1]/oxns:namePart'
|
258
|
+
end
|
259
|
+
# Note: Ruby array indexes begin from 0. In xpath queries (which start from 1 instead of 0), this will be translated accordingly.
|
260
|
+
it "should prepend the xpath for any parent nodes, inserting calls to xpath array lookup where necessary" do
|
261
|
+
@test_full_terminology.xpath_with_indexes( {:conference=>0}, {:role=>1}, :text ).should == '//oxns:name[@type="conference"][1]/oxns:role[2]/oxns:roleTerm[@type="text"]'
|
262
|
+
end
|
263
|
+
it "should be idempotent" do
|
264
|
+
@test_full_terminology.xpath_with_indexes( *[{:title_info=>2}, :main_title] ).should == "//oxns:titleInfo[3]/oxns:title"
|
265
|
+
@test_full_terminology.xpath_with_indexes( *[{:title_info=>2}, :main_title] ).should == "//oxns:titleInfo[3]/oxns:title"
|
266
|
+
@test_full_terminology.xpath_with_indexes( *[{:title_info=>2}, :main_title] ).should == "//oxns:titleInfo[3]/oxns:title"
|
267
|
+
end
|
268
|
+
it "should traverse named term proxies transparently" do
|
269
|
+
proxied_xpath = @test_full_terminology.xpath_with_indexes(:journal, :issue, :pages, :start)
|
270
|
+
@test_full_terminology.xpath_with_indexes( :journal, :issue, :start_page ).should == proxied_xpath
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe "#xml_builder_template" do
|
275
|
+
|
276
|
+
it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
|
277
|
+
@test_full_terminology.xml_builder_template(:person,:date).should == 'xml.namePart( \'#{builder_new_value}\', :type=>\'date\' )'
|
278
|
+
@test_full_terminology.xml_builder_template(:name,:affiliation).should == 'xml.affiliation( \'#{builder_new_value}\' )'
|
279
|
+
end
|
280
|
+
it "should accept extra options" do
|
281
|
+
marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', :type=>\'code\', :authority=>\'marcrelator\' )'
|
282
|
+
@test_full_terminology.xml_builder_template(:role, :code, {:attributes=>{"authority"=>"marcrelator"}} ).should == marcrelator_role_xml_builder_template
|
283
|
+
@test_full_terminology.xml_builder_template(:person, :role, :code, {:attributes=>{"authority"=>"marcrelator"}} ).should == marcrelator_role_xml_builder_template
|
284
|
+
end
|
285
|
+
|
286
|
+
it "should work with deeply nested properties" do
|
287
|
+
@test_full_terminology.xml_builder_template(:issue, :volume).should == "xml.detail( :type=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
|
288
|
+
@test_full_terminology.xml_builder_template(:journal, :issue, :level).should == "xml.detail( :type=>'number' ) { xml.number( '\#{builder_new_value}' ) }"
|
289
|
+
@test_full_terminology.xml_builder_template(:journal, :issue, :volume).should == "xml.detail( :type=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
|
290
|
+
@test_full_terminology.xml_builder_template(:journal, :issue, :pages, :start).should == "xml.start( '\#{builder_new_value}' )"
|
291
|
+
end
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
describe "#term_generic_name" do
|
296
|
+
it "should generate a generic accessor name based on an array of pointers" do
|
297
|
+
OM::XML::Terminology.term_generic_name( {:conference=>0}, {:role=>1}, :text ).should == "conference_role_text"
|
298
|
+
OM::XML::Terminology.term_generic_name( *[{:conference=>0}, {:role=>1}, :text] ).should == "conference_role_text"
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
describe "#term_hierarchical_name" do
|
303
|
+
it "should generate a specific accessor name based on an array of pointers and indexes" do
|
304
|
+
OM::XML::Terminology.term_hierarchical_name( {:conference=>0}, {:role=>1}, :text ).should == "conference_0_role_1_text"
|
305
|
+
OM::XML::Terminology.term_hierarchical_name( *[{:conference=>0}, {:role=>1}, :text] ).should == "conference_0_role_1_text"
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe ".term_builders" do
|
310
|
+
it "should return a hash terms that have been added to the root of the terminology, indexed by term name" do
|
311
|
+
@test_terminology.terms[:name].should == @test_name
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe ".root_terms" do
|
316
|
+
it "should return the terms that have been marked root" do
|
317
|
+
@test_full_terminology.root_terms.length.should == 1
|
318
|
+
@test_full_terminology.root_terms.first.should == @test_full_terminology.terms[:mods]
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
end
|
@@ -27,12 +27,14 @@ describe "OM::XML::Validation" do
|
|
27
27
|
|
28
28
|
describe "#schema" do
|
29
29
|
it "should return an instance of Nokogiri::XML::Schema loaded from the schema url -- fails if no internet connection" do
|
30
|
+
pending "no internet connection"
|
30
31
|
ValidationTest.schema.should be_kind_of Nokogiri::XML::Schema
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
34
35
|
describe "#validate" do
|
35
36
|
it "should validate the provided document against the schema provided in class definition -- fails if no internet connection" do
|
37
|
+
pending "no internet connection"
|
36
38
|
ValidationTest.schema.expects(:validate).with(@sample).returns([])
|
37
39
|
ValidationTest.validate(@sample)
|
38
40
|
end
|
@@ -65,6 +67,7 @@ describe "OM::XML::Validation" do
|
|
65
67
|
|
66
68
|
describe "#file_from_url" do
|
67
69
|
it "should retrieve a file from the provided url over HTTP" do
|
70
|
+
ValidationTest.expects(:open).with("http://google.com")
|
68
71
|
ValidationTest.send(:file_from_url, "http://google.com")
|
69
72
|
end
|
70
73
|
it "should raise an error if the url is invalid" do
|
@@ -72,6 +75,7 @@ describe "OM::XML::Validation" do
|
|
72
75
|
lambda {ValidationTest.send(:file_from_url, "foo")}.should raise_error(RuntimeError, "Could not retrieve file from foo. Error: No such file or directory - foo")
|
73
76
|
end
|
74
77
|
it "should raise an error if file retrieval fails" do
|
78
|
+
pending "no internet connection"
|
75
79
|
lambda {ValidationTest.send(:file_from_url, "http://fedora-commons.org/nonexistent_file")}.should raise_error(RuntimeError, "Could not retrieve file from http://fedora-commons.org/nonexistent_file. Error: 404 Not Found")
|
76
80
|
end
|
77
81
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: om
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Zumwalt
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-15 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -28,8 +28,10 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
hash: 3
|
30
30
|
segments:
|
31
|
-
-
|
32
|
-
|
31
|
+
- 1
|
32
|
+
- 4
|
33
|
+
- 2
|
34
|
+
version: 1.4.2
|
33
35
|
type: :runtime
|
34
36
|
version_requirements: *id001
|
35
37
|
- !ruby/object:Gem::Dependency
|
@@ -101,23 +103,36 @@ extensions: []
|
|
101
103
|
extra_rdoc_files:
|
102
104
|
- LICENSE
|
103
105
|
- README.rdoc
|
106
|
+
- README.textile
|
104
107
|
files:
|
105
108
|
- .document
|
106
109
|
- .gitignore
|
107
110
|
- History.textile
|
108
111
|
- LICENSE
|
109
112
|
- README.rdoc
|
113
|
+
- README.textile
|
110
114
|
- Rakefile
|
111
115
|
- VERSION
|
112
116
|
- container_spec.rb
|
113
117
|
- lib/om.rb
|
118
|
+
- lib/om/samples.rb
|
119
|
+
- lib/om/samples/mods_article.rb
|
120
|
+
- lib/om/tree_node.rb
|
114
121
|
- lib/om/xml.rb
|
115
122
|
- lib/om/xml/accessors.rb
|
116
123
|
- lib/om/xml/container.rb
|
124
|
+
- lib/om/xml/document.rb
|
117
125
|
- lib/om/xml/generator.rb
|
126
|
+
- lib/om/xml/named_term_proxy.rb
|
127
|
+
- lib/om/xml/node_generator.rb
|
118
128
|
- lib/om/xml/properties.rb
|
119
129
|
- lib/om/xml/property_value_operators.rb
|
130
|
+
- lib/om/xml/term.rb
|
131
|
+
- lib/om/xml/term_value_operators.rb
|
132
|
+
- lib/om/xml/term_xpath_generator.rb
|
133
|
+
- lib/om/xml/terminology.rb
|
120
134
|
- lib/om/xml/validation.rb
|
135
|
+
- lib/om/xml/vocabulary.rb
|
121
136
|
- om.gemspec
|
122
137
|
- spec/fixtures/CBF_MODS/ARS0025_016.xml
|
123
138
|
- spec/fixtures/RUBRIC_mods_article_template.xml
|
@@ -129,10 +144,19 @@ files:
|
|
129
144
|
- spec/spec_helper.rb
|
130
145
|
- spec/unit/accessors_spec.rb
|
131
146
|
- spec/unit/container_spec.rb
|
147
|
+
- spec/unit/document_spec.rb
|
132
148
|
- spec/unit/generator_spec.rb
|
149
|
+
- spec/unit/named_term_proxy_spec.rb
|
150
|
+
- spec/unit/node_generator_spec.rb
|
133
151
|
- spec/unit/om_spec.rb
|
134
152
|
- spec/unit/properties_spec.rb
|
135
153
|
- spec/unit/property_value_operators_spec.rb
|
154
|
+
- spec/unit/term_builder_spec.rb
|
155
|
+
- spec/unit/term_spec.rb
|
156
|
+
- spec/unit/term_value_operators_spec.rb
|
157
|
+
- spec/unit/term_xpath_generator_spec.rb
|
158
|
+
- spec/unit/terminology_builder_spec.rb
|
159
|
+
- spec/unit/terminology_spec.rb
|
136
160
|
- spec/unit/validation_spec.rb
|
137
161
|
- spec/unit/xml_spec.rb
|
138
162
|
has_rdoc: true
|
@@ -174,9 +198,18 @@ test_files:
|
|
174
198
|
- spec/spec_helper.rb
|
175
199
|
- spec/unit/accessors_spec.rb
|
176
200
|
- spec/unit/container_spec.rb
|
201
|
+
- spec/unit/document_spec.rb
|
177
202
|
- spec/unit/generator_spec.rb
|
203
|
+
- spec/unit/named_term_proxy_spec.rb
|
204
|
+
- spec/unit/node_generator_spec.rb
|
178
205
|
- spec/unit/om_spec.rb
|
179
206
|
- spec/unit/properties_spec.rb
|
180
207
|
- spec/unit/property_value_operators_spec.rb
|
208
|
+
- spec/unit/term_builder_spec.rb
|
209
|
+
- spec/unit/term_spec.rb
|
210
|
+
- spec/unit/term_value_operators_spec.rb
|
211
|
+
- spec/unit/term_xpath_generator_spec.rb
|
212
|
+
- spec/unit/terminology_builder_spec.rb
|
213
|
+
- spec/unit/terminology_spec.rb
|
181
214
|
- spec/unit/validation_spec.rb
|
182
215
|
- spec/unit/xml_spec.rb
|