roxml 2.4.3 → 2.5.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 +54 -0
- data/Manifest.txt +9 -6
- data/README.rdoc +24 -17
- data/Rakefile +2 -1
- data/TODO +30 -31
- data/examples/active_record.rb +69 -0
- data/examples/amazon.rb +1 -1
- data/examples/current_weather.rb +1 -1
- data/examples/posts.rb +8 -8
- data/examples/twitter.rb +2 -2
- data/examples/xml/active_record.xml +70 -0
- data/lib/roxml.rb +174 -174
- data/lib/roxml/definition.rb +165 -89
- data/lib/roxml/extensions/deprecation.rb +5 -0
- data/lib/roxml/extensions/string/conversions.rb +2 -3
- data/lib/roxml/hash_definition.rb +26 -25
- data/lib/roxml/xml.rb +15 -6
- data/lib/roxml/xml/parsers/libxml.rb +9 -6
- data/lib/roxml/xml/parsers/rexml.rb +1 -1
- data/lib/roxml/xml/references.rb +14 -17
- data/roxml.gemspec +8 -5
- data/spec/definition_spec.rb +563 -0
- data/spec/examples/active_record_spec.rb +43 -0
- data/spec/roxml_spec.rb +372 -0
- data/spec/shared_specs.rb +15 -0
- data/spec/spec_helper.rb +21 -4
- data/spec/string_spec.rb +15 -0
- data/spec/xml/parser_spec.rb +22 -0
- data/test/fixtures/book_valid.xml +1 -1
- data/test/fixtures/person_with_guarded_mothers.xml +3 -3
- data/test/mocks/mocks.rb +57 -45
- data/test/unit/definition_test.rb +161 -12
- data/test/unit/deprecations_test.rb +97 -0
- data/test/unit/to_xml_test.rb +30 -1
- data/test/unit/xml_bool_test.rb +15 -3
- data/test/unit/xml_construct_test.rb +6 -6
- data/test/unit/xml_hash_test.rb +18 -0
- data/test/unit/xml_initialize_test.rb +6 -3
- data/test/unit/xml_object_test.rb +66 -5
- data/test/unit/xml_text_test.rb +3 -0
- metadata +23 -15
- data/test/unit/array_test.rb +0 -16
- data/test/unit/freeze_test.rb +0 -71
- data/test/unit/inheritance_test.rb +0 -63
- data/test/unit/overriden_output_test.rb +0 -33
- data/test/unit/roxml_test.rb +0 -60
- data/test/unit/string_test.rb +0 -11
data/test/unit/array_test.rb
DELETED
@@ -1,16 +0,0 @@
|
|
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
|
data/test/unit/freeze_test.rb
DELETED
@@ -1,71 +0,0 @@
|
|
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,63 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class ParentWithNamespace
|
4
|
-
include ROXML
|
5
|
-
xml_namespace 'parent_namespace'
|
6
|
-
end
|
7
|
-
|
8
|
-
class ChildWithInheritedNamespace < ParentWithNamespace
|
9
|
-
end
|
10
|
-
|
11
|
-
class ChildWithOwnNamespace < ParentWithNamespace
|
12
|
-
xml_namespace 'child_namespace'
|
13
|
-
end
|
14
|
-
|
15
|
-
class InheritedBookWithDepth < Book
|
16
|
-
xml_reader :depth, Measurement
|
17
|
-
end
|
18
|
-
|
19
|
-
class TestInheritance < Test::Unit::TestCase
|
20
|
-
def setup
|
21
|
-
@book_xml = %{
|
22
|
-
<book ISBN="0201710897">
|
23
|
-
<title>The PickAxe</title>
|
24
|
-
<description><![CDATA[Probably the best Ruby book out there]]></description>
|
25
|
-
<author>David Thomas, Andrew Hunt, Dave Thomas</author>
|
26
|
-
<depth units="hundredths-meters">1130</depth>
|
27
|
-
<publisher>Pragmattic Programmers</publisher>
|
28
|
-
<pagecount>500</pagecount>
|
29
|
-
</book>
|
30
|
-
}
|
31
|
-
|
32
|
-
@b = InheritedBookWithDepth.from_xml(@book_xml)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_it_should_include_parents_attributes
|
36
|
-
assert_equal '0201710897', @b.isbn
|
37
|
-
assert_equal 'The PickAxe', @b.title
|
38
|
-
assert_equal 'Probably the best Ruby book out there', @b.description
|
39
|
-
assert_equal 'David Thomas, Andrew Hunt, Dave Thomas', @b.author
|
40
|
-
assert_equal 500, @b.pages
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_it_should_include_its_own_attributes
|
44
|
-
assert_equal '11.3 meters', @b.depth.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_it_should_include_parent_attributes_added_after_the_childs_definition
|
48
|
-
Book.class_eval do
|
49
|
-
xml_reader :publisher, :require => true
|
50
|
-
end
|
51
|
-
|
52
|
-
book = InheritedBookWithDepth.from_xml(@book_xml)
|
53
|
-
assert_equal "Pragmattic Programmers", book.publisher
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_it_should_inherit_namespace
|
57
|
-
assert_equal 'parent_namespace', ChildWithInheritedNamespace.roxml_namespace
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_inherited_namespace_should_be_overridable
|
61
|
-
assert_equal 'child_namespace', ChildWithOwnNamespace.roxml_namespace
|
62
|
-
end
|
63
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
class OctalInteger
|
2
|
-
def self.from_xml(val)
|
3
|
-
new(Integer(val.content))
|
4
|
-
end
|
5
|
-
|
6
|
-
def initialize(value)
|
7
|
-
@val = value
|
8
|
-
end
|
9
|
-
|
10
|
-
def ==(other)
|
11
|
-
@val == other
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_xml
|
15
|
-
sprintf("%#o", @val)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class BookWithOctalPages
|
20
|
-
include ROXML
|
21
|
-
|
22
|
-
xml_accessor :pages_with_to_xml_proc, :as => Integer, :to_xml => proc {|val| sprintf("%#o", val) }, :required => true
|
23
|
-
xml_accessor :pages_with_type, OctalInteger, :required => true
|
24
|
-
end
|
25
|
-
|
26
|
-
class TestToXmlWithOverriddenOutput < Test::Unit::TestCase
|
27
|
-
to_xml_test :book_with_octal_pages
|
28
|
-
def test_padded_numbers_read_properly
|
29
|
-
b = BookWithOctalPages.from_xml(fixture(:book_with_octal_pages))
|
30
|
-
assert_equal 239, b.pages_with_type
|
31
|
-
assert_equal 239, b.pages_with_to_xml_proc
|
32
|
-
end
|
33
|
-
end
|
data/test/unit/roxml_test.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class TestROXML < Test::Unit::TestCase
|
4
|
-
# Malformed XML parsing should throw REXML::ParseException
|
5
|
-
def test_malformed
|
6
|
-
ROXML::XML::Parser.register_error_handler {|err| }
|
7
|
-
assert_raise ROXML::XML::Parser::ParseError do
|
8
|
-
book = Book.from_xml(fixture(:book_malformed))
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# Verify that an exception is thrown when two accessors have the same
|
13
|
-
# name in a ROXML class.
|
14
|
-
def test_duplicate_accessor
|
15
|
-
assert_raise RuntimeError do
|
16
|
-
Class.new do
|
17
|
-
include ROXML
|
18
|
-
|
19
|
-
xml_reader :id
|
20
|
-
xml_accessor :id
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_tag_refs_is_deprecated
|
26
|
-
assert_deprecated do
|
27
|
-
Class.new do
|
28
|
-
include ROXML
|
29
|
-
end.tag_refs
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_from_xml_should_support_pathnames
|
34
|
-
book = BookWithContributors.from_xml(Pathname.new(fixture_path(:book_with_contributors)))
|
35
|
-
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
36
|
-
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
37
|
-
book.contributors.each do |contributor|
|
38
|
-
assert(expected_contributors.include?(contributor.name))
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_from_xml_should_support_uris
|
43
|
-
uri = URI.parse("file://#{File.expand_path(File.expand_path(fixture_path(:book_with_contributors)))}")
|
44
|
-
book = BookWithContributors.from_xml(uri)
|
45
|
-
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
46
|
-
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
47
|
-
book.contributors.each do |contributor|
|
48
|
-
assert(expected_contributors.include?(contributor.name))
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_from_xml_should_support_files
|
53
|
-
book = BookWithContributors.from_xml(File.new(fixture_path(:book_with_contributors)))
|
54
|
-
expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler"]
|
55
|
-
assert_equal("Programming Ruby - 2nd Edition", book.title)
|
56
|
-
book.contributors.each do |contributor|
|
57
|
-
assert(expected_contributors.include?(contributor.name))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
data/test/unit/string_test.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'lib/roxml/extensions/string'
|
2
|
-
|
3
|
-
class TestROXML < Test::Unit::TestCase
|
4
|
-
def test_to_latin_is_accessible
|
5
|
-
assert String.instance_methods.include?('to_latin')
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_to_utf_is_accessible
|
9
|
-
assert String.instance_methods.include?('to_utf')
|
10
|
-
end
|
11
|
-
end
|