om 1.8.0 → 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +1 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +382 -0
- data/.travis.yml +10 -0
- data/Rakefile +1 -1
- data/container_spec.rb +14 -14
- data/gemfiles/gemfile.rails3 +11 -0
- data/gemfiles/gemfile.rails4 +10 -0
- data/lib/om.rb +9 -12
- data/lib/om/samples/mods_article.rb +9 -9
- data/lib/om/tree_node.rb +6 -6
- data/lib/om/version.rb +1 -1
- data/lib/om/xml.rb +18 -20
- data/lib/om/xml/container.rb +12 -12
- data/lib/om/xml/document.rb +3 -7
- data/lib/om/xml/dynamic_node.rb +45 -50
- data/lib/om/xml/named_term_proxy.rb +13 -13
- data/lib/om/xml/node_generator.rb +3 -3
- data/lib/om/xml/template_registry.rb +18 -26
- data/lib/om/xml/term.rb +30 -46
- data/lib/om/xml/term_value_operators.rb +52 -56
- data/lib/om/xml/term_xpath_generator.rb +51 -57
- data/lib/om/xml/terminology.rb +8 -10
- data/lib/om/xml/validation.rb +19 -19
- data/lib/om/xml/vocabulary.rb +4 -4
- data/lib/tasks/om.rake +4 -6
- 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 +15 -15
- data/spec/integration/querying_documents_spec.rb +24 -18
- data/spec/integration/rights_metadata_integration_example_spec.rb +18 -18
- data/spec/integration/selective_querying_spec.rb +1 -1
- data/spec/integration/serialization_spec.rb +13 -13
- data/spec/integration/set_reentrant_terminology_spec.rb +7 -7
- data/spec/integration/xpathy_stuff_spec.rb +16 -16
- data/spec/spec_helper.rb +2 -3
- data/spec/unit/container_spec.rb +28 -29
- data/spec/unit/document_spec.rb +49 -50
- data/spec/unit/dynamic_node_spec.rb +55 -47
- data/spec/unit/named_term_proxy_spec.rb +16 -16
- data/spec/unit/node_generator_spec.rb +7 -7
- data/spec/unit/nokogiri_sanity_spec.rb +30 -30
- data/spec/unit/om_spec.rb +5 -5
- data/spec/unit/template_registry_spec.rb +69 -69
- data/spec/unit/term_builder_spec.rb +77 -77
- data/spec/unit/term_spec.rb +78 -72
- data/spec/unit/term_value_operators_spec.rb +186 -191
- data/spec/unit/term_xpath_generator_spec.rb +37 -43
- data/spec/unit/terminology_builder_spec.rb +85 -85
- data/spec/unit/terminology_spec.rb +98 -98
- data/spec/unit/validation_spec.rb +22 -22
- data/spec/unit/xml_serialization_spec.rb +21 -22
- data/spec/unit/xml_spec.rb +7 -7
- metadata +143 -147
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::NamedTermProxy" do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
|
-
|
7
|
-
class NamedProxyTestDocument
|
6
|
+
|
7
|
+
class NamedProxyTestDocument
|
8
8
|
include OM::XML::Document
|
9
9
|
set_terminology do |t|
|
10
10
|
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")
|
@@ -17,39 +17,39 @@ describe "OM::XML::NamedTermProxy" do
|
|
17
17
|
t.adoptive_parent(:ref=>[:parent], :attributes=>{:type=>"adoptive"})
|
18
18
|
t.parentfoobarproxy(:proxy=>[:parent, :foo, :bar])
|
19
19
|
end
|
20
|
-
def self.xml_template
|
20
|
+
def self.xml_template
|
21
21
|
'<mods xmlns="http://www.loc.gov/mods/v3"><parent><foo/></parent></mods>'
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
@test_terminology = NamedProxyTestDocument.terminology
|
26
|
-
@test_proxy
|
27
|
-
@proxied_term
|
26
|
+
@test_proxy = @test_terminology.retrieve_term(:parent, :my_proxy)
|
27
|
+
@proxied_term = @test_terminology.retrieve_term(:parent, :foo, :bar)
|
28
28
|
@adoptive_parent = @test_terminology.retrieve_term(:adoptive_parent)
|
29
29
|
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
it "should proxy all extra methods to the proxied object" do
|
33
33
|
[:xpath, :xpath_relative, :xml_builder_template].each do |method|
|
34
|
-
@proxied_term.
|
34
|
+
expect(@proxied_term).to receive(method)
|
35
35
|
@test_proxy.send(method)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
it "should proxy the term specified by the builder" do
|
39
|
-
@test_proxy.proxied_term.
|
40
|
-
@test_proxy.xpath.
|
39
|
+
expect(@test_proxy.proxied_term).to eq(@test_terminology.retrieve_term(:parent, :foo, :bar))
|
40
|
+
expect(@test_proxy.xpath).to eq("//oxns:parent/oxns:foo/oxns:bar")
|
41
41
|
end
|
42
42
|
it "should search relative to the parent term when finding the term to proxy" do
|
43
|
-
proxy2 = @test_terminology.retrieve_term(:adoptive_parent, :my_proxy)
|
44
|
-
proxy2.proxied_term.
|
45
|
-
proxy2.xpath.
|
43
|
+
proxy2 = @test_terminology.retrieve_term(:adoptive_parent, :my_proxy)
|
44
|
+
expect(proxy2.proxied_term).to eq(@test_terminology.retrieve_term(:adoptive_parent, :foo, :bar))
|
45
|
+
expect(proxy2.xpath).to eq('//oxns:parent[@type="adoptive"]/oxns:foo/oxns:bar')
|
46
46
|
end
|
47
47
|
it "should support NamedTermProxies that point to root terms" do
|
48
|
-
@test_terminology.xpath_for(:parentfoobarproxy).
|
48
|
+
expect(@test_terminology.xpath_for(:parentfoobarproxy)).to eq("//oxns:parent/oxns:foo/oxns:bar")
|
49
49
|
end
|
50
50
|
it "should be usable in update_values" do
|
51
51
|
document = NamedProxyTestDocument.from_xml(NamedProxyTestDocument.xml_template)
|
52
52
|
document.update_values([:parentfoobarproxy] => "FOObar!")
|
53
|
-
document.term_values(:parentfoobarproxy).
|
53
|
+
expect(document.term_values(:parentfoobarproxy)).to eq(["FOObar!"])
|
54
54
|
end
|
55
55
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::NodeGenerator" do
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
|
6
6
|
before(:each) do
|
7
7
|
@test_mods_term = OM::XML::Term.new(:mods)
|
8
8
|
@test_volume_term = OM::XML::Term.new(:volume, :path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
describe '#generate' do
|
12
12
|
it "should use the corresponding builder template(s) to generate the node" do
|
13
|
-
OM::XML::NodeGenerator.generate(@test_mods_term, "foo").root.to_xml.
|
13
|
+
expect(OM::XML::NodeGenerator.generate(@test_mods_term, "foo").root.to_xml).to eq("<mods>foo</mods>")
|
14
14
|
generated_node = OM::XML::NodeGenerator.generate(@test_volume_term, "108", {:attributes=>{"extraAttr"=>"my value"}})
|
15
|
-
generated_node.xpath('./detail[@type="volume"][@extraAttr="my value"]').xpath("./number").text.
|
15
|
+
expect(generated_node.xpath('./detail[@type="volume"][@extraAttr="my value"]').xpath("./number").text).to eq("108")
|
16
16
|
# Would be great if we wrote a have_node custom rspec matcher...
|
17
17
|
# generated_node.should have_node 'role[@authority="marcrelator"][@type="code"]' do
|
18
18
|
# with_node "roleTerm", "creator"
|
19
19
|
# end
|
20
20
|
end
|
21
21
|
it "should return Nokogiri Documents" do
|
22
|
-
OM::XML::NodeGenerator.generate(@test_mods_term, "foo").class.
|
22
|
+
expect(OM::XML::NodeGenerator.generate(@test_mods_term, "foo").class).to eq(Nokogiri::XML::Document)
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
end
|
@@ -1,77 +1,77 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM::XML::TermValueOperators" do
|
4
|
-
|
4
|
+
|
5
5
|
describe "find_by_terms" do
|
6
6
|
before(:each) do
|
7
7
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should do" do
|
11
|
-
@article.find_by_terms({:journal=>0}).length.
|
11
|
+
expect(@article.find_by_terms({:journal=>0}).length).to eq(1)
|
12
12
|
end
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
describe "update_values" do
|
16
16
|
before(:each) do
|
17
17
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should respond with a hash of updated values and their indexes" do
|
21
|
-
test_args = {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
|
21
|
+
test_args = {[{"person"=>"0"},"description"]=>{"-1"=>"mork", "1"=>"york"}}
|
22
22
|
result = @article.update_values(test_args)
|
23
|
-
result.
|
23
|
+
expect(result).to eq({"person_0_description"=>{"0"=>"mork","1"=>"york"}})
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should update the xml in the specified datatsream and save those changes to Fedora" do
|
27
|
-
@article.term_values({:person=>0}, :first_name).
|
27
|
+
expect(@article.term_values({:person=>0}, :first_name)).to eq(["GIVEN NAMES"])
|
28
28
|
test_args = {[{:person=>0}, :first_name]=>{"0"=>"Replacement FirstName"}}
|
29
29
|
@article.update_values(test_args)
|
30
|
-
@article.term_values({:person=>0}, :first_name).
|
31
|
-
@article.
|
30
|
+
expect(@article.term_values({:person=>0}, :first_name)).to eq(["Replacement FirstName"])
|
31
|
+
expect(@article).to be_changed
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should update the xml according to the find_by_terms_and_values in the given hash" do
|
35
35
|
terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}}
|
36
36
|
result = @article.update_values(terms_update_hash)
|
37
|
-
result.
|
38
|
-
|
37
|
+
expect(result).to eq({"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}})
|
38
|
+
|
39
39
|
# Trying again with a more complex update hash
|
40
40
|
terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}, [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
|
41
41
|
result = @article.update_values(terms_update_hash)
|
42
|
-
result.
|
43
|
-
@article.
|
42
|
+
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"}})
|
43
|
+
expect(@article).to be_changed
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should work when you re-run the command" do
|
47
47
|
terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}}
|
48
48
|
result = @article.update_values(terms_update_hash)
|
49
|
-
@article.term_values( {":person"=>"0"}, "affiliation" ).
|
50
|
-
result.
|
51
|
-
|
49
|
+
expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq(["affiliation1", "affiliation2", "affiliation3"])
|
50
|
+
expect(result).to eq({"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}})
|
51
|
+
|
52
52
|
# result = @article.update_values(terms_update_hash)
|
53
53
|
# result.should == {"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}}
|
54
54
|
terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}}
|
55
55
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
56
56
|
result = @article.update_values(terms_update_hash)
|
57
|
-
@article.term_values( {":person"=>"0"}, "affiliation" ).
|
58
|
-
result.
|
57
|
+
expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq(["affiliation1", "affiliation2", "affiliation3"])
|
58
|
+
expect(result).to eq({"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}})
|
59
59
|
result = @article.update_values(terms_update_hash)
|
60
|
-
|
60
|
+
|
61
61
|
terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}}
|
62
62
|
@article = OM::Samples::ModsArticle.from_xml( fixture( File.join("mods_articles","hydrangea_article1.xml") ) )
|
63
63
|
result = @article.update_values(terms_update_hash)
|
64
|
-
@article.term_values( {":person"=>"0"}, "affiliation" ).
|
65
|
-
result.
|
66
|
-
|
64
|
+
expect(@article.term_values( {":person"=>"0"}, "affiliation" )).to eq(["affiliation1", "affiliation2", "affiliation3"])
|
65
|
+
expect(result).to eq({"person_0_affiliation"=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}})
|
66
|
+
|
67
67
|
# Trying again with a more complex update hash
|
68
68
|
terms_update_hash = {[{":person"=>"0"}, "affiliation"]=>{"0"=>"affiliation1", "1"=>"affiliation2", "2"=>"affiliation3"}, [{:person=>1}, :last_name]=>"Andronicus", [{"person"=>"1"},:first_name]=>["Titus"],[{:person=>1},:role]=>["otherrole1","otherrole2"] }
|
69
69
|
result = @article.update_values(terms_update_hash)
|
70
|
-
result.
|
71
|
-
@article.
|
70
|
+
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"}})
|
71
|
+
expect(@article).to be_changed
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
75
74
|
|
76
|
-
|
75
|
+
|
76
|
+
|
77
77
|
end
|
data/spec/unit/om_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OM" do
|
4
|
-
|
5
|
-
describe "#
|
4
|
+
|
5
|
+
describe "#destringify" do
|
6
6
|
it "should recursively change any strings beginning with : to symbols and any number strings to integers" do
|
7
|
-
OM.destringify( [{":person"=>"0"}, ":last_name"] ).
|
8
|
-
OM.destringify( [{"person"=>"3"}, "last_name"] ).
|
7
|
+
expect(OM.destringify( [{":person"=>"0"}, ":last_name"] )).to eq([{:person=>0}, :last_name])
|
8
|
+
expect(OM.destringify( [{"person"=>"3"}, "last_name"] )).to eq([{:person=>3}, :last_name])
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
end
|
@@ -22,7 +22,7 @@ describe "OM::XML::TemplateRegistry" do
|
|
22
22
|
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
after(:all) do
|
27
27
|
Object.send(:remove_const, :RegistryTest)
|
28
28
|
end
|
@@ -35,193 +35,193 @@ describe "OM::XML::TemplateRegistry" do
|
|
35
35
|
:instead => %{<people xmlns="urn:registry-test"><person title="Builder">Bob</person></people>}
|
36
36
|
}
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
describe "template definitions" do
|
40
40
|
it "should contain predefined templates" do
|
41
|
-
RegistryTest.template_registry.node_types.
|
42
|
-
RegistryTest.template_registry.node_types.
|
41
|
+
expect(RegistryTest.template_registry.node_types).to include(:person)
|
42
|
+
expect(RegistryTest.template_registry.node_types).not_to include(:zombie)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should define new templates" do
|
46
|
-
RegistryTest.template_registry.node_types.
|
46
|
+
expect(RegistryTest.template_registry.node_types).not_to include(:zombie)
|
47
47
|
RegistryTest.define_template :zombie do |xml,name|
|
48
48
|
xml.monster(:wants => 'braaaaainz') do
|
49
49
|
xml.text(name)
|
50
50
|
end
|
51
51
|
end
|
52
|
-
RegistryTest.template_registry.node_types.
|
52
|
+
expect(RegistryTest.template_registry.node_types).to include(:zombie)
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should instantiate a detached node from a template" do
|
56
56
|
node = RegistryTest.template_registry.instantiate(:zombie, 'Zeke')
|
57
57
|
expectation = Nokogiri::XML('<monster wants="braaaaainz">Zeke</monster>').root
|
58
|
-
node.
|
58
|
+
expect(node).to be_equivalent_to(expectation)
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
it "should raise an error when trying to instantiate an unknown node_type" do
|
62
|
-
|
62
|
+
expect { RegistryTest.template_registry.instantiate(:demigod, 'Hercules') }.to raise_error(NameError)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "should raise an exception if a missing method name doesn't match a node_type" do
|
66
|
-
|
66
|
+
expect { RegistryTest.template_registry.demigod('Hercules') }.to raise_error(NameError)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should undefine existing templates" do
|
70
|
-
RegistryTest.template_registry.node_types.
|
70
|
+
expect(RegistryTest.template_registry.node_types).to include(:zombie)
|
71
71
|
RegistryTest.template_registry.undefine :zombie
|
72
|
-
RegistryTest.template_registry.node_types.
|
72
|
+
expect(RegistryTest.template_registry.node_types).not_to include(:zombie)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should complain if the template name isn't a symbol" do
|
76
|
-
|
76
|
+
expect { RegistryTest.template_registry.define("die!") { |xml| xml.this_never_happened } }.to raise_error(TypeError)
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should report on whether a given template is defined" do
|
80
|
-
RegistryTest.template_registry.has_node_type?(:person).
|
81
|
-
RegistryTest.template_registry.has_node_type?(:zombie).
|
80
|
+
expect(RegistryTest.template_registry.has_node_type?(:person)).to eq(true)
|
81
|
+
expect(RegistryTest.template_registry.has_node_type?(:zombie)).to eq(false)
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
it "should include defined node_types as method names for introspection" do
|
85
|
-
RegistryTest.template_registry.methods.
|
85
|
+
expect(RegistryTest.template_registry.methods).to include('person')
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
describe "template-based document manipulations" do
|
90
90
|
it "should accept a Nokogiri::XML::Node as target" do
|
91
91
|
@test_document.template_registry.after(@test_document.ng_xml.root.elements.first, :person, 'Bob', 'Builder')
|
92
|
-
@test_document.ng_xml.root.elements.length.
|
92
|
+
expect(@test_document.ng_xml.root.elements.length).to eq(2)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should accept a Nokogiri::XML::NodeSet as target" do
|
96
96
|
@test_document.template_registry.after(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
|
97
|
-
@test_document.ng_xml.root.elements.length.
|
97
|
+
expect(@test_document.ng_xml.root.elements.length).to eq(2)
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
it "should instantiate a detached node from a template using the template name as a method" do
|
101
101
|
node = RegistryTest.template_registry.person('Odin', 'All-Father')
|
102
102
|
expectation = Nokogiri::XML('<person title="All-Father">Odin</person>').root
|
103
|
-
node.
|
103
|
+
expect(node).to be_equivalent_to(expectation)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it "should add_child" do
|
107
107
|
return_value = @test_document.template_registry.add_child(@test_document.ng_xml.root, :person, 'Bob', 'Builder')
|
108
|
-
return_value.
|
109
|
-
@test_document.ng_xml.
|
108
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
|
109
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
it "should add_next_sibling" do
|
113
113
|
return_value = @test_document.template_registry.add_next_sibling(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
|
114
|
-
return_value.
|
115
|
-
@test_document.ng_xml.
|
114
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
|
115
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
|
116
116
|
end
|
117
117
|
|
118
118
|
it "should add_previous_sibling" do
|
119
119
|
return_value = @test_document.template_registry.add_previous_sibling(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
|
120
|
-
return_value.
|
121
|
-
@test_document.ng_xml.
|
120
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
|
121
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should after" do
|
125
125
|
return_value = @test_document.template_registry.after(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
|
126
|
-
return_value.
|
127
|
-
@test_document.ng_xml.
|
126
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
|
127
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should before" do
|
131
131
|
return_value = @test_document.template_registry.before(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
|
132
|
-
return_value.
|
133
|
-
@test_document.ng_xml.
|
132
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
|
133
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
|
134
134
|
end
|
135
135
|
|
136
136
|
it "should replace" do
|
137
137
|
target_node = @test_document.find_by_terms(:person => 0).first
|
138
138
|
return_value = @test_document.template_registry.replace(target_node, :person, 'Bob', 'Builder')
|
139
|
-
return_value.
|
140
|
-
@test_document.ng_xml.
|
139
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
|
140
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should swap" do
|
144
144
|
target_node = @test_document.find_by_terms(:person => 0).first
|
145
145
|
return_value = @test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder')
|
146
|
-
return_value.
|
147
|
-
@test_document.ng_xml.
|
146
|
+
expect(return_value).to eq(target_node)
|
147
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
it "should yield the result if a block is given" do
|
151
151
|
target_node = @test_document.find_by_terms(:person => 0).first
|
152
152
|
expectation = Nokogiri::XML('<person xmlns="urn:registry-test" title="Actor">Alice</person>').root
|
153
|
-
@test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
|
154
|
-
old_node.
|
153
|
+
expect(@test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
|
154
|
+
expect(old_node).to be_equivalent_to(expectation)
|
155
155
|
old_node
|
156
|
-
}.
|
156
|
+
}).to be_equivalent_to(expectation)
|
157
157
|
end
|
158
158
|
end
|
159
|
-
|
159
|
+
|
160
160
|
describe "document-based document manipulations" do
|
161
161
|
it "should accept a Nokogiri::XML::Node as target" do
|
162
162
|
@test_document.after_node(@test_document.ng_xml.root.elements.first, :person, 'Bob', 'Builder')
|
163
|
-
@test_document.ng_xml.root.elements.length.
|
163
|
+
expect(@test_document.ng_xml.root.elements.length).to eq(2)
|
164
164
|
end
|
165
165
|
|
166
166
|
it "should accept a Nokogiri::XML::NodeSet as target" do
|
167
167
|
@test_document.after_node(@test_document.find_by_terms(:person => 0), :person, 'Bob', 'Builder')
|
168
|
-
@test_document.ng_xml.root.elements.length.
|
168
|
+
expect(@test_document.ng_xml.root.elements.length).to eq(2)
|
169
169
|
end
|
170
|
-
|
170
|
+
|
171
171
|
it "should accept a term-pointer array as target" do
|
172
172
|
@test_document.after_node([:person => 0], :person, 'Bob', 'Builder')
|
173
|
-
@test_document.ng_xml.root.elements.length.
|
173
|
+
expect(@test_document.ng_xml.root.elements.length).to eq(2)
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
it "should instantiate a detached node from a template" do
|
177
177
|
node = @test_document.template(:person, 'Odin', 'All-Father')
|
178
178
|
expectation = Nokogiri::XML('<person title="All-Father">Odin</person>').root
|
179
|
-
node.
|
179
|
+
expect(node).to be_equivalent_to(expectation)
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should add_child_node" do
|
183
183
|
return_value = @test_document.add_child_node(@test_document.ng_xml.root, :person, 'Bob', 'Builder')
|
184
|
-
return_value.
|
185
|
-
@test_document.ng_xml.
|
184
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
|
185
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
|
186
186
|
end
|
187
|
-
|
187
|
+
|
188
188
|
it "should add_next_sibling_node" do
|
189
189
|
return_value = @test_document.add_next_sibling_node([:person => 0], :person, 'Bob', 'Builder')
|
190
|
-
return_value.
|
191
|
-
@test_document.ng_xml.
|
190
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
|
191
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should add_previous_sibling_node" do
|
195
195
|
return_value = @test_document.add_previous_sibling_node([:person => 0], :person, 'Bob', 'Builder')
|
196
|
-
return_value.
|
197
|
-
@test_document.ng_xml.
|
196
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
|
197
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
|
198
198
|
end
|
199
199
|
|
200
200
|
it "should after_node" do
|
201
201
|
return_value = @test_document.after_node([:person => 0], :person, 'Bob', 'Builder')
|
202
|
-
return_value.
|
203
|
-
@test_document.ng_xml.
|
202
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
|
203
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:after]).respecting_element_order
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should before_node" do
|
207
207
|
return_value = @test_document.before_node([:person => 0], :person, 'Bob', 'Builder')
|
208
|
-
return_value.
|
209
|
-
@test_document.ng_xml.
|
208
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 1).first)
|
209
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:before]).respecting_element_order
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should replace_node" do
|
213
213
|
target_node = @test_document.find_by_terms(:person => 0).first
|
214
214
|
return_value = @test_document.replace_node(target_node, :person, 'Bob', 'Builder')
|
215
|
-
return_value.
|
216
|
-
@test_document.ng_xml.
|
215
|
+
expect(return_value).to eq(@test_document.find_by_terms(:person => 0).first)
|
216
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
|
217
217
|
end
|
218
218
|
|
219
219
|
it "should swap_node" do
|
220
220
|
target_node = @test_document.find_by_terms(:person => 0).first
|
221
221
|
return_value = @test_document.swap_node(target_node, :person, 'Bob', 'Builder')
|
222
|
-
return_value.
|
223
|
-
@test_document.ng_xml.
|
222
|
+
expect(return_value).to eq(target_node)
|
223
|
+
expect(@test_document.ng_xml).to be_equivalent_to(@expectations[:instead]).respecting_element_order
|
224
224
|
end
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
end
|