om 1.8.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/.rubocop.yml +1 -0
  4. data/.rubocop_todo.yml +382 -0
  5. data/.travis.yml +10 -0
  6. data/Rakefile +1 -1
  7. data/container_spec.rb +14 -14
  8. data/gemfiles/gemfile.rails3 +11 -0
  9. data/gemfiles/gemfile.rails4 +10 -0
  10. data/lib/om.rb +9 -12
  11. data/lib/om/samples/mods_article.rb +9 -9
  12. data/lib/om/tree_node.rb +6 -6
  13. data/lib/om/version.rb +1 -1
  14. data/lib/om/xml.rb +18 -20
  15. data/lib/om/xml/container.rb +12 -12
  16. data/lib/om/xml/document.rb +3 -7
  17. data/lib/om/xml/dynamic_node.rb +45 -50
  18. data/lib/om/xml/named_term_proxy.rb +13 -13
  19. data/lib/om/xml/node_generator.rb +3 -3
  20. data/lib/om/xml/template_registry.rb +18 -26
  21. data/lib/om/xml/term.rb +30 -46
  22. data/lib/om/xml/term_value_operators.rb +52 -56
  23. data/lib/om/xml/term_xpath_generator.rb +51 -57
  24. data/lib/om/xml/terminology.rb +8 -10
  25. data/lib/om/xml/validation.rb +19 -19
  26. data/lib/om/xml/vocabulary.rb +4 -4
  27. data/lib/tasks/om.rake +4 -6
  28. data/om.gemspec +1 -2
  29. data/spec/integration/differentiated_elements_spec.rb +2 -2
  30. data/spec/integration/element_value_spec.rb +13 -13
  31. data/spec/integration/proxies_and_ref_spec.rb +15 -15
  32. data/spec/integration/querying_documents_spec.rb +24 -18
  33. data/spec/integration/rights_metadata_integration_example_spec.rb +18 -18
  34. data/spec/integration/selective_querying_spec.rb +1 -1
  35. data/spec/integration/serialization_spec.rb +13 -13
  36. data/spec/integration/set_reentrant_terminology_spec.rb +7 -7
  37. data/spec/integration/xpathy_stuff_spec.rb +16 -16
  38. data/spec/spec_helper.rb +2 -3
  39. data/spec/unit/container_spec.rb +28 -29
  40. data/spec/unit/document_spec.rb +49 -50
  41. data/spec/unit/dynamic_node_spec.rb +55 -47
  42. data/spec/unit/named_term_proxy_spec.rb +16 -16
  43. data/spec/unit/node_generator_spec.rb +7 -7
  44. data/spec/unit/nokogiri_sanity_spec.rb +30 -30
  45. data/spec/unit/om_spec.rb +5 -5
  46. data/spec/unit/template_registry_spec.rb +69 -69
  47. data/spec/unit/term_builder_spec.rb +77 -77
  48. data/spec/unit/term_spec.rb +78 -72
  49. data/spec/unit/term_value_operators_spec.rb +186 -191
  50. data/spec/unit/term_xpath_generator_spec.rb +37 -43
  51. data/spec/unit/terminology_builder_spec.rb +85 -85
  52. data/spec/unit/terminology_spec.rb +98 -98
  53. data/spec/unit/validation_spec.rb +22 -22
  54. data/spec/unit/xml_serialization_spec.rb +21 -22
  55. data/spec/unit/xml_spec.rb +7 -7
  56. metadata +143 -147
@@ -1,55 +1,55 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "OM::XML::TermValueOperators" do
4
-
4
+
5
5
  before(:each) do
6
- @sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
7
- @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
8
- @empty_sample = OM::Samples::ModsArticle.from_xml("")
6
+ @sample = OM::Samples::ModsArticle.from_xml( fixture( File.join("test_dummy_mods.xml") ) )
7
+ @article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
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 ignore whitespace elements for a term pointing to a text() node for an element that contains children" do
21
- @article.term_values(:name, :name_content).should == ["Describes a person"]
21
+ expect(@article.term_values(:name, :name_content)).to eq(["Describes a person"])
22
22
  end
23
-
23
+
24
24
  end
25
-
26
-
25
+
26
+
27
27
  describe ".update_values" do
28
28
  it "should update the xml according to the find_by_terms_and_values in the given hash" do
29
29
  terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2".freeze, "2"=>"affiliation3"}, [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
30
30
  result = @article.update_values(terms_update_hash)
31
- result.should == {"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}, "person_1_last_name"=>{"0"=>"Andronicus"},"person_1_first_name"=>{"0"=>"Titus"}, "person_1_role"=>{"0"=>"otherrole1","1"=>"otherrole2"}}
31
+ expect(result).to eq({"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}, "person_1_last_name"=>{"0"=>"Andronicus"},"person_1_first_name"=>{"0"=>"Titus"}, "person_1_role"=>{"0"=>"otherrole1","1"=>"otherrole2"}})
32
32
  person_0_affiliation = @article.find_by_terms({:person=>0}, :affiliation)
33
- person_0_affiliation[0].text.should == "affiliation1"
34
- person_0_affiliation[1].text.should == "affiliation2"
35
- person_0_affiliation[2].text.should == "affiliation3"
36
-
33
+ expect(person_0_affiliation[0].text).to eq("affiliation1")
34
+ expect(person_0_affiliation[1].text).to eq("affiliation2")
35
+ expect(person_0_affiliation[2].text).to eq("affiliation3")
36
+
37
37
  person_1_last_names = @article.find_by_terms({:person=>1}, :last_name)
38
- person_1_last_names.length.should == 1
39
- person_1_last_names.first.text.should == "Andronicus"
40
-
38
+ expect(person_1_last_names.length).to eq(1)
39
+ expect(person_1_last_names.first.text).to eq("Andronicus")
40
+
41
41
  person_1_first_names = @article.find_by_terms({:person=>1}, :first_name)
42
- person_1_first_names.first.text.should == "Titus"
43
-
42
+ expect(person_1_first_names.first.text).to eq("Titus")
43
+
44
44
  person_1_roles = @article.find_by_terms({:person=>1}, :role)
45
- person_1_roles[0].text.should == "otherrole1"
46
- person_1_roles[1].text.should == "otherrole2"
45
+ expect(person_1_roles[0].text).to eq("otherrole1")
46
+ expect(person_1_roles[1].text).to eq("otherrole2")
47
47
  end
48
48
  it "should call term_value_update if the corresponding node already exists" do
49
- @article.expects(:term_value_update).with('//oxns:titleInfo/oxns:title', 0, "My New Title")
49
+ expect(@article).to receive(:term_value_update).with('//oxns:titleInfo/oxns:title', 0, "My New Title")
50
50
  @article.update_values( {[:title_info, :main_title] => "My New Title"} )
51
51
  end
52
-
52
+
53
53
  it "should call term_values_append if the corresponding node does not already exist or if the requested index is -1" do
54
54
  expected_args = {
55
55
  # :parent_select => OM::Samples::ModsArticle.terminology.xpath_with_indexes(*[{:person=>0}]) ,
@@ -58,204 +58,200 @@ describe "OM::XML::TermValueOperators" do
58
58
  :template => [:person, :role],
59
59
  :values => "My New Role"
60
60
  }
61
- @article.expects(:term_values_append).with(expected_args).times(2)
61
+ expect(@article).to receive(:term_values_append).with(expected_args).exactly(2).times
62
62
  @article.update_values( {[{:person=>0}, :role] => {"6"=>"My New Role"}} )
63
63
  @article.update_values( {[{:person=>0}, :role] => {"-1"=>"My New Role"}} )
64
64
  end
65
-
65
+
66
66
  it "should support updating attribute values" do
67
67
  pointer = [:title_info, :language]
68
68
  test_val = "language value"
69
69
  @article.update_values( {pointer=>{"0"=>test_val}} )
70
- @article.term_values(*pointer).first.should == test_val
70
+ expect(@article.term_values(*pointer).first).to eq(test_val)
71
71
  end
72
-
72
+
73
73
  it "should not get tripped up on root nodes" do
74
74
  @article.update_values([:title_info]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"})
75
- @article.term_values(*[:title_info]).should == ["york", "mangle", "mork"]
75
+ expect(@article.term_values(*[:title_info])).to eq(["york", "mangle", "mork"])
76
76
  end
77
77
 
78
78
  it "should destringify the field key/find_by_terms_and_value pointer" do
79
- OM::Samples::ModsArticle.terminology.expects(:xpath_with_indexes).with( *[{:person=>0}, :role]).times(10).returns("//oxns:name[@type=\"personal\"][1]/oxns:role")
80
- OM::Samples::ModsArticle.terminology.stubs(:xpath_with_indexes).with( *[{:person=>0}]).returns("//oxns:name[@type=\"personal\"][1]")
79
+ expect(OM::Samples::ModsArticle.terminology).to receive(:xpath_with_indexes).with( *[{:person=>0}, :role]).and_return("//oxns:name[@type=\"personal\"][1]/oxns:role").exactly(10).times
80
+ allow(OM::Samples::ModsArticle.terminology).to receive(:xpath_with_indexes).with( *[{:person=>0}]).and_return("//oxns:name[@type=\"personal\"][1]")
81
81
  @article.update_values( { [{":person"=>"0"}, "role"]=>"the role" } )
82
82
  @article.update_values( { [{"person"=>"0"}, "role"]=>"the role" } )
83
83
  @article.update_values( { [{:person=>0}, :role]=>"the role" } )
84
84
  end
85
-
85
+
86
86
  it "should traverse named term proxies transparently" do
87
- @article.term_values( :journal, :issue, :start_page).should_not == ["108"]
87
+ expect(@article.term_values( :journal, :issue, :start_page)).not_to eq(["108"])
88
88
  @article.update_values( { ["journal", "issue", "start_page"]=>"108" } )
89
- @article.term_values( :journal, :issue, :start_page).should == ["108"]
90
- @article.term_values( :journal, :issue, :pages, :start).should == ["108"]
89
+ expect(@article.term_values( :journal, :issue, :start_page)).to eq(["108"])
90
+ expect(@article.term_values( :journal, :issue, :pages, :start)).to eq(["108"])
91
91
  end
92
-
92
+
93
93
  it "should create the necessary ancestor nodes when necessary" do
94
- @sample.find_by_terms(:person).length.should == 4
94
+ expect(@sample.find_by_terms(:person).length).to eq(4)
95
95
  @sample.update_values([{:person=>8}, :role, :text]=>"my role")
96
96
  person_entries = @sample.find_by_terms(:person)
97
- person_entries.length.should == 5
98
- person_entries[4].search("./ns3:role").first.text.should == "my role"
97
+ expect(person_entries.length).to eq(5)
98
+ expect(person_entries[4].search("./ns3:role").first.text).to eq("my role")
99
99
  end
100
-
100
+
101
101
  it "should create deep trees of ancestor nodes" do
102
102
  result = @article.update_values( {[{:journal=>0}, {:issue=>3}, :pages, :start]=>{"0"=>"434"} })
103
- @article.find_by_terms({:journal=>0}, :issue).length.should == 2
104
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length.should == 1
105
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length.should == 1
106
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text.should == "434"
107
- #Last argument is a filter, we must explicitly pass no filter
108
- @article.class.terminology.xpath_with_indexes(:subject, {:topic=>1}, {}).should == '//oxns:subject/oxns:topic[2]'
109
- @article.find_by_terms(:subject, {:topic => 1}, {}).text.should == "TOPIC 2"
103
+ expect(@article.find_by_terms({:journal=>0}, :issue).length).to eq(2)
104
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length).to eq(1)
105
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length).to eq(1)
106
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text).to eq("434")
107
+ # Last argument is a filter, we must explicitly pass no filter
108
+ expect(@article.class.terminology.xpath_with_indexes(:subject, {:topic=>1}, {})).to eq('//oxns:subject/oxns:topic[2]')
109
+ expect(@article.find_by_terms(:subject, {:topic => 1}, {}).text).to eq("TOPIC 2")
110
110
  end
111
-
111
+
112
112
  it "should accommodate appending term values with apostrophes in them" do
113
- @article.find_by_terms(:person, :description).should be_empty # making sure that there's no description node -- forces a value_append
113
+ expect(@article.find_by_terms(:person, :description)).to be_empty # making sure that there's no description node -- forces a value_append
114
114
  terms_update_hash = {[:person, :description]=>" 'phrul gyi lde mig"}
115
115
  result = @article.update_values(terms_update_hash)
116
- @article.term_values(:person, :description).should include(" 'phrul gyi lde mig")
116
+ expect(@article.term_values(:person, :description)).to include(" 'phrul gyi lde mig")
117
117
  end
118
-
118
+
119
119
  it "should support inserting nodes with namespaced attributes" do
120
120
  @sample.update_values({['title_info', 'french_title']=>'Le Titre'})
121
- @sample.term_values('title_info', 'french_title').should == ['Le Titre']
121
+ expect(@sample.term_values('title_info', 'french_title')).to eq(['Le Titre'])
122
122
  end
123
123
 
124
124
  it "should support inserting attributes" do
125
- pending "HYDRA-415"
125
+ skip "HYDRA-415"
126
126
  @sample.update_values({['title_info', 'language']=>'Le Titre'})
127
- @sample.term_values('title_info', 'french_title').should == ['Le Titre']
127
+ expect(@sample.term_values('title_info', 'french_title')).to eq(['Le Titre'])
128
128
  end
129
-
129
+
130
130
  it "should support inserting namespaced attributes" do
131
- pending "HYDRA-415"
131
+ skip "HYDRA-415"
132
132
  @sample.update_values({['title_info', 'main_title', 'main_title_lang']=>'eng'})
133
- @sample.term_values('title_info', 'main_title', 'main_title_lang').should == ['eng']
133
+ expect(@sample.term_values('title_info', 'main_title', 'main_title_lang')).to eq(['eng'])
134
134
  ## After a proxy
135
- @article.term_values(:title,:main_title_lang).should == ['eng']
135
+ expect(@article.term_values(:title,:main_title_lang)).to eq(['eng'])
136
136
  end
137
-
137
+
138
138
  ### Examples copied over form nokogiri_datastream_spec
139
-
139
+
140
140
  it "should apply submitted hash to corresponding datastream field values" do
141
141
  result = @article.update_values( {[{":person"=>"0"}, "first_name"]=>{"0"=>"Billy", "1"=>"Bob", "2"=>"Joe"} })
142
- result.should == {"person_0_first_name"=>{"0"=>"Billy", "1"=>"Bob", "2"=>"Joe"}}
142
+ expect(result).to eq({"person_0_first_name"=>{"0"=>"Billy", "1"=>"Bob", "2"=>"Joe"}})
143
143
  # xpath = ds.class.xpath_with_indexes(*field_key)
144
144
  # result = ds.term_values(xpath)
145
- @article.term_values({:person=>0}, :first_name).should == ["Billy","Bob","Joe"]
146
- @article.term_values('//oxns:name[@type="personal"][1]/oxns:namePart[@type="given"]').should == ["Billy","Bob","Joe"]
145
+ expect(@article.term_values({:person=>0}, :first_name)).to eq(["Billy","Bob","Joe"])
146
+ expect(@article.term_values('//oxns:name[@type="personal"][1]/oxns:namePart[@type="given"]')).to eq(["Billy","Bob","Joe"])
147
147
  end
148
148
  it "should support single-value arguments (as opposed to a hash of values with array indexes as keys)" do
149
149
  # In other words, { [:journal, :title_info]=>"dork" } should have the same effect as { [:journal, :title_info]=>{"0"=>"dork"} }
150
150
  result = @article.update_values( { [{":person"=>"0"}, "role"]=>"the role" } )
151
- result.should == {"person_0_role"=>{"0"=>"the role"}}
152
- @article.term_values({:person=>0}, :role).first.should == "the role"
153
- @article.term_values('//oxns:name[@type="personal"][1]/oxns:role').first.should == "the role"
151
+ expect(result).to eq({"person_0_role"=>{"0"=>"the role"}})
152
+ expect(@article.term_values({:person=>0}, :role).first).to eq("the role")
153
+ expect(@article.term_values('//oxns:name[@type="personal"][1]/oxns:role').first).to eq("the role")
154
154
  end
155
155
  it "should do nothing if field key is a string (must be an array or symbol). Will not accept xpath queries!" do
156
156
  xml_before = @article.to_xml
157
- @article.update_values( { "fubar"=>"the role" } ).should == {}
158
- @article.to_xml.should == xml_before
157
+ expect(@article.update_values( { "fubar"=>"the role" } )).to eq({})
158
+ expect(@article.to_xml).to eq(xml_before)
159
159
  end
160
160
  it "should do nothing if there is no term corresponding to the given field key" do
161
161
  xml_before = @article.to_xml
162
- @article.update_values( { [{"fubar"=>"0"}]=>"the role" } ).should == {}
163
- @article.to_xml.should == xml_before
162
+ expect(@article.update_values( { [{"fubar"=>"0"}]=>"the role" } )).to eq({})
163
+ expect(@article.to_xml).to eq(xml_before)
164
164
  end
165
-
166
- it "should work for text fields" do
167
- att= {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
165
+
166
+ it "should work for text fields" do
167
+ att = {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
168
168
  result = @article.update_values(att)
169
- result.should == {"person_0_description"=>{"0"=>"mork","1"=>"york"}}
170
- @article.term_values({:person=>0},:description).should == ['mork', 'york']
171
- att= {[{"person"=>"0"},"description"]=>{"-1"=>"dork"}}
169
+ expect(result).to eq({"person_0_description"=>{"0"=>"mork","1"=>"york"}})
170
+ expect(@article.term_values({:person=>0},:description)).to eq(['mork', 'york'])
171
+ att = {[{"person"=>"0"},"description"]=>{"-1"=>"dork"}}
172
172
  result2 = @article.update_values(att)
173
- result2.should == {"person_0_description"=>{"2"=>"dork"}}
174
- @article.term_values({:person=>0},:description).should == ['mork', 'york', 'dork']
173
+ expect(result2).to eq({"person_0_description"=>{"2"=>"dork"}})
174
+ expect(@article.term_values({:person=>0},:description)).to eq(['mork', 'york', 'dork'])
175
175
  end
176
-
176
+
177
177
  it "should return the new index of any added values" do
178
- @article.term_values({:title_info=>0},:main_title).should == ["ARTICLE TITLE HYDRANGEA ARTICLE 1", "TITLE OF HOST JOURNAL"]
178
+ expect(@article.term_values({:title_info=>0},:main_title)).to eq(["ARTICLE TITLE HYDRANGEA ARTICLE 1", "TITLE OF HOST JOURNAL"])
179
179
  result = @article.update_values [{"title_info"=>"0"},"main_title"]=>{"-1"=>"mork"}
180
- result.should == {"title_info_0_main_title"=>{"2"=>"mork"}}
180
+ expect(result).to eq({"title_info_0_main_title"=>{"2"=>"mork"}})
181
181
  end
182
-
182
+
183
183
  it "should return accurate response when multiple values have been added in a single run" do
184
- pending "THIS SHOULD BE FIXED"
184
+ skip "THIS SHOULD BE FIXED"
185
185
  att= {[:journal, :title_info]=>{"-1"=>"mork", "0"=>"york"}}
186
- @article.update_values(att).should == {"journal_title_info"=>{"0"=>"york", "1"=>"mork"}}
187
- @article.term_values(*att.keys.first).should == ["york", "mork"]
186
+ expect(@article.update_values(att)).to eq({"journal_title_info"=>{"0"=>"york", "1"=>"mork"}})
187
+ expect(@article.term_values(*att.keys.first)).to eq(["york", "mork"])
188
188
  end
189
-
189
+
190
190
  it "should append nodes at the specified index if possible" do
191
191
  @article.update_values([:journal, :title_info]=>["all", "for", "the"])
192
192
  att = {[:journal, :title_info]=>{"3"=>'glory'}}
193
193
  result = @article.update_values(att)
194
- result.should == {"journal_title_info"=>{"3"=>"glory"}}
195
- @article.term_values(:journal, :title_info).should == ["all", "for", "the", "glory"]
194
+ expect(result).to eq({"journal_title_info"=>{"3"=>"glory"}})
195
+ expect(@article.term_values(:journal, :title_info)).to eq(["all", "for", "the", "glory"])
196
196
  end
197
-
197
+
198
198
  it "should append values to the end of the array if the specified index is higher than the length of the values array" do
199
199
  att = {[:journal, :issue, :pages, :end]=>{"3"=>'108'}}
200
- @article.term_values(:journal, :issue, :pages, :end).should == []
200
+ expect(@article.term_values(:journal, :issue, :pages, :end)).to eq([])
201
201
  result = @article.update_values(att)
202
- result.should == {"journal_issue_pages_end"=>{"0"=>"108"}}
203
- @article.term_values(:journal, :issue, :pages, :end).should == ["108"]
202
+ expect(result).to eq({"journal_issue_pages_end"=>{"0"=>"108"}})
203
+ expect(@article.term_values(:journal, :issue, :pages, :end)).to eq(["108"])
204
204
  end
205
-
205
+
206
206
  it "should allow deleting of values and should delete values so that to_xml does not return emtpy nodes" do
207
207
  att= {[:journal, :title_info]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"}}
208
208
  @article.update_values(att)
209
- @article.term_values(:journal, :title_info).should == ['york', 'mangle', 'mork']
210
-
209
+ expect(@article.term_values(:journal, :title_info)).to eq(['york', 'mangle', 'mork'])
210
+
211
211
  @article.update_values({[:journal, :title_info]=>{"1"=>""}})
212
- @article.term_values(:journal, :title_info).should == ['york', 'mork']
213
-
212
+ expect(@article.term_values(:journal, :title_info)).to eq(['york', 'mork'])
213
+
214
214
  @article.update_values({[:journal, :title_info]=>{"0"=>:delete}})
215
- @article.term_values(:journal, :title_info).should == ['mork']
215
+ expect(@article.term_values(:journal, :title_info)).to eq(['mork'])
216
216
  end
217
217
 
218
218
  describe "delete_on_update?" do
219
-
220
219
  before(:each) do
221
220
  att= {[:journal, :title_info]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"}}
222
221
  @article.update_values(att)
223
- @article.term_values(:journal, :title_info).should == ['york', 'mangle', 'mork']
222
+ expect(@article.term_values(:journal, :title_info)).to eq(['york', 'mangle', 'mork'])
224
223
  end
225
-
226
224
  it "by default, setting to empty string deletes the node" do
227
225
  @article.update_values({[:journal, :title_info]=>{"1"=>""}})
228
- @article.term_values(:journal, :title_info).should == ['york', 'mork']
226
+ expect(@article.term_values(:journal, :title_info)).to eq(['york', 'mork'])
229
227
  end
230
-
231
228
  it "if delete_on_update? returns false, setting to empty string won't delete node" do
232
- @article.stubs('delete_on_update?').returns(false)
229
+ allow(@article).to receive('delete_on_update?').and_return(false)
233
230
  @article.update_values({[:journal, :title_info]=>{"1"=>""}})
234
- @article.term_values(:journal, :title_info).should == ['york', '', 'mork']
231
+ expect(@article.term_values(:journal, :title_info)).to eq(['york', '', 'mork'])
235
232
  end
236
-
237
233
  end
238
234
 
239
235
  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
240
- @article.term_values(:name,:name_content).should == ["Describes a person"]
236
+ expect(@article.term_values(:name,:name_content)).to eq(["Describes a person"])
241
237
  @article.update_values({[:name, :name_content]=>"Test text"})
242
- @article.term_values(:name,:name_content).should == ["Test text"]
243
- @article.find_by_terms(:name).children.length().should == 35
238
+ expect(@article.term_values(:name,:name_content)).to eq(["Test text"])
239
+ expect(@article.find_by_terms(:name).children.length()).to eq(35)
244
240
  end
245
-
241
+
246
242
  end
247
-
243
+
248
244
  describe ".term_values_append" do
249
-
250
- 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
245
+
246
+ 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
251
247
  @sample.term_values_append(
252
248
  :parent_select => [:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}] ,
253
249
  :parent_index => :first,
254
250
  :template => [:person, :affiliation],
255
- :values => ["my new value", "another new value"]
251
+ :values => ["my new value", "another new value"]
256
252
  )
257
253
  end
258
-
254
+
259
255
  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
260
256
  # this appends two affiliation nodes into the first person node whose name is Tim Berners-Lee
261
257
  expected_result = '<ns3:name type="personal">
@@ -266,193 +262,192 @@ describe "OM::XML::TermValueOperators" do
266
262
  <ns3:roleTerm type="code" authority="marcrelator">cre</ns3:roleTerm>
267
263
  </ns3:role>
268
264
  <ns3:affiliation>my new value</ns3:affiliation><ns3:affiliation>another new value</ns3:affiliation></ns3:name>'
269
-
270
- @sample.term_values_append(
265
+
266
+ expect(@sample.term_values_append(
271
267
  :parent_select => [:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}] ,
272
268
  :parent_index => :first,
273
269
  :template => [:person, :affiliation],
274
- :values => ["my new value", "another new value"]
275
- ).to_xml.should == expected_result
276
-
277
- @sample.find_by_terms(:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}).first.to_xml.should == expected_result
270
+ :values => ["my new value", "another new value"]
271
+ ).to_xml).to eq(expected_result)
272
+
273
+ expect(@sample.find_by_terms(:person, {:first_name=>"Tim", :last_name=>"Berners-Lee"}).first.to_xml).to eq(expected_result)
278
274
  end
279
-
275
+
280
276
  it "should support adding attribute values" do
281
277
  pointer = [{:title_info=>0}, :language]
282
278
  test_val = "language value"
283
- @article.term_values_append(
279
+ @article.term_values_append(
284
280
  :parent_select => [{:title_info=>0}],
285
281
  :parent_index => 0,
286
282
  :template => [{:title_info=>0}, :language],
287
283
  :values => test_val
288
284
  )
289
- @article.term_values(*pointer).first.should == test_val
285
+ expect(@article.term_values(*pointer).first).to eq(test_val)
290
286
  end
291
-
287
+
292
288
  it "should accept symbols as arguments for generators/find_by_terms_and_values" do
293
289
  # this appends a role of "my role" into the third "person" node in the document
294
290
  @sample.term_values_append(
295
291
  :parent_select => :person ,
296
292
  :parent_index => 3,
297
293
  :template => :role,
298
- :values => "my role"
299
- ).to_xml.should #== expected_result
300
- @sample.find_by_terms(:person)[3].search("./ns3:role[3]").first.text.should == "my role"
294
+ :values => "my role"
295
+ )
296
+ expect(@sample.find_by_terms(:person)[3].search("./ns3:role[3]").first.text).to eq("my role")
301
297
  end
302
-
298
+
303
299
  it "should accept parent_select as an (xpath) string and template as a (template) string" do
304
300
  # this uses the provided template to add a node into the first node resulting from the xpath '//oxns:name[@type="personal"]'
305
301
  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>"
306
-
307
- @sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length.should == 1
308
-
302
+
303
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length).to eq(1)
304
+
309
305
  @sample.term_values_append(
310
306
  :parent_select =>'//oxns:name[@type="personal"]',
311
307
  :parent_index => 0,
312
308
  :template => 'xml.role { xml.roleTerm( \'#{builder_new_value}\', :type=>\'code\', :authority=>\'marcrelator\') }',
313
- :values => "founder"
309
+ :values => "founder"
314
310
  )
315
311
 
316
- @sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length.should == 2
317
- @sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role[last()]/oxns:roleTerm', @sample.ox_namespaces).first.text.should == "founder"
312
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal" and position()=1]/oxns:role', @sample.ox_namespaces).length).to eq(2)
313
+ 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")
318
314
 
319
315
  # @sample.find_by_terms_and_value(:person).first.to_xml.should == expected_result
320
316
  end
321
-
317
+
322
318
  it "should support more complex mixing & matching" do
323
- pending "not working because builder_template is not returning the correct template (returns builder for role instead of roleTerm)"
324
- @sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length.should == 2
319
+ skip "not working because builder_template is not returning the correct template (returns builder for role instead of roleTerm)"
320
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length).to eq(2)
325
321
  @sample.term_values_append(
326
322
  :parent_select =>'//oxns:name[@type="personal"][2]/oxns:role',
327
323
  :parent_index => 0,
328
324
  :template => [ :person, :role, :text, {:attributes=>{"authority"=>"marcrelator"}} ],
329
- :values => "foo"
325
+ :values => "foo"
330
326
  )
331
327
 
332
- @sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length.should == 3
333
- @sample.find_by_terms({:person=>1},:role)[0].search("./oxns:roleTerm[@type=\"text\" and @authority=\"marcrelator\"]", @sample.ox_namespaces).first.text.should == "foo"
328
+ expect(@sample.ng_xml.xpath('//oxns:name[@type="personal"][2]/oxns:role[1]/oxns:roleTerm', @sample.ox_namespaces).length).to eq(3)
329
+ 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")
334
330
  end
335
-
331
+
336
332
  it "should create the necessary ancestor nodes when you insert a new term value" do
337
- @sample.find_by_terms(:person).length.should == 4
333
+ expect(@sample.find_by_terms(:person).length).to eq(4)
338
334
  @sample.term_values_append(
339
335
  :parent_select => :person ,
340
336
  :parent_index => 8,
341
337
  :template => :role,
342
- :values => "my role"
338
+ :values => "my role"
343
339
  )
344
340
  person_entries = @sample.find_by_terms(:person)
345
- person_entries.length.should == 5
346
- person_entries[4].search("./ns3:role").first.text.should == "my role"
341
+ expect(person_entries.length).to eq(5)
342
+ expect(person_entries[4].search("./ns3:role").first.text).to eq("my role")
347
343
  end
348
-
344
+
349
345
  it "should create the necessary ancestor nodes for deep trees of ancestors" do
350
346
  deep_pointer = [{:journal=>0}, {:issue=>3}, :pages, :start]
351
- @article.find_by_terms({:journal=>0}).length.should == 1
352
- @article.find_by_terms({:journal=>0}, :issue).length.should == 1
347
+ expect(@article.find_by_terms({:journal=>0}).length).to eq(1)
348
+ expect(@article.find_by_terms({:journal=>0}, :issue).length).to eq(1)
353
349
  @article.term_values_append(
354
350
  :parent_select => deep_pointer[0..deep_pointer.length-2] ,
355
351
  :parent_index => 0,
356
352
  :template => deep_pointer,
357
- :values => "451"
353
+ :values => "451"
358
354
  )
359
- @article.find_by_terms({:journal=>0}, :issue).length.should == 2
360
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length.should == 1
361
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length.should == 1
362
- @article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text.should == "451"
363
-
355
+ expect(@article.find_by_terms({:journal=>0}, :issue).length).to eq(2)
356
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages).length).to eq(1)
357
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).length).to eq(1)
358
+ expect(@article.find_by_terms({:journal=>0}, {:issue=>1}, :pages, :start).first.text).to eq("451")
364
359
  end
365
-
360
+
366
361
  end
367
-
362
+
368
363
  describe ".term_value_update" do
369
-
364
+
370
365
  it "should accept an xpath as :parent_select" do
371
366
  sample_xpath = '//oxns:name[@type="personal"][4]/oxns:role/oxns:roleTerm[@type="text"]'
372
367
  @sample.term_value_update(sample_xpath,1,"artist")
373
- @sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces)[1].text.should == "artist"
368
+ expect(@sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces)[1].text).to eq("artist")
374
369
  end
375
-
370
+
376
371
  it "if :select is provided, should update the first node provided by that xpath statement" do
377
372
  sample_xpath = '//oxns:name[@type="personal"][1]/oxns:namePart[@type="given"]'
378
373
  @sample.term_value_update(sample_xpath,0,"Timmeh")
379
- @sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces).first.text.should == "Timmeh"
374
+ expect(@sample.ng_xml.xpath(sample_xpath, @sample.ox_namespaces).first.text).to eq("Timmeh")
380
375
  end
381
-
376
+
382
377
  it "should replace the existing node if you pass a template and values" do
383
- pending
378
+ skip 'unimplemented'
384
379
  @sample.term_value_update(
385
380
  :parent_select =>'//oxns:name[@type="personal"]',
386
381
  :parent_index => 1,
387
382
  :template => [ :person, :role, {:attributes=>{"type"=>"code", "authority"=>"marcrelator"}} ],
388
383
  :value => "foo"
389
384
  )
390
- 1.should == 2
385
+ expect(1).to eq(2)
391
386
  end
392
387
  it "should delete nodes if value is :delete or empty string" do
393
388
  @article.update_values([:title_info]=>{"0"=>"york", "1"=>"mangle","2"=>"mork"})
394
389
  xpath = @article.class.terminology.xpath_for(:title_info)
395
-
390
+
396
391
  @article.term_value_update([:title_info], 1, "")
397
- @article.term_values(:title_info).should == ['york', 'mork']
398
-
392
+ expect(@article.term_values(:title_info)).to eq(['york', 'mork'])
393
+
399
394
  @article.term_value_update([:title_info], 1, :delete)
400
- @article.term_values(:title_info).should == ['york']
395
+ expect(@article.term_values(:title_info)).to eq(['york'])
401
396
  end
402
397
  it "should create empty nodes if value is nil" do
403
398
  @article.update_values([:title_info]=>{"0"=>"york", "1"=>nil,"2"=>"mork"})
404
- @article.term_values(:title_info).should == ['york', "", "mork"]
399
+ expect(@article.term_values(:title_info)).to eq(['york', "", "mork"])
405
400
  end
406
401
  end
407
-
402
+
408
403
  describe ".term_value_delete" do
409
404
  it "should accept an xpath query as :select option" do
410
405
  generic_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role'
411
406
  specific_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[oxns:roleTerm="visionary"]'
412
407
  select_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[last()]'
413
-
408
+
414
409
  # Check that we're starting with 2 roles
415
410
  # Check that the specific node we want to delete exists
416
- @sample.find_by_terms_and_value(generic_xpath).length.should == 2
417
- @sample.find_by_terms_and_value(specific_xpath).length.should == 1
411
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(2)
412
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(1)
418
413
 
419
414
  @sample.term_value_delete(
420
415
  :select =>select_xpath
421
416
  )
422
417
  # Check that we're finishing with 1 role
423
- @sample.find_by_terms_and_value(generic_xpath).length.should == 1
418
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(1)
424
419
  # Check that the specific node we want to delete no longer exists
425
- @sample.find_by_terms_and_value(specific_xpath).length.should == 0
426
- end
420
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(0)
421
+ end
427
422
  it "should accept :parent_select, :parent_index and :parent_index options instead of a :select" do
428
-
423
+
429
424
  generic_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role/oxns:roleTerm'
430
425
  specific_xpath = '//oxns:name[@type="personal" and position()=4]/oxns:role[oxns:roleTerm="visionary"]'
431
-
426
+
432
427
  # Check that we're starting with 2 roles
433
428
  # Check that the specific node we want to delete exists
434
- @sample.find_by_terms_and_value(generic_xpath).length.should == 4
435
- @sample.find_by_terms_and_value(specific_xpath).length.should == 1
429
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(4)
430
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(1)
436
431
 
437
- # this is attempting to delete the last child (in this case roleTerm) from the 3rd role in the document.
432
+ # this is attempting to delete the last child (in this case roleTerm) from the 3rd role in the document.
438
433
  @sample.term_value_delete(
439
434
  :parent_select => [:person, :role],
440
435
  :parent_index => 3,
441
436
  :child_index => :last
442
437
  )
443
-
438
+
444
439
  # Check that we're finishing with 1 role
445
- @sample.find_by_terms_and_value(generic_xpath).length.should == 3
440
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(3)
446
441
  # Check that the specific node we want to delete no longer exists
447
- @sample.find_by_terms_and_value(specific_xpath).length.should == 1
442
+ expect(@sample.find_by_terms_and_value(specific_xpath).length).to eq(1)
448
443
  end
449
444
  it "should work if only :parent_select and :parent_index are provided" do
450
445
  generic_xpath = '//oxns:name[@type="personal"]/oxns:role'
451
446
  # specific_xpath = '//oxns:name[@type="personal"]/oxns:role'
452
-
447
+
453
448
  # Check that we're starting with 2 roles
454
449
  # Check that the specific node we want to delete exists
455
- @sample.find_by_terms_and_value(generic_xpath).length.should == 4
450
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(4)
456
451
  # @sample.find_by_terms_and_value(specific_xpath).length.should == 1
457
452
 
458
453
  @sample.term_value_delete(
@@ -460,14 +455,14 @@ describe "OM::XML::TermValueOperators" do
460
455
  :child_index => 3
461
456
  )
462
457
  # Check that we're finishing with 1 role
463
- @sample.find_by_terms_and_value(generic_xpath).length.should == 3
458
+ expect(@sample.find_by_terms_and_value(generic_xpath).length).to eq(3)
464
459
  end
465
460
  end
466
-
461
+
467
462
  describe "build_ancestors" do
468
463
  it "should raise an error if it cant find a starting point for building from" do
469
- 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.")
464
+ 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.")
470
465
  end
471
466
  end
472
-
467
+
473
468
  end