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