om 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{COMMON_OM_PATTERNS.textile → COMMON_OM_PATTERNS.md} +136 -126
- data/CONTRIBUTING.md +2 -2
- data/GETTING_FANCY.md +153 -0
- data/GETTING_STARTED.md +329 -0
- data/Gemfile +1 -1
- data/History.md +164 -0
- data/LICENSE +15 -20
- data/QUERYING_DOCUMENTS.md +162 -0
- data/README.md +2 -2
- data/UPDATING_DOCUMENTS.md +6 -0
- data/gemfiles/gemfile.rails3 +1 -1
- data/gemfiles/gemfile.rails4 +1 -1
- data/lib/om/version.rb +1 -1
- data/lib/om/xml/dynamic_node.rb +42 -51
- data/lib/tasks/om.rake +1 -1
- data/om.gemspec +1 -2
- data/spec/integration/differentiated_elements_spec.rb +2 -2
- data/spec/integration/element_value_spec.rb +13 -13
- data/spec/integration/proxies_and_ref_spec.rb +10 -10
- data/spec/integration/querying_documents_spec.rb +20 -27
- data/spec/integration/rights_metadata_integration_example_spec.rb +4 -4
- data/spec/integration/selective_querying_spec.rb +1 -1
- data/spec/integration/serialization_spec.rb +15 -15
- data/spec/integration/set_reentrant_terminology_spec.rb +6 -6
- data/spec/integration/subclass_terminology_spec.rb +8 -8
- data/spec/integration/xpathy_stuff_spec.rb +10 -10
- data/spec/unit/container_spec.rb +27 -27
- data/spec/unit/document_spec.rb +24 -24
- data/spec/unit/dynamic_node_spec.rb +60 -49
- data/spec/unit/named_term_proxy_spec.rb +12 -7
- data/spec/unit/node_generator_spec.rb +4 -4
- data/spec/unit/nokogiri_sanity_spec.rb +17 -18
- data/spec/unit/om_spec.rb +2 -2
- data/spec/unit/template_registry_spec.rb +51 -51
- data/spec/unit/term_builder_spec.rb +45 -44
- data/spec/unit/term_spec.rb +55 -55
- data/spec/unit/term_value_operators_spec.rb +205 -205
- data/spec/unit/term_xpath_generator_spec.rb +33 -36
- data/spec/unit/terminology_builder_spec.rb +50 -47
- data/spec/unit/terminology_spec.rb +92 -92
- data/spec/unit/validation_spec.rb +12 -12
- data/spec/unit/xml_serialization_spec.rb +20 -20
- data/spec/unit/xml_spec.rb +3 -3
- data/spec/unit/xml_terminology_based_solrizer_spec.rb +18 -18
- metadata +11 -38
- data/GETTING_FANCY.textile +0 -145
- data/GETTING_STARTED.textile +0 -254
- data/History.textile +0 -186
- data/QUERYING_DOCUMENTS.textile +0 -139
- data/UPDATING_DOCUMENTS.textile +0 -3
@@ -68,21 +68,21 @@ describe "an example with :proxy and :ref" do
|
|
68
68
|
|
69
69
|
describe "image" do
|
70
70
|
it "should have the right proxy terms" do
|
71
|
-
subject.ead_fedora_pid.
|
72
|
-
subject.ead_ds_label.
|
73
|
-
subject.ead_size.
|
74
|
-
subject.ead_md5.
|
75
|
-
subject.ead_sha1.
|
71
|
+
expect(subject.ead_fedora_pid).to include "hypatia:ead_file_asset_fixture"
|
72
|
+
expect(subject.ead_ds_label).to include "my_ead.xml"
|
73
|
+
expect(subject.ead_size).to include "47570"
|
74
|
+
expect(subject.ead_md5).to include "123"
|
75
|
+
expect(subject.ead_sha1).to include "456"
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe "ead" do
|
80
80
|
it "should have the right proxy terms" do
|
81
|
-
subject.image_fedora_pid.
|
82
|
-
subject.image_ds_label.
|
83
|
-
subject.image_size.
|
84
|
-
subject.image_md5.
|
85
|
-
subject.image_sha1.
|
81
|
+
expect(subject.image_fedora_pid).to include "hypatia:coll_img_file_asset_fixture"
|
82
|
+
expect(subject.image_ds_label).to include "my_image.jpg"
|
83
|
+
expect(subject.image_size).to include "302080"
|
84
|
+
expect(subject.image_md5).to include "789"
|
85
|
+
expect(subject.image_sha1).to include "666"
|
86
86
|
end
|
87
87
|
end
|
88
88
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Rspec tests for QUERYING_DOCUMENTS.
|
3
|
+
describe "Rspec tests for QUERYING_DOCUMENTS.md" do
|
4
4
|
|
5
5
|
before(:all) do
|
6
6
|
@xml_file = "mods_articles/hydrangea_article1.xml"
|
@@ -11,31 +11,26 @@ describe "Rspec tests for QUERYING_DOCUMENTS.textile" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "xpath_for()" do
|
14
|
-
@term.xpath_for(:name).
|
15
|
-
|
16
|
-
@term.xpath_for(:
|
17
|
-
|
18
|
-
@term.xpath_for(:
|
19
|
-
'//oxns:name[@type="corporate"]'
|
20
|
-
@term.xpath_for(:person, :first_name).should ==
|
21
|
-
'//oxns:name[@type="personal"]/oxns:namePart[@type="given"]'
|
22
|
-
@term.xpath_for(:journal, :issue, :pages, :start).should ==
|
23
|
-
'//oxns:relatedItem[@type="host"]/oxns:part/oxns:extent[@unit="pages"]/oxns:start'
|
14
|
+
expect(@term.xpath_for(:name)).to eq '//oxns:name'
|
15
|
+
expect(@term.xpath_for(:person)).to eq '//oxns:name[@type="personal"]'
|
16
|
+
expect(@term.xpath_for(:organization)).to eq '//oxns:name[@type="corporate"]'
|
17
|
+
expect(@term.xpath_for(:person, :first_name)).to eq '//oxns:name[@type="personal"]/oxns:namePart[@type="given"]'
|
18
|
+
expect(@term.xpath_for(:journal, :issue, :pages, :start)).to eq '//oxns:relatedItem[@type="host"]/oxns:part/oxns:extent[@unit="pages"]/oxns:start'
|
24
19
|
end
|
25
20
|
|
26
21
|
it "term_values()" do
|
27
|
-
@doc.term_values(:person, :first_name).
|
28
|
-
@doc.term_values(:person, :last_name).
|
29
|
-
@doc.term_values(:organization, :namePart).
|
30
|
-
@doc.term_values(:journal, :issue, :pages, :start).
|
31
|
-
@doc.term_values(:journal, :title_info, :main_title).
|
22
|
+
expect(@doc.term_values(:person, :first_name)).to eq ["GIVEN NAMES", "Siddartha"]
|
23
|
+
expect(@doc.term_values(:person, :last_name)).to eq ["FAMILY NAME", "Gautama"]
|
24
|
+
expect(@doc.term_values(:organization, :namePart)).to eq ['NSF']
|
25
|
+
expect(@doc.term_values(:journal, :issue, :pages, :start)).to eq ['195']
|
26
|
+
expect(@doc.term_values(:journal, :title_info, :main_title)).to eq ["TITLE OF HOST JOURNAL"]
|
32
27
|
end
|
33
28
|
|
34
29
|
it "xpath_for(): relative vs absolute" do
|
35
30
|
xp_rel = '//oxns:titleInfo/oxns:title'
|
36
31
|
xp_abs = '//oxns:mods/oxns:titleInfo/oxns:title'
|
37
|
-
@term.xpath_for( :title_info, :main_title).
|
38
|
-
@term.xpath_for(:mods, :title_info, :main_title).
|
32
|
+
expect(@term.xpath_for( :title_info, :main_title)).to eq xp_rel
|
33
|
+
expect(@term.xpath_for(:mods, :title_info, :main_title)).to eq xp_abs
|
39
34
|
end
|
40
35
|
|
41
36
|
it "term_values(): relative vs absolute" do
|
@@ -45,16 +40,16 @@ describe "Rspec tests for QUERYING_DOCUMENTS.textile" do
|
|
45
40
|
"TITLE OF HOST JOURNAL",
|
46
41
|
]
|
47
42
|
xp_abs = '//oxns:mods/oxns:titleInfo/oxns:title'
|
48
|
-
@doc.term_values( :title_info, :main_title).
|
49
|
-
@doc.term_values(:mods, :title_info, :main_title).
|
43
|
+
expect(@doc.term_values( :title_info, :main_title)).to eq exp
|
44
|
+
expect(@doc.term_values(:mods, :title_info, :main_title)).to eq exp[0..1]
|
50
45
|
end
|
51
46
|
|
52
47
|
it "find_by_terms()" do
|
53
48
|
exp_xml_role = '<role><roleTerm authority="marcrelator" type="text">funder</roleTerm></role>'
|
54
49
|
exp_xml_start = '<start>195</start>'
|
55
|
-
@doc.find_by_terms(:organization, :role).class.
|
56
|
-
@doc.find_by_terms(:organization, :role).to_xml.
|
57
|
-
@doc.find_by_terms(:journal, :issue, :pages, :start).to_xml.
|
50
|
+
expect(@doc.find_by_terms(:organization, :role).class).to eq Nokogiri::XML::NodeSet
|
51
|
+
expect(@doc.find_by_terms(:organization, :role).to_xml).to be_equivalent_to exp_xml_role
|
52
|
+
expect(@doc.find_by_terms(:journal, :issue, :pages, :start).to_xml).to eq exp_xml_start
|
58
53
|
end
|
59
54
|
|
60
55
|
it "find_by_terms() error" do
|
@@ -63,10 +58,8 @@ describe "Rspec tests for QUERYING_DOCUMENTS.textile" do
|
|
63
58
|
end
|
64
59
|
|
65
60
|
it "proxies" do
|
66
|
-
@term.xpath_for(:title).
|
67
|
-
|
68
|
-
@term.xpath_for(:journal_title)
|
69
|
-
'//oxns:relatedItem[@type="host"]/oxns:titleInfo/oxns:title'
|
61
|
+
expect(@term.xpath_for(:title)).to eq '//oxns:titleInfo/oxns:title'
|
62
|
+
expect(@term.xpath_for(:journal_title)).to eq'//oxns:relatedItem[@type="host"]/oxns:titleInfo/oxns:title'
|
70
63
|
end
|
71
64
|
|
72
65
|
end
|
@@ -66,10 +66,10 @@ describe "OM::XML::Accessors" do
|
|
66
66
|
describe "update_properties" do
|
67
67
|
it "should update the declared properties" do
|
68
68
|
skip "nesting is too deep..."
|
69
|
-
@sample.retrieve(*[:edit_access, :machine, :person]).length.
|
70
|
-
@sample.update_properties([:edit_access, :machine, :person]=>"user id").
|
71
|
-
@sample.retrieve(*[:edit_access, :machine, :person]).length.
|
72
|
-
@sample.retrieve(*[:edit_access, :machine, :person]).first.text.
|
69
|
+
expect(@sample.retrieve(*[:edit_access, :machine, :person]).length).to eq 0
|
70
|
+
expect(@sample.update_properties([:edit_access, :machine, :person]=>"user id")).to eq({"edit_access_machine_person"=>{"-1"=>"user id"}})
|
71
|
+
expect(@sample.retrieve(*[:edit_access, :machine, :person]).length).to eq 1
|
72
|
+
expect(@sample.retrieve(*[:edit_access, :machine, :person]).first.text).to eq "user id"
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -83,7 +83,7 @@ describe "Selecting nodes based on (a) position in hierarchy and (b) attributes"
|
|
83
83
|
[ 'inner_note_a', %w( i3a i4a) ],
|
84
84
|
[ 'inner_note_not_a', %w( i1 i2 ) ],
|
85
85
|
]
|
86
|
-
tests.each { |meth, exp| @doc.send(meth).
|
86
|
+
tests.each { |meth, exp| expect(@doc.send(meth)).to eq exp }
|
87
87
|
end
|
88
88
|
|
89
89
|
end
|
@@ -35,16 +35,16 @@ EOF
|
|
35
35
|
subject { datastream }
|
36
36
|
describe "reading values" do
|
37
37
|
it "should deserialize date" do
|
38
|
-
subject.my_date.
|
38
|
+
expect(subject.my_date).to eq [Date.parse('2012-10-30')]
|
39
39
|
end
|
40
40
|
it "should deserialize time" do
|
41
|
-
subject.my_time.
|
41
|
+
expect(subject.my_time).to eq [DateTime.parse('2012-10-30T12:22:33Z')]
|
42
42
|
end
|
43
43
|
it "should deserialize ints" do
|
44
|
-
subject.my_int.
|
44
|
+
expect(subject.my_int).to eq [7]
|
45
45
|
end
|
46
46
|
it "should deserialize boolean" do
|
47
|
-
subject.active.
|
47
|
+
expect(subject.active).to eq [true]
|
48
48
|
end
|
49
49
|
end
|
50
50
|
describe "Writing to xml" do
|
@@ -52,7 +52,7 @@ EOF
|
|
52
52
|
context "with a valid time" do
|
53
53
|
subject { datastream.to_xml }
|
54
54
|
before { datastream.my_time = [DateTime.parse('2011-01-30T03:45:15Z')] }
|
55
|
-
it {
|
55
|
+
it { is_expected.to be_equivalent_to '<?xml version="1.0"?>
|
56
56
|
<outer outerId="hypatia:outer" type="outer type">
|
57
57
|
<my_date>2012-10-30</my_date>
|
58
58
|
<my_time>2011-01-30T03:45:15Z</my_time>
|
@@ -77,7 +77,7 @@ EOF
|
|
77
77
|
context "with a valid date" do
|
78
78
|
|
79
79
|
before { datastream.my_date = [Date.parse('2012-09-22')] }
|
80
|
-
it {
|
80
|
+
it { is_expected.to be_equivalent_to '<?xml version="1.0"?>
|
81
81
|
<outer outerId="hypatia:outer" type="outer type">
|
82
82
|
<my_date>2012-09-22</my_date>
|
83
83
|
<my_time>2012-10-30T12:22:33Z</my_time>
|
@@ -89,7 +89,7 @@ EOF
|
|
89
89
|
|
90
90
|
it "should serialize ints" do
|
91
91
|
subject.my_int = [9]
|
92
|
-
subject.to_xml.
|
92
|
+
expect(subject.to_xml).to be_equivalent_to '<?xml version="1.0"?>
|
93
93
|
<outer outerId="hypatia:outer" type="outer type">
|
94
94
|
<my_date>2012-10-30</my_date>
|
95
95
|
<my_time>2012-10-30T12:22:33Z</my_time>
|
@@ -99,7 +99,7 @@ EOF
|
|
99
99
|
end
|
100
100
|
it "should serialize boolean" do
|
101
101
|
subject.active = [false]
|
102
|
-
subject.to_xml.
|
102
|
+
expect(subject.to_xml).to be_equivalent_to '<?xml version="1.0"?>
|
103
103
|
<outer outerId="hypatia:outer" type="outer type">
|
104
104
|
<my_date>2012-10-30</my_date>
|
105
105
|
<my_time>2012-10-30T12:22:33Z</my_time>
|
@@ -122,19 +122,19 @@ EOF
|
|
122
122
|
end
|
123
123
|
describe "reading values" do
|
124
124
|
it "should deserialize date" do
|
125
|
-
subject.my_date.
|
125
|
+
expect(subject.my_date).to eq [nil]
|
126
126
|
end
|
127
127
|
it "should deserialize ints" do
|
128
|
-
subject.my_int.
|
128
|
+
expect(subject.my_int).to eq [nil]
|
129
129
|
end
|
130
130
|
it "should deserialize bools" do
|
131
|
-
subject.active.
|
131
|
+
expect(subject.active).to eq [false]
|
132
132
|
end
|
133
133
|
end
|
134
134
|
describe "Writing to xml" do
|
135
135
|
it "should serialize date" do
|
136
136
|
subject.my_date = [Date.parse('2012-09-22')]
|
137
|
-
subject.to_xml.
|
137
|
+
expect(subject.to_xml).to be_equivalent_to '<?xml version="1.0"?>
|
138
138
|
<outer outerId="hypatia:outer" type="outer type">
|
139
139
|
<my_date>2012-09-22</my_date>
|
140
140
|
<my_int></my_int>
|
@@ -143,7 +143,7 @@ EOF
|
|
143
143
|
end
|
144
144
|
it "should serialize ints" do
|
145
145
|
subject.my_int = [9]
|
146
|
-
subject.to_xml.
|
146
|
+
expect(subject.to_xml).to be_equivalent_to '<?xml version="1.0"?>
|
147
147
|
<outer outerId="hypatia:outer" type="outer type">
|
148
148
|
<my_date></my_date>
|
149
149
|
<my_int>9</my_int>
|
@@ -152,7 +152,7 @@ EOF
|
|
152
152
|
end
|
153
153
|
it "should serialize booleans" do
|
154
154
|
subject.active = [true]
|
155
|
-
subject.to_xml.
|
155
|
+
expect(subject.to_xml).to be_equivalent_to '<?xml version="1.0"?>
|
156
156
|
<outer outerId="hypatia:outer" type="outer type">
|
157
157
|
<my_date></my_date>
|
158
158
|
<my_int></my_int>
|
@@ -163,7 +163,7 @@ EOF
|
|
163
163
|
subject.my_int = [nil]
|
164
164
|
subject.my_date = [nil]
|
165
165
|
subject.active = [nil]
|
166
|
-
subject.to_xml.
|
166
|
+
expect(subject.to_xml).to be_equivalent_to '<?xml version="1.0"?>
|
167
167
|
<outer outerId="hypatia:outer" type="outer type">
|
168
168
|
</outer>'
|
169
169
|
end
|
@@ -21,7 +21,7 @@ describe "calling set_terminology more than once" do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it "can get foo" do
|
24
|
-
subject.foo.
|
24
|
+
expect(subject.foo).to eq ['fooval']
|
25
25
|
end
|
26
26
|
|
27
27
|
it "cannot get bar" do
|
@@ -51,7 +51,7 @@ describe "calling set_terminology more than once" do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "can now get bar" do
|
54
|
-
subject.bar.
|
54
|
+
expect(subject.bar).to eq ['barval']
|
55
55
|
end
|
56
56
|
|
57
57
|
end
|
@@ -80,11 +80,11 @@ describe "calling set_terminology more than once" do
|
|
80
80
|
end
|
81
81
|
|
82
82
|
it "can get foo" do
|
83
|
-
subject.foo.
|
83
|
+
expect(subject.foo).to eq ['fooval']
|
84
84
|
end
|
85
85
|
|
86
86
|
it "can get bar" do
|
87
|
-
subject.bar.
|
87
|
+
expect(subject.bar).to eq ['barval']
|
88
88
|
end
|
89
89
|
|
90
90
|
end
|
@@ -122,11 +122,11 @@ describe "calling set_terminology more than once" do
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it "can get foo" do
|
125
|
-
subject.foo.
|
125
|
+
expect(subject.foo).to eq ['fooval']
|
126
126
|
end
|
127
127
|
|
128
128
|
it "can get bar" do
|
129
|
-
subject.bar.
|
129
|
+
expect(subject.bar).to eq ['barval']
|
130
130
|
end
|
131
131
|
|
132
132
|
end
|
@@ -31,12 +31,12 @@ describe "Inherited terminology" do
|
|
31
31
|
|
32
32
|
it "should inherit terminology" do
|
33
33
|
subject.foo = "Test value"
|
34
|
-
subject.foo.
|
34
|
+
expect(subject.foo).to eq ["Test value"]
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should have extended terminology" do
|
38
38
|
subject.bar = "Test value"
|
39
|
-
subject.bar.
|
39
|
+
expect(subject.bar).to eq ["Test value"]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -48,7 +48,7 @@ describe "Inherited terminology" do
|
|
48
48
|
|
49
49
|
it "should have terminology" do
|
50
50
|
subject.foo = "Test value"
|
51
|
-
subject.foo.
|
51
|
+
expect(subject.foo).to eq ["Test value"]
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should not have extended terminology" do
|
@@ -99,14 +99,14 @@ describe "Inherited terminology" do
|
|
99
99
|
|
100
100
|
it "should inherit templates" do
|
101
101
|
subject.add_child_node subject.ng_xml.root, :creator, 'Test author', 'Primary'
|
102
|
-
subject.ng_xml.xpath('//pbcoreCreator/creatorRole[@source="PBCore creatorRole"]').text.
|
102
|
+
expect(subject.ng_xml.xpath('//pbcoreCreator/creatorRole[@source="PBCore creatorRole"]').text).to eq "Primary"
|
103
103
|
end
|
104
104
|
|
105
105
|
it "should inherit but not extend its parent's templates" do
|
106
|
-
OtherConcreteTerminology.template_registry.
|
107
|
-
OtherConcreteTerminology.template_registry.
|
108
|
-
AbstractTerminology.template_registry.
|
109
|
-
ConcreteTerminology.template_registry.
|
106
|
+
expect(OtherConcreteTerminology.template_registry).to have_node_type(:creator)
|
107
|
+
expect(OtherConcreteTerminology.template_registry).to have_node_type(:foo)
|
108
|
+
expect(AbstractTerminology.template_registry).not_to have_node_type(:foo)
|
109
|
+
expect(ConcreteTerminology.template_registry).not_to have_node_type(:foo)
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -51,11 +51,11 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should have a content term" do
|
54
|
-
subject.content.first.
|
54
|
+
expect(subject.content.first).to match /content/
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should have an html term" do
|
58
|
-
subject.html.first.
|
58
|
+
expect(subject.html.first).to match /html/
|
59
59
|
end
|
60
60
|
|
61
61
|
|
@@ -121,14 +121,14 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
121
121
|
|
122
122
|
it "should have the terms :author_given and :author_family to get the author name" do
|
123
123
|
skip "This doesn't seem to work?"
|
124
|
-
subject.author_given.
|
125
|
-
subject.author_family.
|
124
|
+
expect(subject.author_given).to include("Mary")
|
125
|
+
expect(subject.author_family).to include("Pickral")
|
126
126
|
end
|
127
127
|
|
128
128
|
it "should have the terms :advisor_given and :advisor_family to get the advisor name" do
|
129
129
|
skip "This doesn't seem to work?"
|
130
|
-
subject.advisor_given.
|
131
|
-
subject.advisor_family.
|
130
|
+
expect(subject.advisor_given).to include("David")
|
131
|
+
expect(subject.advisor_family).to include("Small")
|
132
132
|
end
|
133
133
|
|
134
134
|
end
|
@@ -185,19 +185,19 @@ describe "an example of xpath-y stuff, also using :proxy and :ref and namespaces
|
|
185
185
|
end
|
186
186
|
|
187
187
|
it "should give a creator value" do
|
188
|
-
subject.creator.
|
188
|
+
expect(subject.creator).to include "David Small"
|
189
189
|
end
|
190
190
|
|
191
191
|
it "should give a repository value" do
|
192
|
-
subject.repository.
|
192
|
+
expect(subject.repository).to include "Graphic Novel Repository"
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should have a person term 'for more generic xml'" do
|
196
|
-
subject.person.
|
196
|
+
expect(subject.person).to include "David Small"
|
197
197
|
end
|
198
198
|
|
199
199
|
it "should have a corporate term 'for more generic xml'" do
|
200
|
-
subject.corporate.
|
200
|
+
expect(subject.corporate).to include "Graphic Novel Repository"
|
201
201
|
end
|
202
202
|
end
|
203
203
|
end
|
data/spec/unit/container_spec.rb
CHANGED
@@ -1,80 +1,80 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::Container" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
class ContainerTest
|
7
7
|
include OM::XML::Container
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
subject {
|
12
12
|
ContainerTest.from_xml("<foo><bar>1</bar></foo>")
|
13
13
|
}
|
14
14
|
|
15
15
|
it "should add .ng_xml accessor" do
|
16
|
-
subject.
|
17
|
-
subject.
|
16
|
+
expect(subject).to respond_to(:ng_xml)
|
17
|
+
expect(subject).to respond_to(:ng_xml=)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "should initialize" do
|
21
|
-
ContainerTest.new.ng_xml.
|
21
|
+
expect(ContainerTest.new.ng_xml).to be_a_kind_of Nokogiri::XML::Document
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
describe "new" do
|
25
25
|
it "should populate ng_xml with an instance of Nokogiri::XML::Document" do
|
26
|
-
subject.ng_xml.class.
|
26
|
+
expect(subject.ng_xml.class).to eq Nokogiri::XML::Document
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "#from_xml" do
|
31
31
|
it "should accept a String, parse it and store it in .ng_xml" do
|
32
|
-
Nokogiri::XML::Document.
|
32
|
+
expect(Nokogiri::XML::Document).to receive(:parse).and_return("parsed xml")
|
33
33
|
container1 = ContainerTest.from_xml("<foo><bar>1</bar></foo>")
|
34
|
-
container1.ng_xml.
|
34
|
+
expect(container1.ng_xml).to eq "parsed xml"
|
35
35
|
end
|
36
36
|
it "should accept a File, parse it and store it in .ng_xml" do
|
37
37
|
file = fixture(File.join("mods_articles", "hydrangea_article1.xml"))
|
38
|
-
Nokogiri::XML::Document.
|
38
|
+
expect(Nokogiri::XML::Document).to receive(:parse).and_return("parsed xml")
|
39
39
|
container1 = ContainerTest.from_xml(file)
|
40
|
-
container1.ng_xml.
|
40
|
+
expect(container1.ng_xml).to eq "parsed xml"
|
41
41
|
end
|
42
42
|
it "should accept Nokogiri nodes as input and leave them as-is" do
|
43
43
|
parsed_xml = Nokogiri::XML::Document.parse("<foo><bar>1</bar></foo>")
|
44
44
|
container1 = ContainerTest.from_xml(parsed_xml)
|
45
|
-
container1.ng_xml.
|
45
|
+
expect(container1.ng_xml).to eq parsed_xml
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
describe ".to_xml" do
|
50
50
|
it "should call .ng_xml.to_xml" do
|
51
|
-
subject.ng_xml.
|
52
|
-
subject.to_xml.
|
51
|
+
expect(subject.ng_xml).to receive(:to_xml).and_return("ng xml")
|
52
|
+
expect(subject.to_xml).to eq("ng xml")
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (mocked test)' do
|
56
56
|
doc = Nokogiri::XML::Document.parse("<test_xml/>")
|
57
57
|
mock_new_node = double("new node")
|
58
|
-
doc.root.
|
58
|
+
expect(doc.root).to receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
59
59
|
result = subject.to_xml(doc)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it 'should accept an optional Nokogiri::XML Document as an argument and insert its fields into that (functional test)' do
|
63
63
|
doc = Nokogiri::XML::Document.parse("<test_xml/>")
|
64
|
-
subject.to_xml(doc).
|
64
|
+
expect(subject.to_xml(doc)).to eq "<?xml version=\"1.0\"?>\n<test_xml>\n <foo>\n <bar>1</bar>\n </foo>\n</test_xml>\n"
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it 'should add to root of Nokogiri::XML::Documents, but add directly to the elements if a Nokogiri::XML::Node is passed in' do
|
68
68
|
mock_new_node = double("new node")
|
69
|
-
mock_new_node.
|
70
|
-
|
69
|
+
allow(mock_new_node).to receive(:to_xml).and_return("foo")
|
71
70
|
doc = Nokogiri::XML::Document.parse("<test_document/>")
|
72
71
|
el = Nokogiri::XML::Node.new("test_element", Nokogiri::XML::Document.new)
|
73
|
-
|
74
|
-
|
75
|
-
subject.
|
76
|
-
subject.to_xml(
|
72
|
+
skip "Test not fully implemented"
|
73
|
+
expect(doc.root).to receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
74
|
+
expect(el).to receive(:add_child).with(subject.ng_xml.root).and_return(mock_new_node)
|
75
|
+
# expect(subject.to_xml(doc)).to be_equivalent_to
|
76
|
+
# expect(subject.to_xml(el )).to be_equivalent_to
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
end
|