Empact-roxml 2.1 → 2.2

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.
@@ -2,13 +2,33 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class TestXMLName < Test::Unit::TestCase
4
4
  def test_named_books_picked_up
5
- named = Library.parse(fixture(:library))
5
+ named = Library.from_xml(fixture(:library))
6
6
  assert named.books
7
7
  assert_equal :book, named.books.first.tag_name
8
8
  end
9
9
 
10
10
  def test_nameless_books_missing
11
- nameless = LibraryWithBooksOfUnderivableName.parse(fixture(:library))
11
+ nameless = LibraryWithBooksOfUnderivableName.from_xml(fixture(:library))
12
12
  assert nameless.novels.empty?
13
13
  end
14
+
15
+ def test_tag_name
16
+ assert_equal :dictionary, DictionaryOfTexts.tag_name
17
+
18
+ dict = DictionaryOfTexts.from_xml(fixture(:dictionary_of_texts))
19
+
20
+ assert_equal :dictionary, dict.tag_name
21
+ end
22
+
23
+ def test_tag_refs
24
+ assert_equal 'definition', DictionaryOfTexts.tag_refs.only.name
25
+ assert_equal 'word', DictionaryOfTexts.tag_refs.only.hash.key.name
26
+ assert_equal 'meaning', DictionaryOfTexts.tag_refs.only.hash.value.name
27
+
28
+ dict = DictionaryOfTexts.from_xml(fixture(:dictionary_of_texts))
29
+
30
+ assert_equal 'definition', dict.tag_refs.only.name
31
+ assert_equal 'word', dict.tag_refs.only.hash.key.name
32
+ assert_equal 'meaning', dict.tag_refs.only.hash.value.name
33
+ end
14
34
  end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class TestXMLNamespaces < Test::Unit::TestCase
4
4
  def setup
5
- @book = BookWithContributions.parse(fixture(:book_with_default_namespace))
5
+ @book = BookWithContributions.from_xml(fixture(:book_with_default_namespace))
6
6
  end
7
7
 
8
8
  def test_default_namespace_doesnt_interfere_with_normal_operation
@@ -29,8 +29,9 @@ class TestXMLNamespaces < Test::Unit::TestCase
29
29
  xml = LibXML::XML::Parser.string(
30
30
  '<container xmlns="http://defaultnamespace.org"><node>Yeah, content</node><node><subnode>Another</subnode></node></container>').parse
31
31
 
32
- assert_equal nil, xml.find_first('container')
33
- assert_equal "Yeah, content", xml.find_first('container:node', 'container:http://defaultnamespace.org').content
34
- assert_equal "Another", xml.find_first('container:node/container:subnode', 'container:http://defaultnamespace.org').content
32
+ assert_equal nil, xml.find_first('node')
33
+ assert_equal "Yeah, content", xml.find_first('ns:node', 'ns:http://defaultnamespace.org').content
34
+ assert_equal nil, xml.find_first('ns:node/subnode', 'ns:http://defaultnamespace.org')
35
+ assert_equal "Another", xml.find_first('ns:node/ns:subnode', 'ns:http://defaultnamespace.org').content
35
36
  end
36
37
  end
@@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
3
3
  class TestXMLObject < Test::Unit::TestCase
4
4
  # Test book with text and attribute
5
5
  def test_book_author_text_attribute
6
- book = BookWithAuthorTextAttribute.parse(fixture(:book_text_with_attribute))
6
+ book = BookWithAuthorTextAttribute.from_xml(fixture(:book_text_with_attribute))
7
7
  assert_equal("primary",book.author.role)
8
8
  assert_equal("David Thomas",book.author.text)
9
9
  end
@@ -12,7 +12,7 @@ class TestXMLObject < Test::Unit::TestCase
12
12
  # In this case, book with contibutions
13
13
  def test_one_to_many_with_container
14
14
  expected_authors = ["David Thomas","Andrew Hunt","Chad Fowler"]
15
- book = BookWithContributions.parse(fixture(:book_with_contributions))
15
+ book = BookWithContributions.from_xml(fixture(:book_with_contributions))
16
16
  assert_equal("Programming Ruby - 2nd Edition", book.title)
17
17
  book.contributions.each do |contributor|
18
18
  assert expected_authors.include?(contributor.name)
@@ -23,24 +23,46 @@ class TestXMLObject < Test::Unit::TestCase
23
23
  # In this case, book with contibutions
24
24
  def test_one_to_many_without_container
25
25
  expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler"]
26
- book = BookWithContributors.parse(fixture(:book_with_contributors))
26
+ book = BookWithContributors.from_xml(fixture(:book_with_contributors))
27
27
  assert_equal("Programming Ruby - 2nd Edition", book.title)
28
28
  book.contributors.each do |contributor|
29
29
  assert(expected_contributors.include?(contributor.name))
30
30
  end
31
31
  end
32
32
 
33
+ # when building objects that contain arrays, the second object seems to
34
+ # inherit data from the first
35
+ #
36
+ def test_one_to_many_without_container_sequence
37
+ contrib = WriteableContributor.new
38
+ contrib.name = "David Thomas"
39
+
40
+ book_one = WriteableBookWithContributors.new
41
+ book_one.isbn = "9781843549161"
42
+ book_one.title = "Anathem"
43
+ book_one.description = "A new title from Neal Stephenson"
44
+ book_one.contributors << contrib
45
+
46
+ # this book should be completely empty
47
+ book_two = WriteableBookWithContributors.new
48
+
49
+ assert_equal(nil, book_two.isbn)
50
+ assert_equal(nil, book_two.title)
51
+ assert_equal(nil, book_two.description)
52
+ assert_equal(0, book_two.contributors.size)
53
+ end
54
+
33
55
  # Test XML object containing one other XML object (one-to-one)
34
56
  # In this case, book with publisher
35
57
  def test_one_to_one
36
- book = BookWithPublisher.parse(fixture(:book_with_publisher))
58
+ book = BookWithPublisher.from_xml(fixture(:book_with_publisher))
37
59
  assert_equal("Programming Ruby - 2nd Edition", book.title)
38
60
  assert_equal("Pragmatic Bookshelf", book.publisher.name)
39
61
  end
40
62
 
41
63
  # Test XML object containing type of self (self-reference)
42
64
  def test_self_reference
43
- book = BookPair.parse(fixture(:book_pair))
65
+ book = BookPair.from_xml(fixture(:book_pair))
44
66
  assert_equal("Programming Ruby - 2nd Edition", book.title)
45
67
  assert_equal("Agile Web Development with Rails", book.book.title)
46
68
  end
@@ -49,7 +71,7 @@ class TestXMLObject < Test::Unit::TestCase
49
71
  def test_one_to_many_to_many
50
72
  expected_contributors = ["David Thomas","Andrew Hunt","Chad Fowler", "David Heinemeier Hansson"]
51
73
  expected_books = ["Programming Ruby - 2nd Edition", "Agile Web Development with Rails"]
52
- library = Library.parse(fixture(:library))
74
+ library = Library.from_xml(fixture(:library))
53
75
  assert_equal("Ruby library", library.name)
54
76
  assert !library.books.empty?
55
77
  library.books.each do |book|
@@ -61,17 +83,17 @@ class TestXMLObject < Test::Unit::TestCase
61
83
  end
62
84
 
63
85
  def test_without_needed_from
64
- assert_equal [], UppercaseLibrary.parse(fixture(:library)).books
65
- assert_equal [], Library.parse(fixture(:library_uppercase)).books
86
+ assert_equal [], UppercaseLibrary.from_xml(fixture(:library)).books
87
+ assert_equal [], Library.from_xml(fixture(:library_uppercase)).books
66
88
  end
67
89
 
68
90
  def test_with_needed_from
69
- assert Library.parse(fixture(:library)).books
70
- assert UppercaseLibrary.parse(fixture(:library_uppercase)).books
91
+ assert Library.from_xml(fixture(:library)).books
92
+ assert UppercaseLibrary.from_xml(fixture(:library_uppercase)).books
71
93
  end
72
94
 
73
95
  def test_with_recursion
74
- p = PersonWithMother.parse(fixture(:person_with_mothers))
96
+ p = PersonWithMother.from_xml(fixture(:person_with_mothers))
75
97
  assert_equal 'Ben Franklin', p.name
76
98
  assert_equal 'Abiah Folger', p.mother.name
77
99
  assert_equal 'Madeup Mother', p.mother.mother.name
@@ -79,7 +101,7 @@ class TestXMLObject < Test::Unit::TestCase
79
101
  end
80
102
 
81
103
  def test_with_guarded_recursion
82
- p = PersonWithGuardedMother.parse(fixture(:person_with_guarded_mothers))
104
+ p = PersonWithGuardedMother.from_xml(fixture(:person_with_guarded_mothers))
83
105
  assert_equal 'Ben Franklin', p.name
84
106
  assert_equal 'Abiah Folger', p.mother.name
85
107
  assert_equal 'Madeup Mother', p.mother.mother.name
@@ -87,8 +109,8 @@ class TestXMLObject < Test::Unit::TestCase
87
109
  end
88
110
 
89
111
  def test_recursive_with_default_initialization
90
- p = PersonWithMotherOrMissing.parse(fixture(:person_with_mothers))
112
+ p = PersonWithMotherOrMissing.from_xml(fixture(:person_with_mothers))
91
113
  assert_equal 'Unknown', p.mother.mother.mother.name
92
114
  assert_equal Person, p.mother.mother.mother.class
93
115
  end
94
- end
116
+ end
@@ -3,26 +3,26 @@ require File.join(File.dirname(__FILE__), '..', 'test_helper')
3
3
  class TestXMLText < Test::Unit::TestCase
4
4
  # Test a simple mapping with no composition
5
5
  def test_valid_simple
6
- book = Book.parse(fixture(:book_valid))
6
+ book = Book.from_xml(fixture(:book_valid))
7
7
  assert_equal("The PickAxe", book.title)
8
8
  end
9
9
 
10
10
  def test_without_needed_from
11
- assert !Library.parse(fixture(:library_uppercase)).name
11
+ assert !Library.from_xml(fixture(:library_uppercase)).name
12
12
  end
13
13
 
14
14
  def test_with_needed_from
15
- assert_equal "Ruby library", Library.parse(fixture(:library)).name
16
- assert_equal "Ruby library", UppercaseLibrary.parse(fixture(:library_uppercase)).name
15
+ assert_equal "Ruby library", Library.from_xml(fixture(:library)).name
16
+ assert_equal "Ruby library", UppercaseLibrary.from_xml(fixture(:library_uppercase)).name
17
17
  end
18
18
 
19
19
  def test_as_array
20
20
  assert_equal ["David Thomas","Andrew Hunt","Dave Thomas"].sort,
21
- BookWithAuthors.parse(fixture(:book_with_authors)).authors.sort
21
+ BookWithAuthors.from_xml(fixture(:book_with_authors)).authors.sort
22
22
  end
23
23
 
24
24
  def test_text_modification
25
- person = Person.parse(fixture(:person))
25
+ person = Person.from_xml(fixture(:person))
26
26
  assert_equal("Ben Franklin", person.name)
27
27
  person.name = "Fred"
28
28
  xml=person.to_xml.to_s
@@ -30,27 +30,27 @@ class TestXMLText < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_default_initialization
33
- person = PersonWithMotherOrMissing.parse(fixture(:nameless_ageless_youth))
33
+ person = PersonWithMotherOrMissing.from_xml(fixture(:nameless_ageless_youth))
34
34
  assert_equal "Anonymous", person.name
35
35
  end
36
36
 
37
37
  def test_default_initialization_of_content
38
- person = Person.parse(fixture(:nameless_ageless_youth))
38
+ person = Person.from_xml(fixture(:nameless_ageless_youth))
39
39
  assert_equal "Unknown", person.name
40
40
  end
41
41
 
42
42
  def test_recursive_with_default_initialization
43
- p = PersonWithMotherOrMissing.parse(fixture(:person_with_mothers))
43
+ p = PersonWithMotherOrMissing.from_xml(fixture(:person_with_mothers))
44
44
  assert_equal 'Unknown', p.mother.mother.mother.name
45
45
  end
46
46
 
47
47
  def test_get_with_block
48
- p = Book.parse(fixture(:book_valid))
48
+ p = Book.from_xml(fixture(:book_valid))
49
49
  assert_equal 357, p.pages
50
50
  end
51
51
 
52
52
  def test_no_name_clashes
53
- n = NodeWithNameConflicts.parse(fixture(:node_with_name_conflicts))
53
+ n = NodeWithNameConflicts.from_xml(fixture(:node_with_name_conflicts))
54
54
  assert_equal "Just junk... really", n.content
55
55
  assert_equal "Cartwheel", n.name
56
56
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Empact-roxml
3
3
  version: !ruby/object:Gem::Version
4
- version: "2.1"
4
+ version: "2.2"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Woosley
@@ -12,10 +12,18 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2008-08-13 00:00:00 -07:00
15
+ date: 2008-10-27 00:00:00 -07:00
16
16
  default_executable:
17
- dependencies: []
18
-
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: extensions
20
+ version_requirement:
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.6.0
26
+ version:
19
27
  description: 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.
20
28
  email: ben.woosley@gmail.com
21
29
  executables: []
@@ -30,9 +38,13 @@ files:
30
38
  - Rakefile
31
39
  - roxml.gemspec
32
40
  - lib/roxml.rb
33
- - lib/roxml/array.rb
41
+ - lib/roxml/extensions/array.rb
42
+ - lib/roxml/extensions/array/conversions.rb
43
+ - lib/roxml/extensions/string.rb
44
+ - lib/roxml/extensions/string/conversions.rb
45
+ - lib/roxml/extensions/string/iterators.rb
46
+ - lib/roxml/extensions/deprecation.rb
34
47
  - lib/roxml/options.rb
35
- - lib/roxml/string.rb
36
48
  - lib/roxml/xml.rb
37
49
  - lib/roxml/xml/libxml.rb
38
50
  - lib/roxml/xml/rexml.rb
@@ -47,11 +59,18 @@ files:
47
59
  - test/fixtures/book_with_default_namespace.xml
48
60
  - test/fixtures/book_with_depth.xml
49
61
  - test/fixtures/book_with_publisher.xml
62
+ - test/fixtures/book_with_wrapped_attr.xml
50
63
  - test/fixtures/dictionary_of_attrs.xml
64
+ - test/fixtures/dictionary_of_attr_name_clashes.xml
65
+ - test/fixtures/dictionary_of_guarded_names.xml
51
66
  - test/fixtures/dictionary_of_mixeds.xml
67
+ - test/fixtures/dictionary_of_names.xml
68
+ - test/fixtures/dictionary_of_name_clashes.xml
52
69
  - test/fixtures/dictionary_of_texts.xml
53
70
  - test/fixtures/library_uppercase.xml
54
71
  - test/fixtures/library.xml
72
+ - test/fixtures/node_with_attr_name_conflicts.xml
73
+ - test/fixtures/node_with_name_conflicts.xml
55
74
  - test/fixtures/nameless_ageless_youth.xml
56
75
  - test/fixtures/person_with_guarded_mothers.xml
57
76
  - test/fixtures/person_with_mothers.xml
data/lib/roxml/array.rb DELETED
@@ -1,15 +0,0 @@
1
- class Array
2
- # Translates an array into a hash, where each element of the array is
3
- # an array with 2 elements:
4
- #
5
- # >> [[:key, :value], [1, 2], ['key', 'value']].to_h
6
- # => {:key => :value, 1 => 2, 'key' => 'value}
7
- #
8
- def to_h
9
- returning({}) do |result|
10
- each do |(k, v)|
11
- result[k] = v
12
- end
13
- end
14
- end
15
- end
data/lib/roxml/string.rb DELETED
@@ -1,35 +0,0 @@
1
- # Extension of String class to handle conversion from/to
2
- # UTF-8/ISO-8869-1
3
- class Object
4
- require 'iconv'
5
-
6
- #
7
- # Return an utf-8 representation of this string.
8
- #
9
- def to_utf
10
- begin
11
- Iconv.new("utf-8", "iso-8859-1").iconv(to_s)
12
- rescue Iconv::IllegalSequence
13
- STDERR << "!! Failed converting from UTF-8 -> ISO-8859-1 (#{self}). Already the right charset?"
14
- self
15
- end
16
- end
17
-
18
- #
19
- # Convert this string to iso-8850-1
20
- #
21
- def to_latin
22
- begin
23
- Iconv.new("iso-8859-1", "utf-8").iconv(to_s)
24
- rescue Iconv::IllegalSequence
25
- STDERR << "!! Failed converting from ISO-8859-1 -> UTF-8 (#{self}). Already the right charset?"
26
- self
27
- end
28
- end
29
- end
30
-
31
- class String
32
- def between(separator, &block)
33
- split(separator).collect(&block).join(separator)
34
- end
35
- end