om 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,14 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::Term::Builder" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:each) do
|
6
6
|
@test_terminology_builder = OM::XML::Terminology::Builder.new do |t|
|
7
7
|
t.fruit_trees {
|
8
8
|
t.citrus(:attributes=>{"citric_acid"=>"true"}, :index_as=>[:facetable]) {
|
9
9
|
t.randomness
|
10
10
|
}
|
11
|
-
t.stone_fruit(:path=>"prunus", :attributes=>{:genus=>"Prunus"})
|
11
|
+
t.stone_fruit(:path=>"prunus", :attributes=>{:genus=>"Prunus"})
|
12
12
|
t.peach(:ref=>[:fruit_trees, :stone_fruit], :attributes=>{:subgenus=>"Amygdalus", :species=>"Prunus persica"})
|
13
13
|
t.nectarine(:ref=>[:fruit_trees, :peach], :attributes=>{:cultivar=>"nectarine"})
|
14
14
|
t.almond(:ref=>[:fruit_trees, :peach], :attributes=>{:species=>"Prunus dulcis"})
|
@@ -17,184 +17,184 @@ describe "OM::XML::Term::Builder" do
|
|
17
17
|
t.banana(:ref=>:coconut)
|
18
18
|
t.pineapple(:ref=>:banana)
|
19
19
|
end
|
20
|
-
|
21
|
-
@citrus
|
20
|
+
|
21
|
+
@citrus = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :citrus)
|
22
22
|
@stone_fruit = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :stone_fruit)
|
23
|
-
@peach
|
24
|
-
@nectarine
|
25
|
-
@almond
|
26
|
-
@pineapple
|
23
|
+
@peach = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :peach)
|
24
|
+
@nectarine = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :nectarine)
|
25
|
+
@almond = @test_terminology_builder.retrieve_term_builder(:fruit_trees, :almond)
|
26
|
+
@pineapple = @test_terminology_builder.retrieve_term_builder(:pineapple)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
before(:each) do
|
30
|
-
@test_builder
|
30
|
+
@test_builder = OM::XML::Term::Builder.new("term1")
|
31
31
|
@test_builder_2 = OM::XML::Term::Builder.new("term2")
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
describe '#new' do
|
35
35
|
it "should set terminology_builder attribute if provided" do
|
36
|
-
mock_terminology_builder =
|
37
|
-
OM::XML::Term::Builder.new("term1", mock_terminology_builder).terminology_builder.
|
36
|
+
mock_terminology_builder = double("TerminologyBuilder")
|
37
|
+
expect(OM::XML::Term::Builder.new("term1", mock_terminology_builder).terminology_builder).to eq(mock_terminology_builder)
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
describe "configuration methods" do
|
42
42
|
it "should set the corresponding .settings value return the mapping object" do
|
43
43
|
[:path, :index_as, :required, :type, :variant_of, :path, :attributes, :default_content_path].each do |method_name|
|
44
|
-
@test_builder.send(method_name, "#{method_name.to_s}foo").
|
45
|
-
@test_builder.settings[method_name].
|
44
|
+
expect(@test_builder.send(method_name, "#{method_name.to_s}foo")).to eq(@test_builder)
|
45
|
+
expect(@test_builder.settings[method_name]).to eq("#{method_name.to_s}foo")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
it "should be chainable" do
|
49
|
-
test_builder = OM::XML::Term::Builder.new("chainableTerm").index_as(:facetable, :searchable, :sortable, :displayable).required(true).type(:text)
|
49
|
+
test_builder = OM::XML::Term::Builder.new("chainableTerm").index_as(:facetable, :searchable, :sortable, :displayable).required(true).type(:text)
|
50
50
|
resulting_settings = test_builder.settings
|
51
|
-
resulting_settings[:index_as].
|
52
|
-
resulting_settings[:required].
|
53
|
-
resulting_settings[:type].
|
51
|
+
expect(resulting_settings[:index_as]).to eq([:facetable, :searchable, :sortable, :displayable])
|
52
|
+
expect(resulting_settings[:required]).to eq(true)
|
53
|
+
expect(resulting_settings[:type]).to eq(:text)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe "settings" do
|
58
58
|
describe "defaults" do
|
59
59
|
it "should be set" do
|
60
|
-
@test_builder.settings[:required].
|
61
|
-
@test_builder.settings[:type].
|
62
|
-
@test_builder.settings[:variant_of].
|
63
|
-
@test_builder.settings[:attributes].
|
64
|
-
@test_builder.settings[:default_content_path].
|
60
|
+
expect(@test_builder.settings[:required]).to eq(false)
|
61
|
+
expect(@test_builder.settings[:type]).to eq(:string)
|
62
|
+
expect(@test_builder.settings[:variant_of]).to be_nil
|
63
|
+
expect(@test_builder.settings[:attributes]).to be_nil
|
64
|
+
expect(@test_builder.settings[:default_content_path]).to be_nil
|
65
65
|
end
|
66
66
|
end
|
67
67
|
describe ":data_type" do
|
68
68
|
it "is deprecated and should be assinged to the :type setting" do
|
69
69
|
deprecated_term = OM::XML::Term::Builder.new("depreated_term").data_type(:thing)
|
70
|
-
deprecated_term.settings[:type].
|
71
|
-
end
|
70
|
+
expect(deprecated_term.settings[:type]).to eq(:thing)
|
71
|
+
end
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
describe ".add_child" do
|
76
76
|
it "should insert the given Term Builder into the current Term Builder's children" do
|
77
77
|
@test_builder.add_child(@test_builder_2)
|
78
|
-
@test_builder.children[@test_builder_2.name].
|
79
|
-
@test_builder.ancestors.
|
78
|
+
expect(@test_builder.children[@test_builder_2.name]).to eq(@test_builder_2)
|
79
|
+
expect(@test_builder.ancestors).to include(@test_builder_2)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
describe ".retrieve_child" do
|
83
83
|
it "should fetch the child identified by the given name" do
|
84
84
|
@test_builder.add_child(@test_builder_2)
|
85
|
-
@test_builder.retrieve_child(@test_builder_2.name).
|
85
|
+
expect(@test_builder.retrieve_child(@test_builder_2.name)).to eq(@test_builder.children[@test_builder_2.name])
|
86
86
|
end
|
87
87
|
end
|
88
88
|
describe ".children" do
|
89
89
|
it "should return a hash of Term Builders that are the children of the current object, indexed by name" do
|
90
90
|
@test_builder.add_child(@test_builder_2)
|
91
|
-
@test_builder.children[@test_builder_2.name].
|
91
|
+
expect(@test_builder.children[@test_builder_2.name]).to eq(@test_builder_2)
|
92
92
|
end
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
describe ".build" do
|
96
96
|
it "should build a Term with the given settings and generate its xpath values" do
|
97
|
-
test_builder = OM::XML::Term::Builder.new("requiredTextFacet").index_as([:facetable, :searchable, :sortable, :displayable]).required(true).type(:text)
|
97
|
+
test_builder = OM::XML::Term::Builder.new("requiredTextFacet").index_as([:facetable, :searchable, :sortable, :displayable]).required(true).type(:text)
|
98
98
|
result = test_builder.build
|
99
|
-
result.
|
100
|
-
result.index_as.
|
101
|
-
result.required.
|
102
|
-
result.type.
|
103
|
-
|
104
|
-
result.xpath.
|
105
|
-
result.xpath_constrained.
|
106
|
-
result.xpath_relative.
|
99
|
+
expect(result).to be_instance_of OM::XML::Term
|
100
|
+
expect(result.index_as).to eq([:facetable, :searchable, :sortable, :displayable])
|
101
|
+
expect(result.required).to eq(true)
|
102
|
+
expect(result.type).to eq(:text)
|
103
|
+
|
104
|
+
expect(result.xpath).to eq(OM::XML::TermXpathGenerator.generate_absolute_xpath(result))
|
105
|
+
expect(result.xpath_constrained).to eq(OM::XML::TermXpathGenerator.generate_constrained_xpath(result))
|
106
|
+
expect(result.xpath_relative).to eq(OM::XML::TermXpathGenerator.generate_relative_xpath(result))
|
107
107
|
end
|
108
108
|
it "should create proxy terms if :proxy is set" do
|
109
109
|
test_builder = OM::XML::Term::Builder.new("my_proxy").proxy([:foo, :bar])
|
110
110
|
result = test_builder.build
|
111
|
-
result.
|
111
|
+
expect(result).to be_kind_of OM::XML::NamedTermProxy
|
112
112
|
end
|
113
113
|
it "should set path to match name if it is empty" do
|
114
|
-
@test_builder.settings[:path].
|
115
|
-
@test_builder.build.path.
|
114
|
+
expect(@test_builder.settings[:path]).to be_nil
|
115
|
+
expect(@test_builder.build.path).to eq(@test_builder.name.to_s)
|
116
116
|
end
|
117
117
|
it "should work recursively, calling .build on any of its children" do
|
118
|
-
OM::XML::Term.
|
118
|
+
allow_any_instance_of(OM::XML::Term).to receive(:generate_xpath_queries!)
|
119
119
|
built_child1 = OM::XML::Term.new("child1")
|
120
120
|
built_child2 = OM::XML::Term.new("child2")
|
121
121
|
|
122
|
-
mock1 =
|
123
|
-
mock2 =
|
124
|
-
mock1.
|
125
|
-
mock2.
|
122
|
+
mock1 = double("Builder1", :build => built_child1 )
|
123
|
+
mock2 = double("Builder2", :build => built_child2 )
|
124
|
+
allow(mock1).to receive(:name).and_return("child1")
|
125
|
+
allow(mock2).to receive(:name).and_return("child2")
|
126
126
|
|
127
127
|
@test_builder.children = {:mock1=>mock1, :mock2=>mock2}
|
128
128
|
result = @test_builder.build
|
129
|
-
result.children[:child1].
|
130
|
-
result.children[:child2].
|
131
|
-
result.children.length.
|
129
|
+
expect(result.children[:child1]).to eq(built_child1)
|
130
|
+
expect(result.children[:child2]).to eq(built_child2)
|
131
|
+
expect(result.children.length).to eq(2)
|
132
132
|
end
|
133
133
|
end
|
134
|
-
|
134
|
+
|
135
135
|
describe ".lookup_refs" do
|
136
136
|
it "should return an empty array if no refs are declared" do
|
137
|
-
@test_builder.lookup_refs.
|
137
|
+
expect(@test_builder.lookup_refs).to eq([])
|
138
138
|
end
|
139
139
|
it "should should look up the referenced TermBuilder from the terminology_builder" do
|
140
|
-
@peach.lookup_refs.
|
140
|
+
expect(@peach.lookup_refs).to eq([@stone_fruit])
|
141
141
|
end
|
142
142
|
it "should support recursive refs" do
|
143
|
-
@almond.lookup_refs.
|
143
|
+
expect(@almond.lookup_refs).to eq([@peach, @stone_fruit])
|
144
144
|
end
|
145
145
|
it "should raise an error if the TermBuilder does not have a reference to a terminology builder" do
|
146
|
-
|
146
|
+
expect { OM::XML::Term::Builder.new("referrer").ref("bongos").lookup_refs }.to raise_error(StandardError,"Cannot perform lookup_ref for the referrer builder. It doesn't have a reference to any terminology builder")
|
147
147
|
end
|
148
148
|
it "should raise an error if the referece points to a nonexistent term builder" do
|
149
149
|
tb = OM::XML::Term::Builder.new("mork",@test_terminology_builder).ref(:characters, :aliens)
|
150
|
-
|
150
|
+
expect { tb.lookup_refs }.to raise_error(OM::XML::Terminology::BadPointerError,"This TerminologyBuilder does not have a root TermBuilder defined that corresponds to \":characters\"")
|
151
151
|
end
|
152
152
|
it "should raise an error with informative error when given circular references" do
|
153
|
-
|
153
|
+
expect { @pineapple.lookup_refs }.to raise_error(OM::XML::Terminology::CircularReferenceError,"Circular reference in Terminology: :pineapple => :banana => :coconut => :pineapple")
|
154
154
|
end
|
155
155
|
end
|
156
|
-
|
157
|
-
describe ".resolve_refs!" do
|
156
|
+
|
157
|
+
describe ".resolve_refs!" do
|
158
158
|
it "should do nothing if settings don't include a :ref" do
|
159
159
|
settings_pre = @test_builder.settings
|
160
160
|
children_pre = @test_builder.children
|
161
161
|
|
162
162
|
@test_builder.resolve_refs!
|
163
|
-
@test_builder.settings.
|
164
|
-
@test_builder.children.
|
163
|
+
expect(@test_builder.settings).to eq(settings_pre)
|
164
|
+
expect(@test_builder.children).to eq(children_pre)
|
165
165
|
end
|
166
166
|
it "should should look up the referenced TermBuilder, use its settings and duplicate its children without changing the name" do
|
167
167
|
term_builder = OM::XML::Term::Builder.new("orange",@test_terminology_builder).ref(:fruit_trees, :citrus)
|
168
168
|
term_builder.resolve_refs!
|
169
169
|
# Make sure children and settings were copied
|
170
|
-
term_builder.settings.
|
171
|
-
term_builder.children.
|
172
|
-
|
170
|
+
expect(term_builder.settings).to eq(@citrus.settings.merge(:path=>"citrus"))
|
171
|
+
expect(term_builder.children).to eq(@citrus.children)
|
172
|
+
|
173
173
|
# Make sure name and parent of both the term_builder and its target were left alone
|
174
|
-
term_builder.name.
|
175
|
-
@citrus.name.
|
174
|
+
expect(term_builder.name).to eq(:orange)
|
175
|
+
expect(@citrus.name).to eq(:citrus)
|
176
176
|
end
|
177
177
|
it "should set path based on the ref's path if set" do
|
178
178
|
[@peach,@almond].each { |x| x.resolve_refs! }
|
179
|
-
@peach.settings[:path].
|
180
|
-
@almond.settings[:path].
|
179
|
+
expect(@peach.settings[:path]).to eq("prunus")
|
180
|
+
expect(@almond.settings[:path]).to eq("prunus")
|
181
181
|
end
|
182
182
|
it "should set path based on the first ref's name if no path is set" do
|
183
183
|
orange_builder = OM::XML::Term::Builder.new("orange",@test_terminology_builder).ref(:fruit_trees, :citrus)
|
184
184
|
orange_builder.resolve_refs!
|
185
|
-
orange_builder.settings[:path].
|
185
|
+
expect(orange_builder.settings[:path]).to eq("citrus")
|
186
186
|
end
|
187
|
-
# It should not be a problem if multiple TermBuilders refer to the same child TermBuilder since the parent-child relationship is set up after calling TermBuilder.build
|
188
|
-
it "should result in clean trees of Terms after building"
|
189
|
-
|
187
|
+
# It should not be a problem if multiple TermBuilders refer to the same child TermBuilder since the parent-child relationship is set up after calling TermBuilder.build
|
188
|
+
# it "should result in clean trees of Terms after building"
|
189
|
+
|
190
190
|
it "should preserve any extra settings specific to this builder (for variant terms)" do
|
191
191
|
tb = OM::XML::Term::Builder.new("orange",@test_terminology_builder).ref(:fruit_trees, :citrus).attributes(:color=>"orange").required(true)
|
192
192
|
tb.resolve_refs!
|
193
|
-
tb.settings.
|
193
|
+
expect(tb.settings).to eq({:path=>"citrus", :attributes=>{"citric_acid"=>"true", :color=>"orange"}, :required=>true, :type=>:string, :index_as=>[:facetable]})
|
194
194
|
end
|
195
195
|
it "should aggregate all settings from refs, combining them with a cascading approach" do
|
196
196
|
@almond.resolve_refs!
|
197
|
-
@almond.settings[:attributes].
|
197
|
+
expect(@almond.settings[:attributes]).to eq({:genus=>"Prunus",:subgenus=>"Amygdalus", :species=>"Prunus dulcis"})
|
198
198
|
end
|
199
199
|
end
|
200
200
|
end
|
data/spec/unit/term_spec.rb
CHANGED
@@ -3,46 +3,54 @@ require 'spec_helper'
|
|
3
3
|
describe OM::XML::Term do
|
4
4
|
describe "without a type" do
|
5
5
|
subject { OM::XML::Term.new(:test_term) }
|
6
|
-
|
6
|
+
|
7
|
+
describe (:type) do
|
8
|
+
subject { super().send((:type)) }
|
9
|
+
it { is_expected.to eq(:string) }
|
10
|
+
end
|
7
11
|
end
|
8
12
|
describe "when type is specified" do
|
9
13
|
subject { OM::XML::Term.new(:test_term, :type=>:date)}
|
10
|
-
|
14
|
+
|
15
|
+
describe (:type) do
|
16
|
+
subject { super().send((:type)) }
|
17
|
+
it { is_expected.to eq(:date) }
|
18
|
+
end
|
11
19
|
end
|
12
20
|
|
13
21
|
describe "a big test" do
|
14
22
|
before(:each) do
|
15
|
-
@test_name_part
|
16
|
-
@test_volume
|
17
|
-
@test_date
|
18
|
-
@test_person
|
23
|
+
@test_name_part = OM::XML::Term.new(:namePart, {}).generate_xpath_queries!
|
24
|
+
@test_volume = OM::XML::Term.new(:volume, :path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
|
25
|
+
@test_date = OM::XML::Term.new(:namePart, :attributes=>{:type=> "date"})
|
26
|
+
@test_person = OM::XML::Term.new(:namePart, :attributes=>{:type=> :none})
|
19
27
|
@test_affiliation = OM::XML::Term.new(:affiliation)
|
20
|
-
@test_role_code
|
21
|
-
@test_type
|
28
|
+
@test_role_code = OM::XML::Term.new(:roleTerm, :attributes=>{:type=>"code"})
|
29
|
+
@test_type = OM::XML::Term.new(:class)
|
22
30
|
end
|
23
31
|
|
24
32
|
describe '#new' do
|
25
33
|
it "should set path from mapper name if no path is provided" do
|
26
|
-
@test_name_part.path.
|
34
|
+
expect(@test_name_part.path).to eq("namePart")
|
27
35
|
end
|
28
36
|
it "should populate the xpath values if no options are provided" do
|
29
37
|
local_mapping = OM::XML::Term.new(:namePart)
|
30
|
-
local_mapping.xpath_relative.
|
31
|
-
local_mapping.xpath.
|
32
|
-
local_mapping.xpath_constrained.
|
38
|
+
expect(local_mapping.xpath_relative).to be_nil
|
39
|
+
expect(local_mapping.xpath).to be_nil
|
40
|
+
expect(local_mapping.xpath_constrained).to be_nil
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
44
|
describe 'inner_xml' do
|
37
45
|
it "should be a kind of Nokogiri::XML::Node" do
|
38
|
-
|
39
|
-
@test_mapping.inner_xml.
|
46
|
+
skip
|
47
|
+
expect(@test_mapping.inner_xml).to be_kind_of(Nokogiri::XML::Node)
|
40
48
|
end
|
41
49
|
end
|
42
50
|
|
43
51
|
describe '#from_node' do
|
44
52
|
it "should create a mapper from a nokogiri node" do
|
45
|
-
|
53
|
+
skip "probably should do this in the Builder"
|
46
54
|
ng_builder = Nokogiri::XML::Builder.new do |xml|
|
47
55
|
xml.mapper(:name=>"person", :path=>"name") {
|
48
56
|
xml.attribute(:name=>"type", :value=>"personal")
|
@@ -55,17 +63,17 @@ describe OM::XML::Term do
|
|
55
63
|
# node = Nokogiri::XML::Document.parse( '<mapper name="first_name" path="namePart"><attribute name="type" value="given"/><attribute name="another_attribute" value="myval"/></mapper>' ).root
|
56
64
|
node = ng_builder.doc.root
|
57
65
|
mapper = OM::XML::Term.from_node(node)
|
58
|
-
mapper.name.
|
59
|
-
mapper.path.
|
60
|
-
mapper.attributes.
|
61
|
-
mapper.internal_xml.
|
66
|
+
expect(mapper.name).to eq(:person)
|
67
|
+
expect(mapper.path).to eq("name")
|
68
|
+
expect(mapper.attributes).to eq({:type=>"personal"})
|
69
|
+
expect(mapper.internal_xml).to eq(node)
|
62
70
|
|
63
71
|
child = mapper.children[:first_name]
|
64
72
|
|
65
|
-
child.name.
|
66
|
-
child.path.
|
67
|
-
child.attributes.
|
68
|
-
child.internal_xml.
|
73
|
+
expect(child.name).to eq(:first_name)
|
74
|
+
expect(child.path).to eq("namePart")
|
75
|
+
expect(child.attributes).to eq({:type=>"given", :another_attribute=>"myval"})
|
76
|
+
expect(child.internal_xml).to eq(node.xpath("./mapper").first)
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
@@ -75,20 +83,20 @@ describe OM::XML::Term do
|
|
75
83
|
|
76
84
|
describe ".retrieve_term" do
|
77
85
|
it "should crawl down into mapper children to find the desired term" do
|
78
|
-
mock_role =
|
79
|
-
mock_conference =
|
80
|
-
@test_name_part.
|
81
|
-
@test_name_part.retrieve_term(:conference, :role, :text).
|
86
|
+
mock_role = double("mapper", :children =>{:text=>"the target"})
|
87
|
+
mock_conference = double("mapper", :children =>{:role=>mock_role})
|
88
|
+
expect(@test_name_part).to receive(:children).and_return({:conference=>mock_conference})
|
89
|
+
expect(@test_name_part.retrieve_term(:conference, :role, :text)).to eq("the target")
|
82
90
|
end
|
83
91
|
it "should return an empty hash if no term can be found" do
|
84
|
-
@test_name_part.retrieve_term(:journal, :issue, :end_page).
|
92
|
+
expect(@test_name_part.retrieve_term(:journal, :issue, :end_page)).to eq(nil)
|
85
93
|
end
|
86
94
|
end
|
87
95
|
|
88
96
|
describe 'inner_xml' do
|
89
97
|
it "should be a kind of Nokogiri::XML::Node" do
|
90
|
-
|
91
|
-
@test_name_part.inner_xml.
|
98
|
+
skip
|
99
|
+
expect(@test_name_part.inner_xml).to be_kind_of(Nokogiri::XML::Node)
|
92
100
|
end
|
93
101
|
end
|
94
102
|
|
@@ -96,8 +104,8 @@ describe OM::XML::Term do
|
|
96
104
|
it "should set the corresponding .settings value and return the current value" do
|
97
105
|
# :index_as is a special case
|
98
106
|
[:path, :required, :type, :variant_of, :path, :attributes, :default_content_path, :namespace_prefix].each do |method_name|
|
99
|
-
@test_name_part.send(method_name.to_s+"=", "#{method_name.to_s}foo").
|
100
|
-
@test_name_part.send(method_name).
|
107
|
+
expect(@test_name_part.send(method_name.to_s+"=", "#{method_name.to_s}foo")).to eq("#{method_name.to_s}foo")
|
108
|
+
expect(@test_name_part.send(method_name)).to eq("#{method_name.to_s}foo")
|
101
109
|
end
|
102
110
|
end
|
103
111
|
end
|
@@ -106,7 +114,7 @@ describe OM::XML::Term do
|
|
106
114
|
subject {
|
107
115
|
class TestTerminology
|
108
116
|
include OM::XML::Document
|
109
|
-
|
117
|
+
|
110
118
|
set_terminology do |t|
|
111
119
|
t.as_array :index_as => [:not_searchable]
|
112
120
|
t.as_symbol :index_as => :not_searchable
|
@@ -117,77 +125,75 @@ describe OM::XML::Term do
|
|
117
125
|
}
|
118
126
|
|
119
127
|
it "should accept an array as an :index_as value" do
|
120
|
-
subject.terminology.terms[:as_array].index_as.
|
121
|
-
subject.terminology.terms[:as_array].index_as.
|
128
|
+
expect(subject.terminology.terms[:as_array].index_as).to be_a_kind_of(Array)
|
129
|
+
expect(subject.terminology.terms[:as_array].index_as).to eq([:not_searchable])
|
122
130
|
end
|
123
131
|
it "should accept a plain symbol as a value to :index_as" do
|
124
|
-
subject.terminology.terms[:as_symbol].index_as.
|
125
|
-
subject.terminology.terms[:as_symbol].index_as.
|
132
|
+
expect(subject.terminology.terms[:as_symbol].index_as).to be_a_kind_of(Array)
|
133
|
+
expect(subject.terminology.terms[:as_symbol].index_as).to eq([:not_searchable])
|
126
134
|
end
|
127
135
|
end
|
128
136
|
it "should have a .terminology attribute accessor" do
|
129
|
-
@test_volume.
|
130
|
-
@test_volume.
|
137
|
+
expect(@test_volume).to respond_to :terminology
|
138
|
+
expect(@test_volume).to respond_to :terminology=
|
131
139
|
end
|
132
140
|
describe ".ancestors" do
|
133
141
|
it "should return an array of Terms that are the ancestors of the current object, ordered from the top/root of the hierarchy" do
|
134
142
|
@test_volume.set_parent(@test_name_part)
|
135
|
-
@test_volume.ancestors.
|
143
|
+
expect(@test_volume.ancestors).to eq([@test_name_part])
|
136
144
|
end
|
137
145
|
end
|
138
146
|
describe ".parent" do
|
139
147
|
it "should retrieve the immediate parent of the given object from the ancestors array" do
|
140
148
|
# @test_name_part.expects(:ancestors).returns(["ancestor1","ancestor2","ancestor3"])
|
141
149
|
@test_name_part.ancestors = ["ancestor1","ancestor2","ancestor3"]
|
142
|
-
@test_name_part.parent.
|
150
|
+
expect(@test_name_part.parent).to eq("ancestor3")
|
143
151
|
end
|
144
152
|
end
|
145
153
|
describe ".children" do
|
146
154
|
it "should return a hash of Terms that are the children of the current object, indexed by name" do
|
147
155
|
@test_volume.add_child(@test_name_part)
|
148
|
-
@test_volume.children[@test_name_part.name].
|
156
|
+
expect(@test_volume.children[@test_name_part.name]).to eq(@test_name_part)
|
149
157
|
end
|
150
158
|
end
|
151
159
|
describe ".retrieve_child" do
|
152
160
|
it "should fetch the child identified by the given name" do
|
153
161
|
@test_volume.add_child(@test_name_part)
|
154
|
-
@test_volume.retrieve_child(@test_name_part.name).
|
162
|
+
expect(@test_volume.retrieve_child(@test_name_part.name)).to eq(@test_volume.children[@test_name_part.name])
|
155
163
|
end
|
156
164
|
end
|
157
165
|
describe ".set_parent" do
|
158
166
|
it "should insert the mapper into the given parent" do
|
159
167
|
@test_name_part.set_parent(@test_volume)
|
160
|
-
@test_name_part.ancestors.
|
161
|
-
@test_volume.children[@test_name_part.name].
|
168
|
+
expect(@test_name_part.ancestors).to include(@test_volume)
|
169
|
+
expect(@test_volume.children[@test_name_part.name]).to eq(@test_name_part)
|
162
170
|
end
|
163
171
|
end
|
164
172
|
describe ".add_child" do
|
165
173
|
it "should insert the given mapper into the current mappers children" do
|
166
174
|
@test_volume.add_child(@test_name_part)
|
167
|
-
@test_volume.children[@test_name_part.name].
|
168
|
-
@test_name_part.ancestors.
|
175
|
+
expect(@test_volume.children[@test_name_part.name]).to eq(@test_name_part)
|
176
|
+
expect(@test_name_part.ancestors).to include(@test_volume)
|
169
177
|
end
|
170
178
|
end
|
171
179
|
|
172
180
|
describe "generate_xpath_queries!" do
|
173
181
|
it "should return the current object" do
|
174
|
-
@test_name_part.generate_xpath_queries
|
182
|
+
expect(@test_name_part.generate_xpath_queries!).to eq(@test_name_part)
|
175
183
|
end
|
176
184
|
it "should regenerate the xpath values" do
|
177
|
-
@test_volume.xpath_relative.
|
178
|
-
@test_volume.xpath.
|
179
|
-
@test_volume.xpath_constrained.
|
180
|
-
|
181
|
-
@test_volume.
|
182
|
-
|
183
|
-
@test_volume.
|
184
|
-
@test_volume.xpath.should == '//detail[@type="volume"]'
|
185
|
-
@test_volume.xpath_constrained.should == '//detail[@type="volume" and contains(number, "#{constraint_value}")]'.gsub('"', '\"')
|
185
|
+
expect(@test_volume.xpath_relative).to be_nil
|
186
|
+
expect(@test_volume.xpath).to be_nil
|
187
|
+
expect(@test_volume.xpath_constrained).to be_nil
|
188
|
+
expect(@test_volume.generate_xpath_queries!).to eq(@test_volume)
|
189
|
+
expect(@test_volume.xpath_relative).to eq('detail[@type="volume"]')
|
190
|
+
expect(@test_volume.xpath).to eq('//detail[@type="volume"]')
|
191
|
+
expect(@test_volume.xpath_constrained).to eq('//detail[@type="volume" and contains(number, "#{constraint_value}")]'.gsub('"', '\"'))
|
186
192
|
end
|
187
193
|
it "should trigger update on any child objects" do
|
188
|
-
mock_child =
|
189
|
-
mock_child.
|
190
|
-
@test_name_part.
|
194
|
+
mock_child = double("child term")
|
195
|
+
expect(mock_child).to receive(:generate_xpath_queries!).exactly(3).times
|
196
|
+
expect(@test_name_part).to receive(:children).and_return({1=>mock_child, 2=>mock_child, 3=>mock_child})
|
191
197
|
@test_name_part.generate_xpath_queries!
|
192
198
|
end
|
193
199
|
end
|
@@ -195,9 +201,9 @@ describe OM::XML::Term do
|
|
195
201
|
describe "#xml_builder_template" do
|
196
202
|
|
197
203
|
it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
|
198
|
-
@test_date.xml_builder_template.
|
199
|
-
@test_person.xml_builder_template.
|
200
|
-
@test_affiliation.xml_builder_template.
|
204
|
+
expect(@test_date.xml_builder_template).to eq('xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )')
|
205
|
+
expect(@test_person.xml_builder_template).to eq('xml.namePart( \'#{builder_new_value}\' )')
|
206
|
+
expect(@test_affiliation.xml_builder_template).to eq('xml.affiliation( \'#{builder_new_value}\' )')
|
201
207
|
end
|
202
208
|
|
203
209
|
it "should accept extra options" do
|
@@ -206,37 +212,37 @@ describe OM::XML::Term do
|
|
206
212
|
e1 = %q{xml.roleTerm( '#{builder_new_value}', 'type'=>'code', 'authority'=>'marcrelator' )}
|
207
213
|
e2 = %q{xml.roleTerm( '#{builder_new_value}', 'authority'=>'marcrelator', 'type'=>'code' )}
|
208
214
|
got = @test_role_code.xml_builder_template(:attributes=>{"authority"=>"marcrelator"})
|
209
|
-
[e1, e2].
|
215
|
+
expect([e1, e2]).to include(got)
|
210
216
|
end
|
211
217
|
|
212
218
|
it "should work for namespaced nodes" do
|
213
219
|
@ical_date = OM::XML::Term.new(:ical_date, :path=>"ical:date")
|
214
|
-
@ical_date.xml_builder_template.
|
220
|
+
expect(@ical_date.xml_builder_template).to eq("xml[\'ical\'].date( '\#{builder_new_value}' )")
|
215
221
|
@ical_date = OM::XML::Term.new(:ical_date, :path=>"date", :namespace_prefix=>"ical")
|
216
|
-
@ical_date.xml_builder_template.
|
222
|
+
expect(@ical_date.xml_builder_template).to eq("xml[\'ical\'].date( '\#{builder_new_value}' )")
|
217
223
|
end
|
218
224
|
|
219
225
|
it "should work for nodes with default_content_path" do
|
220
|
-
@test_volume.xml_builder_template.
|
226
|
+
expect(@test_volume.xml_builder_template).to eq("xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }")
|
221
227
|
end
|
222
228
|
|
223
229
|
it "should support terms that are attributes" do
|
224
230
|
@type_attribute_term = OM::XML::Term.new(:type_attribute, :path=>{:attribute=>:type})
|
225
|
-
@type_attribute_term.xml_builder_template.
|
231
|
+
expect(@type_attribute_term.xml_builder_template).to eq("xml.@type( '\#{builder_new_value}' )")
|
226
232
|
end
|
227
233
|
|
228
234
|
it "should support terms with namespaced attributes" do
|
229
235
|
@french_title = OM::XML::Term.new(:french_title, :path=>"title", :attributes=>{"xml:lang"=>"fre"})
|
230
|
-
@french_title.xml_builder_template.
|
236
|
+
expect(@french_title.xml_builder_template).to eq("xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )")
|
231
237
|
end
|
232
238
|
|
233
239
|
it "should support terms that are namespaced attributes" do
|
234
240
|
@xml_lang_attribute_term = OM::XML::Term.new(:xml_lang_attribute, :path=>{:attribute=>"xml:lang"})
|
235
|
-
@xml_lang_attribute_term.xml_builder_template.
|
241
|
+
expect(@xml_lang_attribute_term.xml_builder_template).to eq("xml.@xml:lang( '\#{builder_new_value}' )")
|
236
242
|
end
|
237
|
-
|
243
|
+
|
238
244
|
it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block) for terms that share a name with an existing method on the builder" do
|
239
|
-
@test_type.xml_builder_template.
|
245
|
+
expect(@test_type.xml_builder_template).to eq('xml.class_( \'#{builder_new_value}\' )')
|
240
246
|
end
|
241
247
|
end
|
242
248
|
end
|