om 1.8.0 → 1.8.1
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.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +382 -0
- data/.travis.yml +10 -0
- data/Rakefile +1 -1
- data/container_spec.rb +14 -14
- data/gemfiles/gemfile.rails3 +11 -0
- data/gemfiles/gemfile.rails4 +10 -0
- data/lib/om.rb +9 -12
- data/lib/om/samples/mods_article.rb +9 -9
- data/lib/om/tree_node.rb +6 -6
- data/lib/om/version.rb +1 -1
- data/lib/om/xml.rb +18 -20
- data/lib/om/xml/container.rb +12 -12
- data/lib/om/xml/document.rb +3 -7
- data/lib/om/xml/dynamic_node.rb +45 -50
- data/lib/om/xml/named_term_proxy.rb +13 -13
- data/lib/om/xml/node_generator.rb +3 -3
- data/lib/om/xml/template_registry.rb +18 -26
- data/lib/om/xml/term.rb +30 -46
- data/lib/om/xml/term_value_operators.rb +52 -56
- data/lib/om/xml/term_xpath_generator.rb +51 -57
- data/lib/om/xml/terminology.rb +8 -10
- data/lib/om/xml/validation.rb +19 -19
- data/lib/om/xml/vocabulary.rb +4 -4
- data/lib/tasks/om.rake +4 -6
- data/om.gemspec +1 -2
- data/spec/integration/differentiated_elements_spec.rb +2 -2
- data/spec/integration/element_value_spec.rb +13 -13
- data/spec/integration/proxies_and_ref_spec.rb +15 -15
- data/spec/integration/querying_documents_spec.rb +24 -18
- data/spec/integration/rights_metadata_integration_example_spec.rb +18 -18
- data/spec/integration/selective_querying_spec.rb +1 -1
- data/spec/integration/serialization_spec.rb +13 -13
- data/spec/integration/set_reentrant_terminology_spec.rb +7 -7
- data/spec/integration/xpathy_stuff_spec.rb +16 -16
- data/spec/spec_helper.rb +2 -3
- data/spec/unit/container_spec.rb +28 -29
- data/spec/unit/document_spec.rb +49 -50
- data/spec/unit/dynamic_node_spec.rb +55 -47
- data/spec/unit/named_term_proxy_spec.rb +16 -16
- data/spec/unit/node_generator_spec.rb +7 -7
- data/spec/unit/nokogiri_sanity_spec.rb +30 -30
- data/spec/unit/om_spec.rb +5 -5
- data/spec/unit/template_registry_spec.rb +69 -69
- data/spec/unit/term_builder_spec.rb +77 -77
- data/spec/unit/term_spec.rb +78 -72
- data/spec/unit/term_value_operators_spec.rb +186 -191
- data/spec/unit/term_xpath_generator_spec.rb +37 -43
- data/spec/unit/terminology_builder_spec.rb +85 -85
- data/spec/unit/terminology_spec.rb +98 -98
- data/spec/unit/validation_spec.rb +22 -22
- data/spec/unit/xml_serialization_spec.rb +21 -22
- data/spec/unit/xml_spec.rb +7 -7
- metadata +143 -147
@@ -8,7 +8,7 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
8
8
|
include OM::XML::Document
|
9
9
|
|
10
10
|
set_terminology do |t|
|
11
|
-
t.root(:path=>"contentMetadata", :xmlns => '', :namespace_prefix => nil)
|
11
|
+
t.root(:path=>"contentMetadata", :xmlns => '', :namespace_prefix => nil)
|
12
12
|
|
13
13
|
t.resource(:namespace_prefix => nil) {
|
14
14
|
t.file(:ref=>[:file], :namespace_prefix => nil)
|
@@ -51,11 +51,11 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should have a content term" do
|
54
|
-
subject.content.first.
|
54
|
+
expect(subject.content.first).to match(/content/)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should have an html term" do
|
58
|
-
subject.html.first.
|
58
|
+
expect(subject.html.first).to match(/html/)
|
59
59
|
end
|
60
60
|
|
61
61
|
|
@@ -63,7 +63,7 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
63
63
|
|
64
64
|
describe "an example from MODS" do
|
65
65
|
before(:all) do
|
66
|
-
class ModsXpathyStuffTerminology
|
66
|
+
class ModsXpathyStuffTerminology
|
67
67
|
include OM::XML::Document
|
68
68
|
|
69
69
|
set_terminology do |t|
|
@@ -120,15 +120,15 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
120
120
|
end
|
121
121
|
|
122
122
|
it "should have the terms :author_given and :author_family to get the author name" do
|
123
|
-
|
124
|
-
subject.author_given.
|
125
|
-
subject.author_family.
|
123
|
+
skip "This doesn't seem to work?"
|
124
|
+
expect(subject.author_given).to include("Mary")
|
125
|
+
expect(subject.author_family).to include("Pickral")
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should have the terms :advisor_given and :advisor_family to get the advisor name" do
|
129
|
-
|
130
|
-
subject.advisor_given.
|
131
|
-
subject.advisor_family.
|
129
|
+
skip "This doesn't seem to work?"
|
130
|
+
expect(subject.advisor_given).to include("David")
|
131
|
+
expect(subject.advisor_family).to include("Small")
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
@@ -136,7 +136,7 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
136
136
|
describe "more MODS examples, with a given namespace prefix?" do
|
137
137
|
|
138
138
|
before(:all) do
|
139
|
-
class ModsXpathyStuffTerminology
|
139
|
+
class ModsXpathyStuffTerminology
|
140
140
|
include OM::XML::Document
|
141
141
|
|
142
142
|
set_terminology do |t|
|
@@ -153,7 +153,7 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
153
153
|
t.role_term_text(:path=>"roleTerm", :attributes=>{:type=>"text"})
|
154
154
|
}
|
155
155
|
|
156
|
-
t.person_full(:ref=>:name, :attributes=>{:type=>"personal"})
|
156
|
+
t.person_full(:ref=>:name, :attributes=>{:type=>"personal"})
|
157
157
|
t.person(:proxy=>[:person_full, :name_part])
|
158
158
|
t.creator(:ref=>:person, :path=>'name[mods:role/mods:roleTerm="creator"]', :xmlns=>"http://www.loc.gov/mods/v3", :namespace_prefix => "mods")
|
159
159
|
|
@@ -185,19 +185,19 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should give a creator value" do
|
188
|
-
subject.creator.
|
188
|
+
expect(subject.creator).to include "David Small"
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should give a repository value" do
|
192
|
-
subject.repository.
|
192
|
+
expect(subject.repository).to include "Graphic Novel Repository"
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should have a person term 'for more generic xml'" do
|
196
|
-
subject.person.
|
196
|
+
expect(subject.person).to include "David Small"
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should have a corporate term 'for more generic xml'" do
|
200
|
-
subject.corporate.
|
200
|
+
expect(subject.corporate).to include "Graphic Novel Repository"
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
if ENV['COVERAGE']
|
1
|
+
if ENV['COVERAGE'] && RUBY_VERSION =~ /^1.9/
|
2
2
|
require 'simplecov'
|
3
3
|
require 'simplecov-rcov'
|
4
|
-
|
5
4
|
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
6
5
|
SimpleCov.start
|
7
6
|
end
|
@@ -11,7 +10,7 @@ require 'rspec'
|
|
11
10
|
require 'equivalent-xml/rspec_matchers'
|
12
11
|
|
13
12
|
RSpec.configure do |config|
|
14
|
-
|
13
|
+
|
15
14
|
end
|
16
15
|
|
17
16
|
def fixture(file)
|
data/spec/unit/container_spec.rb
CHANGED
@@ -1,80 +1,79 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::Container" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
class ContainerTest
|
7
7
|
include OM::XML::Container
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
subject {
|
12
12
|
ContainerTest.from_xml("<foo><bar>1</bar></foo>")
|
13
13
|
}
|
14
14
|
|
15
15
|
it "should add .ng_xml accessor" do
|
16
|
-
subject.
|
17
|
-
subject.
|
16
|
+
expect(subject).to respond_to(:ng_xml)
|
17
|
+
expect(subject).to respond_to(:ng_xml=)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should initialize" do
|
21
|
-
ContainerTest.new.ng_xml.
|
21
|
+
expect(ContainerTest.new.ng_xml).to be_a_kind_of Nokogiri::XML::Document
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
describe "new" do
|
25
25
|
it "should populate ng_xml with an instance of Nokogiri::XML::Document" do
|
26
|
-
subject.ng_xml.class.
|
26
|
+
expect(subject.ng_xml.class).to eq(Nokogiri::XML::Document)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#from_xml" do
|
31
31
|
it "should accept a String, parse it and store it in .ng_xml" do
|
32
|
-
Nokogiri::XML::Document.
|
32
|
+
expect(Nokogiri::XML::Document).to receive(:parse).and_return("parsed xml")
|
33
33
|
container1 = ContainerTest.from_xml("<foo><bar>1</bar></foo>")
|
34
|
-
container1.ng_xml.
|
34
|
+
expect(container1.ng_xml).to eq("parsed xml")
|
35
35
|
end
|
36
36
|
it "should accept a File, parse it and store it in .ng_xml" do
|
37
37
|
file = fixture(File.join("mods_articles", "hydrangea_article1.xml"))
|
38
|
-
Nokogiri::XML::Document.
|
38
|
+
expect(Nokogiri::XML::Document).to receive(:parse).and_return("parsed xml")
|
39
39
|
container1 = ContainerTest.from_xml(file)
|
40
|
-
container1.ng_xml.
|
40
|
+
expect(container1.ng_xml).to eq("parsed xml")
|
41
41
|
end
|
42
42
|
it "should accept Nokogiri nodes as input and leave them as-is" do
|
43
43
|
parsed_xml = Nokogiri::XML::Document.parse("<foo><bar>1</bar></foo>")
|
44
44
|
container1 = ContainerTest.from_xml(parsed_xml)
|
45
|
-
container1.ng_xml.
|
45
|
+
expect(container1.ng_xml).to eq(parsed_xml)
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
describe ".to_xml" do
|
50
50
|
it "should call .ng_xml.to_xml" do
|
51
|
-
subject.ng_xml.
|
52
|
-
subject.to_xml.
|
51
|
+
expect(subject.ng_xml).to receive(:to_xml).and_return("ng xml")
|
52
|
+
expect(subject.to_xml).to eq("ng xml")
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
|
56
56
|
doc = Nokogiri::XML::Document.parse("<test_xml/>")
|
57
|
-
mock_new_node =
|
58
|
-
doc.root.
|
57
|
+
mock_new_node = double("new node")
|
58
|
+
expect(doc.root).to receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
59
59
|
result = subject.to_xml(doc)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
|
63
63
|
doc = Nokogiri::XML::Document.parse("<test_xml/>")
|
64
|
-
subject.to_xml(doc).
|
64
|
+
expect(subject.to_xml(doc)).to eq("<?xml version=\"1.0\"?>\n<test_xml>\n <foo>\n <bar>1</bar>\n </foo>\n</test_xml>\n")
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it 'should add to root of Nokogiri::XML::Documents, but add directly to the elements if a Nokogiri::XML::Node is passed in' do
|
68
|
-
mock_new_node =
|
69
|
-
mock_new_node.
|
70
|
-
|
68
|
+
mock_new_node = double("new node")
|
69
|
+
allow(mock_new_node).to receive(:to_xml).and_return("foo")
|
71
70
|
doc = Nokogiri::XML::Document.parse("<test_document/>")
|
72
|
-
el
|
73
|
-
doc.root.
|
74
|
-
el.
|
75
|
-
subject.to_xml(doc)
|
71
|
+
el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
|
72
|
+
expect(doc.root).to receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
73
|
+
expect(el).to receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
74
|
+
subject.to_xml(doc)
|
76
75
|
subject.to_xml(el)
|
77
76
|
end
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
end
|
data/spec/unit/document_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::Document" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
|
-
#ModsHelpers.name_("Beethoven, Ludwig van", :date=>"1770-1827", :role=>"creator")
|
7
|
-
class DocumentTest
|
6
|
+
# ModsHelpers.name_("Beethoven, Ludwig van", :date=>"1770-1827", :role=>"creator")
|
7
|
+
class DocumentTest
|
8
|
+
|
9
|
+
include OM::XML::Document
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
# Could add support for multiple root declarations.
|
11
|
+
# Could add support for multiple root declarations.
|
12
12
|
# For now, assume that any modsCollections have already been broken up and fed in as individual mods documents
|
13
|
-
# root :mods_collection, :path=>"modsCollection",
|
13
|
+
# root :mods_collection, :path=>"modsCollection",
|
14
14
|
# :attributes=>[],
|
15
15
|
# :subelements => :mods
|
16
|
-
|
16
|
+
|
17
17
|
set_terminology do |t|
|
18
18
|
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
|
19
19
|
|
20
20
|
t.title_info(:path=>"titleInfo") {
|
21
21
|
t.main_title(:path=>"title", :label=>"title")
|
22
22
|
t.language(:path=>{:attribute=>"lang"})
|
23
|
-
}
|
23
|
+
}
|
24
24
|
# This is a mods:name. The underscore is purely to avoid namespace conflicts.
|
25
25
|
t.name_ {
|
26
26
|
# this is a namepart
|
@@ -36,7 +36,7 @@ describe "OM::XML::Document" do
|
|
36
36
|
t.terms_of_address(:path=>"namePart", :attributes=>{:type=>"termsOfAddress"})
|
37
37
|
t.person_id(:path=>"namePart", :attributes=>{:type=>:none})
|
38
38
|
}
|
39
|
-
# lookup :person, :first_name
|
39
|
+
# lookup :person, :first_name
|
40
40
|
t.person(:ref=>:name, :attributes=>{:type=>"personal"})
|
41
41
|
|
42
42
|
t.role {
|
@@ -59,104 +59,103 @@ describe "OM::XML::Document" do
|
|
59
59
|
t.publication_date(:path=>"date")
|
60
60
|
}
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
before(:each) do
|
68
68
|
@fixturemods = DocumentTest.from_xml( fixture( File.join("CBF_MODS", "ARS0025_016.xml") ) )
|
69
69
|
article_xml = fixture( File.join("mods_articles", "hydrangea_article1.xml") )
|
70
70
|
@mods_article = DocumentTest.from_xml(article_xml)
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
after(:all) do
|
74
74
|
Object.send(:remove_const, :DocumentTest)
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it "should automatically include the necessary modules" do
|
78
|
-
DocumentTest.included_modules.
|
79
|
-
DocumentTest.included_modules.
|
80
|
-
DocumentTest.included_modules.
|
78
|
+
expect(DocumentTest.included_modules).to include(OM::XML::Container)
|
79
|
+
expect(DocumentTest.included_modules).to include(OM::XML::TermValueOperators)
|
80
|
+
expect(DocumentTest.included_modules).to include(OM::XML::Validation)
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
describe ".ox_namespaces" do
|
84
84
|
it "should merge terminology namespaces with document namespaces" do
|
85
|
-
@fixturemods.ox_namespaces.
|
85
|
+
expect(@fixturemods.ox_namespaces).to eq({"oxns"=>"http://www.loc.gov/mods/v3", "xmlns:ns2"=>"http://www.w3.org/1999/xlink", "xmlns:xsi"=>"http://www.w3.org/2001/XMLSchema-instance", "xmlns:ns3"=>"http://www.loc.gov/mods/v3", "xmlns"=>"http://www.loc.gov/mods/v3"})
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
89
|
-
|
88
|
+
|
89
|
+
|
90
90
|
describe ".find_by_terms_and_value" do
|
91
91
|
it "should fail gracefully if you try to look up nodes for an undefined property" do
|
92
|
-
|
93
|
-
@fixturemods.find_by_terms_and_value(:nobody_home).
|
92
|
+
skip "better to get an informative error?"
|
93
|
+
expect(@fixturemods.find_by_terms_and_value(:nobody_home)).to eq([])
|
94
94
|
end
|
95
95
|
it "should use Nokogiri to retrieve a NodeSet corresponding to the term pointers" do
|
96
|
-
@mods_article.find_by_terms_and_value( :person ).length.
|
96
|
+
expect(@mods_article.find_by_terms_and_value( :person ).length).to eq(2)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should allow you to search by term pointer" do
|
100
|
-
@fixturemods.ng_xml.
|
100
|
+
expect(@fixturemods.ng_xml).to receive(:xpath).with('//oxns:name[@type="personal"]', @fixturemods.ox_namespaces)
|
101
101
|
@fixturemods.find_by_terms_and_value(:person)
|
102
102
|
end
|
103
103
|
it "should allow you to constrain your searches" do
|
104
|
-
@fixturemods.ng_xml.
|
104
|
+
expect(@fixturemods.ng_xml).to receive(:xpath).with('//oxns:name[@type="personal" and contains(., "Beethoven, Ludwig van")]', @fixturemods.ox_namespaces)
|
105
105
|
@fixturemods.find_by_terms_and_value(:person, "Beethoven, Ludwig van")
|
106
106
|
end
|
107
107
|
it "should allow you to use complex constraints" do
|
108
|
-
@fixturemods.ng_xml.
|
108
|
+
expect(@fixturemods.ng_xml).to receive(:xpath).with('//oxns:name[@type="personal"]/oxns:namePart[@type="date" and contains(., "2010")]', @fixturemods.ox_namespaces)
|
109
109
|
@fixturemods.find_by_terms_and_value(:person, :date=>"2010")
|
110
|
-
|
111
|
-
@fixturemods.ng_xml.expects(:xpath).with('//oxns:name[@type="personal"]/oxns:role[contains(., "donor")]', @fixturemods.ox_namespaces)
|
110
|
+
expect(@fixturemods.ng_xml).to receive(:xpath).with('//oxns:name[@type="personal"]/oxns:role[contains(., "donor")]', @fixturemods.ox_namespaces)
|
112
111
|
@fixturemods.find_by_terms_and_value(:person, :role=>"donor")
|
113
112
|
end
|
114
113
|
end
|
115
114
|
describe ".find_by_terms" do
|
116
115
|
it "should use Nokogiri to retrieve a NodeSet corresponding to the combination of term pointers and array/nodeset indexes" do
|
117
|
-
@mods_article.find_by_terms( :person ).length.
|
118
|
-
@mods_article.find_by_terms( {:person=>1} ).first.
|
119
|
-
@mods_article.find_by_terms( {:person=>1}, :first_name ).class.
|
120
|
-
@mods_article.find_by_terms( {:person=>1}, :first_name ).first.text.
|
116
|
+
expect(@mods_article.find_by_terms( :person ).length).to eq(2)
|
117
|
+
expect(@mods_article.find_by_terms( {:person=>1} ).first).to eq(@mods_article.ng_xml.xpath('//oxns:name[@type="personal"][2]', "oxns"=>"http://www.loc.gov/mods/v3").first)
|
118
|
+
expect(@mods_article.find_by_terms( {:person=>1}, :first_name ).class).to eq(Nokogiri::XML::NodeSet)
|
119
|
+
expect(@mods_article.find_by_terms( {:person=>1}, :first_name ).first.text).to eq("Siddartha")
|
121
120
|
end
|
122
121
|
it "should find a NodeSet where a terminology attribute has been set to :none" do
|
123
|
-
@mods_article.find_by_terms( {:person=>1}, :person_id).first.text.
|
122
|
+
expect(@mods_article.find_by_terms( {:person=>1}, :person_id).first.text).to eq("123987")
|
124
123
|
end
|
125
124
|
it "should support accessors whose relative_xpath is a lookup array instead of an xpath string" do
|
126
125
|
# pending "this only impacts scenarios where we want to display & edit"
|
127
|
-
DocumentTest.terminology.retrieve_term(:title_info, :language).path.
|
126
|
+
expect(DocumentTest.terminology.retrieve_term(:title_info, :language).path).to eq({:attribute=>"lang"})
|
128
127
|
# @sample.retrieve( :title, 1 ).first.text.should == "Artikkelin otsikko Hydrangea artiklan 1"
|
129
|
-
@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text.
|
128
|
+
expect(@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text).to eq("finnish")
|
130
129
|
end
|
131
|
-
|
130
|
+
|
132
131
|
it "should support xpath queries as the pointer" do
|
133
|
-
@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text.
|
132
|
+
expect(@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text).to eq("FAMILY NAME")
|
134
133
|
end
|
135
|
-
|
134
|
+
|
136
135
|
it "should return nil if the xpath fails to generate" do
|
137
|
-
|
138
|
-
@mods_article.find_by_terms( {:foo=>20}, :bar ).
|
136
|
+
skip "Can't decide if it's better to return nil or raise an error. Choosing informative errors for now."
|
137
|
+
expect(@mods_article.find_by_terms( {:foo=>20}, :bar )).to eq(nil)
|
139
138
|
end
|
140
|
-
|
139
|
+
|
141
140
|
it "should support terms that point to attributes instead of nodes" do
|
142
|
-
@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text.
|
141
|
+
expect(@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text).to eq("finnish")
|
143
142
|
end
|
144
143
|
|
145
144
|
it "should support xpath queries as the pointer" do
|
146
|
-
@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text.
|
145
|
+
expect(@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text).to eq("FAMILY NAME")
|
147
146
|
end
|
148
147
|
end
|
149
|
-
|
148
|
+
|
150
149
|
describe "node_exists?" do
|
151
150
|
it "should return true if any nodes are found" do
|
152
|
-
@mods_article.node_exists?( {:person=>1}, :first_name).
|
151
|
+
expect(@mods_article.node_exists?( {:person=>1}, :first_name)).to be_truthy
|
153
152
|
end
|
154
153
|
it "should return false if no nodes are found" do
|
155
|
-
@mods_article.node_exists?( {:person=>8}, :first_name ).
|
154
|
+
expect(@mods_article.node_exists?( {:person=>8}, :first_name )).to be_falsey
|
156
155
|
end
|
157
156
|
it "should support xpath queries" do
|
158
|
-
@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').
|
157
|
+
expect(@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]')).to be_truthy
|
159
158
|
end
|
160
159
|
end
|
161
|
-
|
160
|
+
|
162
161
|
end
|
@@ -23,125 +23,133 @@ describe "OM::XML::DynamicNode" do
|
|
23
23
|
end
|
24
24
|
it "should create templates for dynamic nodes" do
|
25
25
|
@sample.creator = "Foo"
|
26
|
-
@sample.creator.
|
26
|
+
expect(@sample.creator).to eq(['Foo'])
|
27
27
|
end
|
28
28
|
it "should create templates for dynamic nodes with multiple values" do
|
29
29
|
@sample.creator = ["Foo", "Bar"]
|
30
|
-
@sample.creator.
|
30
|
+
expect(@sample.creator).to eq(['Foo', 'Bar'])
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
34
|
-
|
33
|
+
|
34
|
+
|
35
35
|
describe "with a template" do
|
36
36
|
before(:each) do
|
37
37
|
@sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
|
38
38
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe "dynamically created nodes" do
|
42
42
|
|
43
43
|
it "should return build an array of values from the nodeset corresponding to the given term" do
|
44
44
|
expected_values = ["Berners-Lee", "Jobs", "Wozniak", "Klimt"]
|
45
45
|
result = @sample.person.last_name
|
46
|
-
result.length.
|
47
|
-
expected_values.each {|v| result.
|
46
|
+
expect(result.length).to eq(expected_values.length)
|
47
|
+
expected_values.each {|v| expect(result).to include(v)}
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should be able to set first level elements" do
|
51
51
|
@article.abstract = "My Abstract"
|
52
|
-
@article.abstract.
|
52
|
+
expect(@article.abstract).to eq(["My Abstract"])
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should be able to set first level elements that are arrays" do
|
56
56
|
@article.abstract = ["My Abstract", "two"]
|
57
|
-
@article.abstract.
|
57
|
+
expect(@article.abstract).to eq(["My Abstract", 'two'])
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should delegate all methods (i.e. to_s, first, etc.) to the found array" do
|
61
|
-
@article.person.last_name.to_s.
|
62
|
-
@article.person.last_name.first.
|
61
|
+
expect(@article.person.last_name.to_s).to eq(["FAMILY NAME", "Gautama"].to_s)
|
62
|
+
expect(@article.person.last_name.first).to eq("FAMILY NAME")
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should delegate with blocks to the found array" do
|
66
66
|
arr = []
|
67
67
|
@article.person.last_name.each{|x| arr << x}
|
68
|
-
arr.
|
68
|
+
expect(arr).to eq(["FAMILY NAME", "Gautama"])
|
69
69
|
end
|
70
70
|
|
71
|
-
|
72
71
|
describe "setting attributes" do
|
73
72
|
it "when they exist" do
|
74
73
|
@article.title_info(0).main_title.main_title_lang = "ger"
|
75
|
-
@article.title_info(0).main_title.main_title_lang.
|
74
|
+
expect(@article.title_info(0).main_title.main_title_lang).to eq(["ger"])
|
76
75
|
end
|
77
76
|
it "when they don't exist" do
|
78
77
|
title = @article.title_info(0)
|
79
78
|
title.language = "rus"
|
80
|
-
@article.title_info(0).language.
|
79
|
+
expect(@article.title_info(0).language).to eq(["rus"])
|
81
80
|
end
|
82
|
-
|
83
81
|
end
|
84
82
|
|
85
83
|
it "should find elements two deep" do
|
86
|
-
#TODO reimplement so that method_missing with name is only called once. Create a new method for name.
|
87
|
-
@article.name.name_content.val.
|
88
|
-
@article.name.name_content.
|
89
|
-
@article.name.name_content(0).
|
84
|
+
# TODO reimplement so that method_missing with name is only called once. Create a new method for name.
|
85
|
+
expect(@article.name.name_content.val).to eq(["Describes a person"])
|
86
|
+
expect(@article.name.name_content ).to eq(["Describes a person"])
|
87
|
+
expect(@article.name.name_content(0) ).to eq(["Describes a person"])
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should offer some awareness for respond_to?' do
|
91
|
+
expect(@article.name.name_content.include?('Describes a person')).to be_truthy
|
92
|
+
expect(@article.name.name_content.respond_to?(:include?)).to be_truthy
|
93
|
+
expect(@article.name.name_content).to include('Describes a person')
|
90
94
|
end
|
91
95
|
|
92
|
-
it "should not find elements that don't
|
93
|
-
|
96
|
+
it "should not find elements that don't exist" do
|
97
|
+
expect{@article.name.hedgehog }.to raise_exception NoMethodError, /hedgehog/
|
98
|
+
expect{@article.name.hedgehog = 5 }.to raise_exception NoMethodError, /hedgehog/
|
99
|
+
expect{@article.name.hedgehog(5) }.to raise_exception NoMethodError, /hedgehog/
|
100
|
+
expect{@article.name.hedgehog(5,1)}.to raise_exception NoMethodError, /hedgehog/
|
101
|
+
expect{@article.name.name_content.hedgehog }.to raise_exception NoMethodError, /hedgehog/
|
102
|
+
expect{@article.name.name_content.hedgehog = 'foo' }.to raise_exception NoMethodError, /hedgehog/
|
103
|
+
expect{@article.name.name_content.hedgehog(1) }.to raise_exception NoMethodError, /hedgehog/
|
104
|
+
expect{@article.name.name_content.hedgehog(1,'foo')}.to raise_exception NoMethodError, /hedgehog/
|
94
105
|
end
|
95
106
|
|
96
107
|
it "should allow you to call methods on the return value" do
|
97
|
-
@article.name.name_content.first.
|
108
|
+
expect(@article.name.name_content.first).to eq("Describes a person")
|
98
109
|
end
|
99
110
|
|
100
111
|
it "Should work with proxies" do
|
101
|
-
@article.title.
|
102
|
-
@article.title.main_title_lang.
|
103
|
-
|
104
|
-
@article.
|
105
|
-
|
106
|
-
@article.journal_title.xpath.should == "//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title"
|
107
|
-
@article.journal_title.should == ["TITLE OF HOST JOURNAL"]
|
112
|
+
expect(@article.title).to eq(["ARTICLE TITLE HYDRANGEA ARTICLE 1", "Artikkelin otsikko Hydrangea artiklan 1", "TITLE OF HOST JOURNAL"])
|
113
|
+
expect(@article.title.main_title_lang).to eq(['eng'])
|
114
|
+
expect(@article.title(1).to_pointer).to eq([{:title => 1}])
|
115
|
+
expect(@article.journal_title.xpath).to eq("//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title")
|
116
|
+
expect(@article.journal_title).to eq(["TITLE OF HOST JOURNAL"])
|
108
117
|
end
|
109
118
|
|
110
119
|
it "Should be addressable to a specific node" do
|
111
120
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
|
112
121
|
|
113
122
|
@article.subject.topic(1).to_pointer == [:subject, {:topic => 1}]
|
114
|
-
@article.journal(0).issue.length.
|
123
|
+
expect(@article.journal(0).issue.length).to eq(2)
|
115
124
|
@article.journal(0).issue(1).pages.to_pointer == [{:journal=>0}, {:issue=>1}, :pages]
|
116
|
-
@article.journal(0).issue(1).pages.length.
|
117
|
-
@article.journal(0).issue(1).pages.start.length.
|
118
|
-
@article.journal(0).issue(1).pages.start.first.
|
119
|
-
|
120
|
-
@article.subject.topic(1).
|
121
|
-
@article.subject.topic(1).xpath.should == "//oxns:subject/oxns:topic[2]"
|
125
|
+
expect(@article.journal(0).issue(1).pages.length).to eq(1)
|
126
|
+
expect(@article.journal(0).issue(1).pages.start.length).to eq(1)
|
127
|
+
expect(@article.journal(0).issue(1).pages.start.first).to eq("434")
|
128
|
+
expect(@article.subject.topic(1)).to eq(["TOPIC 2"])
|
129
|
+
expect(@article.subject.topic(1).xpath).to eq("//oxns:subject/oxns:topic[2]")
|
122
130
|
end
|
123
|
-
|
131
|
+
|
124
132
|
describe ".nodeset" do
|
125
133
|
it "should return a Nokogiri NodeSet" do
|
126
134
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
|
127
135
|
nodeset = @article.journal(0).issue(1).pages.start.nodeset
|
128
|
-
nodeset.
|
129
|
-
nodeset.length.
|
130
|
-
nodeset.first.text.
|
136
|
+
expect(nodeset).to be_kind_of Nokogiri::XML::NodeSet
|
137
|
+
expect(nodeset.length).to eq(@article.journal(0).issue(1).pages.start.length)
|
138
|
+
expect(nodeset.first.text).to eq(@article.journal(0).issue(1).pages.start.first)
|
131
139
|
end
|
132
140
|
end
|
133
141
|
|
134
142
|
it "should append nodes at the specified index if possible, setting dirty to true if the object responds to dirty" do
|
135
143
|
# backwards-compatible stuff..
|
136
|
-
@article.
|
137
|
-
@article.
|
138
|
-
|
144
|
+
allow(@article).to receive(:respond_to?).with(any_args).and_call_original
|
145
|
+
allow(@article).to receive(:respond_to?).with(:dirty=).and_return(true)
|
146
|
+
expect(@article).to receive(:dirty=).with(true).at_least(2).times
|
139
147
|
@article.journal.title_info = ["all", "for", "the"]
|
140
148
|
@article.journal.title_info(3, 'glory')
|
141
|
-
@article.term_values(:journal, :title_info).
|
142
|
-
@article.
|
149
|
+
expect(@article.term_values(:journal, :title_info)).to eq(["all", "for", "the", "glory"])
|
150
|
+
expect(@article).to be_changed
|
143
151
|
end
|
144
|
-
|
152
|
+
|
145
153
|
end
|
146
154
|
end
|
147
155
|
end
|