roxml 2.3.2 → 2.4.0
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/History.txt +145 -0
- data/Manifest.txt +81 -0
- data/Rakefile +85 -95
- data/TODO +42 -0
- data/html/index.html +278 -0
- data/html/style.css +79 -0
- data/lib/roxml.rb +112 -49
- data/lib/roxml/extensions/active_support.rb +37 -12
- data/lib/roxml/extensions/array/conversions.rb +12 -2
- data/lib/roxml/extensions/deprecation.rb +4 -4
- data/lib/roxml/options.rb +39 -30
- data/lib/roxml/xml.rb +119 -54
- data/lib/roxml/xml/rexml.rb +2 -2
- data/roxml.gemspec +40 -101
- data/tasks/test.rake +42 -0
- data/test/bugs/rexml_bugs.rb +15 -0
- data/test/fixtures/book_with_octal_pages.xml +4 -0
- data/test/mocks/mocks.rb +0 -4
- data/test/test_helper.rb +1 -1
- data/test/unit/array_test.rb +16 -0
- data/test/unit/freeze_test.rb +71 -0
- data/test/unit/inheritance_test.rb +26 -3
- data/test/unit/options_test.rb +20 -19
- data/test/unit/overriden_output_test.rb +33 -0
- data/test/unit/roxml_test.rb +7 -0
- data/test/unit/xml_bool_test.rb +16 -11
- data/test/unit/xml_convention_test.rb +150 -0
- data/test/unit/xml_hash_test.rb +41 -0
- data/test/unit/xml_name_test.rb +29 -6
- data/test/unit/xml_object_test.rb +30 -0
- data/vendor/override_rake_task/README +30 -0
- data/vendor/override_rake_task/init.rb +1 -0
- data/vendor/override_rake_task/install.rb +46 -0
- data/vendor/override_rake_task/lib/override_rake_task.rb +16 -0
- metadata +77 -34
data/lib/roxml/xml/rexml.rb
CHANGED
@@ -39,11 +39,11 @@ module ROXML
|
|
39
39
|
class Parser
|
40
40
|
class << self
|
41
41
|
def parse(string)
|
42
|
-
REXML::Document.new(string)
|
42
|
+
REXML::Document.new(string, :ignore_whitespace_nodes => :all)
|
43
43
|
end
|
44
44
|
|
45
45
|
def parse_file(path)
|
46
|
-
|
46
|
+
parse(open(path))
|
47
47
|
end
|
48
48
|
|
49
49
|
def register_error_handler(&block)
|
data/roxml.gemspec
CHANGED
@@ -1,105 +1,44 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
1
3
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.
|
4
|
-
|
5
|
-
s.
|
6
|
-
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = %q{roxml}
|
5
|
+
s.version = "2.4.0"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
7
8
|
s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
|
12
|
-
|
13
|
-
'Rakefile',
|
14
|
-
'roxml.gemspec',
|
15
|
-
'lib/roxml.rb',
|
16
|
-
'lib/roxml/extensions/active_support.rb',
|
17
|
-
'lib/roxml/extensions/array.rb',
|
18
|
-
'lib/roxml/extensions/array/conversions.rb',
|
19
|
-
'lib/roxml/extensions/string.rb',
|
20
|
-
'lib/roxml/extensions/string/conversions.rb',
|
21
|
-
'lib/roxml/extensions/string/iterators.rb',
|
22
|
-
'lib/roxml/extensions/deprecation.rb',
|
23
|
-
'lib/roxml/options.rb',
|
24
|
-
'lib/roxml/xml.rb',
|
25
|
-
'lib/roxml/xml/libxml.rb',
|
26
|
-
'lib/roxml/xml/rexml.rb',
|
27
|
-
'test/fixtures/book_malformed.xml',
|
28
|
-
'test/fixtures/book_pair.xml',
|
29
|
-
'test/fixtures/book_text_with_attribute.xml',
|
30
|
-
'test/fixtures/book_valid.xml',
|
31
|
-
'test/fixtures/book_with_authors.xml',
|
32
|
-
'test/fixtures/book_with_contributions.xml',
|
33
|
-
'test/fixtures/book_with_contributors_attrs.xml',
|
34
|
-
'test/fixtures/book_with_contributors.xml',
|
35
|
-
'test/fixtures/book_with_default_namespace.xml',
|
36
|
-
'test/fixtures/book_with_depth.xml',
|
37
|
-
'test/fixtures/book_with_publisher.xml',
|
38
|
-
'test/fixtures/book_with_wrapped_attr.xml',
|
39
|
-
'test/fixtures/dictionary_of_attrs.xml',
|
40
|
-
'test/fixtures/dictionary_of_attr_name_clashes.xml',
|
41
|
-
'test/fixtures/dictionary_of_guarded_names.xml',
|
42
|
-
'test/fixtures/dictionary_of_mixeds.xml',
|
43
|
-
'test/fixtures/dictionary_of_names.xml',
|
44
|
-
'test/fixtures/dictionary_of_name_clashes.xml',
|
45
|
-
'test/fixtures/dictionary_of_texts.xml',
|
46
|
-
'test/fixtures/library_uppercase.xml',
|
47
|
-
'test/fixtures/library.xml',
|
48
|
-
'test/fixtures/muffins.xml',
|
49
|
-
'test/fixtures/node_with_attr_name_conflicts.xml',
|
50
|
-
'test/fixtures/node_with_name_conflicts.xml',
|
51
|
-
'test/fixtures/nameless_ageless_youth.xml',
|
52
|
-
'test/fixtures/numerology.xml',
|
53
|
-
'test/fixtures/person_with_guarded_mothers.xml',
|
54
|
-
'test/fixtures/person_with_mothers.xml',
|
55
|
-
'test/fixtures/person.xml',
|
56
|
-
'test/mocks/mocks.rb',
|
57
|
-
'test/mocks/dictionaries.rb',
|
58
|
-
'test/release/dependencies_test.rb',
|
59
|
-
'test/test_helper.rb',
|
60
|
-
'test/unit/inheritance_test.rb',
|
61
|
-
'test/unit/options_test.rb',
|
62
|
-
'test/unit/roxml_test.rb',
|
63
|
-
'test/unit/string_test.rb',
|
64
|
-
'test/unit/to_xml_test.rb',
|
65
|
-
'test/unit/xml_attribute_test.rb',
|
66
|
-
'test/unit/xml_block_test.rb',
|
67
|
-
'test/unit/xml_bool_test.rb',
|
68
|
-
'test/unit/xml_construct_test.rb',
|
69
|
-
'test/unit/xml_hash_test.rb',
|
70
|
-
'test/unit/xml_initialize_test.rb',
|
71
|
-
'test/unit/xml_name_test.rb',
|
72
|
-
'test/unit/xml_namespace_test.rb',
|
73
|
-
'test/unit/xml_object_test.rb',
|
74
|
-
'test/unit/xml_required_test.rb',
|
75
|
-
'test/unit/xml_text_test.rb']
|
76
|
-
s.requirements << 'none'
|
77
|
-
s.add_dependency 'extensions', '>= 0.6.0'
|
78
|
-
s.add_dependency 'activesupport', '>= 2.0.0'
|
79
|
-
s.require_path = 'lib'
|
80
|
-
s.test_files = [
|
81
|
-
'test/unit/inheritance_test.rb',
|
82
|
-
'test/unit/options_test.rb',
|
83
|
-
'test/unit/roxml_test.rb',
|
84
|
-
'test/unit/string_test.rb',
|
85
|
-
'test/unit/to_xml_test.rb',
|
86
|
-
'test/unit/xml_attribute_test.rb',
|
87
|
-
'test/unit/xml_block_test.rb',
|
88
|
-
'test/unit/xml_bool_test.rb',
|
89
|
-
'test/unit/xml_construct_test.rb',
|
90
|
-
'test/unit/xml_hash_test.rb',
|
91
|
-
'test/unit/xml_initialize_test.rb',
|
92
|
-
'test/unit/xml_name_test.rb',
|
93
|
-
'test/unit/xml_namespace_test.rb',
|
94
|
-
'test/unit/xml_object_test.rb',
|
95
|
-
'test/unit/xml_required_test.rb',
|
96
|
-
'test/unit/xml_text_test.rb']
|
9
|
+
s.date = %q{2009-01-15}
|
10
|
+
s.description = %q{ROXML is a Ruby library designed to make it easier for Ruby developers to work with XML. Using simple annotations, it enables Ruby classes to be mapped to XML. ROXML takes care of the marshalling and unmarshalling of mapped attributes so that developers can focus on building first-class Ruby classes. As a result, ROXML simplifies the development of RESTful applications, Web Services, and XML-RPC.}
|
11
|
+
s.email = %q{ben.woosley@gmail.com}
|
12
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
13
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "html/index.html", "html/style.css", "lib/roxml.rb", "lib/roxml/extensions/active_support.rb", "lib/roxml/extensions/array.rb", "lib/roxml/extensions/array/conversions.rb", "lib/roxml/extensions/deprecation.rb", "lib/roxml/extensions/string.rb", "lib/roxml/extensions/string/conversions.rb", "lib/roxml/extensions/string/iterators.rb", "lib/roxml/options.rb", "lib/roxml/xml.rb", "lib/roxml/xml/libxml.rb", "lib/roxml/xml/rexml.rb", "roxml.gemspec", "tasks/test.rake", "test/bugs/rexml_bugs.rb", "test/fixtures/book_malformed.xml", "test/fixtures/book_pair.xml", "test/fixtures/book_text_with_attribute.xml", "test/fixtures/book_valid.xml", "test/fixtures/book_with_authors.xml", "test/fixtures/book_with_contributions.xml", "test/fixtures/book_with_contributors.xml", "test/fixtures/book_with_contributors_attrs.xml", "test/fixtures/book_with_default_namespace.xml", "test/fixtures/book_with_depth.xml", "test/fixtures/book_with_octal_pages.xml", "test/fixtures/book_with_publisher.xml", "test/fixtures/book_with_wrapped_attr.xml", "test/fixtures/dictionary_of_attr_name_clashes.xml", "test/fixtures/dictionary_of_attrs.xml", "test/fixtures/dictionary_of_guarded_names.xml", "test/fixtures/dictionary_of_mixeds.xml", "test/fixtures/dictionary_of_name_clashes.xml", "test/fixtures/dictionary_of_names.xml", "test/fixtures/dictionary_of_texts.xml", "test/fixtures/library.xml", "test/fixtures/library_uppercase.xml", "test/fixtures/muffins.xml", "test/fixtures/nameless_ageless_youth.xml", "test/fixtures/node_with_attr_name_conflicts.xml", "test/fixtures/node_with_name_conflicts.xml", "test/fixtures/numerology.xml", "test/fixtures/person.xml", "test/fixtures/person_with_guarded_mothers.xml", "test/fixtures/person_with_mothers.xml", "test/mocks/dictionaries.rb", "test/mocks/mocks.rb", "test/release/dependencies_test.rb", "test/test_helper.rb", "test/unit/array_test.rb", "test/unit/freeze_test.rb", "test/unit/inheritance_test.rb", "test/unit/options_test.rb", "test/unit/overriden_output_test.rb", "test/unit/roxml_test.rb", "test/unit/string_test.rb", "test/unit/to_xml_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_construct_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_hash_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_text_test.rb", "vendor/override_rake_task/README", "vendor/override_rake_task/init.rb", "vendor/override_rake_task/install.rb", "vendor/override_rake_task/lib/override_rake_task.rb"]
|
97
14
|
s.has_rdoc = true
|
98
|
-
s.
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
15
|
+
s.homepage = %q{http://roxml.rubyforge.org}
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.rubyforge_project = %q{ROXML}
|
19
|
+
s.rubygems_version = %q{1.3.1.xported}
|
20
|
+
s.summary = %q{Ruby Object to XML mapping library}
|
21
|
+
s.test_files = ["test/unit/freeze_test.rb", "test/unit/array_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_bool_test.rb", "test/unit/roxml_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_construct_test.rb", "test/unit/options_test.rb", "test/unit/string_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_text_test.rb", "test/unit/overriden_output_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/inheritance_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_hash_test.rb", "test/unit/to_xml_test.rb"]
|
22
|
+
|
23
|
+
if s.respond_to? :specification_version then
|
24
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
25
|
+
s.specification_version = 2
|
26
|
+
|
27
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
28
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.1.0"])
|
29
|
+
s.add_runtime_dependency(%q<extensions>, [">= 0.6.0"])
|
30
|
+
s.add_development_dependency(%q<newgem>, [">= 1.2.3"])
|
31
|
+
s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
|
32
|
+
else
|
33
|
+
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
34
|
+
s.add_dependency(%q<extensions>, [">= 0.6.0"])
|
35
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
36
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
37
|
+
end
|
38
|
+
else
|
39
|
+
s.add_dependency(%q<activesupport>, [">= 2.1.0"])
|
40
|
+
s.add_dependency(%q<extensions>, [">= 0.6.0"])
|
41
|
+
s.add_dependency(%q<newgem>, [">= 1.2.3"])
|
42
|
+
s.add_dependency(%q<hoe>, [">= 1.8.0"])
|
43
|
+
end
|
105
44
|
end
|
data/tasks/test.rake
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# We need to override hoe's test task in order to support separate REXML & LibXML testing
|
2
|
+
require File.join(File.dirname(__FILE__), '../vendor/override_rake_task/lib/override_rake_task')
|
3
|
+
|
4
|
+
Rake::TestTask.new(:bugs) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.test_files = FileList['test/bugs/*_bugs.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
remove_task :test
|
11
|
+
desc "Test ROXML using the default parser selection behavior"
|
12
|
+
task :test do
|
13
|
+
module ROXML
|
14
|
+
SILENCE_XML_NAME_WARNING = true
|
15
|
+
end
|
16
|
+
require 'lib/roxml'
|
17
|
+
require 'rake/runtest'
|
18
|
+
Rake.run_tests $hoe.test_globs
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :test do
|
22
|
+
desc "Test ROXML under the LibXML parser"
|
23
|
+
task :libxml do
|
24
|
+
module ROXML
|
25
|
+
XML_PARSER = 'libxml'
|
26
|
+
end
|
27
|
+
Rake::Task["test"].invoke
|
28
|
+
end
|
29
|
+
|
30
|
+
desc "Test ROXML under the REXML parser"
|
31
|
+
task :rexml do
|
32
|
+
module ROXML
|
33
|
+
XML_PARSER = 'rexml'
|
34
|
+
end
|
35
|
+
Rake::Task["test"].invoke
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Runs tests under RCOV"
|
39
|
+
task :rcov do
|
40
|
+
system "rcov -T --no-html -x '^/' #{FileList[$hoe.test_globs]}"
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class RexmlBugs < Test::Unit::TestCase
|
4
|
+
def test_that_some_illegal_chars_are_parsed_without_complaint
|
5
|
+
p "REXML ignores illegal ']]>' brackets in xml content"
|
6
|
+
assert_nothing_raised do
|
7
|
+
# The right angle bracket (>) may be represented using the string ">", and MUST, for compatibility,
|
8
|
+
# be escaped using either ">" or a character reference when it appears in the string "]]>" in content,
|
9
|
+
# when that string is not marking the end of a CDATA section.
|
10
|
+
# - http://www.w3.org/TR/xml11/#syntax
|
11
|
+
xml = "<title>The Big Book of ]]> everything more</title>"
|
12
|
+
assert_equal xml, REXML::Document.new(xml).to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/test/mocks/mocks.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class TestXmlArray < Test::Unit::TestCase
|
4
|
+
def test_as_array_with_auto_guard
|
5
|
+
result = BookWithContributors.from_xml(%{
|
6
|
+
<book isbn="0974514055">
|
7
|
+
<contributors>
|
8
|
+
<contributor role="author"><name>David Thomas</name></contributor>
|
9
|
+
<contributor role="supporting author"><name>Andrew Hunt</name></contributor>
|
10
|
+
<contributor role="supporting author"><name>Chad Fowler</name></contributor>
|
11
|
+
</contributors>
|
12
|
+
</book>
|
13
|
+
}).contributors.map(&:name).sort
|
14
|
+
assert_equal ["David Thomas","Andrew Hunt","Chad Fowler"].sort, result
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
+
|
3
|
+
class DescriptionReadonly
|
4
|
+
include ROXML
|
5
|
+
|
6
|
+
xml_reader :writable, :content
|
7
|
+
xml_reader :readonly, :content, :frozen => true
|
8
|
+
end
|
9
|
+
|
10
|
+
class BookWithContributionsReadonly
|
11
|
+
include ROXML
|
12
|
+
|
13
|
+
xml_name :book
|
14
|
+
xml_reader :isbn, :attr, :frozen => true
|
15
|
+
xml_reader :title, :frozen => true
|
16
|
+
xml_reader :description, DescriptionReadonly, :frozen => true
|
17
|
+
xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions", :frozen => true
|
18
|
+
end
|
19
|
+
|
20
|
+
class DictionaryOfGuardedNamesReadonly
|
21
|
+
include ROXML
|
22
|
+
|
23
|
+
xml_name :dictionary
|
24
|
+
xml_reader :definitions, {:key => :name,
|
25
|
+
:value => :content}, :in => :definitions, :frozen => true
|
26
|
+
end
|
27
|
+
|
28
|
+
class TestFreeze < Test::Unit::TestCase
|
29
|
+
def setup
|
30
|
+
@writable = BookWithContributions.from_xml(fixture(:book_with_contributions))
|
31
|
+
@readonly = BookWithContributionsReadonly.from_xml(fixture(:book_with_contributions))
|
32
|
+
@dict_readonly = DictionaryOfGuardedNamesReadonly.from_xml(fixture(:dictionary_of_guarded_names))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_attr_is_unmodifiable
|
36
|
+
assert !@writable.isbn.frozen?
|
37
|
+
assert @readonly.isbn.frozen?
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_text_is_unmodifiable
|
41
|
+
assert !@writable.title.frozen?
|
42
|
+
assert @readonly.title.frozen?
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_objects_are_unmodifiable
|
46
|
+
assert @readonly.description.frozen?
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_indirect_attrs_can_be_frozen_or_not
|
50
|
+
assert @readonly.description.readonly.frozen?
|
51
|
+
assert !@readonly.description.writable.frozen?
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_arrays_are_unmodifiable
|
55
|
+
assert !@writable.contributions.frozen?
|
56
|
+
assert @readonly.contributions.frozen?
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_array_elements_are_unmodifiable
|
60
|
+
assert @readonly.contributions.all?(&:frozen?)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_hashes_are_unmodifiable
|
64
|
+
assert @dict_readonly.definitions.frozen?
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_hash_keys_and_values_are_unmodifiable
|
68
|
+
assert @dict_readonly.definitions.keys.all?(&:frozen?)
|
69
|
+
assert @dict_readonly.definitions.values.all?(&:frozen?)
|
70
|
+
end
|
71
|
+
end
|
@@ -1,11 +1,25 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
|
+
class InheritedBookWithDepth < Book
|
4
|
+
xml_reader :depth, Measurement
|
5
|
+
end
|
6
|
+
|
3
7
|
class TestInheritance < Test::Unit::TestCase
|
4
8
|
def setup
|
5
|
-
@
|
9
|
+
@book_xml = %{
|
10
|
+
<book ISBN="0201710897">
|
11
|
+
<title>The PickAxe</title>
|
12
|
+
<description><![CDATA[Probably the best Ruby book out there]]></description>
|
13
|
+
<author>David Thomas, Andrew Hunt, Dave Thomas</author>
|
14
|
+
<depth units="hundredths-meters">1130</depth>
|
15
|
+
<publisher>Pragmattic Programmers</publisher>
|
16
|
+
</book>
|
17
|
+
}
|
18
|
+
|
19
|
+
@b = InheritedBookWithDepth.from_xml(@book_xml)
|
6
20
|
end
|
7
21
|
|
8
|
-
def
|
22
|
+
def test_it_should_include_parents_attributes
|
9
23
|
assert_equal '0201710897', @b.isbn
|
10
24
|
assert_equal 'The PickAxe', @b.title
|
11
25
|
assert_equal 'Probably the best Ruby book out there', @b.description
|
@@ -13,7 +27,16 @@ class TestInheritance < Test::Unit::TestCase
|
|
13
27
|
assert_equal 0, @b.pages
|
14
28
|
end
|
15
29
|
|
16
|
-
def
|
30
|
+
def test_it_should_include_its_own_attributes
|
17
31
|
assert_equal '11.3 meters', @b.depth.to_s
|
18
32
|
end
|
33
|
+
|
34
|
+
def test_it_should_include_parent_attributes_added_after_the_childs_definition
|
35
|
+
Book.class_eval do
|
36
|
+
xml_reader :publisher, :require => true
|
37
|
+
end
|
38
|
+
|
39
|
+
book = InheritedBookWithDepth.from_xml(@book_xml)
|
40
|
+
assert_equal "Pragmattic Programmers", book.publisher
|
41
|
+
end
|
19
42
|
end
|
data/test/unit/options_test.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
3
|
class TestOptions < Test::Unit::TestCase
|
4
|
+
def assert_hash(opts, kvp)
|
5
|
+
assert opts.hash?
|
6
|
+
assert !opts.array?
|
7
|
+
assert_equal kvp, {opts.hash.key.type => opts.hash.key.name,
|
8
|
+
opts.hash.value.type => opts.hash.value.name}
|
9
|
+
end
|
10
|
+
|
4
11
|
def test_text_in_array_means_as_array_for_text
|
5
12
|
opts = ROXML::Opts.new(:authors, [:text])
|
6
13
|
assert opts.array?
|
@@ -33,44 +40,38 @@ class TestOptions < Test::Unit::TestCase
|
|
33
40
|
assert_raise ArgumentError do
|
34
41
|
ROXML::Opts.new(:author, :content, :required => true, :else => 'Johnny')
|
35
42
|
end
|
36
|
-
|
43
|
+
assert_nothing_raised do
|
44
|
+
ROXML::Opts.new(:author, :content, :required => false, :else => 'Johnny')
|
45
|
+
end
|
37
46
|
end
|
38
47
|
|
39
48
|
def test_hash_of_attrs
|
40
49
|
opts = ROXML::Opts.new(:attributes, {:attrs => [:name, :value]})
|
41
|
-
|
42
|
-
assert !opts.array?
|
43
|
-
assert_equal [ROXML::XMLAttributeRef, ROXML::XMLAttributeRef], opts.hash.types
|
44
|
-
assert_equal ['name', 'value'], opts.hash.names
|
50
|
+
assert_hash(opts, :attr => 'name', :attr => 'value')
|
45
51
|
end
|
46
52
|
|
47
53
|
def test_hash_with_attr_key_and_text_val
|
48
54
|
opts = ROXML::Opts.new(:attributes, {:key => {:attr => :name},
|
49
55
|
:value => :value})
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
56
|
+
assert_hash(opts, :attr => 'name', :text => 'value')
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_hash_with_string_class_for_type
|
60
|
+
opts = ROXML::Opts.new(:attributes, {:key => {String => 'name'},
|
61
|
+
:value => {String => 'value'}})
|
62
|
+
assert_hash(opts, :text => 'name', :text => 'value')
|
54
63
|
end
|
55
64
|
|
56
65
|
def test_hash_with_attr_key_and_content_val
|
57
66
|
opts = ROXML::Opts.new(:attributes, {:key => {:attr => :name},
|
58
67
|
:value => :content})
|
59
|
-
|
60
|
-
assert !opts.array?
|
61
|
-
assert opts.hash.value.content?
|
62
|
-
assert_equal [ROXML::XMLAttributeRef, ROXML::XMLTextRef], opts.hash.types
|
63
|
-
assert_equal ['name', ''], opts.hash.names
|
68
|
+
assert_hash(opts, :attr => 'name', :content => '')
|
64
69
|
end
|
65
70
|
|
66
71
|
def test_hash_with_options
|
67
72
|
opts = ROXML::Opts.new(:definitions, {:attrs => [:dt, :dd]},
|
68
73
|
:in => :definitions)
|
69
|
-
|
70
|
-
assert opts.hash?
|
71
|
-
assert !opts.array?
|
72
|
-
assert_equal [ROXML::XMLAttributeRef, ROXML::XMLAttributeRef], opts.hash.types
|
73
|
-
assert_equal ['dt', 'dd'], opts.hash.names
|
74
|
+
assert_hash(opts, :attr => 'dt', :attr => 'dd')
|
74
75
|
end
|
75
76
|
|
76
77
|
def test_no_block_shorthand_means_no_block
|