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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/{COMMON_OM_PATTERNS.textile → COMMON_OM_PATTERNS.md} +136 -126
  3. data/CONTRIBUTING.md +2 -2
  4. data/GETTING_FANCY.md +153 -0
  5. data/GETTING_STARTED.md +329 -0
  6. data/Gemfile +1 -1
  7. data/History.md +164 -0
  8. data/LICENSE +15 -20
  9. data/QUERYING_DOCUMENTS.md +162 -0
  10. data/README.md +2 -2
  11. data/UPDATING_DOCUMENTS.md +6 -0
  12. data/gemfiles/gemfile.rails3 +1 -1
  13. data/gemfiles/gemfile.rails4 +1 -1
  14. data/lib/om/version.rb +1 -1
  15. data/lib/om/xml/dynamic_node.rb +42 -51
  16. data/lib/tasks/om.rake +1 -1
  17. data/om.gemspec +1 -2
  18. data/spec/integration/differentiated_elements_spec.rb +2 -2
  19. data/spec/integration/element_value_spec.rb +13 -13
  20. data/spec/integration/proxies_and_ref_spec.rb +10 -10
  21. data/spec/integration/querying_documents_spec.rb +20 -27
  22. data/spec/integration/rights_metadata_integration_example_spec.rb +4 -4
  23. data/spec/integration/selective_querying_spec.rb +1 -1
  24. data/spec/integration/serialization_spec.rb +15 -15
  25. data/spec/integration/set_reentrant_terminology_spec.rb +6 -6
  26. data/spec/integration/subclass_terminology_spec.rb +8 -8
  27. data/spec/integration/xpathy_stuff_spec.rb +10 -10
  28. data/spec/unit/container_spec.rb +27 -27
  29. data/spec/unit/document_spec.rb +24 -24
  30. data/spec/unit/dynamic_node_spec.rb +60 -49
  31. data/spec/unit/named_term_proxy_spec.rb +12 -7
  32. data/spec/unit/node_generator_spec.rb +4 -4
  33. data/spec/unit/nokogiri_sanity_spec.rb +17 -18
  34. data/spec/unit/om_spec.rb +2 -2
  35. data/spec/unit/template_registry_spec.rb +51 -51
  36. data/spec/unit/term_builder_spec.rb +45 -44
  37. data/spec/unit/term_spec.rb +55 -55
  38. data/spec/unit/term_value_operators_spec.rb +205 -205
  39. data/spec/unit/term_xpath_generator_spec.rb +33 -36
  40. data/spec/unit/terminology_builder_spec.rb +50 -47
  41. data/spec/unit/terminology_spec.rb +92 -92
  42. data/spec/unit/validation_spec.rb +12 -12
  43. data/spec/unit/xml_serialization_spec.rb +20 -20
  44. data/spec/unit/xml_spec.rb +3 -3
  45. data/spec/unit/xml_terminology_based_solrizer_spec.rb +18 -18
  46. metadata +11 -38
  47. data/GETTING_FANCY.textile +0 -145
  48. data/GETTING_STARTED.textile +0 -254
  49. data/History.textile +0 -186
  50. data/QUERYING_DOCUMENTS.textile +0 -139
  51. data/UPDATING_DOCUMENTS.textile +0 -3
@@ -3,12 +3,12 @@ require 'spec_helper'
3
3
  describe OM::XML::Term do
4
4
  describe "without a type" do
5
5
  it "should default to string" do
6
- OM::XML::Term.new(:test_term).type.should == :string
6
+ expect(OM::XML::Term.new(:test_term).type).to eq(:string)
7
7
  end
8
8
  end
9
9
  describe "when type is specified" do
10
10
  it "should accept date" do
11
- OM::XML::Term.new(:test_term, :type=>:date).type.should == :date
11
+ expect(OM::XML::Term.new(:test_term, :type=>:date).type).to eq :date
12
12
  end
13
13
  end
14
14
 
@@ -25,20 +25,20 @@ describe OM::XML::Term do
25
25
 
26
26
  describe '#new' do
27
27
  it "should set path from mapper name if no path is provided" do
28
- @test_name_part.path.should == "namePart"
28
+ expect(@test_name_part.path).to eq "namePart"
29
29
  end
30
30
  it "should populate the xpath values if no options are provided" do
31
31
  local_mapping = OM::XML::Term.new(:namePart)
32
- local_mapping.xpath_relative.should be_nil
33
- local_mapping.xpath.should be_nil
34
- local_mapping.xpath_constrained.should be_nil
32
+ expect(local_mapping.xpath_relative).to be_nil
33
+ expect(local_mapping.xpath).to be_nil
34
+ expect(local_mapping.xpath_constrained).to be_nil
35
35
  end
36
36
  end
37
37
 
38
38
  describe 'inner_xml' do
39
39
  it "should be a kind of Nokogiri::XML::Node" do
40
40
  skip
41
- @test_mapping.inner_xml.should be_kind_of(Nokogiri::XML::Node)
41
+ expect(@test_mapping.inner_xml).to be_kind_of(Nokogiri::XML::Node)
42
42
  end
43
43
  end
44
44
 
@@ -57,17 +57,17 @@ describe OM::XML::Term do
57
57
  # node = Nokogiri::XML::Document.parse( '<mapper name="first_name" path="namePart"><attribute name="type" value="given"/><attribute name="another_attribute" value="myval"/></mapper>' ).root
58
58
  node = ng_builder.doc.root
59
59
  mapper = OM::XML::Term.from_node(node)
60
- mapper.name.should == :person
61
- mapper.path.should == "name"
62
- mapper.attributes.should == {:type=>"personal"}
63
- mapper.internal_xml.should == node
60
+ expect(mapper.name).to eq :person
61
+ expect(mapper.path).to eq "name"
62
+ expect(mapper.attributes).to eq({:type=>"personal"})
63
+ expect(mapper.internal_xml).to eq node
64
64
 
65
65
  child = mapper.children[:first_name]
66
66
 
67
- child.name.should == :first_name
68
- child.path.should == "namePart"
69
- child.attributes.should == {:type=>"given", :another_attribute=>"myval"}
70
- child.internal_xml.should == node.xpath("./mapper").first
67
+ expect(child.name).to eq :first_name
68
+ expect(child.path).to eq "namePart"
69
+ expect(child.attributes).to eq({:type=>"given", :another_attribute=>"myval"})
70
+ expect(child.internal_xml).to eq node.xpath("./mapper").first
71
71
  end
72
72
  end
73
73
 
@@ -79,18 +79,18 @@ describe OM::XML::Term do
79
79
  it "should crawl down into mapper children to find the desired term" do
80
80
  mock_role = double("mapper", :children =>{:text=>"the target"})
81
81
  mock_conference = double("mapper", :children =>{:role=>mock_role})
82
- @test_name_part.should_receive(:children).and_return({:conference=>mock_conference})
83
- @test_name_part.retrieve_term(:conference, :role, :text).should == "the target"
82
+ expect(@test_name_part).to receive(:children).and_return({:conference=>mock_conference})
83
+ expect(@test_name_part.retrieve_term(:conference, :role, :text)).to eq "the target"
84
84
  end
85
85
  it "should return an empty hash if no term can be found" do
86
- @test_name_part.retrieve_term(:journal, :issue, :end_page).should == nil
86
+ expect(@test_name_part.retrieve_term(:journal, :issue, :end_page)).to be_nil
87
87
  end
88
88
  end
89
89
 
90
90
  describe 'inner_xml' do
91
91
  it "should be a kind of Nokogiri::XML::Node" do
92
92
  skip
93
- @test_name_part.inner_xml.should be_kind_of(Nokogiri::XML::Node)
93
+ expect(@test_name_part.inner_xml).to be_kind_of(Nokogiri::XML::Node)
94
94
  end
95
95
  end
96
96
 
@@ -100,7 +100,7 @@ describe OM::XML::Term do
100
100
 
101
101
  [:path, :required, :type, :variant_of, :path, :attributes, :default_content_path, :namespace_prefix].each do |method_name|
102
102
  @test_name_part.send((method_name.to_s+"=").to_sym, "#{method_name.to_s}foo")
103
- @test_name_part.send(method_name).should == "#{method_name.to_s}foo"
103
+ expect(@test_name_part.send(method_name)).to eq "#{method_name.to_s}foo"
104
104
  end
105
105
  end
106
106
  end
@@ -120,76 +120,76 @@ describe OM::XML::Term do
120
120
  }
121
121
 
122
122
  it "should accept an array as an :index_as value" do
123
- subject.terminology.terms[:as_array].index_as.should be_a_kind_of(Array)
124
- subject.terminology.terms[:as_array].index_as.should == [:not_searchable]
123
+ expect(subject.terminology.terms[:as_array].index_as).to be_a_kind_of(Array)
124
+ expect(subject.terminology.terms[:as_array].index_as).to eq [:not_searchable]
125
125
  end
126
126
  it "should accept a plain symbol as a value to :index_as" do
127
- subject.terminology.terms[:as_symbol].index_as.should be_a_kind_of(Array)
128
- subject.terminology.terms[:as_symbol].index_as.should == [:not_searchable]
127
+ expect(subject.terminology.terms[:as_symbol].index_as).to be_a_kind_of(Array)
128
+ expect(subject.terminology.terms[:as_symbol].index_as).to eq [:not_searchable]
129
129
  end
130
130
  end
131
131
  it "should have a .terminology attribute accessor" do
132
- @test_volume.should respond_to :terminology
133
- @test_volume.should respond_to :terminology=
132
+ expect(@test_volume).to respond_to :terminology
133
+ expect(@test_volume).to respond_to :terminology=
134
134
  end
135
135
  describe ".ancestors" do
136
136
  it "should return an array of Terms that are the ancestors of the current object, ordered from the top/root of the hierarchy" do
137
137
  @test_volume.set_parent(@test_name_part)
138
- @test_volume.ancestors.should == [@test_name_part]
138
+ expect(@test_volume.ancestors).to eq [@test_name_part]
139
139
  end
140
140
  end
141
141
  describe ".parent" do
142
142
  it "should retrieve the immediate parent of the given object from the ancestors array" do
143
143
  @test_name_part.ancestors = ["ancestor1","ancestor2","ancestor3"]
144
- @test_name_part.parent.should == "ancestor3"
144
+ expect(@test_name_part.parent).to eq "ancestor3"
145
145
  end
146
146
  end
147
147
  describe ".children" do
148
148
  it "should return a hash of Terms that are the children of the current object, indexed by name" do
149
149
  @test_volume.add_child(@test_name_part)
150
- @test_volume.children[@test_name_part.name].should == @test_name_part
150
+ expect(@test_volume.children[@test_name_part.name]).to eq @test_name_part
151
151
  end
152
152
  end
153
153
  describe ".retrieve_child" do
154
154
  it "should fetch the child identified by the given name" do
155
155
  @test_volume.add_child(@test_name_part)
156
- @test_volume.retrieve_child(@test_name_part.name).should == @test_volume.children[@test_name_part.name]
156
+ expect(@test_volume.retrieve_child(@test_name_part.name)).to eq @test_volume.children[@test_name_part.name]
157
157
  end
158
158
  end
159
159
  describe ".set_parent" do
160
160
  it "should insert the mapper into the given parent" do
161
161
  @test_name_part.set_parent(@test_volume)
162
- @test_name_part.ancestors.should include(@test_volume)
163
- @test_volume.children[@test_name_part.name].should == @test_name_part
162
+ expect(@test_name_part.ancestors).to include(@test_volume)
163
+ expect(@test_volume.children[@test_name_part.name]).to eq @test_name_part
164
164
  end
165
165
  end
166
166
  describe ".add_child" do
167
167
  it "should insert the given mapper into the current mappers children" do
168
168
  @test_volume.add_child(@test_name_part)
169
- @test_volume.children[@test_name_part.name].should == @test_name_part
170
- @test_name_part.ancestors.should include(@test_volume)
169
+ expect(@test_volume.children[@test_name_part.name]).to eq @test_name_part
170
+ expect(@test_name_part.ancestors).to include(@test_volume)
171
171
  end
172
172
  end
173
173
 
174
174
  describe "generate_xpath_queries!" do
175
175
  it "should return the current object" do
176
- @test_name_part.generate_xpath_queries!.should == @test_name_part
176
+ expect(@test_name_part.generate_xpath_queries!).to eq @test_name_part
177
177
  end
178
178
  it "should regenerate the xpath values" do
179
- @test_volume.xpath_relative.should be_nil
180
- @test_volume.xpath.should be_nil
181
- @test_volume.xpath_constrained.should be_nil
179
+ expect(@test_volume.xpath_relative).to be_nil
180
+ expect(@test_volume.xpath).to be_nil
181
+ expect(@test_volume.xpath_constrained).to be_nil
182
182
 
183
- @test_volume.generate_xpath_queries!.should == @test_volume
183
+ expect(@test_volume.generate_xpath_queries!).to eq @test_volume
184
184
 
185
- @test_volume.xpath_relative.should == 'detail[@type="volume"]'
186
- @test_volume.xpath.should == '//detail[@type="volume"]'
187
- @test_volume.xpath_constrained.should == '//detail[@type="volume" and contains(number, "#{constraint_value}")]'.gsub('"', '\"')
185
+ expect(@test_volume.xpath_relative).to eq 'detail[@type="volume"]'
186
+ expect(@test_volume.xpath).to eq '//detail[@type="volume"]'
187
+ expect(@test_volume.xpath_constrained).to eq '//detail[@type="volume" and contains(number, "#{constraint_value}")]'.gsub('"', '\"')
188
188
  end
189
189
  it "should trigger update on any child objects" do
190
190
  mock_child = double("child term")
191
- mock_child.should_receive(:generate_xpath_queries!).exactly(3).times
192
- @test_name_part.should_receive(:children).and_return({1=>mock_child, 2=>mock_child, 3=>mock_child})
191
+ expect(mock_child).to receive(:generate_xpath_queries!).exactly(3).times
192
+ expect(@test_name_part).to receive(:children).and_return({1=>mock_child, 2=>mock_child, 3=>mock_child})
193
193
  @test_name_part.generate_xpath_queries!
194
194
  end
195
195
  end
@@ -197,9 +197,9 @@ describe OM::XML::Term do
197
197
  describe "#xml_builder_template" do
198
198
 
199
199
  it "should generate a template call for passing into the builder block (assumes 'xml' as the argument for the block)" do
200
- @test_date.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
201
- @test_person.xml_builder_template.should == 'xml.namePart( \'#{builder_new_value}\' )'
202
- @test_affiliation.xml_builder_template.should == 'xml.affiliation( \'#{builder_new_value}\' )'
200
+ expect(@test_date.xml_builder_template).to eq 'xml.namePart( \'#{builder_new_value}\', \'type\'=>\'date\' )'
201
+ expect(@test_person.xml_builder_template).to eq 'xml.namePart( \'#{builder_new_value}\' )'
202
+ expect(@test_affiliation.xml_builder_template).to eq 'xml.affiliation( \'#{builder_new_value}\' )'
203
203
  end
204
204
 
205
205
  it "should accept extra options" do
@@ -208,37 +208,37 @@ describe OM::XML::Term do
208
208
  e1 = %q{xml.roleTerm( '#{builder_new_value}', 'type'=>'code', 'authority'=>'marcrelator' )}
209
209
  e2 = %q{xml.roleTerm( '#{builder_new_value}', 'authority'=>'marcrelator', 'type'=>'code' )}
210
210
  got = @test_role_code.xml_builder_template(:attributes=>{"authority"=>"marcrelator"})
211
- [e1, e2].should include(got)
211
+ expect([e1, e2]).to include(got)
212
212
  end
213
213
 
214
214
  it "should work for namespaced nodes" do
215
215
  @ical_date = OM::XML::Term.new(:ical_date, :path=>"ical:date")
216
- @ical_date.xml_builder_template.should == "xml[\'ical\'].date( '\#{builder_new_value}' )"
216
+ expect(@ical_date.xml_builder_template).to eq "xml[\'ical\'].date( '\#{builder_new_value}' )"
217
217
  @ical_date = OM::XML::Term.new(:ical_date, :path=>"date", :namespace_prefix=>"ical")
218
- @ical_date.xml_builder_template.should == "xml[\'ical\'].date( '\#{builder_new_value}' )"
218
+ expect(@ical_date.xml_builder_template).to eq "xml[\'ical\'].date( '\#{builder_new_value}' )"
219
219
  end
220
220
 
221
221
  it "should work for nodes with default_content_path" do
222
- @test_volume.xml_builder_template.should == "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
222
+ expect(@test_volume.xml_builder_template).to eq "xml.detail( \'type\'=>'volume' ) { xml.number( '\#{builder_new_value}' ) }"
223
223
  end
224
224
 
225
225
  it "should support terms that are attributes" do
226
226
  @type_attribute_term = OM::XML::Term.new(:type_attribute, :path=>{:attribute=>:type})
227
- @type_attribute_term.xml_builder_template.should == "xml.@type( '\#{builder_new_value}' )"
227
+ expect(@type_attribute_term.xml_builder_template).to eq "xml.@type( '\#{builder_new_value}' )"
228
228
  end
229
229
 
230
230
  it "should support terms with namespaced attributes" do
231
231
  @french_title = OM::XML::Term.new(:french_title, :path=>"title", :attributes=>{"xml:lang"=>"fre"})
232
- @french_title.xml_builder_template.should == "xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )"
232
+ expect(@french_title.xml_builder_template).to eq "xml.title( '\#{builder_new_value}', 'xml:lang'=>'fre' )"
233
233
  end
234
234
 
235
235
  it "should support terms that are namespaced attributes" do
236
236
  @xml_lang_attribute_term = OM::XML::Term.new(:xml_lang_attribute, :path=>{:attribute=>"xml:lang"})
237
- @xml_lang_attribute_term.xml_builder_template.should == "xml.@xml:lang( '\#{builder_new_value}' )"
237
+ expect(@xml_lang_attribute_term.xml_builder_template).to eq "xml.@xml:lang( '\#{builder_new_value}' )"
238
238
  end
239
239
 
240
240
  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
241
- @test_type.xml_builder_template.should == 'xml.class_( \'#{builder_new_value}\' )'
241
+ expect(@test_type.xml_builder_template).to eq 'xml.class_( \'#{builder_new_value}\' )'
242
242
  end
243
243
  end
244
244
  end
@@ -1,66 +1,66 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "OM::XML::TermValueOperators" do
4
-
4
+
5
5
  before(:each) do
6
6
  @sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
7
7
  @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
8
8
  @empty_sample = OM::Samples::ModsArticle.from_xml("")
9
9
  end
10
-
10
+
11
11
  describe ".term_values" do
12
12
 
13
13
  it "should return build an array of values from the nodeset corresponding to the given term" do
14
14
  expected_values = ["Berners-Lee", "Jobs", "Wozniak", "Klimt"]
15
15
  result = @sample.term_values(:person, :last_name)
16
- result.length.should == expected_values.length
17
- expected_values.each {|v| result.should include(v)}
16
+ expect(result.length).to eq expected_values.length
17
+ expected_values.each {|v| expect(result).to include(v)}
18
18
  end
19
19
 
20
20
  it "should look at the index" do
21
21
  result = @sample.term_values(:role, {:text => 3})
22
- result.should == ['visionary']
22
+ expect(result).to eq ['visionary']
23
23
  end
24
24
 
25
25
  it "should ignore whitespace elements for a term pointing to a text() node for an element that contains children" do
26
- @article.term_values(:name, :name_content).should == ["Describes a person"]
26
+ expect(@article.term_values(:name, :name_content)).to eq ["Describes a person"]
27
27
  end
28
-
28
+
29
29
  end
30
-
31
-
30
+
31
+
32
32
  describe ".update_values" do
33
33
  it "should update the xml according to the find_by_terms_and_values in the given hash" do
34
34
  terms_attributes = {[{":person"=>"0"}, "affiliation"]=>{'1' => "affiliation1", '2'=> "affiliation2", '3' => "affiliation3"}, [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
35
35
  result = @article.update_values(terms_attributes)
36
- result.should == {"person_0_affiliation"=>["affiliation1", "affiliation2", "affiliation3"], "person_1_last_name"=>["Andronicus"], "person_1_first_name"=>["Titus"], "person_1_role"=>["otherrole1","otherrole2"]}
36
+ 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"]})
37
37
  person_0_affiliation = @article.find_by_terms({:person=>0}, :affiliation)
38
- person_0_affiliation[0].text.should == "affiliation1"
39
- person_0_affiliation[1].text.should == "affiliation2"
40
- person_0_affiliation[2].text.should == "affiliation3"
41
-
38
+ expect(person_0_affiliation[0].text).to eq "affiliation1"
39
+ expect(person_0_affiliation[1].text).to eq "affiliation2"
40
+ expect(person_0_affiliation[2].text).to eq "affiliation3"
41
+
42
42
  person_1_last_names = @article.find_by_terms({:person=>1}, :last_name)
43
- person_1_last_names.length.should == 1
44
- person_1_last_names.first.text.should == "Andronicus"
45
-
43
+ expect(person_1_last_names.length).to eq 1
44
+ expect(person_1_last_names.first.text).to eq "Andronicus"
45
+
46
46
  person_1_first_names = @article.find_by_terms({:person=>1}, :first_name)
47
- person_1_first_names.first.text.should == "Titus"
48
-
47
+ expect(person_1_first_names.first.text).to eq "Titus"
48
+
49
49
  person_1_roles = @article.find_by_terms({:person=>1}, :role)
50
- person_1_roles[0].text.should == "otherrole1"
51
- person_1_roles[1].text.should == "otherrole2"
50
+ expect(person_1_roles[0].text).to eq "otherrole1"
51
+ expect(person_1_roles[1].text).to eq "otherrole2"
52
52
  end
53
53
 
54
54
  it "should allow setting a blank string " do
55
55
  @article.update_values([:abstract]=>[''])
56
- @article.term_values(:abstract).should == [""]
56
+ expect(@article.term_values(:abstract)).to eq [""]
57
57
  end
58
58
 
59
59
  it "should call term_value_update if the corresponding node already exists" do
60
- @article.should_receive(:term_value_update).with('//oxns:titleInfo/oxns:title', 0, "My New Title")
60
+ expect(@article).to receive(:term_value_update).with('//oxns:titleInfo/oxns:title', 0, "My New Title")
61
61
  @article.update_values( {[:title_info, :main_title] => "My New Title"} )
62
62
  end
63
-
63
+
64
64
  it "should call term_values_append if the corresponding node does not already exist or if the requested index is -1" do
65
65
  expected_args = {
66
66
  # :parent_select => OM::Samples::ModsArticle.terminology.xpath_with_indexes(*[{:person=>0}]) ,
@@ -69,159 +69,159 @@ describe "OM::XML::TermValueOperators" do
69
69
  :template => [:person, :role],
70
70
  :values => "My New Role"
71
71
  }
72
- @article.should_receive(:term_values_append).with(expected_args).twice
72
+ expect(@article).to receive(:term_values_append).with(expected_args).twice
73
73
  @article.update_values( {[{:person=>0}, {:role => 6}] => "My New Role"} )
74
74
  @article.update_values( {[{:person=>0}, {:role => 7}] => "My New Role"} )
75
75
  end
76
-
76
+
77
77
  it "should support updating attribute values" do
78
78
  pointer = [:title_info, :language]
79
79
  test_val = "language value"
80
80
  @article.update_values( {pointer=>test_val} )
81
- @article.term_values(*pointer).first.should == test_val
81
+ expect(@article.term_values(*pointer).first).to eq test_val
82
82
  end
83
-
83
+
84
84
  it "should not get tripped up on root nodes" do
85
85
  @article.update_values([:title_info]=>["york", "mangle","mork"])
86
- @article.term_values(*[:title_info]).should == ["york", "mangle", "mork"]
86
+ expect(@article.term_values(*[:title_info])).to eq ["york", "mangle", "mork"]
87
87
  end
88
88
 
89
89
  it "should destringify the field key/find_by_terms_and_value pointer" do
90
90
  expected_result = {"person_0_role"=>["the role"]}
91
- @article.update_values( { [{":person"=>"0"}, "role"]=>"the role" }).should == expected_result
92
- @article.update_values( { [{"person"=>"0"}, "role"]=>"the role" }).should == expected_result
93
- @article.update_values( { [{:person=>0}, :role]=>"the role" }).should == expected_result
91
+ expect(@article.update_values( { [{":person"=>"0"}, "role"]=>"the role" })).to eq expected_result
92
+ expect(@article.update_values( { [{"person"=>"0"}, "role"]=>"the role" })).to eq expected_result
93
+ expect(@article.update_values( { [{:person=>0}, :role]=>"the role" })).to eq expected_result
94
94
  end
95
95
 
96
96
  it "should replace stuff with the same value (in this case 'one')" do
97
97
  @article.update_values( { [{:person=>0}, :role]=>["one"] })
98
98
  @article.update_values( { [{:person=>0}, :role]=>["one", "two"] })
99
- @article.term_values( {:person=>0}, :role).should == ["one", "two"]
99
+ expect(@article.term_values( {:person=>0}, :role)).to eq ["one", "two"]
100
100
  end
101
-
101
+
102
102
  it "should traverse named term proxies transparently" do
103
- @article.term_values( :journal, :issue, :start_page).should_not == ["108"]
103
+ expect(@article.term_values( :journal, :issue, :start_page)).not_to eq ["108"]
104
104
  @article.update_values( { ["journal", "issue", "start_page"]=>"108" } )
105
- @article.term_values( :journal, :issue, :start_page).should == ["108"]
106
- @article.term_values( :journal, :issue, :pages, :start).should == ["108"]
105
+ expect(@article.term_values( :journal, :issue, :start_page)).to eq ["108"]
106
+ expect(@article.term_values( :journal, :issue, :pages, :start)).to eq ["108"]
107
107
  end
108
-
108
+
109
109
  it "should create the necessary ancestor nodes when necessary" do
110
- @sample.find_by_terms(:person).length.should == 4
111
- @sample.update_values([{:person=>8}, :role, :text]=>"my role")
110
+ expect(@sample.find_by_terms(:person).length).to eq(4)
111
+ @sample.update_values([{:person=>8}, :role, :text]=>"my role")
112
112
  person_entries = @sample.find_by_terms(:person)
113
- person_entries.length.should == 5
114
- person_entries[4].search("./ns3:role").first.text.should == "my role"
115
- end
116
-
113
+ expect(person_entries.length).to eq 5
114
+ expect(person_entries[4].search("./ns3:role").first.text).to eq "my role"
115
+ end
116
+
117
117
  it "should create deep trees of ancestor nodes" do
118
118
  result = @article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>"434" })
119
- @article.find_by_terms({:journal=>0}, :issue).length.should == 2
120
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length.should == 1
121
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length.should == 1
122
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text.should == "434"
119
+ expect(@article.find_by_terms({:journal=>0}, :issue).length).to eq 2
120
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length).to eq 1
121
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length).to eq 1
122
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text).to eq "434"
123
123
  #Last argument is a filter, we must explicitly pass no filter
124
- @article.class.terminology.xpath_with_indexes(:subject, {:topic=>1}, {}).should == '//oxns:subject/oxns:topic[2]'
125
- @article.find_by_terms(:subject, {:topic => 1}, {}).text.should == "TOPIC 2"
126
- end
127
-
128
- it "should accommodate appending term values with apostrophes in them" do
129
- @article.find_by_terms(:person, :description).should be_empty # making sure that there's no description node -- forces a value_append
124
+ expect(@article.class.terminology.xpath_with_indexes(:subject, {:topic=>1}, {})).to eq '//oxns:subject/oxns:topic[2]'
125
+ expect(@article.find_by_terms(:subject, {:topic => 1}, {}).text).to eq "TOPIC 2"
126
+ end
127
+
128
+ it "should accommodate appending term values with apostrophes in them" do
129
+ expect(@article.find_by_terms(:person, :description)).to be_empty # making sure that there's no description node -- forces a value_append
130
130
  terms_update_hash = {[:person, :description]=>" 'phrul gyi lde mig"}
131
131
  result = @article.update_values(terms_update_hash)
132
- @article.term_values(:person, :description).should include(" 'phrul gyi lde mig")
132
+ expect(@article.term_values(:person, :description)).to include(" 'phrul gyi lde mig")
133
133
  end
134
-
134
+
135
135
  it "should support inserting nodes with namespaced attributes" do
136
136
  @sample.update_values({['title_info', 'french_title']=>'Le Titre'})
137
- @sample.term_values('title_info', 'french_title').should == ['Le Titre']
137
+ expect(@sample.term_values('title_info', 'french_title')).to eq ['Le Titre']
138
138
  end
139
139
 
140
140
  it "should support inserting attributes" do
141
141
  skip "HYDRA-415"
142
142
  @sample.update_values({['title_info', 'language']=>'Le Titre'})
143
- @sample.term_values('title_info', 'french_title').should == ['Le Titre']
143
+ expect(@sample.term_values('title_info', 'french_title')).to eq ['Le Titre']
144
144
  end
145
-
145
+
146
146
  it "should support inserting namespaced attributes" do
147
147
  skip "HYDRA-415"
148
148
  @sample.update_values({['title_info', 'main_title', 'main_title_lang']=>'eng'})
149
- @sample.term_values('title_info', 'main_title', 'main_title_lang').should == ['eng']
149
+ expect(@sample.term_values('title_info', 'main_title', 'main_title_lang')).to eq ['eng']
150
150
  ## After a proxy
151
- @article.term_values(:title,:main_title_lang).should == ['eng']
151
+ expect(@article.term_values(:title,:main_title_lang)).to eq ['eng']
152
152
  end
153
-
153
+
154
154
  ### Examples copied over form nokogiri_datastream_spec
155
-
155
+
156
156
  it "should apply submitted hash to corresponding datastream field values" do
157
157
  result = @article.update_values( {[{":person"=>"0"}, "first_name"]=>["Billy", "Bob", "Joe"] })
158
- result.should == {"person_0_first_name"=>["Billy", "Bob", "Joe"]}
158
+ expect(result).to eq({"person_0_first_name"=>["Billy", "Bob", "Joe"]})
159
159
  # xpath = ds.class.xpath_with_indexes(*field_key)
160
160
  # result = ds.term_values(xpath)
161
- @article.term_values({:person=>0}, :first_name).should == ["Billy","Bob","Joe"]
162
- @article.term_values('//oxns:name[@type="personal"][1]/oxns:namePart[@type="given"]').should == ["Billy","Bob","Joe"]
161
+ expect(@article.term_values({:person=>0}, :first_name)).to eq ["Billy","Bob","Joe"]
162
+ expect(@article.term_values('//oxns:name[@type="personal"][1]/oxns:namePart[@type="given"]')).to eq ["Billy","Bob","Joe"]
163
163
  end
164
164
  it "should support single-value arguments (as opposed to a hash of values with array indexes as keys)" do
165
165
  # In other words, { [:journal, :title_info]=>"dork" } should have the same effect as { [:journal, :title_info]=>{"0"=>"dork"} }
166
166
  result = @article.update_values( { [{":person"=>"0"}, "role"]=>"the role" } )
167
- result.should == {"person_0_role"=>["the role"]}
168
- @article.term_values({:person=>0}, :role).first.should == "the role"
169
- @article.term_values('//oxns:name[@type="personal"][1]/oxns:role').first.should == "the role"
167
+ expect(result).to eq({"person_0_role"=>["the role"]})
168
+ expect(@article.term_values({:person=>0}, :role).first).to eq "the role"
169
+ expect(@article.term_values('//oxns:name[@type="personal"][1]/oxns:role').first).to eq "the role"
170
170
  end
171
171
  it "should do nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!" do
172
172
  xml_before = @article.to_xml
173
- @article.update_values( { "fubar"=>"the role" } ).should == {}
174
- @article.to_xml.should == xml_before
173
+ expect(@article.update_values( { "fubar"=>"the role" } )).to eq({})
174
+ expect(@article.to_xml).to eq xml_before
175
175
  end
176
176
  it "should do nothing if there is no term corresponding to the given field key" do
177
177
  xml_before = @article.to_xml
178
- @article.update_values( { [{"fubar"=>"0"}]=>"the role" } ).should == {}
179
- @article.to_xml.should == xml_before
178
+ expect(@article.update_values( { [{"fubar"=>"0"}]=>"the role" } )).to eq({})
179
+ expect(@article.to_xml).to eq xml_before
180
180
  end
181
-
182
- it "should work for text fields" do
181
+
182
+ it "should work for text fields" do
183
183
  att= {[{"person"=>"0"},"description"]=>["mork", "york"]}
184
184
  result = @article.update_values(att)
185
- result.should == {"person_0_description"=>["mork", "york"]}
186
- @article.term_values({:person=>0},:description).should == ['mork', 'york']
185
+ expect(result).to eq({"person_0_description"=>["mork", "york"]})
186
+ expect(@article.term_values({:person=>0},:description)).to eq ['mork', 'york']
187
187
  att= {[{"person"=>"0"},{"description" => 2}]=>"dork"}
188
188
  result2 = @article.update_values(att)
189
- result2.should == {"person_0_description_2"=>["dork"]}
190
- @article.term_values({:person=>0},:description).should == ['mork', 'york', 'dork']
189
+ expect(result2).to eq({"person_0_description_2"=>["dork"]})
190
+ expect(@article.term_values({:person=>0},:description)).to eq ['mork', 'york', 'dork']
191
191
  end
192
-
192
+
193
193
  it "should append nodes at the specified index if possible" do
194
194
  @article.update_values([:journal, :title_info]=>["all", "for", "the"])
195
195
  att = {[:journal, {:title_info => 3}]=>'glory'}
196
196
  result = @article.update_values(att)
197
- result.should == {"journal_title_info_3"=>["glory"]}
198
- @article.term_values(:journal, :title_info).should == ["all", "for", "the", "glory"]
197
+ expect(result).to eq({"journal_title_info_3"=>["glory"]})
198
+ expect(@article.term_values(:journal, :title_info)).to eq ["all", "for", "the", "glory"]
199
199
  end
200
200
 
201
201
  it "should remove extra nodes if fewer are given than currently exist" do
202
202
  @article.update_values([:journal, :title_info]=>%W(one two three four five))
203
203
  result = @article.update_values({[:journal, :title_info]=>["six", "seven"]})
204
- @article.term_values(:journal, :title_info).should == ["six", "seven"]
204
+ expect((@article.term_values(:journal, :title_info))).to eq ["six", "seven"]
205
205
  end
206
-
206
+
207
207
  it "should append values to the end of the array if the specified index is higher than the length of the values array" do
208
208
  att = {[:journal, :issue, :pages, {:end => 3}]=>'108'}
209
- @article.term_values(:journal, :issue, :pages, :end).should == []
209
+ expect(@article.term_values(:journal, :issue, :pages, :end)).to eq []
210
210
  result = @article.update_values(att)
211
- result.should == {"journal_issue_pages_end_3"=>["108"]}
212
- @article.term_values(:journal, :issue, :pages, :end).should == ["108"]
211
+ expect(result).to eq({"journal_issue_pages_end_3"=>["108"]})
212
+ expect(@article.term_values(:journal, :issue, :pages, :end)).to eq ["108"]
213
213
  end
214
-
214
+
215
215
  it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
216
216
  att= {[:journal, :title_info]=>["york", "mangle","mork"]}
217
217
  @article.update_values(att)
218
- @article.term_values(:journal, :title_info).should == ['york', 'mangle', 'mork']
219
-
218
+ expect(@article.term_values(:journal, :title_info)).to eq ['york', 'mangle', 'mork']
219
+
220
220
  @article.update_values({[:journal, {:title_info => 1}]=>nil})
221
- @article.term_values(:journal, :title_info).should == ['york', 'mork']
222
-
221
+ expect(@article.term_values(:journal, :title_info)).to eq ['york', 'mork']
222
+
223
223
  @article.update_values({[:journal, {:title_info => 0}]=>:delete})
224
- @article.term_values(:journal, :title_info).should == ['mork']
224
+ expect(@article.term_values(:journal, :title_info)).to eq ['mork']
225
225
  end
226
226
 
227
227
  describe "delete_on_update?" do
@@ -229,45 +229,34 @@ describe "OM::XML::TermValueOperators" do
229
229
  before(:each) do
230
230
  att= {[:journal, :title_info]=>["york", "mangle","mork"]}
231
231
  @article.update_values(att)
232
- @article.term_values(:journal, :title_info).should == ['york', 'mangle', 'mork']
232
+ expect(@article.term_values(:journal, :title_info)).to eq ['york', 'mangle', 'mork']
233
233
  end
234
234
 
235
235
  it "by default, setting to nil deletes the node" do
236
236
  @article.update_values({[:journal, {:title_info => 1}]=>nil})
237
- @article.term_values(:journal, :title_info).should == ['york', 'mork']
237
+ expect(@article.term_values(:journal, :title_info)).to eq ['york', 'mork']
238
238
  end
239
239
 
240
240
  it "if delete_on_update? returns false, setting to nil won't delete node" do
241
- @article.stub('delete_on_update?').and_return(false)
241
+ allow(@article).to receive('delete_on_update?').and_return(false)
242
242
  @article.update_values({[:journal, {:title_info => 1}]=>""})
243
- @article.term_values(:journal, :title_info).should == ['york', '', 'mork']
243
+ expect(@article.term_values(:journal, :title_info)).to eq ['york', '', 'mork']
244
244
  end
245
245
 
246
246
  end
247
247
 
248
248
  it "should retain other child nodes when updating a text content term and shoud not append an additional text node but update text in place" do
249
- @article.term_values(:name,:name_content).should == ["Describes a person"]
249
+ expect(@article.term_values(:name,:name_content)).to eq ["Describes a person"]
250
250
  @article.update_values({[:name, :name_content]=>"Test text"})
251
- @article.term_values(:name,:name_content).should == ["Test text"]
252
- @article.find_by_terms(:name).children.length().should == 35
251
+ expect(@article.term_values(:name,:name_content)).to eq ["Test text"]
252
+ expect(@article.find_by_terms(:name).children.length()).to eq 35
253
253
  end
254
-
254
+
255
255
  end
256
-
256
+
257
257
  describe ".term_values_append" do
258
-
259
- it "looks up the parent using :parent_select, uses :parent_index to choose the parent node from the result set, uses :template to build the node(s) to be inserted, inserts the :values(s) into the node(s) and adds the node(s) to the parent" do
260
- @sample.term_values_append(
261
- :parent_select => [:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}] ,
262
- :parent_index => :first,
263
- :template => [:person, :affiliation],
264
- :values => ["my new value", "another new value"]
265
- )
266
- end
267
-
268
- it "should accept parent_select and template [term_reference, find_by_terms_and_value_opts] as argument arrays for generators/find_by_terms_and_values" do
269
- # this appends two affiliation nodes into the first person node whose name is Tim Berners-Lee
270
- expected_result = '<ns3:name type="personal">
258
+ before :each do
259
+ @expected_result = '<ns3:name type="personal">
271
260
  <ns3:namePart type="family">Berners-Lee</ns3:namePart>
272
261
  <ns3:namePart type="given">Tim</ns3:namePart>
273
262
  <ns3:role>
@@ -275,119 +264,130 @@ describe "OM::XML::TermValueOperators" do
275
264
  <ns3:roleTerm type="code" authority="marcrelator">cre</ns3:roleTerm>
276
265
  </ns3:role>
277
266
  <ns3:affiliation>my new value</ns3:affiliation><ns3:affiliation>another new value</ns3:affiliation></ns3:name>'
278
-
279
- @sample.term_values_append(
267
+ end
268
+
269
+ it "looks up the parent using :parent_select, uses :parent_index to choose the parent node from the result set, uses :template to build the node(s) to be inserted, inserts the :values(s) into the node(s) and adds the node(s) to the parent" do
270
+ @sample.term_values_append(
280
271
  :parent_select => [:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}] ,
281
272
  :parent_index => :first,
282
273
  :template => [:person, :affiliation],
283
- :values => ["my new value", "another new value"]
284
- ).to_xml.should == expected_result
285
-
286
- @sample.find_by_terms(:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}).first.to_xml.should == expected_result
274
+ :values => ["my new value", "another new value"]
275
+ )
276
+ end
277
+
278
+ it "should accept parent_select and template [term_reference, find_by_terms_and_value_opts] as argument arrays for generators/find_by_terms_and_values" do
279
+ # this appends two affiliation nodes into the first person node whose name is Tim Berners-Lee
280
+ expect(@sample.term_values_append(
281
+ :parent_select => [:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}] ,
282
+ :parent_index => :first,
283
+ :template => [:person, :affiliation],
284
+ :values => ["my new value", "another new value"]
285
+ ).to_xml).to eq(@expected_result)
286
+
287
+ expect(@sample.find_by_terms(:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}).first.to_xml).to eq(@expected_result)
287
288
  end
288
-
289
+
289
290
  it "should support adding attribute values" do
290
291
  pointer = [{:title_info=>0}, :language]
291
292
  test_val = "language value"
292
- @article.term_values_append(
293
+ @article.term_values_append(
293
294
  :parent_select => [{:title_info=>0}],
294
295
  :parent_index => 0,
295
296
  :template => [{:title_info=>0}, :language],
296
297
  :values => test_val
297
298
  )
298
- @article.term_values(*pointer).first.should == test_val
299
+ expect(@article.term_values(*pointer).first).to eq(test_val)
299
300
  end
300
-
301
+
301
302
  it "should accept symbols as arguments for generators/find_by_terms_and_values" do
302
303
  # this appends a role of "my role" into the third "person" node in the document
303
304
  @sample.term_values_append(
304
- :parent_select => :person ,
305
+ :parent_select => :person,
305
306
  :parent_index => 3,
306
307
  :template => :role,
307
- :values => "my role"
308
- ).to_xml.should #== expected_result
309
- @sample.find_by_terms(:person)[3].search("./ns3:role[3]").first.text.should == "my role"
308
+ :values => "my role"
309
+ )
310
+ expect(@sample.find_by_terms(:person)[3].search("./ns3:role[3]").first.text).to eq("my role")
310
311
  end
311
-
312
+
312
313
  it "should accept parent_select as an (xpath) string and template as a (template) string" do
313
314
  # this uses the provided template to add a node into the first node resulting from the xpath '//oxns:name[@type="personal"]'
314
315
  expected_result = "<ns3:name type=\"personal\">\n <ns3:namePart type=\"family\">Berners-Lee</ns3:namePart>\n <ns3:namePart type=\"given\">Tim</ns3:namePart>\n <ns3:role>\n <ns3:roleTerm type=\"text\" authority=\"marcrelator\">creator</ns3:roleTerm>\n <ns3:roleTerm type=\"code\" authority=\"marcrelator\">cre</ns3:roleTerm>\n </ns3:role>\n <ns3:role type=\"code\" authority=\"marcrelator\"><ns3:roleTerm>creator</ns3:roleTerm></ns3:role></ns3:name>"
315
-
316
- @sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length.should == 1
317
-
316
+
317
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length).to eq(1)
318
+
318
319
  @sample.term_values_append(
319
320
  :parent_select =>'//oxns:name[@type="personal"]',
320
321
  :parent_index => 0,
321
322
  :template => 'xml.role { xml.roleTerm( \'#{builder_new_value}\', :type=>\'code\', :authority=>\'marcrelator\') }',
322
- :values => "founder"
323
+ :values => "founder"
323
324
  )
324
325
 
325
- @sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length.should == 2
326
- @sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role[last()]/oxns:roleTerm', @sample.ox_namespaces).first.text.should == "founder"
326
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length).to eq(2)
327
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role[last()]/oxns:roleTerm', @sample.ox_namespaces).first.text).to eq("founder")
327
328
 
328
329
  # @sample.find_by_terms_and_value(:person).first.to_xml.should == expected_result
329
330
  end
330
-
331
- it "should support more complex mixing & matching" do
332
- skip "not working because builder_template is not returning the correct template (returns builder for role instead of roleTerm)"
333
- @sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length.should == 2
334
- @sample.term_values_append(
331
+
332
+ it "should support more complex mixing & matching" do
333
+ skip "not working because builder_template is not returning the correct template (returns builder for role instead of roleTerm)"
334
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length).to eq(2)
335
+ @sample.term_values_append(
335
336
  :parent_select =>'//oxns:name[@type="personal"][2]/oxns:role',
336
337
  :parent_index => 0,
337
338
  :template => [ :person, :role, :text, {:attributes=>{"authority"=>"marcrelator"}} ],
338
- :values => "foo"
339
+ :values => "foo"
339
340
  )
340
341
 
341
- @sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length.should == 3
342
- @sample.find_by_terms({:person=>1},:role)[0].search("./oxns:roleTerm[@type=\"text\" and @authority=\"marcrelator\"]", @sample.ox_namespaces).first.text.should == "foo"
343
- end
344
-
345
- it "should create the necessary ancestor nodes when you insert a new term value" do
346
- @sample.find_by_terms(:person).length.should == 4
347
- @sample.term_values_append(
348
- :parent_select => :person ,
342
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length).to eq(3)
343
+ expect(@sample.find_by_terms({:person=>1},:role)[0].search("./oxns:roleTerm[@type=\"text\" and @authority=\"marcrelator\"]", @sample.ox_namespaces).first.text).to eq("foo")
344
+ end
345
+
346
+ it "should create the necessary ancestor nodes when you insert a new term value" do
347
+ expect(@sample.find_by_terms(:person).length).to eq(4)
348
+ @sample.term_values_append(
349
+ :parent_select => :person,
349
350
  :parent_index => 8,
350
351
  :template => :role,
351
- :values => "my role"
352
+ :values => "my role"
352
353
  )
353
354
  person_entries = @sample.find_by_terms(:person)
354
- person_entries.length.should == 5
355
- person_entries[4].search("./ns3:role").first.text.should == "my role"
356
- end
357
-
358
- it "should create the necessary ancestor nodes for deep trees of ancestors" do
359
- deep_pointer = [{:journal=>0}, {:issue=>3}, :pages, :start]
360
- @article.find_by_terms({:journal=>0}).length.should == 1
361
- @article.find_by_terms({:journal=>0}, :issue).length.should == 1
362
- @article.term_values_append(
355
+ expect(person_entries.length).to eq(5)
356
+ expect(person_entries[4].search("./ns3:role").first.text).to eq("my role")
357
+ end
358
+
359
+ it "should create the necessary ancestor nodes for deep trees of ancestors" do
360
+ deep_pointer = [{:journal=>0}, {:issue=>3}, :pages, :start]
361
+ expect(@article.find_by_terms({:journal=>0}).length).to eq(1)
362
+ expect(@article.find_by_terms({:journal=>0}, :issue).length).to eq(1)
363
+ @article.term_values_append(
363
364
  :parent_select => deep_pointer[0..deep_pointer.length-2] ,
364
365
  :parent_index => 0,
365
366
  :template => deep_pointer,
366
- :values => "451"
367
+ :values => "451"
367
368
  )
368
- @article.find_by_terms({:journal=>0}, :issue).length.should == 2
369
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length.should == 1
370
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length.should == 1
371
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text.should == "451"
372
-
373
- end
374
-
369
+ expect(@article.find_by_terms({:journal=>0}, :issue).length).to eq(2)
370
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length).to eq(1)
371
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length).to eq(1)
372
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text).to eq("451")
373
+
374
+ end
375
375
  end
376
-
376
+
377
377
  describe ".term_value_update" do
378
-
378
+
379
379
  it "should accept an xpath as :parent_select" do
380
- sample_xpath = '//oxns:name[@type="personal"][4]/oxns:role/oxns:roleTerm[@type="text"]'
381
- @sample.term_value_update(sample_xpath,1,"artist")
382
- @sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces)[1].text.should == "artist"
380
+ sample_xpath = '//oxns:name[@type="personal"][4]/oxns:role/oxns:roleTerm[@type="text"]'
381
+ @sample.term_value_update(sample_xpath,1,"artist")
382
+ expect(@sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces)[1].text).to eq("artist")
383
383
  end
384
-
384
+
385
385
  it "if :select is provided, should update the first node provided by that xpath statement" do
386
386
  sample_xpath = '//oxns:name[@type="personal"][1]/oxns:namePart[@type="given"]'
387
387
  @sample.term_value_update(sample_xpath,0,"Timmeh")
388
- @sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces).first.text.should == "Timmeh"
388
+ expect(@sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces).first.text).to eq("Timmeh")
389
389
  end
390
-
390
+
391
391
  it "should replace the existing node if you pass a template and values" do
392
392
  skip
393
393
  @sample.term_value_update(
@@ -396,72 +396,72 @@ describe "OM::XML::TermValueOperators" do
396
396
  :template => [ :person, :role, {:attributes=>{"type"=>"code", "authority"=>"marcrelator"}} ],
397
397
  :value => "foo"
398
398
  )
399
- 1.should == 2
399
+ expect(1).to eq(2)
400
400
  end
401
401
  it "should delete nodes if value is :delete or nil" do
402
402
  @article.update_values([:title_info]=>["york", "mangle","mork"])
403
403
  xpath = @article.class.terminology.xpath_for(:title_info)
404
-
404
+
405
405
  @article.term_value_update([:title_info], 1, nil)
406
- @article.term_values(:title_info).should == ['york', 'mork']
407
-
406
+ expect(@article.term_values(:title_info)).to eq(['york', 'mork'])
407
+
408
408
  @article.term_value_update([:title_info], 1, :delete)
409
- @article.term_values(:title_info).should == ['york']
409
+ expect(@article.term_values(:title_info)).to eq(['york'])
410
410
  end
411
411
  it "should create empty nodes if value is empty string" do
412
412
  @article.update_values([:title_info]=>["york", '', "mork"])
413
- @article.term_values(:title_info).should == ['york', "", "mork"]
413
+ expect(@article.term_values(:title_info)).to eq(['york', "", "mork"])
414
414
  end
415
415
  end
416
-
416
+
417
417
  describe ".term_value_delete" do
418
418
  it "should accept an xpath query as :select option" do
419
- generic_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role'
419
+ generic_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role'
420
420
  specific_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[oxns:roleTerm="visionary"]'
421
- select_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[last()]'
422
-
421
+ select_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[last()]'
422
+
423
423
  # Check that we're starting with 2 roles
424
424
  # Check that the specific node we want to delete exists
425
- @sample.find_by_terms_and_value(generic_xpath).length.should == 2
426
- @sample.find_by_terms_and_value(specific_xpath).length.should == 1
425
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(2)
426
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(1)
427
427
 
428
428
  @sample.term_value_delete(
429
429
  :select =>select_xpath
430
430
  )
431
431
  # Check that we're finishing with 1 role
432
- @sample.find_by_terms_and_value(generic_xpath).length.should == 1
432
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(1)
433
433
  # Check that the specific node we want to delete no longer exists
434
- @sample.find_by_terms_and_value(specific_xpath).length.should == 0
435
- end
434
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(0)
435
+ end
436
436
  it "should accept :parent_select, :parent_index and :parent_index options instead of a :select" do
437
-
437
+
438
438
  generic_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role/oxns:roleTerm'
439
439
  specific_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[oxns:roleTerm="visionary"]'
440
-
440
+
441
441
  # Check that we're starting with 2 roles
442
442
  # Check that the specific node we want to delete exists
443
- @sample.find_by_terms_and_value(generic_xpath).length.should == 4
444
- @sample.find_by_terms_and_value(specific_xpath).length.should == 1
443
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(4)
444
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(1)
445
445
 
446
- # this is attempting to delete the last child (in this case roleTerm) from the 3rd role in the document.
446
+ # this is attempting to delete the last child (in this case roleTerm) from the 3rd role in the document.
447
447
  @sample.term_value_delete(
448
448
  :parent_select => [:person, :role],
449
449
  :parent_index => 3,
450
450
  :child_index => :last
451
451
  )
452
-
452
+
453
453
  # Check that we're finishing with 1 role
454
- @sample.find_by_terms_and_value(generic_xpath).length.should == 3
454
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(3)
455
455
  # Check that the specific node we want to delete no longer exists
456
- @sample.find_by_terms_and_value(specific_xpath).length.should == 1
456
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(1)
457
457
  end
458
458
  it "should work if only :parent_select and :parent_index are provided" do
459
459
  generic_xpath = '//oxns:name[@type="personal"]/oxns:role'
460
460
  # specific_xpath = '//oxns:name[@type="personal"]/oxns:role'
461
-
461
+
462
462
  # Check that we're starting with 2 roles
463
463
  # Check that the specific node we want to delete exists
464
- @sample.find_by_terms_and_value(generic_xpath).length.should == 4
464
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(4)
465
465
  # @sample.find_by_terms_and_value(specific_xpath).length.should == 1
466
466
 
467
467
  @sample.term_value_delete(
@@ -469,14 +469,14 @@ describe "OM::XML::TermValueOperators" do
469
469
  :child_index => 3
470
470
  )
471
471
  # Check that we're finishing with 1 role
472
- @sample.find_by_terms_and_value(generic_xpath).length.should == 3
472
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(3)
473
473
  end
474
474
  end
475
-
475
+
476
476
  describe "build_ancestors" do
477
477
  it "should raise an error if it cant find a starting point for building from" do
478
- lambda { @empty_sample.build_ancestors( [:journal, :issue], 0) }.should raise_error(OM::XML::TemplateMissingException, "Cannot insert nodes into the document because it is empty. Try defining self.xml_template on the OM::Samples::ModsArticle class.")
478
+ expect { @empty_sample.build_ancestors( [:journal, :issue], 0) }.to raise_error(OM::XML::TemplateMissingException, "Cannot insert nodes into the document because it is empty. Try defining self.xml_template on the OM::Samples::ModsArticle class.")
479
479
  end
480
480
  end
481
-
481
+
482
482
  end