om 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -147,5 +147,17 @@ describe "OM::XML::Document" do
147
147
  @mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text.should == "FAMILY NAME"
148
148
  end
149
149
  end
150
+
151
+ describe "node_exists?" do
152
+ it "should return true if any nodes are found" do
153
+ @mods_article.node_exists?( {:person=>1}, :first_name).should be_true
154
+ end
155
+ it "should return false if no nodes are found" do
156
+ @mods_article.node_exists?( {:person=>8}, :first_name ).should be_false
157
+ end
158
+ it "should support xpath queries" do
159
+ @mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').should be_true
160
+ end
161
+ end
150
162
 
151
163
  end
@@ -5,21 +5,29 @@ describe "OM::XML::NamedTermProxy" do
5
5
 
6
6
  before(:all) do
7
7
 
8
- @test_terminology_builder = OM::XML::Terminology::Builder.new do |t|
9
- t.parent {
10
- t.foo {
11
- t.bar
8
+ class NamedProxyTestDocument
9
+ include OM::XML::Document
10
+ set_terminology do |t|
11
+ t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
12
+ t.parent {
13
+ t.foo {
14
+ t.bar
15
+ }
16
+ t.my_proxy(:proxy=>[:foo, :bar])
12
17
  }
13
- t.my_proxy(:proxy=>[:foo, :bar])
14
- }
15
- t.adoptive_parent(:ref=>[:parent], :attributes=>{:type=>"adoptive"})
16
- t.parentfoobarproxy(:proxy=>[:parent, :foo, :bar])
18
+ t.adoptive_parent(:ref=>[:parent], :attributes=>{:type=>"adoptive"})
19
+ t.parentfoobarproxy(:proxy=>[:parent, :foo, :bar])
20
+ end
21
+ def self.xml_template
22
+ '<mods xmlns="http://www.loc.gov/mods/v3"><parent><foo/></parent></mods>'
23
+ end
17
24
  end
18
25
 
19
- @test_terminology = @test_terminology_builder.build
26
+ @test_terminology = NamedProxyTestDocument.terminology
20
27
  @test_proxy = @test_terminology.retrieve_term(:parent, :my_proxy)
21
28
  @proxied_term = @test_terminology.retrieve_term(:parent, :foo, :bar)
22
29
  @adoptive_parent = @test_terminology.retrieve_term(:adoptive_parent)
30
+
23
31
  end
24
32
 
25
33
  it "should proxy all extra methods to the proxied object" do
@@ -40,4 +48,9 @@ describe "OM::XML::NamedTermProxy" do
40
48
  it "should support NamedTermProxies that point to root terms" do
41
49
  @test_terminology.xpath_for(:parentfoobarproxy).should == "//oxns:parent/oxns:foo/oxns:bar"
42
50
  end
51
+ it "should be usable in update_values" do
52
+ document = NamedProxyTestDocument.from_xml(NamedProxyTestDocument.xml_template)
53
+ document.update_values([:parentfoobarproxy] => "FOObar!")
54
+ document.term_values(:parentfoobarproxy).should == ["FOObar!"]
55
+ end
43
56
  end
@@ -142,7 +142,7 @@ describe "OM::XML::Term::Builder" do
142
142
  end
143
143
  it "should raise an error if the referece points to a nonexistent term builder" do
144
144
  tb = OM::XML::Term::Builder.new("mork",@test_terminology_builder).ref(:characters, :aliens)
145
- lambda { tb.lookup_refs }.should raise_error(OM::XML::Terminology::BadPointerError,"#{tb.name} refers to a Term Builder that doesn't exist. The bad pointer is [:characters, :aliens]")
145
+ lambda { tb.lookup_refs }.should raise_error(OM::XML::Terminology::BadPointerError,"This TerminologyBuilder does not have a root TermBuilder defined that corresponds to \":characters\"")
146
146
  end
147
147
  it "should raise an error with informative error when given circular references" do
148
148
  lambda { @pineapple.lookup_refs }.should raise_error(OM::XML::Terminology::CircularReferenceError,"Circular reference in Terminology: :pineapple => :banana => :coconut => :pineapple")
@@ -163,16 +163,33 @@ describe "OM::XML::Term" do
163
163
  describe "#xml_builder_template" do
164
164
 
165
165
  it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
166
- @test_date.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\', :type=>\'date\' )'
166
+ @test_date.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
167
167
  @test_affiliation.xml_builder_template.should == 'xml.affiliation( \'#{builder_new_value}\' )'
168
168
  end
169
169
  it "should accept extra options" do
170
- marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', :type=>\'code\', :authority=>\'marcrelator\' )'
170
+ marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', \'type\'=>\'code\', \'authority\'=>\'marcrelator\' )'
171
171
  @test_role_code.xml_builder_template(:attributes=>{"authority"=>"marcrelator"}).should == marcrelator_role_xml_builder_template
172
172
  end
173
173
 
174
174
  it "should work for nodes with default_content_path" do
175
- @test_volume.xml_builder_template.should == "xml.detail( :type=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
175
+ @test_volume.xml_builder_template.should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
176
+ end
177
+
178
+ it "should support terms that are attributes" do
179
+ pending "HYDRA-415"
180
+ @type_attribute_term = OM::XML::Term.new(:type_attribute, :path=>{:attribute=>:type})
181
+ @type_attribute_term.xml_builder_template.should == "TODO!"
182
+ end
183
+
184
+ it "should support terms with namespaced attributes" do
185
+ @french_title = OM::XML::Term.new(:french_title, :path=>"title", :attributes=>{"xml:lang"=>"fre"})
186
+ @french_title.xml_builder_template.should == "xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )"
187
+ end
188
+
189
+ it "should support terms that are namespaced attributes" do
190
+ pending "HYDRA-415"
191
+ @xml_lang_attribute_term = OM::XML::Term.new(:xml_lang_attribute, :path=>{:attribute=>"xml:lang"})
192
+ @xml_lang_attribute_term.xml_builder_template.should == "TODO!"
176
193
  end
177
194
 
178
195
  end
@@ -6,6 +6,7 @@ describe "OM::XML::TermValueOperators" do
6
6
  before(:each) do
7
7
  @sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
8
8
  @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
9
+ @empty_sample = OM::Samples::ModsArticle.from_xml("")
9
10
  end
10
11
 
11
12
  describe ".term_values" do
@@ -113,6 +114,23 @@ describe "OM::XML::TermValueOperators" do
113
114
  @article.term_values(:person, :description).should include(" 'phrul gyi lde mig")
114
115
  end
115
116
 
117
+ it "should support inserting nodes with namespaced attributes" do
118
+ @sample.update_values({['title_info', 'french_title']=>'Le Titre'})
119
+ @sample.term_values('title_info', 'french_title').should == ['Le Titre']
120
+ end
121
+
122
+ it "should support inserting attributes" do
123
+ pending "HYDRA-415"
124
+ @sample.update_values({['title_info', 'language']=>'Le Titre'})
125
+ @sample.term_values('title_info', 'french_title').should == ['Le Titre']
126
+ end
127
+
128
+ it "should support inserting namespaced attributes" do
129
+ pending "HYDRA-415"
130
+ @sample.update_values({['title_info', 'main_title', 'main_title_lang']=>'eng'})
131
+ @sample.term_values('title_info', 'main_title', 'main_title_lang').should == ['eng']
132
+ end
133
+
116
134
  ### Examples copied over form nokogiri_datastream_spec
117
135
 
118
136
  it "should apply submitted hash to corresponding datastream field values" do
@@ -422,4 +440,10 @@ describe "OM::XML::TermValueOperators" do
422
440
  end
423
441
  end
424
442
 
443
+ describe "build_ancestors" do
444
+ it "should raise an error if it cant find a starting point for building from" do
445
+ lambda { @empty_sample.build_ancestors( [:journal, :issue], 0) }.should raise_error(OM::XML::TemplateMissingException, "Cannot insert nodes into the document because it is empty.")
446
+ end
447
+ end
448
+
425
449
  end
@@ -279,19 +279,19 @@ describe "OM::XML::Terminology" do
279
279
  describe "#xml_builder_template" do
280
280
 
281
281
  it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
282
- @test_full_terminology.xml_builder_template(:person,:date).should == 'xml.namePart( \'#{builder_new_value}\', :type=>\'date\' )'
282
+ @test_full_terminology.xml_builder_template(:person,:date).should == 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
283
283
  @test_full_terminology.xml_builder_template(:name,:affiliation).should == 'xml.affiliation( \'#{builder_new_value}\' )'
284
284
  end
285
285
  it "should accept extra options" do
286
- marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', :type=>\'code\', :authority=>\'marcrelator\' )'
286
+ marcrelator_role_xml_builder_template = 'xml.roleTerm( \'#{builder_new_value}\', \'type\'=>\'code\', \'authority\'=>\'marcrelator\' )'
287
287
  @test_full_terminology.xml_builder_template(:role, :code, {:attributes=>{"authority"=>"marcrelator"}} ).should == marcrelator_role_xml_builder_template
288
288
  @test_full_terminology.xml_builder_template(:person, :role, :code, {:attributes=>{"authority"=>"marcrelator"}} ).should == marcrelator_role_xml_builder_template
289
289
  end
290
290
 
291
291
  it "should work with deeply nested properties" do
292
- @test_full_terminology.xml_builder_template(:issue, :volume).should == "xml.detail( :type=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
293
- @test_full_terminology.xml_builder_template(:journal, :issue, :level).should == "xml.detail( :type=>'number' ) { xml.number( '\#{builder_new_value}' ) }"
294
- @test_full_terminology.xml_builder_template(:journal, :issue, :volume).should == "xml.detail( :type=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
292
+ @test_full_terminology.xml_builder_template(:issue, :volume).should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
293
+ @test_full_terminology.xml_builder_template(:journal, :issue, :level).should == "xml.detail( \'type\'=>'number' ) { xml.number( '\#{builder_new_value}' ) }"
294
+ @test_full_terminology.xml_builder_template(:journal, :issue, :volume).should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
295
295
  @test_full_terminology.xml_builder_template(:journal, :issue, :pages, :start).should == "xml.start( '\#{builder_new_value}' )"
296
296
  end
297
297
 
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+ require "om"
3
+ require "om/samples"
4
+
5
+ describe "OM::XML::Terminology.to_xml" do
6
+ before(:all) do
7
+ @terminology = OM::Samples::ModsArticle.terminology
8
+ end
9
+ it "should put terminology details into the xml" do
10
+ expected_xml = "<namespaces>\n <namespace>\n <name>oxns</name>\n <identifier>http://www.loc.gov/mods/v3</identifier>\n </namespace>\n <namespace>\n <name>xmlns:foo</name>\n <identifier>http://my.custom.namespace</identifier>\n </namespace>\n <namespace>\n <name>xmlns</name>\n <identifier>http://www.loc.gov/mods/v3</identifier>\n </namespace>\n</namespaces>"
11
+ xml = @terminology.to_xml
12
+ xml.xpath("/terminology/schema").to_xml.should == "<schema>http://www.loc.gov/standards/mods/v3/mods-3-2.xsd</schema>"
13
+ xml.xpath("/terminology/namespaces").to_xml.should be_equivalent_to expected_xml
14
+ # file = File.open(File.dirname(__FILE__)+"/../fixtures/mods_article_terminology.xml", "w")
15
+ # file.write(xml.to_xml)
16
+ end
17
+ it "should call .to_xml on all of the terms" do
18
+ options = {}
19
+ doc = Nokogiri::XML::Document.new
20
+ @terminology.terms.values.each {|term| term.expects(:to_xml) }
21
+ @terminology.to_xml(options,doc)
22
+ end
23
+ end
24
+
25
+
26
+ describe "OM::XML::Term.to_xml" do
27
+ before(:all) do
28
+ @terminology = OM::Samples::ModsArticle.terminology
29
+ @person = @terminology.retrieve_term(:person)
30
+ @person_first_name = @terminology.retrieve_term(:person, :first_name)
31
+ end
32
+ it "should return an xml representation of the Term" do
33
+ xml = @person_first_name.to_xml
34
+ xml.xpath("/term").first.attributes["name"].value.should == "first_name"
35
+ xml.xpath("/term/attributes/type").first.text.should == "given"
36
+ xml.xpath("/term/path").first.text.should == "namePart"
37
+ xml.xpath("/term/namespace_prefix").first.text.should == "oxns"
38
+ xml.xpath("/term/children/*").should be_empty
39
+ xml.xpath("/term/xpath/relative").first.text.should == "oxns:namePart[@type=\"given\"]"
40
+ xml.xpath("/term/xpath/absolute").first.text.should == "//oxns:name[@type=\"personal\"]/oxns:namePart[@type=\"given\"]"
41
+ xml.xpath("/term/xpath/constrained").first.text.should == "//oxns:name[@type=\\\"personal\\\"]/oxns:namePart[@type=\\\"given\\\" and contains(., \\\"\#{constraint_value}\\\")]"
42
+ xml.xpath("/term/index_as").first.text.should == ""
43
+ xml.xpath("/term/required").first.text.should == "false"
44
+ xml.xpath("/term/data_type").first.text.should == "string"
45
+ end
46
+ it "should capture root term info" do
47
+ xml = @terminology.root_terms.first.to_xml
48
+ xml.xpath("/term/is_root_term").text.should == "true"
49
+ @person_first_name.to_xml.xpath("/term/is_root_term").should be_empty
50
+ end
51
+ it "should allow you to pass in a document to add the term to" do
52
+ doc = Nokogiri::XML::Document.new
53
+ @person_first_name.to_xml({}, doc).should == doc
54
+ end
55
+ it "should include children" do
56
+ children = @person.to_xml.xpath("//term[@name=\"person\"]/children/*")
57
+ children.length.should == 12
58
+ children.each {|child| child.name.should == "term"}
59
+ end
60
+ it "should skip children if :children=>false" do
61
+ @person.to_xml(:children=>false).xpath("children").should be_empty
62
+ end
63
+ 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: 21
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
- - 5
10
- version: 1.2.5
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Zumwalt
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-31 00:00:00 Z
18
+ date: 2011-07-26 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: nokogiri
@@ -121,7 +122,6 @@ files:
121
122
  - README.textile
122
123
  - Rakefile
123
124
  - UPDATING_DOCUMENTS.textile
124
- - VERSION
125
125
  - container_spec.rb
126
126
  - lib/om.rb
127
127
  - lib/om/samples.rb
@@ -145,6 +145,7 @@ files:
145
145
  - spec/fixtures/CBF_MODS/ARS0025_016.xml
146
146
  - spec/fixtures/RUBRIC_mods_article_template.xml
147
147
  - spec/fixtures/mods-3-2.xsd
148
+ - spec/fixtures/mods_article_terminology.xml
148
149
  - spec/fixtures/mods_articles/hydrangea_article1.xml
149
150
  - spec/fixtures/test_dummy_mods.xml
150
151
  - spec/integration/rights_metadata_integration_example_spec.rb
@@ -164,7 +165,9 @@ files:
164
165
  - spec/unit/terminology_builder_spec.rb
165
166
  - spec/unit/terminology_spec.rb
166
167
  - spec/unit/validation_spec.rb
168
+ - spec/unit/xml_serialization_spec.rb
167
169
  - spec/unit/xml_spec.rb
170
+ has_rdoc: true
168
171
  homepage: http://github.com/mediashelf/om
169
172
  licenses: []
170
173
 
@@ -194,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
197
  requirements: []
195
198
 
196
199
  rubyforge_project:
197
- rubygems_version: 1.7.2
200
+ rubygems_version: 1.6.2
198
201
  signing_key:
199
202
  specification_version: 3
200
203
  summary: "OM (Opinionated Metadata): A library to help you tame sprawling XML schemas like MODS."
@@ -202,6 +205,7 @@ test_files:
202
205
  - spec/fixtures/CBF_MODS/ARS0025_016.xml
203
206
  - spec/fixtures/RUBRIC_mods_article_template.xml
204
207
  - spec/fixtures/mods-3-2.xsd
208
+ - spec/fixtures/mods_article_terminology.xml
205
209
  - spec/fixtures/mods_articles/hydrangea_article1.xml
206
210
  - spec/fixtures/test_dummy_mods.xml
207
211
  - spec/integration/rights_metadata_integration_example_spec.rb
@@ -221,5 +225,5 @@ test_files:
221
225
  - spec/unit/terminology_builder_spec.rb
222
226
  - spec/unit/terminology_spec.rb
223
227
  - spec/unit/validation_spec.rb
228
+ - spec/unit/xml_serialization_spec.rb
224
229
  - spec/unit/xml_spec.rb
225
- has_rdoc:
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.2.4