om 3.1.0 → 3.1.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 +4 -4
- data/{COMMON_OM_PATTERNS.textile → COMMON_OM_PATTERNS.md} +136 -126
- data/CONTRIBUTING.md +2 -2
- data/GETTING_FANCY.md +153 -0
- data/GETTING_STARTED.md +329 -0
- data/Gemfile +1 -1
- data/History.md +164 -0
- data/LICENSE +15 -20
- data/QUERYING_DOCUMENTS.md +162 -0
- data/README.md +2 -2
- data/UPDATING_DOCUMENTS.md +6 -0
- data/gemfiles/gemfile.rails3 +1 -1
- data/gemfiles/gemfile.rails4 +1 -1
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/dynamic_node.rb +42 -51
- data/lib/tasks/om.rake +1 -1
- 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 +10 -10
- data/spec/integration/querying_documents_spec.rb +20 -27
- data/spec/integration/rights_metadata_integration_example_spec.rb +4 -4
- data/spec/integration/selective_querying_spec.rb +1 -1
- data/spec/integration/serialization_spec.rb +15 -15
- data/spec/integration/set_reentrant_terminology_spec.rb +6 -6
- data/spec/integration/subclass_terminology_spec.rb +8 -8
- data/spec/integration/xpathy_stuff_spec.rb +10 -10
- data/spec/unit/container_spec.rb +27 -27
- data/spec/unit/document_spec.rb +24 -24
- data/spec/unit/dynamic_node_spec.rb +60 -49
- data/spec/unit/named_term_proxy_spec.rb +12 -7
- data/spec/unit/node_generator_spec.rb +4 -4
- data/spec/unit/nokogiri_sanity_spec.rb +17 -18
- data/spec/unit/om_spec.rb +2 -2
- data/spec/unit/template_registry_spec.rb +51 -51
- data/spec/unit/term_builder_spec.rb +45 -44
- data/spec/unit/term_spec.rb +55 -55
- data/spec/unit/term_value_operators_spec.rb +205 -205
- data/spec/unit/term_xpath_generator_spec.rb +33 -36
- data/spec/unit/terminology_builder_spec.rb +50 -47
- data/spec/unit/terminology_spec.rb +92 -92
- data/spec/unit/validation_spec.rb +12 -12
- data/spec/unit/xml_serialization_spec.rb +20 -20
- data/spec/unit/xml_spec.rb +3 -3
- data/spec/unit/xml_terminology_based_solrizer_spec.rb +18 -18
- metadata +11 -38
- data/GETTING_FANCY.textile +0 -145
- data/GETTING_STARTED.textile +0 -254
- data/History.textile +0 -186
- data/QUERYING_DOCUMENTS.textile +0 -139
- data/UPDATING_DOCUMENTS.textile +0 -3
data/spec/unit/document_spec.rb
CHANGED
@@ -75,14 +75,14 @@ describe "OM::XML::Document" do
|
|
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
88
|
|
@@ -90,72 +90,72 @@ describe "OM::XML::Document" do
|
|
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
92
|
skip "better to get an informative error?"
|
93
|
-
@fixturemods.find_by_terms_and_value(:nobody_home).
|
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
110
|
|
111
|
-
@fixturemods.ng_xml.
|
111
|
+
expect(@fixturemods.ng_xml).to receive(:xpath).with('//oxns:name[@type="personal"]/oxns:role[contains(., "donor")]', @fixturemods.ox_namespaces)
|
112
112
|
@fixturemods.find_by_terms_and_value(:person, :role=>"donor")
|
113
113
|
end
|
114
114
|
end
|
115
115
|
describe ".find_by_terms" do
|
116
116
|
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.
|
117
|
+
expect(@mods_article.find_by_terms( :person ).length).to eq 2
|
118
|
+
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
|
119
|
+
expect(@mods_article.find_by_terms( {:person=>1}, :first_name ).class).to eq Nokogiri::XML::NodeSet
|
120
|
+
expect(@mods_article.find_by_terms( {:person=>1}, :first_name ).first.text).to eq "Siddartha"
|
121
121
|
end
|
122
122
|
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.
|
123
|
+
expect(@mods_article.find_by_terms( {:person=>1}, :person_id).first.text).to eq "123987"
|
124
124
|
end
|
125
125
|
it "should support accessors whose relative_xpath is a lookup array instead of an xpath string" do
|
126
126
|
# skip "this only impacts scenarios where we want to display & edit"
|
127
|
-
DocumentTest.terminology.retrieve_term(:title_info, :language).path.
|
127
|
+
expect(DocumentTest.terminology.retrieve_term(:title_info, :language).path).to eq({:attribute=>"lang"})
|
128
128
|
# @sample.retrieve( :title, 1 ).first.text.should == "Artikkelin otsikko Hydrangea artiklan 1"
|
129
|
-
@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text.
|
129
|
+
expect(@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text).to eq "finnish"
|
130
130
|
end
|
131
131
|
|
132
132
|
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.
|
133
|
+
expect(@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text).to eq "FAMILY NAME"
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should return nil if the xpath fails to generate" do
|
137
137
|
skip "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 ).
|
138
|
+
expect(@mods_article.find_by_terms( {:foo=>20}, :bar )).to eq nil
|
139
139
|
end
|
140
140
|
|
141
141
|
it "should support terms that point to attributes instead of nodes" do
|
142
|
-
@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text.
|
142
|
+
expect(@mods_article.find_by_terms( {:title_info=>1}, :language ).first.text).to eq "finnish"
|
143
143
|
end
|
144
144
|
|
145
145
|
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.
|
146
|
+
expect(@mods_article.find_by_terms('//oxns:name[@type="personal"][1]/oxns:namePart[1]').first.text).to eq "FAMILY NAME"
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
150
150
|
describe "node_exists?" do
|
151
151
|
it "should return true if any nodes are found" do
|
152
|
-
@mods_article.node_exists?( {:person=>1}, :first_name).
|
152
|
+
expect(@mods_article.node_exists?( {:person=>1}, :first_name)).to be true
|
153
153
|
end
|
154
154
|
it "should return false if no nodes are found" do
|
155
|
-
@mods_article.node_exists?( {:person=>8}, :first_name ).
|
155
|
+
expect(@mods_article.node_exists?( {:person=>8}, :first_name )).to be false
|
156
156
|
end
|
157
157
|
it "should support xpath queries" do
|
158
|
-
@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]').
|
158
|
+
expect(@mods_article.node_exists?('//oxns:name[@type="personal"][1]/oxns:namePart[1]')).to be true
|
159
159
|
end
|
160
160
|
end
|
161
161
|
|
@@ -26,26 +26,26 @@ describe "OM::XML::DynamicNode" do
|
|
26
26
|
|
27
27
|
it "should create templates for dynamic nodes" do
|
28
28
|
@sample.creator = "Foo"
|
29
|
-
@sample.creator.
|
29
|
+
expect(@sample.creator).to eq ['Foo']
|
30
30
|
end
|
31
31
|
it "should create templates for dynamic nodes with multiple values" do
|
32
32
|
@sample.creator = ["Foo", "Bar"]
|
33
|
-
@sample.creator.
|
33
|
+
expect(@sample.creator).to eq ['Foo', 'Bar']
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should create templates for dynamic nodes with empty string values" do
|
37
37
|
@sample.creator = ['']
|
38
|
-
@sample.creator.
|
38
|
+
expect(@sample.creator).to eq ['']
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should create templates for plain nodes" do
|
42
42
|
@sample.foo = ['in a galaxy far far away']
|
43
|
-
@sample.foo.
|
43
|
+
expect(@sample.foo).to eq ['in a galaxy far far away']
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should create templates for dynamic nodes with a period in the element name" do
|
47
47
|
@sample.date_created = ['A long time ago']
|
48
|
-
@sample.date_created.
|
48
|
+
expect(@sample.date_created).to eq ['A long time ago']
|
49
49
|
end
|
50
50
|
|
51
51
|
it "checks inequality" do
|
@@ -53,36 +53,36 @@ describe "OM::XML::DynamicNode" do
|
|
53
53
|
expect(@sample.foo != ['nearby']).to be true
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
|
-
|
56
|
+
|
57
|
+
|
58
58
|
describe "with a template" do
|
59
59
|
before(:each) do
|
60
60
|
@sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
|
61
61
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
describe "dynamically created nodes" do
|
65
65
|
|
66
66
|
it "should return build an array of values from the nodeset corresponding to the given term" do
|
67
67
|
expected_values = ["Berners-Lee", "Jobs", "Wozniak", "Klimt"]
|
68
68
|
result = @sample.person.last_name
|
69
|
-
result.length.
|
70
|
-
expected_values.each {|v| result.
|
69
|
+
expect(result.length).to eq expected_values.length
|
70
|
+
expected_values.each {|v| expect(result).to include(v)}
|
71
71
|
end
|
72
72
|
|
73
73
|
it "should be able to set first level elements" do
|
74
74
|
@article.abstract = "My Abstract"
|
75
|
-
@article.abstract.
|
75
|
+
expect(@article.abstract).to eq ["My Abstract"]
|
76
76
|
end
|
77
77
|
|
78
78
|
it "should be able to set first level elements that are arrays" do
|
79
79
|
@article.abstract = ["My Abstract", "two"]
|
80
|
-
@article.abstract.
|
80
|
+
expect(@article.abstract).to eq ["My Abstract", 'two']
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should delegate all methods (i.e. to_s, first, etc.) to the found array" do
|
84
|
-
@article.person.last_name.to_s.
|
85
|
-
@article.person.last_name.first.
|
84
|
+
expect(@article.person.last_name.to_s).to eq ["FAMILY NAME", "Gautama"].to_s
|
85
|
+
expect(@article.person.last_name.first).to eq "FAMILY NAME"
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should respond_to? things an array can do" do
|
@@ -92,98 +92,109 @@ describe "OM::XML::DynamicNode" do
|
|
92
92
|
it "should delegate with blocks to the found array" do
|
93
93
|
arr = []
|
94
94
|
@article.person.last_name.each{|x| arr << x}
|
95
|
-
arr.
|
95
|
+
expect(arr).to eq ["FAMILY NAME", "Gautama"]
|
96
96
|
end
|
97
97
|
|
98
|
-
|
99
98
|
describe "setting attributes" do
|
100
99
|
it "when they exist" do
|
101
100
|
@article.title_info(0).main_title.main_title_lang = "ger"
|
102
|
-
@article.title_info(0).main_title.main_title_lang.
|
101
|
+
expect(@article.title_info(0).main_title.main_title_lang).to eq ["ger"]
|
103
102
|
end
|
104
103
|
it "when they don't exist" do
|
105
104
|
title = @article.title_info(0)
|
106
105
|
title.language = "rus"
|
107
|
-
@article.title_info(0).language.
|
106
|
+
expect(@article.title_info(0).language).to eq ["rus"]
|
108
107
|
end
|
109
|
-
|
110
108
|
end
|
111
109
|
|
112
110
|
it "should find elements two deep" do
|
113
|
-
#TODO reimplement so that method_missing with name is only called once. Create a new method for name.
|
114
|
-
@article.name.name_content.val.
|
115
|
-
@article.name.name_content.
|
116
|
-
@article.name.name_content(0).
|
111
|
+
# TODO reimplement so that method_missing with name is only called once. Create a new method for name.
|
112
|
+
expect(@article.name.name_content.val).to eq(["Describes a person"])
|
113
|
+
expect(@article.name.name_content ).to eq(["Describes a person"])
|
114
|
+
expect(@article.name.name_content(0) ).to eq(["Describes a person"])
|
117
115
|
end
|
118
116
|
|
119
|
-
it
|
120
|
-
|
117
|
+
it 'should offer some awareness for respond_to?' do
|
118
|
+
expect(@article.name.name_content.include?('Describes a person')).to be_truthy
|
119
|
+
expect(@article.name.name_content.respond_to?(:include?)).to be_truthy
|
120
|
+
expect(@article.name.name_content).to include('Describes a person')
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not find elements that don't exist" do
|
124
|
+
expect{@article.name.hedgehog }.to raise_exception NoMethodError, /hedgehog/
|
125
|
+
expect{@article.name.hedgehog = 5 }.to raise_exception NoMethodError, /hedgehog/
|
126
|
+
expect{@article.name.hedgehog(5) }.to raise_exception NoMethodError, /hedgehog/
|
127
|
+
expect{@article.name.hedgehog(5,1)}.to raise_exception NoMethodError, /hedgehog/
|
128
|
+
expect{@article.name.name_content.hedgehog }.to raise_exception NoMethodError, /hedgehog/
|
129
|
+
expect{@article.name.name_content.hedgehog = 'foo' }.to raise_exception NoMethodError, /hedgehog/
|
130
|
+
expect{@article.name.name_content.hedgehog(1) }.to raise_exception NoMethodError, /hedgehog/
|
131
|
+
expect{@article.name.name_content.hedgehog(1,'foo')}.to raise_exception NoMethodError, /hedgehog/
|
121
132
|
end
|
122
133
|
|
123
134
|
it "should allow you to call methods on the return value" do
|
124
|
-
@article.name.name_content.first.
|
135
|
+
expect(@article.name.name_content.first).to eq "Describes a person"
|
125
136
|
end
|
126
137
|
|
127
138
|
it "Should work with proxies" do
|
128
|
-
@article.title.
|
129
|
-
@article.title.main_title_lang.
|
139
|
+
expect(@article.title).to eq(["ARTICLE TITLE HYDRANGEA ARTICLE 1", "Artikkelin otsikko Hydrangea artiklan 1", "TITLE OF HOST JOURNAL"])
|
140
|
+
expect(@article.title.main_title_lang).to eq ['eng']
|
130
141
|
|
131
|
-
@article.title(1).to_pointer.
|
142
|
+
expect(@article.title(1).to_pointer).to eq [{:title => 1}]
|
132
143
|
|
133
|
-
@article.journal_title.xpath.
|
134
|
-
@article.journal_title.
|
144
|
+
expect(@article.journal_title.xpath).to eq "//oxns:relatedItem[@type=\"host\"]/oxns:titleInfo/oxns:title"
|
145
|
+
expect(@article.journal_title).to eq ["TITLE OF HOST JOURNAL"]
|
135
146
|
end
|
136
147
|
|
137
148
|
it "Should be addressable to a specific node" do
|
138
149
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>"434"})
|
139
150
|
|
140
151
|
@article.subject.topic(1).to_pointer == [:subject, {:topic => 1}]
|
141
|
-
@article.journal(0).issue.length.
|
142
|
-
@article.journal(0).issue(1).pages.to_pointer
|
143
|
-
@article.journal(0).issue(1).pages.length.
|
144
|
-
@article.journal(0).issue(1).pages.start.length.
|
145
|
-
@article.journal(0).issue(1).pages.start.first.
|
152
|
+
expect(@article.journal(0).issue.length).to eq 2
|
153
|
+
expect(@article.journal(0).issue(1).pages.to_pointer).to eq [{:journal=>0}, {:issue=>1}, :pages]
|
154
|
+
expect(@article.journal(0).issue(1).pages.length).to eq 1
|
155
|
+
expect(@article.journal(0).issue(1).pages.start.length).to eq 1
|
156
|
+
expect(@article.journal(0).issue(1).pages.start.first).to eq "434"
|
146
157
|
|
147
|
-
@article.subject.topic(1).
|
148
|
-
@article.subject.topic(1).xpath.
|
158
|
+
expect(@article.subject.topic(1)).to eq ["TOPIC 2"]
|
159
|
+
expect(@article.subject.topic(1).xpath).to eq "//oxns:subject/oxns:topic[2]"
|
149
160
|
end
|
150
|
-
|
161
|
+
|
151
162
|
describe ".nodeset" do
|
152
163
|
it "should return a Nokogiri NodeSet" do
|
153
164
|
@article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>"434" })
|
154
165
|
nodeset = @article.journal(0).issue(1).pages.start.nodeset
|
155
|
-
nodeset.
|
156
|
-
nodeset.length.
|
157
|
-
nodeset.first.text.
|
166
|
+
expect(nodeset).to be_kind_of Nokogiri::XML::NodeSet
|
167
|
+
expect(nodeset.length).to eq @article.journal(0).issue(1).pages.start.length
|
168
|
+
expect(nodeset.first.text).to eq @article.journal(0).issue(1).pages.start.first
|
158
169
|
end
|
159
170
|
end
|
160
171
|
|
161
172
|
it "should append nodes at the specified index if possible" do
|
162
173
|
@article.journal.title_info = ["all", "for", "the"]
|
163
174
|
@article.journal.title_info(3, 'glory')
|
164
|
-
@article.term_values(:journal, :title_info).
|
165
|
-
@article.
|
175
|
+
expect(@article.term_values(:journal, :title_info)).to eq ["all", "for", "the", "glory"]
|
176
|
+
expect(@article).to be_changed
|
166
177
|
end
|
167
|
-
|
178
|
+
|
168
179
|
it "should remove extra nodes if fewer are given than currently exist" do
|
169
180
|
@article.journal.title_info = %W(one two three four five)
|
170
181
|
@article.journal.title_info = %W(six seven)
|
171
|
-
@article.journal.title_info.
|
182
|
+
expect(@article.journal.title_info).to eq ["six", "seven"]
|
172
183
|
end
|
173
184
|
|
174
185
|
describe '==' do
|
175
186
|
it "returns true when values of dynamic nodes are equal." do
|
176
187
|
@article.name(0).last_name = "Steven"
|
177
188
|
@article.name(0).first_name = "Steven"
|
178
|
-
(@article.name(0).last_name
|
189
|
+
expect(@article.name(0).last_name).to eq @article.name(0).first_name
|
179
190
|
end
|
180
191
|
|
181
192
|
it 'returns false when values of dynamic nodes are not equal.' do
|
182
193
|
@article.name(0).first_name = "Horatio"
|
183
194
|
@article.name(0).last_name = "Hogginobble"
|
184
|
-
(@article.name(0).last_name == @article.name(0).first_name).
|
195
|
+
expect(@article.name(0).last_name == @article.name(0).first_name).to be false
|
185
196
|
end
|
186
|
-
end
|
197
|
+
end
|
187
198
|
end
|
188
199
|
end
|
189
200
|
end
|
@@ -31,25 +31,30 @@ describe "OM::XML::NamedTermProxy" do
|
|
31
31
|
|
32
32
|
it "should proxy all extra methods to the proxied object" do
|
33
33
|
[:xpath, :xpath_relative, :xml_builder_template].each do |method|
|
34
|
-
@proxied_term.
|
34
|
+
expect(@proxied_term).to receive(method)
|
35
35
|
@test_proxy.send(method)
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
38
39
|
it "should proxy the term specified by the builder" do
|
39
|
-
@test_proxy.proxied_term.
|
40
|
-
@test_proxy.xpath.
|
40
|
+
expect(@test_proxy.proxied_term).to eq(@test_terminology.retrieve_term(:parent, :foo, :bar))
|
41
|
+
expect(@test_proxy.xpath).to eq "//oxns:parent/oxns:foo/oxns:bar"
|
41
42
|
end
|
43
|
+
|
42
44
|
it "should search relative to the parent term when finding the term to proxy" do
|
43
45
|
proxy2 = @test_terminology.retrieve_term(:adoptive_parent, :my_proxy)
|
44
|
-
proxy2.proxied_term.
|
45
|
-
proxy2.xpath.
|
46
|
+
expect(proxy2.proxied_term).to eq @test_terminology.retrieve_term(:adoptive_parent, :foo, :bar)
|
47
|
+
expect(proxy2.xpath).to eq '//oxns:parent[@type="adoptive"]/oxns:foo/oxns:bar'
|
46
48
|
end
|
49
|
+
|
47
50
|
it "should support NamedTermProxies that point to root terms" do
|
48
|
-
@test_terminology.xpath_for(:parentfoobarproxy).
|
51
|
+
expect(@test_terminology.xpath_for(:parentfoobarproxy)).to eq("//oxns:parent/oxns:foo/oxns:bar")
|
49
52
|
end
|
53
|
+
|
50
54
|
it "should be usable in update_values" do
|
51
55
|
document = NamedProxyTestDocument.from_xml(NamedProxyTestDocument.xml_template)
|
52
56
|
document.update_values([:parentfoobarproxy] => "FOObar!")
|
53
|
-
document.term_values(:parentfoobarproxy).
|
57
|
+
expect(document.term_values(:parentfoobarproxy)).to eq ["FOObar!"]
|
54
58
|
end
|
59
|
+
|
55
60
|
end
|
@@ -10,17 +10,17 @@ describe "OM::XML::NodeGenerator" do
|
|
10
10
|
|
11
11
|
describe '#generate' do
|
12
12
|
it "should use the corresponding builder template(s) to generate the node" do
|
13
|
-
OM::XML::NodeGenerator.generate(@test_mods_term, "foo").root.to_xml.
|
13
|
+
expect(OM::XML::NodeGenerator.generate(@test_mods_term, "foo").root.to_xml).to eq "<mods>foo</mods>"
|
14
14
|
generated_node = OM::XML::NodeGenerator.generate(@test_volume_term, "108", {:attributes=>{"extraAttr"=>"my value"}})
|
15
|
-
generated_node.xpath('./detail[@type="volume"][@extraAttr="my value"]').xpath("./number").text.
|
15
|
+
expect(generated_node.xpath('./detail[@type="volume"][@extraAttr="my value"]').xpath("./number").text).to eq "108"
|
16
16
|
# Would be great if we wrote a have_node custom rspec matcher...
|
17
17
|
# generated_node.should have_node 'role[@authority="marcrelator"][@type="code"]' do
|
18
18
|
# with_node "roleTerm", "creator"
|
19
19
|
# end
|
20
20
|
end
|
21
|
+
|
21
22
|
it "should return Nokogiri Documents" do
|
22
|
-
OM::XML::NodeGenerator.generate(@test_mods_term, "foo").class.
|
23
|
+
expect(OM::XML::NodeGenerator.generate(@test_mods_term, "foo").class).to eq Nokogiri::XML::Document
|
23
24
|
end
|
24
25
|
end
|
25
|
-
|
26
26
|
end
|
@@ -8,7 +8,7 @@ describe "OM::XML::TermValueOperators" do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should do" do
|
11
|
-
@article.find_by_terms({:journal=>0}).length.
|
11
|
+
expect(@article.find_by_terms({:journal=>0}).length).to eq 1
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
@@ -20,56 +20,55 @@ describe "OM::XML::TermValueOperators" do
|
|
20
20
|
it "should respond with a hash of updated values and their indexes" do
|
21
21
|
test_args = {[{"person"=>"0"},"description"]=>["mork", "york"]}
|
22
22
|
result = @article.update_values(test_args)
|
23
|
-
result.
|
23
|
+
expect(result).to eq({"person_0_description"=>["mork", "york"]})
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should update the xml in the specified datastream and know that changes have been made" do
|
27
|
-
@article.term_values({:person=>0}, :first_name).
|
27
|
+
expect(@article.term_values({:person=>0}, :first_name)).to eq ["GIVEN NAMES"]
|
28
28
|
test_args = {[{:person=>0}, :first_name]=>"Replacement FirstName"}
|
29
29
|
@article.update_values(test_args)
|
30
|
-
@article.term_values({:person=>0}, :first_name).
|
31
|
-
@article.
|
30
|
+
expect(@article.term_values({:person=>0}, :first_name)).to eq ["Replacement FirstName"]
|
31
|
+
expect(@article).to be_changed
|
32
32
|
end
|
33
33
|
|
34
34
|
it "should update the xml according to the find_by_terms_and_values in the given hash" do
|
35
35
|
terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
|
36
36
|
result = @article.update_values(terms_attributes)
|
37
|
-
result.
|
37
|
+
expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
|
38
38
|
|
39
39
|
# Trying again with a more complex update hash
|
40
40
|
terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"], [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
|
41
41
|
result = @article.update_values(terms_attributes)
|
42
|
-
result.
|
43
|
-
@article.
|
42
|
+
expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"], "person_1_last_name"=>["Andronicus"],"person_1_first_name"=>["Titus"], "person_1_role"=>["otherrole1","otherrole2"]})
|
43
|
+
expect(@article).to be_changed
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should work when you re-run the command" do
|
47
47
|
terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
|
48
48
|
result = @article.update_values(terms_attributes)
|
49
|
-
|
50
|
-
|
49
|
+
|
50
|
+
expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq ["affiliation1", "affiliation2", "affiliation3"]
|
51
|
+
expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
|
51
52
|
|
52
53
|
terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
|
53
54
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
54
55
|
result = @article.update_values(terms_attributes)
|
55
|
-
@article.term_values( {":person"=>"0"}, "affiliation" ).
|
56
|
-
result.
|
56
|
+
expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq ["affiliation1", "affiliation2", "affiliation3"]
|
57
|
+
expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
|
57
58
|
result = @article.update_values(terms_attributes)
|
58
59
|
|
59
60
|
terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"]}
|
60
61
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
61
62
|
result = @article.update_values(terms_attributes)
|
62
|
-
@article.term_values( {":person"=>"0"}, "affiliation" ).
|
63
|
-
result.
|
63
|
+
expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq ["affiliation1", "affiliation2", "affiliation3"]
|
64
|
+
expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"]})
|
64
65
|
|
65
66
|
# Trying again with a more complex update hash
|
66
67
|
terms_attributes = {[{":person"=>"0"}, "affiliation"]=>["affiliation1", "affiliation2", "affiliation3"], [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
|
67
68
|
result = @article.update_values(terms_attributes)
|
68
|
-
result.
|
69
|
-
@article.
|
69
|
+
expect(result).to eq({"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"], "person_1_last_name"=>["Andronicus"],"person_1_first_name"=>["Titus"], "person_1_role"=>["otherrole1", "otherrole2"]})
|
70
|
+
expect(@article).to be_changed
|
70
71
|
end
|
71
72
|
end
|
72
|
-
|
73
73
|
|
74
|
-
|
75
74
|
end
|