Empact-roxml 2.3.0 → 2.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  require 'rubygems'
2
+ require 'active_support/core_ext/symbol'
2
3
  require 'active_support/core_ext/blank'
3
4
  require 'active_support/core_ext/duplicable'
4
5
  require 'active_support/core_ext/array/extract_options'
@@ -10,6 +11,7 @@ require 'active_support/inflector'
10
11
  require 'active_support/core_ext/string/inflections'
11
12
  require 'active_support/core_ext/string/starts_ends_with'
12
13
 
14
+ require 'extensions/enumerable'
13
15
  require 'extensions/array'
14
16
 
15
17
  class Module
data/roxml.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "roxml"
3
3
  s.summary = "Ruby Object to XML mapping library"
4
- s.version = "2.3.0"
4
+ s.version = "2.3.1"
5
5
  s.homepage = "http://roxml.rubyforge.org"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
@@ -45,41 +45,54 @@ Gem::Specification.new do |s|
45
45
  'test/fixtures/dictionary_of_texts.xml',
46
46
  'test/fixtures/library_uppercase.xml',
47
47
  'test/fixtures/library.xml',
48
+ 'test/fixtures/muffins.xml',
48
49
  'test/fixtures/node_with_attr_name_conflicts.xml',
49
50
  'test/fixtures/node_with_name_conflicts.xml',
50
51
  'test/fixtures/nameless_ageless_youth.xml',
52
+ 'test/fixtures/numerology.xml',
51
53
  'test/fixtures/person_with_guarded_mothers.xml',
52
54
  'test/fixtures/person_with_mothers.xml',
53
55
  'test/fixtures/person.xml',
54
56
  'test/mocks/mocks.rb',
55
57
  'test/mocks/dictionaries.rb',
58
+ 'test/release/dependencies_test.rb',
56
59
  'test/test_helper.rb',
60
+ 'test/unit/inheritance_test.rb',
57
61
  'test/unit/options_test.rb',
58
62
  'test/unit/roxml_test.rb',
59
63
  'test/unit/string_test.rb',
60
64
  'test/unit/to_xml_test.rb',
61
65
  'test/unit/xml_attribute_test.rb',
66
+ 'test/unit/xml_block_test.rb',
67
+ 'test/unit/xml_bool_test.rb',
62
68
  'test/unit/xml_construct_test.rb',
63
69
  'test/unit/xml_hash_test.rb',
70
+ 'test/unit/xml_initialize_test.rb',
64
71
  'test/unit/xml_name_test.rb',
65
72
  'test/unit/xml_namespace_test.rb',
66
73
  'test/unit/xml_object_test.rb',
74
+ 'test/unit/xml_required_test.rb',
67
75
  'test/unit/xml_text_test.rb']
68
76
  s.requirements << 'none'
69
77
  s.add_dependency 'extensions', '>= 0.6.0'
70
78
  s.add_dependency 'activesupport', '>= 2.0.0'
71
79
  s.require_path = 'lib'
72
80
  s.test_files = [
81
+ 'test/unit/inheritance_test.rb',
73
82
  'test/unit/options_test.rb',
74
83
  'test/unit/roxml_test.rb',
75
84
  'test/unit/string_test.rb',
76
85
  'test/unit/to_xml_test.rb',
77
86
  'test/unit/xml_attribute_test.rb',
87
+ 'test/unit/xml_block_test.rb',
88
+ 'test/unit/xml_bool_test.rb',
78
89
  'test/unit/xml_construct_test.rb',
79
90
  'test/unit/xml_hash_test.rb',
91
+ 'test/unit/xml_initialize_test.rb',
80
92
  'test/unit/xml_name_test.rb',
81
93
  'test/unit/xml_namespace_test.rb',
82
94
  'test/unit/xml_object_test.rb',
95
+ 'test/unit/xml_required_test.rb',
83
96
  'test/unit/xml_text_test.rb']
84
97
  s.has_rdoc = true
85
98
  s.description = <<EOF
@@ -0,0 +1,3 @@
1
+ <muffins>
2
+ <bakers_dozens>3</bakers_dozens>
3
+ </muffins>
@@ -0,0 +1,4 @@
1
+ <numerology>
2
+ <prediction number="13" meaning="A bad number" />
3
+ <prediction number="7" meaning="A good number" />
4
+ </numerology>
@@ -0,0 +1,32 @@
1
+ require 'test/unit'
2
+
3
+ class TestDependencies < Test::Unit::TestCase
4
+ def assert_dependency_included(*args)
5
+ # assert methods are removed
6
+ args.each do |type, method, source|
7
+ type.send(:remove_method, method) if type.instance_methods.include?(method.to_s)
8
+ assert !type.instance_methods.include?(method.to_s)
9
+ end
10
+
11
+ load File.join(File.dirname(__FILE__), '../../lib/roxml.rb')
12
+
13
+ # assert_instance_methods returned to their rightful positions
14
+ args.each do |type, method, source|
15
+ assert type.instance_methods.include?(method.to_s)
16
+ end
17
+
18
+ #assert ROXML has what it needs
19
+ assert_nothing_raised do
20
+ Class.new do
21
+ include ROXML
22
+
23
+ xml_reader :deps
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_symbol_to_proc_is_added_by_roxml
29
+ assert_dependency_included([Symbol, :to_proc, 'active_support/core_ext/symbol.rb'],
30
+ [Enumerable, :one?, 'extensions/enumerable.rb'])
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class TestInheritance < Test::Unit::TestCase
4
+ def setup
5
+ @b = InheritedBookWithDepth.from_xml(fixture(:book_with_depth))
6
+ end
7
+
8
+ def test_inherited_object_should_include_parents_attributes
9
+ assert_equal '0201710897', @b.isbn
10
+ assert_equal 'The PickAxe', @b.title
11
+ assert_equal 'Probably the best Ruby book out there', @b.description
12
+ assert_equal 'David Thomas, Andrew Hunt, Dave Thomas', @b.author
13
+ assert_equal 0, @b.pages
14
+ end
15
+
16
+ def test_inherited_object_should_include_its_own_attributes
17
+ assert_equal '11.3 meters', @b.depth.to_s
18
+ end
19
+ end
@@ -0,0 +1,81 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class ArrayWithBlockShorthand
4
+ include ROXML
5
+
6
+ xml_reader :array, [:text], :from => 'number', :as => Integer
7
+ end
8
+
9
+ class ArrayWithBlock
10
+ include ROXML
11
+
12
+ xml_reader :array, [:text], :from => 'number' do |arr|
13
+ arr.map(&:to_i).reverse
14
+ end
15
+ end
16
+
17
+ class TestXMLBlocks < Test::Unit::TestCase
18
+ def test_block_is_applied
19
+ muffins = Muffins.from_xml(fixture(:muffins))
20
+
21
+ assert muffins.count > 0
22
+ assert_equal 0, muffins.count % 13
23
+ end
24
+
25
+ def test_block_is_applied_to_hash
26
+ numerology = Numerology.from_xml(fixture(:numerology))
27
+
28
+ assert !numerology.predictions.keys.empty?
29
+ assert numerology.predictions.keys.all? {|k| k.is_a? Integer }
30
+ assert numerology.predictions.values.all? {|k| k.is_a? String }
31
+ end
32
+
33
+ def test_stacked_blocks_are_applied
34
+ muffins = MuffinsWithStackedBlocks.from_xml(fixture(:muffins))
35
+
36
+ assert muffins.count > 0
37
+ assert_equal 0, muffins.count % 13
38
+ end
39
+
40
+ def test_block_shorthand_applied_properly_to_array
41
+ obj = ArrayWithBlockShorthand.from_xml(%{
42
+ <array_with_block_shorthand>
43
+ <number>1</number>
44
+ <number>2</number>
45
+ <number>3</number>
46
+ </array_with_block_shorthand>
47
+ })
48
+
49
+ assert_equal [1, 2, 3], obj.array
50
+ end
51
+
52
+ def test_block_applied_properly_to_array
53
+ obj = ArrayWithBlock.from_xml(%{
54
+ <array_with_block>
55
+ <number>1</number>
56
+ <number>2</number>
57
+ <number>3</number>
58
+ </array_with_block>
59
+ })
60
+
61
+ assert_equal [3, 2, 1], obj.array
62
+ end
63
+
64
+ def test_block_shorthand_applied_properly_to_empty_array
65
+ obj = ArrayWithBlockShorthand.from_xml(%{
66
+ <array_with_block_shorthand>
67
+ </array_with_block_shorthand>
68
+ })
69
+
70
+ assert_equal [], obj.array
71
+ end
72
+
73
+ def test_block_applied_properly_to_empty_array
74
+ obj = ArrayWithBlock.from_xml(%{
75
+ <array_with_block>
76
+ </array_with_block>
77
+ })
78
+
79
+ assert_equal [], obj.array
80
+ end
81
+ end
@@ -0,0 +1,104 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class XmlBool
4
+ include ROXML
5
+
6
+ xml_reader :true_from_TRUE?
7
+ xml_reader :false_from_FALSE?, :text => 'text_for_FALSE'
8
+ xml_reader :true_from_one?, :attr => 'attr_for_one'
9
+ xml_reader :false_from_zero?, :text => 'text_for_zero', :in => 'container'
10
+ xml_reader :true_from_True?, :attr => 'attr_for_True', :in => 'container'
11
+ xml_reader :false_from_False?, :text => 'false_from_cdata_False', :as => :cdata
12
+ xml_reader :true_from_true?
13
+ xml_reader :false_from_false?
14
+ xml_reader :missing?
15
+ end
16
+
17
+ class XmlBoolRequired
18
+ include ROXML
19
+
20
+ xml_reader :required?, :required => true
21
+ end
22
+
23
+ class XmlBoolUnexpected
24
+ include ROXML
25
+
26
+ xml_reader :unexpected?
27
+ end
28
+
29
+ class XmlBoolUnexpectedWithBlock
30
+ include ROXML
31
+
32
+ xml_reader :unexpected? do |val|
33
+ val
34
+ end
35
+ end
36
+
37
+ class TestXMLBool < Test::Unit::TestCase
38
+ def setup
39
+ @bool_xml = %{
40
+ <xml_bool attr_for_one="1">
41
+ <true_from_TRUE>TRUE</true_from_TRUE>
42
+ <text_for_FALSE>FALSE</text_for_FALSE>
43
+ <container attr_for_True="True">
44
+ <text_for_zero>0</text_for_zero>
45
+ </container>
46
+ <false_from_cdata_False><![CDATA[False]]></false_from_cdata_False>
47
+ <true_from_true>true</true_from_true>
48
+ <false_from_false>false</false_from_false>
49
+ <present_and_required>true</present_and_required>
50
+ </xml_bool>
51
+ }
52
+ @present = %{
53
+ <xml_bool_required>
54
+ <required>true</required>
55
+ </xml_bool_required>
56
+ }
57
+ @absent = %{
58
+ <xml_bool_required>
59
+ </xml_bool_required>
60
+ }
61
+ @unexpected_value_xml = %{
62
+ <xml_bool_unexpected>
63
+ <unexpected>Unexpected Value</unexpected>
64
+ </xml_bool_unexpected>
65
+ }
66
+ end
67
+
68
+ def test_bool_results_for_various_inputs
69
+ x = XmlBool.from_xml(@bool_xml)
70
+ assert_equal true, x.true_from_TRUE?
71
+ assert_equal false, x.false_from_FALSE?
72
+ assert_equal true, x.true_from_one?
73
+ assert_equal false, x.false_from_zero?
74
+ assert_equal true, x.true_from_True?
75
+ assert_equal false, x.false_from_False?
76
+ assert_equal true, x.true_from_true?
77
+ assert_equal false, x.false_from_false?
78
+ end
79
+
80
+ def test_missing_results_in_nil
81
+ x = XmlBool.from_xml(@bool_xml)
82
+ assert_equal nil, x.missing?
83
+ end
84
+
85
+ def test_unexpected_value_results_in_nil
86
+ x = XmlBoolUnexpected.from_xml(@unexpected_value_xml)
87
+ assert_equal nil, x.unexpected?
88
+ end
89
+
90
+ def test_block_recieves_unexpected_value_rather_than_nil
91
+ x = XmlBoolUnexpectedWithBlock.from_xml(@unexpected_value_xml)
92
+ assert_equal "Unexpected Value", x.unexpected?
93
+ end
94
+
95
+ def test_required_raises_on_missing
96
+ assert_nothing_raised do
97
+ XmlBoolRequired.from_xml(@present)
98
+ end
99
+
100
+ assert_raises(ROXML::RequiredElementMissing) do
101
+ XmlBoolRequired.from_xml(@absent)
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,50 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class BookWithXmlInitialize < BookWithDepth
4
+ attr_reader :created_at, :creator
5
+
6
+ def initialize(created_at, creator = "Unknown")
7
+ @created_at = created_at
8
+ @creator = creator
9
+ end
10
+ alias_method :xml_initialize, :initialize
11
+ end
12
+
13
+ class TestXMLInitialize < Test::Unit::TestCase
14
+ def test_xml_construct_not_in_use
15
+ assert Measurement.xml_construction_args_without_deprecation.empty?
16
+ end
17
+
18
+ def test_initialize_is_run
19
+ m = Measurement.from_xml('<measurement units="hundredths-meters">1130</measurement>')
20
+ assert_equal 11.3, m.value
21
+ assert_equal 'meters', m.units
22
+ end
23
+
24
+ def test_initialize_is_run_for_nested_type
25
+ b = BookWithDepth.from_xml(fixture(:book_with_depth))
26
+ assert_equal Measurement.new(11.3, 'meters'), b.depth
27
+ end
28
+
29
+ def test_initialize_is_run_for_nested_type_with_inheritance
30
+ b = InheritedBookWithDepth.from_xml(fixture(:book_with_depth))
31
+ assert_equal Measurement.new(11.3, 'meters'), b.depth
32
+ end
33
+
34
+ def test_initialize_fails_on_missing_required_arg
35
+ assert_raises(ArgumentError) do
36
+ b = BookWithXmlInitialize.from_xml(fixture(:book_with_depth))
37
+ end
38
+ end
39
+
40
+ def test_initialize_with_extra_args
41
+ now = Time.now
42
+ b = BookWithXmlInitialize.from_xml(fixture(:book_with_depth), now)
43
+ assert_equal now, b.created_at
44
+ assert_equal "Unknown", b.creator
45
+
46
+ b = BookWithXmlInitialize.from_xml(fixture(:book_with_depth), Time.now, "Joe Librarian")
47
+ assert now < b.created_at
48
+ assert_equal "Joe Librarian", b.creator
49
+ end
50
+ end
@@ -0,0 +1,93 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ class TestXMLRequired < Test::Unit::TestCase
4
+ def setup
5
+ @full_book = <<BOOK
6
+ <book ISBN="1234">
7
+ <title>This &amp; that</title>
8
+ <contributor_array>
9
+ <contributor role="Author">
10
+ <name>Johnny</name>
11
+ </contributor>
12
+ </contributor_array>
13
+ <contributor_hash>
14
+ <contributor role="Author" name="Johnny" />
15
+ </contributor_hash>
16
+ </book>
17
+ BOOK
18
+
19
+ @book_missing_attr = <<BOOK
20
+ <book>
21
+ <title>This &amp; that</title>
22
+ <contributor_array>
23
+ <contributor role="Author">
24
+ <name>Johnny</name>
25
+ </contributor>
26
+ </contributor_array>
27
+ <contributor_hash>
28
+ <contributor role="Author" name="Johnny" />
29
+ </contributor_hash>
30
+ </book>
31
+ BOOK
32
+
33
+ @book_missing_text = <<BOOK
34
+ <book ISBN="1234">
35
+ <contributor_array>
36
+ <contributor role="Author">
37
+ <name>Johnny</name>
38
+ </contributor>
39
+ </contributor_array>
40
+ <contributor_hash>
41
+ <contributor role="Author" name="Johnny" />
42
+ </contributor_hash>
43
+ </book>
44
+ BOOK
45
+
46
+ @book_missing_array = <<BOOK
47
+ <book ISBN="1234">
48
+ <title>This &amp; that</title>
49
+ <contributor_hash>
50
+ <contributor role="Author" name="Johnny" />
51
+ </contributor_hash>
52
+ </book>
53
+ BOOK
54
+
55
+ @book_missing_hash = <<BOOK
56
+ <book ISBN="1234">
57
+ <title>This &amp; that</title>
58
+ <contributor_array>
59
+ <contributor role="Author">
60
+ <name>Johnny</name>
61
+ </contributor>
62
+ </contributor_array>
63
+ </book>
64
+ BOOK
65
+ end
66
+
67
+ def test_required_passes_on_prescence
68
+ BookWithRequired.from_xml(@full_book)
69
+ end
70
+
71
+ def test_required_throws_on_attr_absence
72
+ assert_raise ROXML::RequiredElementMissing do
73
+ BookWithRequired.from_xml(@book_missing_attr)
74
  end
75
+ end
76
+
77
+ def test_required_throws_on_text_absence
78
+ assert_raise ROXML::RequiredElementMissing do
79
+ BookWithRequired.from_xml(@book_missing_text)
80
+ end
81
+ end
82
+
83
+ def test_required_throws_on_array_absence
84
+ assert_raise ROXML::RequiredElementMissing do
85
+ BookWithRequired.from_xml(@book_missing_array)
86
+ end
87
+ end
88
+
89
+ def test_required_throws_on_hash_absence
90
+ assert_raise ROXML::RequiredElementMissing do
91
+ BookWithRequired.from_xml(@book_missing_hash)
92
+ end
93
+ end
94
+ 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.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Woosley
@@ -79,25 +79,33 @@ files:
79
79
  - test/fixtures/dictionary_of_texts.xml
80
80
  - test/fixtures/library_uppercase.xml
81
81
  - test/fixtures/library.xml
82
+ - test/fixtures/muffins.xml
82
83
  - test/fixtures/node_with_attr_name_conflicts.xml
83
84
  - test/fixtures/node_with_name_conflicts.xml
84
85
  - test/fixtures/nameless_ageless_youth.xml
86
+ - test/fixtures/numerology.xml
85
87
  - test/fixtures/person_with_guarded_mothers.xml
86
88
  - test/fixtures/person_with_mothers.xml
87
89
  - test/fixtures/person.xml
88
90
  - test/mocks/mocks.rb
89
91
  - test/mocks/dictionaries.rb
92
+ - test/release/dependencies_test.rb
90
93
  - test/test_helper.rb
94
+ - test/unit/inheritance_test.rb
91
95
  - test/unit/options_test.rb
92
96
  - test/unit/roxml_test.rb
93
97
  - test/unit/string_test.rb
94
98
  - test/unit/to_xml_test.rb
95
99
  - test/unit/xml_attribute_test.rb
100
+ - test/unit/xml_block_test.rb
101
+ - test/unit/xml_bool_test.rb
96
102
  - test/unit/xml_construct_test.rb
97
103
  - test/unit/xml_hash_test.rb
104
+ - test/unit/xml_initialize_test.rb
98
105
  - test/unit/xml_name_test.rb
99
106
  - test/unit/xml_namespace_test.rb
100
107
  - test/unit/xml_object_test.rb
108
+ - test/unit/xml_required_test.rb
101
109
  - test/unit/xml_text_test.rb
102
110
  has_rdoc: true
103
111
  homepage: http://roxml.rubyforge.org
@@ -126,14 +134,19 @@ signing_key:
126
134
  specification_version: 2
127
135
  summary: Ruby Object to XML mapping library
128
136
  test_files:
137
+ - test/unit/inheritance_test.rb
129
138
  - test/unit/options_test.rb
130
139
  - test/unit/roxml_test.rb
131
140
  - test/unit/string_test.rb
132
141
  - test/unit/to_xml_test.rb
133
142
  - test/unit/xml_attribute_test.rb
143
+ - test/unit/xml_block_test.rb
144
+ - test/unit/xml_bool_test.rb
134
145
  - test/unit/xml_construct_test.rb
135
146
  - test/unit/xml_hash_test.rb
147
+ - test/unit/xml_initialize_test.rb
136
148
  - test/unit/xml_name_test.rb
137
149
  - test/unit/xml_namespace_test.rb
138
150
  - test/unit/xml_object_test.rb
151
+ - test/unit/xml_required_test.rb
139
152
  - test/unit/xml_text_test.rb