om 1.8.1 → 1.9.0.pre1
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/Rakefile +1 -1
- data/container_spec.rb +14 -14
- data/lib/om.rb +12 -9
- 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 +33 -31
- data/lib/om/xml/container.rb +12 -12
- data/lib/om/xml/document.rb +19 -18
- data/lib/om/xml/dynamic_node.rb +50 -45
- 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 +26 -18
- data/lib/om/xml/term.rb +46 -30
- data/lib/om/xml/term_value_operators.rb +56 -52
- data/lib/om/xml/term_xpath_generator.rb +57 -51
- data/lib/om/xml/terminology.rb +10 -8
- data/lib/om/xml/terminology_based_solrizer.rb +90 -0
- data/lib/om/xml/validation.rb +19 -19
- data/lib/om/xml/vocabulary.rb +4 -4
- data/lib/tasks/om.rake +6 -4
- data/om.gemspec +2 -1
- data/spec/fixtures/mods_article.rb +90 -0
- data/spec/fixtures/mods_articles/hydrangea_article1.xml +2 -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 +18 -24
- 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 +10 -10
- data/spec/integration/xpathy_stuff_spec.rb +16 -16
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/container_spec.rb +29 -28
- data/spec/unit/document_spec.rb +50 -49
- data/spec/unit/dynamic_node_spec.rb +45 -57
- 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 +73 -79
- data/spec/unit/term_value_operators_spec.rb +191 -186
- data/spec/unit/term_xpath_generator_spec.rb +43 -37
- 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 +22 -21
- data/spec/unit/xml_spec.rb +7 -7
- data/spec/unit/xml_terminology_based_solrizer_spec.rb +109 -0
- metadata +57 -17
- checksums.yaml +0 -7
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -382
- data/.travis.yml +0 -10
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
if ENV['COVERAGE']
|
1
|
+
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
|
2
2
|
require 'simplecov'
|
3
3
|
require 'simplecov-rcov'
|
4
|
+
|
4
5
|
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
5
6
|
SimpleCov.start
|
6
7
|
end
|
@@ -10,7 +11,6 @@ require 'rspec'
|
|
10
11
|
require 'equivalent-xml/rspec_matchers'
|
11
12
|
|
12
13
|
RSpec.configure do |config|
|
13
|
-
|
14
14
|
end
|
15
15
|
|
16
16
|
def fixture(file)
|
data/spec/unit/container_spec.rb
CHANGED
@@ -1,79 +1,80 @@
|
|
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
|
-
|
17
|
-
|
16
|
+
subject.should respond_to(:ng_xml)
|
17
|
+
subject.should respond_to(:ng_xml=)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should initialize" do
|
21
|
-
|
21
|
+
ContainerTest.new.ng_xml.should 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
|
-
|
26
|
+
subject.ng_xml.class.should == 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
|
-
|
32
|
+
Nokogiri::XML::Document.should_receive(:parse).and_return("parsed xml")
|
33
33
|
container1 = ContainerTest.from_xml("<foo><bar>1</bar></foo>")
|
34
|
-
|
34
|
+
container1.ng_xml.should == "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
|
-
|
38
|
+
Nokogiri::XML::Document.should_receive(:parse).and_return("parsed xml")
|
39
39
|
container1 = ContainerTest.from_xml(file)
|
40
|
-
|
40
|
+
container1.ng_xml.should == "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
|
-
|
45
|
+
container1.ng_xml.should == 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
|
-
|
52
|
-
|
51
|
+
subject.ng_xml.should_receive(:to_xml).and_return("ng xml")
|
52
|
+
subject.to_xml.should == "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
|
-
|
57
|
+
mock_new_node = mock("new node")
|
58
|
+
doc.root.should_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
|
-
|
64
|
+
subject.to_xml(doc).should == "<?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
|
-
|
68
|
+
mock_new_node = mock("new node")
|
69
|
+
mock_new_node.stub(:to_xml).and_return("foo")
|
70
|
+
|
70
71
|
doc = Nokogiri::XML::Document.parse("<test_document/>")
|
71
|
-
el
|
72
|
-
|
73
|
-
|
74
|
-
subject.to_xml(doc)
|
72
|
+
el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
|
73
|
+
doc.root.should_receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
74
|
+
el.should_receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
75
|
+
subject.to_xml(doc).should
|
75
76
|
subject.to_xml(el)
|
76
77
|
end
|
77
78
|
end
|
78
|
-
|
79
|
+
|
79
80
|
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
|
-
#
|
7
|
-
class DocumentTest
|
8
|
-
|
9
|
-
include OM::XML::Document
|
6
|
+
#ModsHelpers.name_("Beethoven, Ludwig van", :date=>"1770-1827", :role=>"creator")
|
7
|
+
class DocumentTest
|
10
8
|
|
11
|
-
|
9
|
+
include OM::XML::Document
|
10
|
+
|
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,103 +59,104 @@ 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
|
-
|
79
|
-
|
80
|
-
|
78
|
+
DocumentTest.included_modules.should include(OM::XML::Container)
|
79
|
+
DocumentTest.included_modules.should include(OM::XML::TermValueOperators)
|
80
|
+
DocumentTest.included_modules.should 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
|
-
|
85
|
+
@fixturemods.ox_namespaces.should == {"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
|
-
|
92
|
+
pending "better to get an informative error?"
|
93
|
+
@fixturemods.find_by_terms_and_value(:nobody_home).should == []
|
94
94
|
end
|
95
95
|
it "should use Nokogiri to retrieve a NodeSet corresponding to the term pointers" do
|
96
|
-
|
96
|
+
@mods_article.find_by_terms_and_value( :person ).length.should == 2
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should allow you to search by term pointer" do
|
100
|
-
|
100
|
+
@fixturemods.ng_xml.should_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
|
-
|
104
|
+
@fixturemods.ng_xml.should_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
|
-
|
108
|
+
@fixturemods.ng_xml.should_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
|
-
|
110
|
+
|
111
|
+
@fixturemods.ng_xml.should_receive(:xpath).with('//oxns:name[@type="personal"]/oxns:role[contains(., "donor")]', @fixturemods.ox_namespaces)
|
111
112
|
@fixturemods.find_by_terms_and_value(:person, :role=>"donor")
|
112
113
|
end
|
113
114
|
end
|
114
115
|
describe ".find_by_terms" do
|
115
116
|
it "should use Nokogiri to retrieve a NodeSet corresponding to the combination of term pointers and array/nodeset indexes" do
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
117
|
+
@mods_article.find_by_terms( :person ).length.should == 2
|
118
|
+
@mods_article.find_by_terms( {:person=>1} ).first.should == @mods_article.ng_xml.xpath('//oxns:name[@type="personal"][2]', "oxns"=>"http://www.loc.gov/mods/v3").first
|
119
|
+
@mods_article.find_by_terms( {:person=>1}, :first_name ).class.should == Nokogiri::XML::NodeSet
|
120
|
+
@mods_article.find_by_terms( {:person=>1}, :first_name ).first.text.should == "Siddartha"
|
120
121
|
end
|
121
122
|
it "should find a NodeSet where a terminology attribute has been set to :none" do
|
122
|
-
|
123
|
+
@mods_article.find_by_terms( {:person=>1}, :person_id).first.text.should == "123987"
|
123
124
|
end
|
124
125
|
it "should support accessors whose relative_xpath is a lookup array instead of an xpath string" do
|
125
126
|
# pending "this only impacts scenarios where we want to display & edit"
|
126
|
-
|
127
|
+
DocumentTest.terminology.retrieve_term(:title_info, :language).path.should == {:attribute=>"lang"}
|
127
128
|
# @sample.retrieve( :title, 1 ).first.text.should == "Artikkelin otsikko Hydrangea artiklan 1"
|
128
|
-
|
129
|
+
@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text.should == "finnish"
|
129
130
|
end
|
130
|
-
|
131
|
+
|
131
132
|
it "should support xpath queries as the pointer" do
|
132
|
-
|
133
|
+
@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text.should == "FAMILY NAME"
|
133
134
|
end
|
134
|
-
|
135
|
+
|
135
136
|
it "should return nil if the xpath fails to generate" do
|
136
|
-
|
137
|
-
|
137
|
+
pending "Can't decide if it's better to return nil or raise an error. Choosing informative errors for now."
|
138
|
+
@mods_article.find_by_terms( {:foo=>20}, :bar ).should == nil
|
138
139
|
end
|
139
|
-
|
140
|
+
|
140
141
|
it "should support terms that point to attributes instead of nodes" do
|
141
|
-
|
142
|
+
@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text.should == "finnish"
|
142
143
|
end
|
143
144
|
|
144
145
|
it "should support xpath queries as the pointer" do
|
145
|
-
|
146
|
+
@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text.should == "FAMILY NAME"
|
146
147
|
end
|
147
148
|
end
|
148
|
-
|
149
|
+
|
149
150
|
describe "node_exists?" do
|
150
151
|
it "should return true if any nodes are found" do
|
151
|
-
|
152
|
+
@mods_article.node_exists?( {:person=>1}, :first_name).should be_true
|
152
153
|
end
|
153
154
|
it "should return false if no nodes are found" do
|
154
|
-
|
155
|
+
@mods_article.node_exists?( {:person=>8}, :first_name ).should be_false
|
155
156
|
end
|
156
157
|
it "should support xpath queries" do
|
157
|
-
|
158
|
+
@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').should be_true
|
158
159
|
end
|
159
160
|
end
|
160
|
-
|
161
|
+
|
161
162
|
end
|
@@ -23,133 +23,121 @@ describe "OM::XML::DynamicNode" do
|
|
23
23
|
end
|
24
24
|
it "should create templates for dynamic nodes" do
|
25
25
|
@sample.creator = "Foo"
|
26
|
-
|
26
|
+
@sample.creator.should == ['Foo']
|
27
27
|
end
|
28
28
|
it "should create templates for dynamic nodes with multiple values" do
|
29
29
|
@sample.creator = ["Foo", "Bar"]
|
30
|
-
|
30
|
+
@sample.creator.should == ['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
|
-
|
47
|
-
expected_values.each {|v|
|
46
|
+
result.length.should == expected_values.length
|
47
|
+
expected_values.each {|v| result.should 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
|
-
|
52
|
+
@article.abstract.should == ["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
|
-
|
57
|
+
@article.abstract.should == ["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
|
-
|
62
|
-
|
61
|
+
@article.person.last_name.to_s.should == ["FAMILY NAME", "Gautama"].to_s
|
62
|
+
@article.person.last_name.first.should == "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
|
-
|
68
|
+
arr.should == ["FAMILY NAME", "Gautama"]
|
69
69
|
end
|
70
70
|
|
71
|
+
|
71
72
|
describe "setting attributes" do
|
72
73
|
it "when they exist" do
|
73
74
|
@article.title_info(0).main_title.main_title_lang = "ger"
|
74
|
-
|
75
|
+
@article.title_info(0).main_title.main_title_lang.should == ["ger"]
|
75
76
|
end
|
76
77
|
it "when they don't exist" do
|
77
78
|
title = @article.title_info(0)
|
78
79
|
title.language = "rus"
|
79
|
-
|
80
|
+
@article.title_info(0).language.should == ["rus"]
|
80
81
|
end
|
81
|
-
end
|
82
82
|
|
83
|
-
it "should find elements two deep" do
|
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
83
|
end
|
89
84
|
|
90
|
-
it
|
91
|
-
|
92
|
-
|
93
|
-
|
85
|
+
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.should == ["Describes a person"]
|
88
|
+
@article.name.name_content.should == ["Describes a person"]
|
89
|
+
@article.name.name_content(0).should == ["Describes a person"]
|
94
90
|
end
|
95
91
|
|
96
|
-
it "should not find elements that don't
|
97
|
-
|
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/
|
92
|
+
it "should not find elements that don't exist" do
|
93
|
+
lambda {@article.name.hedgehog}.should raise_exception NoMethodError
|
105
94
|
end
|
106
95
|
|
107
96
|
it "should allow you to call methods on the return value" do
|
108
|
-
|
97
|
+
@article.name.name_content.first.should == "Describes a person"
|
109
98
|
end
|
110
99
|
|
111
100
|
it "Should work with proxies" do
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
101
|
+
@article.title.should == ["ARTICLE TITLE HYDRANGEA ARTICLE 1", "Artikkelin otsikko Hydrangea artiklan 1", "TITLE OF HOST JOURNAL"]
|
102
|
+
@article.title.main_title_lang.should == ['eng']
|
103
|
+
|
104
|
+
@article.title(1).to_pointer.should == [{:title => 1}]
|
105
|
+
|
106
|
+
@article.journal_title.xpath.should == "//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title"
|
107
|
+
@article.journal_title.should == ["TITLE OF HOST JOURNAL"]
|
117
108
|
end
|
118
109
|
|
119
110
|
it "Should be addressable to a specific node" do
|
120
111
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
|
121
112
|
|
122
113
|
@article.subject.topic(1).to_pointer == [:subject, {:topic => 1}]
|
123
|
-
|
114
|
+
@article.journal(0).issue.length.should == 2
|
124
115
|
@article.journal(0).issue(1).pages.to_pointer == [{:journal=>0}, {:issue=>1}, :pages]
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
expect(@article.subject.topic(1)).to eq(["TOPIC 2"])
|
129
|
-
expect(@article.subject.topic(1).xpath).to eq("//oxns:subject/oxns:topic[2]")
|
130
|
-
end
|
116
|
+
@article.journal(0).issue(1).pages.length.should == 1
|
117
|
+
@article.journal(0).issue(1).pages.start.length.should == 1
|
118
|
+
@article.journal(0).issue(1).pages.start.first.should == "434"
|
131
119
|
|
120
|
+
@article.subject.topic(1).should == ["TOPIC 2"]
|
121
|
+
@article.subject.topic(1).xpath.should == "//oxns:subject/oxns:topic[2]"
|
122
|
+
end
|
123
|
+
|
132
124
|
describe ".nodeset" do
|
133
125
|
it "should return a Nokogiri NodeSet" do
|
134
126
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
|
135
127
|
nodeset = @article.journal(0).issue(1).pages.start.nodeset
|
136
|
-
|
137
|
-
|
138
|
-
|
128
|
+
nodeset.should be_kind_of Nokogiri::XML::NodeSet
|
129
|
+
nodeset.length.should == @article.journal(0).issue(1).pages.start.length
|
130
|
+
nodeset.first.text.should == @article.journal(0).issue(1).pages.start.first
|
139
131
|
end
|
140
132
|
end
|
141
133
|
|
142
|
-
it "should append nodes at the specified index if possible
|
143
|
-
# backwards-compatible stuff..
|
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
|
134
|
+
it "should append nodes at the specified index if possible" do
|
147
135
|
@article.journal.title_info = ["all", "for", "the"]
|
148
136
|
@article.journal.title_info(3, 'glory')
|
149
|
-
|
150
|
-
|
137
|
+
@article.term_values(:journal, :title_info).should == ["all", "for", "the", "glory"]
|
138
|
+
@article.should be_changed
|
151
139
|
end
|
152
|
-
|
140
|
+
|
153
141
|
end
|
154
142
|
end
|
155
143
|
end
|