om 1.8.1 → 1.9.0.pre1
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.
- data/Rakefile +1 -1
- data/container_spec.rb +14 -14
- data/lib/om.rb +12 -9
- 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 +33 -31
- data/lib/om/xml/container.rb +12 -12
- data/lib/om/xml/document.rb +19 -18
- data/lib/om/xml/dynamic_node.rb +50 -45
- 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 +26 -18
- data/lib/om/xml/term.rb +46 -30
- data/lib/om/xml/term_value_operators.rb +56 -52
- data/lib/om/xml/term_xpath_generator.rb +57 -51
- data/lib/om/xml/terminology.rb +10 -8
- data/lib/om/xml/terminology_based_solrizer.rb +90 -0
- data/lib/om/xml/validation.rb +19 -19
- data/lib/om/xml/vocabulary.rb +4 -4
- data/lib/tasks/om.rake +6 -4
- data/om.gemspec +2 -1
- data/spec/fixtures/mods_article.rb +90 -0
- data/spec/fixtures/mods_articles/hydrangea_article1.xml +2 -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 +18 -24
- 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 +10 -10
- data/spec/integration/xpathy_stuff_spec.rb +16 -16
- data/spec/spec_helper.rb +2 -2
- data/spec/unit/container_spec.rb +29 -28
- data/spec/unit/document_spec.rb +50 -49
- data/spec/unit/dynamic_node_spec.rb +45 -57
- 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 +73 -79
- data/spec/unit/term_value_operators_spec.rb +191 -186
- data/spec/unit/term_xpath_generator_spec.rb +43 -37
- 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 +22 -21
- data/spec/unit/xml_spec.rb +7 -7
- data/spec/unit/xml_terminology_based_solrizer_spec.rb +109 -0
- metadata +57 -17
- checksums.yaml +0 -7
- data/.rspec +0 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -382
- data/.travis.yml +0 -10
- data/gemfiles/gemfile.rails3 +0 -11
- data/gemfiles/gemfile.rails4 +0 -10
@@ -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
|
-
|
34
|
+
@proxied_term.should_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
|
-
|
40
|
-
|
39
|
+
@test_proxy.proxied_term.should == @test_terminology.retrieve_term(:parent, :foo, :bar)
|
40
|
+
@test_proxy.xpath.should == "//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
|
-
|
45
|
-
|
43
|
+
proxy2 = @test_terminology.retrieve_term(:adoptive_parent, :my_proxy)
|
44
|
+
proxy2.proxied_term.should == @test_terminology.retrieve_term(:adoptive_parent, :foo, :bar)
|
45
|
+
proxy2.xpath.should == '//oxns:parent[@type="adoptive"]/oxns:foo/oxns:bar'
|
46
46
|
end
|
47
47
|
it "should support NamedTermProxies that point to root terms" do
|
48
|
-
|
48
|
+
@test_terminology.xpath_for(:parentfoobarproxy).should == "//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
|
-
|
53
|
+
document.term_values(:parentfoobarproxy).should == ["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
|
-
|
13
|
+
OM::XML::NodeGenerator.generate(@test_mods_term, "foo").root.to_xml.should == "<mods>foo</mods>"
|
14
14
|
generated_node = OM::XML::NodeGenerator.generate(@test_volume_term, "108", {:attributes=>{"extraAttr"=>"my value"}})
|
15
|
-
|
15
|
+
generated_node.xpath('./detail[@type="volume"][@extraAttr="my value"]').xpath("./number").text.should == "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
|
-
|
22
|
+
OM::XML::NodeGenerator.generate(@test_mods_term, "foo").class.should == 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
|
-
|
11
|
+
@article.find_by_terms({:journal=>0}).length.should == 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
|
-
|
23
|
+
result.should == {"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
|
-
|
27
|
+
@article.term_values({:person=>0}, :first_name).should == ["GIVEN NAMES"]
|
28
28
|
test_args = {[{:person=>0}, :first_name]=>{"0"=>"Replacement FirstName"}}
|
29
29
|
@article.update_values(test_args)
|
30
|
-
|
31
|
-
|
30
|
+
@article.term_values({:person=>0}, :first_name).should == ["Replacement FirstName"]
|
31
|
+
@article.should 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
|
-
|
38
|
-
|
37
|
+
result.should == {"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
|
-
|
43
|
-
|
42
|
+
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"}}
|
43
|
+
@article.should 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
|
-
|
50
|
-
|
51
|
-
|
49
|
+
@article.term_values( {":person"=>"0"}, "affiliation" ).should == ["affiliation1", "affiliation2", "affiliation3"]
|
50
|
+
result.should == {"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
|
-
|
58
|
-
|
57
|
+
@article.term_values( {":person"=>"0"}, "affiliation" ).should == ["affiliation1", "affiliation2", "affiliation3"]
|
58
|
+
result.should == {"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
|
-
|
65
|
-
|
66
|
-
|
64
|
+
@article.term_values( {":person"=>"0"}, "affiliation" ).should == ["affiliation1", "affiliation2", "affiliation3"]
|
65
|
+
result.should == {"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
|
-
|
71
|
-
|
70
|
+
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"}}
|
71
|
+
@article.should be_changed
|
72
72
|
end
|
73
73
|
end
|
74
|
+
|
74
75
|
|
75
|
-
|
76
|
-
|
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 "#destringify" do
|
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
|
-
|
8
|
-
|
7
|
+
OM.destringify( [{":person"=>"0"}, ":last_name"] ).should == [{:person=>0}, :last_name]
|
8
|
+
OM.destringify( [{"person"=>"3"}, "last_name"] ).should == [{: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
|
-
|
42
|
-
|
41
|
+
RegistryTest.template_registry.node_types.should include(:person)
|
42
|
+
RegistryTest.template_registry.node_types.should_not include(:zombie)
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should define new templates" do
|
46
|
-
|
46
|
+
RegistryTest.template_registry.node_types.should_not 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
|
-
|
52
|
+
RegistryTest.template_registry.node_types.should 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
|
-
|
58
|
+
node.should 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
|
+
lambda { RegistryTest.template_registry.instantiate(:demigod, 'Hercules') }.should 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
|
+
lambda { RegistryTest.template_registry.demigod('Hercules') }.should raise_error(NameError)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should undefine existing templates" do
|
70
|
-
|
70
|
+
RegistryTest.template_registry.node_types.should include(:zombie)
|
71
71
|
RegistryTest.template_registry.undefine :zombie
|
72
|
-
|
72
|
+
RegistryTest.template_registry.node_types.should_not include(:zombie)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should complain if the template name isn't a symbol" do
|
76
|
-
|
76
|
+
lambda { RegistryTest.template_registry.define("die!") { |xml| xml.this_never_happened } }.should raise_error(TypeError)
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
79
|
it "should report on whether a given template is defined" do
|
80
|
-
|
81
|
-
|
80
|
+
RegistryTest.template_registry.has_node_type?(:person).should == true
|
81
|
+
RegistryTest.template_registry.has_node_type?(:zombie).should == false
|
82
82
|
end
|
83
|
-
|
83
|
+
|
84
84
|
it "should include defined node_types as method names for introspection" do
|
85
|
-
|
85
|
+
RegistryTest.template_registry.methods.should 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
|
-
|
92
|
+
@test_document.ng_xml.root.elements.length.should == 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
|
-
|
97
|
+
@test_document.ng_xml.root.elements.length.should == 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
|
-
|
103
|
+
node.should 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
|
-
|
109
|
-
|
108
|
+
return_value.should == @test_document.find_by_terms(:person => 1).first
|
109
|
+
@test_document.ng_xml.should 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
|
-
|
115
|
-
|
114
|
+
return_value.should == @test_document.find_by_terms(:person => 1).first
|
115
|
+
@test_document.ng_xml.should 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
|
-
|
121
|
-
|
120
|
+
return_value.should == @test_document.find_by_terms(:person => 0).first
|
121
|
+
@test_document.ng_xml.should 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
|
-
|
127
|
-
|
126
|
+
return_value.should == @test_document.find_by_terms(:person => 0).first
|
127
|
+
@test_document.ng_xml.should 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
|
-
|
133
|
-
|
132
|
+
return_value.should == @test_document.find_by_terms(:person => 1).first
|
133
|
+
@test_document.ng_xml.should 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
|
-
|
140
|
-
|
139
|
+
return_value.should == @test_document.find_by_terms(:person => 0).first
|
140
|
+
@test_document.ng_xml.should 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
|
-
|
147
|
-
|
146
|
+
return_value.should == target_node
|
147
|
+
@test_document.ng_xml.should 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
|
-
|
154
|
-
|
153
|
+
@test_document.template_registry.swap(target_node, :person, 'Bob', 'Builder') { |old_node|
|
154
|
+
old_node.should be_equivalent_to(expectation)
|
155
155
|
old_node
|
156
|
-
}
|
156
|
+
}.should 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
|
-
|
163
|
+
@test_document.ng_xml.root.elements.length.should == 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
|
-
|
168
|
+
@test_document.ng_xml.root.elements.length.should == 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
|
-
|
173
|
+
@test_document.ng_xml.root.elements.length.should == 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
|
-
|
179
|
+
node.should 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
|
-
|
185
|
-
|
184
|
+
return_value.should == @test_document.find_by_terms(:person => 1).first
|
185
|
+
@test_document.ng_xml.should 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
|
-
|
191
|
-
|
190
|
+
return_value.should == @test_document.find_by_terms(:person => 1).first
|
191
|
+
@test_document.ng_xml.should 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
|
-
|
197
|
-
|
196
|
+
return_value.should == @test_document.find_by_terms(:person => 0).first
|
197
|
+
@test_document.ng_xml.should 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
|
-
|
203
|
-
|
202
|
+
return_value.should == @test_document.find_by_terms(:person => 0).first
|
203
|
+
@test_document.ng_xml.should 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
|
-
|
209
|
-
|
208
|
+
return_value.should == @test_document.find_by_terms(:person => 1).first
|
209
|
+
@test_document.ng_xml.should 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
|
-
|
216
|
-
|
215
|
+
return_value.should == @test_document.find_by_terms(:person => 0).first
|
216
|
+
@test_document.ng_xml.should 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
|
-
|
223
|
-
|
222
|
+
return_value.should == target_node
|
223
|
+
@test_document.ng_xml.should be_equivalent_to(@expectations[:instead]).respecting_element_order
|
224
224
|
end
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
end
|