roxml 2.5.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.gitmodules +3 -0
- data/History.txt +38 -1
- data/README.rdoc +8 -5
- data/Rakefile +35 -36
- data/TODO +12 -35
- data/VERSION +1 -0
- data/examples/amazon.rb +8 -6
- data/examples/posts.rb +1 -1
- data/examples/{active_record.rb → rails.rb} +2 -2
- data/examples/twitter.rb +1 -1
- data/lib/roxml.rb +86 -151
- data/lib/roxml/definition.rb +64 -152
- data/lib/roxml/hash_definition.rb +5 -40
- data/lib/roxml/xml.rb +12 -9
- data/lib/roxml/xml/parsers/libxml.rb +22 -17
- data/lib/roxml/xml/parsers/nokogiri.rb +77 -0
- data/lib/roxml/xml/references.rb +66 -57
- data/roxml.gemspec +170 -19
- data/spec/definition_spec.rb +121 -198
- data/spec/examples/active_record_spec.rb +2 -2
- data/spec/examples/amazon_spec.rb +3 -2
- data/spec/examples/current_weather_spec.rb +2 -2
- data/spec/examples/dashed_elements_spec.rb +2 -2
- data/spec/examples/library_spec.rb +11 -6
- data/spec/examples/post_spec.rb +3 -3
- data/spec/examples/twitter_spec.rb +2 -2
- data/spec/roxml_spec.rb +15 -15
- data/spec/shared_specs.rb +1 -1
- data/spec/spec_helper.rb +8 -27
- data/spec/support/libxml.rb +3 -0
- data/spec/support/nokogiri.rb +3 -0
- data/spec/xml/attributes_spec.rb +36 -0
- data/spec/xml/namespace_spec.rb +240 -0
- data/spec/xml/namespaces_spec.rb +32 -0
- data/spec/xml/parser_spec.rb +9 -30
- data/tasks/rdoc.rake +13 -0
- data/tasks/rspec.rake +21 -17
- data/tasks/test.rake +13 -20
- data/test/mocks/dictionaries.rb +8 -7
- data/test/mocks/mocks.rb +20 -20
- data/test/support/fixtures.rb +11 -0
- data/test/test_helper.rb +3 -14
- data/test/unit/definition_test.rb +21 -95
- data/test/unit/deprecations_test.rb +1 -74
- data/test/unit/to_xml_test.rb +3 -3
- data/test/unit/xml_attribute_test.rb +1 -1
- data/test/unit/xml_block_test.rb +3 -3
- data/test/unit/xml_bool_test.rb +4 -4
- data/test/unit/xml_convention_test.rb +3 -3
- data/test/unit/xml_hash_test.rb +5 -14
- data/test/unit/xml_initialize_test.rb +2 -6
- data/test/unit/xml_name_test.rb +5 -24
- data/test/unit/xml_namespace_test.rb +1 -46
- data/test/unit/xml_object_test.rb +6 -6
- data/test/unit/xml_required_test.rb +3 -2
- data/test/unit/xml_text_test.rb +2 -2
- data/website/index.html +1 -1
- metadata +68 -51
- data/Manifest.txt +0 -106
- data/lib/roxml/extensions.rb +0 -6
- data/lib/roxml/extensions/array.rb +0 -13
- data/lib/roxml/extensions/array/conversions.rb +0 -35
- data/lib/roxml/extensions/deprecation.rb +0 -33
- data/lib/roxml/extensions/string.rb +0 -21
- data/lib/roxml/extensions/string/conversions.rb +0 -43
- data/lib/roxml/extensions/string/iterators.rb +0 -12
- data/lib/roxml/xml/parsers/rexml.rb +0 -84
- data/spec/string_spec.rb +0 -15
- data/test/bugs/rexml_bugs.rb +0 -15
- data/test/release/dependencies_test.rb +0 -32
- data/test/unit/xml_construct_test.rb +0 -77
- data/vendor/override_rake_task/README +0 -30
- data/vendor/override_rake_task/init.rb +0 -1
- data/vendor/override_rake_task/install.rb +0 -46
- data/vendor/override_rake_task/lib/override_rake_task.rb +0 -16
data/Manifest.txt
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
MIT-LICENSE
|
3
|
-
Manifest.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
TODO
|
7
|
-
config/website.yml
|
8
|
-
examples/active_record.rb
|
9
|
-
examples/amazon.rb
|
10
|
-
examples/current_weather.rb
|
11
|
-
examples/dashed_elements.rb
|
12
|
-
examples/library.rb
|
13
|
-
examples/posts.rb
|
14
|
-
examples/twitter.rb
|
15
|
-
examples/xml/active_record.xml
|
16
|
-
examples/xml/amazon.xml
|
17
|
-
examples/xml/current_weather.xml
|
18
|
-
examples/xml/dashed_elements.xml
|
19
|
-
examples/xml/posts.xml
|
20
|
-
examples/xml/twitter.xml
|
21
|
-
lib/roxml.rb
|
22
|
-
lib/roxml/definition.rb
|
23
|
-
lib/roxml/extensions.rb
|
24
|
-
lib/roxml/extensions/array.rb
|
25
|
-
lib/roxml/extensions/array/conversions.rb
|
26
|
-
lib/roxml/extensions/deprecation.rb
|
27
|
-
lib/roxml/extensions/string.rb
|
28
|
-
lib/roxml/extensions/string/conversions.rb
|
29
|
-
lib/roxml/extensions/string/iterators.rb
|
30
|
-
lib/roxml/hash_definition.rb
|
31
|
-
lib/roxml/xml.rb
|
32
|
-
lib/roxml/xml/parsers/libxml.rb
|
33
|
-
lib/roxml/xml/parsers/rexml.rb
|
34
|
-
lib/roxml/xml/references.rb
|
35
|
-
roxml.gemspec
|
36
|
-
spec/definition_spec.rb
|
37
|
-
spec/examples/active_record_spec.rb
|
38
|
-
spec/examples/amazon_spec.rb
|
39
|
-
spec/examples/current_weather_spec.rb
|
40
|
-
spec/examples/dashed_elements_spec.rb
|
41
|
-
spec/examples/library_spec.rb
|
42
|
-
spec/examples/post_spec.rb
|
43
|
-
spec/examples/twitter_spec.rb
|
44
|
-
spec/roxml_spec.rb
|
45
|
-
spec/shared_specs.rb
|
46
|
-
spec/spec.opts
|
47
|
-
spec/spec_helper.rb
|
48
|
-
spec/string_spec.rb
|
49
|
-
spec/xml/parser_spec.rb
|
50
|
-
tasks/rspec.rake
|
51
|
-
tasks/test.rake
|
52
|
-
test/bugs/rexml_bugs.rb
|
53
|
-
test/fixtures/book_malformed.xml
|
54
|
-
test/fixtures/book_pair.xml
|
55
|
-
test/fixtures/book_text_with_attribute.xml
|
56
|
-
test/fixtures/book_valid.xml
|
57
|
-
test/fixtures/book_with_authors.xml
|
58
|
-
test/fixtures/book_with_contributions.xml
|
59
|
-
test/fixtures/book_with_contributors.xml
|
60
|
-
test/fixtures/book_with_contributors_attrs.xml
|
61
|
-
test/fixtures/book_with_default_namespace.xml
|
62
|
-
test/fixtures/book_with_depth.xml
|
63
|
-
test/fixtures/book_with_octal_pages.xml
|
64
|
-
test/fixtures/book_with_publisher.xml
|
65
|
-
test/fixtures/book_with_wrapped_attr.xml
|
66
|
-
test/fixtures/dictionary_of_attr_name_clashes.xml
|
67
|
-
test/fixtures/dictionary_of_attrs.xml
|
68
|
-
test/fixtures/dictionary_of_guarded_names.xml
|
69
|
-
test/fixtures/dictionary_of_mixeds.xml
|
70
|
-
test/fixtures/dictionary_of_name_clashes.xml
|
71
|
-
test/fixtures/dictionary_of_names.xml
|
72
|
-
test/fixtures/dictionary_of_texts.xml
|
73
|
-
test/fixtures/library.xml
|
74
|
-
test/fixtures/library_uppercase.xml
|
75
|
-
test/fixtures/muffins.xml
|
76
|
-
test/fixtures/nameless_ageless_youth.xml
|
77
|
-
test/fixtures/node_with_attr_name_conflicts.xml
|
78
|
-
test/fixtures/node_with_name_conflicts.xml
|
79
|
-
test/fixtures/numerology.xml
|
80
|
-
test/fixtures/person.xml
|
81
|
-
test/fixtures/person_with_guarded_mothers.xml
|
82
|
-
test/fixtures/person_with_mothers.xml
|
83
|
-
test/mocks/dictionaries.rb
|
84
|
-
test/mocks/mocks.rb
|
85
|
-
test/release/dependencies_test.rb
|
86
|
-
test/test_helper.rb
|
87
|
-
test/unit/definition_test.rb
|
88
|
-
test/unit/deprecations_test.rb
|
89
|
-
test/unit/to_xml_test.rb
|
90
|
-
test/unit/xml_attribute_test.rb
|
91
|
-
test/unit/xml_block_test.rb
|
92
|
-
test/unit/xml_bool_test.rb
|
93
|
-
test/unit/xml_construct_test.rb
|
94
|
-
test/unit/xml_convention_test.rb
|
95
|
-
test/unit/xml_hash_test.rb
|
96
|
-
test/unit/xml_initialize_test.rb
|
97
|
-
test/unit/xml_name_test.rb
|
98
|
-
test/unit/xml_namespace_test.rb
|
99
|
-
test/unit/xml_object_test.rb
|
100
|
-
test/unit/xml_required_test.rb
|
101
|
-
test/unit/xml_text_test.rb
|
102
|
-
vendor/override_rake_task/README
|
103
|
-
vendor/override_rake_task/init.rb
|
104
|
-
vendor/override_rake_task/install.rb
|
105
|
-
vendor/override_rake_task/lib/override_rake_task.rb
|
106
|
-
website/index.html
|
data/lib/roxml/extensions.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Enumerable #:nodoc:all
|
2
|
-
unless method_defined?(:one?)
|
3
|
-
def one?
|
4
|
-
size == 1
|
5
|
-
end
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
require File.join(File.dirname(__FILE__), 'array/conversions')
|
10
|
-
|
11
|
-
class Array #:nodoc:
|
12
|
-
include ROXML::CoreExtensions::Array::Conversions
|
13
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module ROXML
|
2
|
-
module CoreExtensions
|
3
|
-
module Array #:nodoc:all
|
4
|
-
module Conversions
|
5
|
-
# Translates an array into a hash, where each element of the array is
|
6
|
-
# an array with 2 elements:
|
7
|
-
#
|
8
|
-
# >> [[:key, :value], [1, 2], ['key', 'value']].to_h
|
9
|
-
# => {:key => :value, 1 => 2, 'key' => 'value'}
|
10
|
-
#
|
11
|
-
def to_hash
|
12
|
-
hash = inject({}) do |result, (k, v)|
|
13
|
-
result[k] ||= []
|
14
|
-
result[k] << v
|
15
|
-
result
|
16
|
-
end
|
17
|
-
hash.each_pair do |k, v|
|
18
|
-
hash[k] = v.first if v.one?
|
19
|
-
end
|
20
|
-
hash
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_h #:nodoc:
|
24
|
-
to_hash
|
25
|
-
end
|
26
|
-
deprecate :to_h => :to_hash
|
27
|
-
|
28
|
-
def apply_to(val)
|
29
|
-
# Only makes sense for arrays of blocks... maybe better outside Array...
|
30
|
-
inject(val) {|val, block| block.call(val) }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/kernel/reporting'
|
2
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
-
require 'active_support/deprecation'
|
4
|
-
require 'active_support/version'
|
5
|
-
|
6
|
-
module ActiveSupport # :nodoc:all
|
7
|
-
module Deprecation
|
8
|
-
class << self
|
9
|
-
def warn_with_internals_exclusion(message = nil, callstack = caller)
|
10
|
-
warn_without_internals_exclusion(message, callstack.reject {|line| line =~ /\/roxml(-[\d\.]+)?\/lib\// })
|
11
|
-
end
|
12
|
-
alias_method_chain :warn, :internals_exclusion
|
13
|
-
|
14
|
-
if VERSION::MAJOR <= 2 && VERSION::MINOR <= 1
|
15
|
-
def deprecation_message(callstack, message = nil)
|
16
|
-
message ||= "You are using deprecated behavior which will be removed from the next major or minor release"
|
17
|
-
"DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module ClassMethods
|
23
|
-
def deprecated_method_warning(method_name, message=nil)
|
24
|
-
warning = "#{method_name} is deprecated and will be removed from the next major or minor release"
|
25
|
-
case message
|
26
|
-
when Symbol then "#{warning}. (use #{message} instead)"
|
27
|
-
when String then "#{warning}. (#{message})"
|
28
|
-
else warning
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'string/conversions')
|
2
|
-
require File.join(File.dirname(__FILE__), 'string/iterators')
|
3
|
-
|
4
|
-
class String #:nodoc:
|
5
|
-
include ROXML::CoreExtensions::String::Conversions
|
6
|
-
include ROXML::CoreExtensions::String::Iterators
|
7
|
-
end
|
8
|
-
|
9
|
-
class Object #:nodoc:
|
10
|
-
# Deprecated in favor of explicit #to_s.to_utf
|
11
|
-
def to_utf
|
12
|
-
ActiveSupport::Deprecation.warn "This method will be removed from Object please use String#to_utf instead via explicit #to_s"
|
13
|
-
to_s.to_utf
|
14
|
-
end
|
15
|
-
|
16
|
-
# Deprecated in favor of explicit #to_s.to_latin
|
17
|
-
def to_latin
|
18
|
-
ActiveSupport::Deprecation.warn "This method will be removed from Object please use String#to_latin instead via explicit #to_s"
|
19
|
-
to_s.to_latin
|
20
|
-
end
|
21
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module ROXML
|
2
|
-
module CoreExtensions #:nodoc:
|
3
|
-
module String
|
4
|
-
# Extension of String class to handle conversion from/to
|
5
|
-
# UTF-8/ISO-8869-1
|
6
|
-
module Conversions
|
7
|
-
require 'iconv'
|
8
|
-
|
9
|
-
#
|
10
|
-
# Return an utf-8 representation of this string.
|
11
|
-
#
|
12
|
-
def to_utf
|
13
|
-
begin
|
14
|
-
Iconv.new("utf-8", "iso-8859-1").iconv(to_s)
|
15
|
-
rescue Iconv::IllegalSequence
|
16
|
-
STDERR << "!! Failed converting from UTF-8 -> ISO-8859-1 (#{self}). Already the right charset?"
|
17
|
-
self
|
18
|
-
end
|
19
|
-
end
|
20
|
-
deprecate :to_utf
|
21
|
-
|
22
|
-
#
|
23
|
-
# Convert this string to iso-8850-1
|
24
|
-
#
|
25
|
-
def to_latin
|
26
|
-
begin
|
27
|
-
Iconv.new("iso-8859-1", "utf-8").iconv(to_s)
|
28
|
-
rescue Iconv::IllegalSequence
|
29
|
-
STDERR << "!! Failed converting from ISO-8859-1 -> UTF-8 (#{self}). Already the right charset?"
|
30
|
-
self
|
31
|
-
end
|
32
|
-
end
|
33
|
-
deprecate :to_latin
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class String
|
40
|
-
def between(separator, &block)
|
41
|
-
split(separator).collect(&block).join(separator)
|
42
|
-
end
|
43
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module ROXML
|
2
|
-
module CoreExtensions
|
3
|
-
module String #:nodoc:all
|
4
|
-
module Iterators
|
5
|
-
# Allows you to iterate over and modify the sub-strings between _separator_. Returns the joined result of the modification.
|
6
|
-
def between(separator, &block)
|
7
|
-
split(separator).collect(&block).join(separator)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'rexml/document'
|
2
|
-
|
3
|
-
module ROXML
|
4
|
-
module XML # :nodoc:all
|
5
|
-
Document = REXML::Document
|
6
|
-
Node = REXML::Element
|
7
|
-
|
8
|
-
module Error
|
9
|
-
def self.reset_handler
|
10
|
-
# noop
|
11
|
-
end
|
12
|
-
end
|
13
|
-
[REXML::ParseException, REXML::UndefinedNamespaceException, REXML::Validation::ValidationException].each do |exception|
|
14
|
-
exception.send(:include, Error)
|
15
|
-
end
|
16
|
-
|
17
|
-
class Node
|
18
|
-
class << self
|
19
|
-
def new_cdata(content)
|
20
|
-
REXML::CData.new(content)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
alias_attribute :content, :text
|
25
|
-
|
26
|
-
def search(xpath)
|
27
|
-
begin
|
28
|
-
REXML::XPath.match(self, xpath)
|
29
|
-
rescue Exception => ex
|
30
|
-
raise ex, xpath
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def add_child(element)
|
35
|
-
if element.is_a?(REXML::CData)
|
36
|
-
REXML::CData.new(element, true, self)
|
37
|
-
else
|
38
|
-
add_element(element)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def ==(other)
|
43
|
-
to_s == other.to_s
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class Parser
|
48
|
-
class << self
|
49
|
-
def parse(source)
|
50
|
-
REXML::Document.new(source, :ignore_whitespace_nodes => :all)
|
51
|
-
end
|
52
|
-
|
53
|
-
def parse_file(path) #:nodoc:
|
54
|
-
path = path.sub('file:', '') if path.starts_with?('file:')
|
55
|
-
parse(open(path))
|
56
|
-
end
|
57
|
-
|
58
|
-
def parse_io(path) #:nodoc:
|
59
|
-
parse(path)
|
60
|
-
end
|
61
|
-
|
62
|
-
def register_error_handler(&block)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
ParseError = REXML::ParseException
|
66
|
-
end
|
67
|
-
|
68
|
-
class Document
|
69
|
-
delegate :search, :to => :root
|
70
|
-
|
71
|
-
def root=(node)
|
72
|
-
raise ArgumentError, "Root is already defined" if root
|
73
|
-
add(node)
|
74
|
-
end
|
75
|
-
|
76
|
-
def save(destination, opts = {:formatter => REXML::Formatters::Default.new})
|
77
|
-
self << REXML::XMLDecl.new unless xml_decl != REXML::XMLDecl.default # always output xml declaration
|
78
|
-
File.open(destination, "w") do |f|
|
79
|
-
opts[:formatter].write(self, f)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
data/spec/string_spec.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
-
|
3
|
-
describe String do
|
4
|
-
describe "#to_latin" do
|
5
|
-
it "should be accessible" do
|
6
|
-
"".should respond_to(:to_latin)
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "#to_utf" do
|
11
|
-
it "should be accessible" do
|
12
|
-
"".should respond_to(:to_utf)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
data/test/bugs/rexml_bugs.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class RexmlBugs < ActiveSupport::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
|
@@ -1,32 +0,0 @@
|
|
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
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
|
-
|
3
|
-
class MeasurementWithXmlConstruct
|
4
|
-
include ROXML
|
5
|
-
|
6
|
-
xml_reader :units, :from => :attr
|
7
|
-
xml_reader :value, :from => :content
|
8
|
-
|
9
|
-
xml_construct_without_deprecation :value, :units
|
10
|
-
|
11
|
-
def initialize(value, units = 'pixels')
|
12
|
-
@value = Float(value)
|
13
|
-
@units = units.to_s
|
14
|
-
if @units.starts_with? 'hundredths-'
|
15
|
-
@value /= 100
|
16
|
-
@units = @units.split('hundredths-')[1]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def ==(other)
|
21
|
-
other.units == @units && other.value == @value
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class BookWithDepthWithXmlConstruct
|
26
|
-
include ROXML
|
27
|
-
|
28
|
-
xml_reader :isbn, :from => '@ISBN'
|
29
|
-
xml_reader :title
|
30
|
-
xml_reader :description, :cdata => true
|
31
|
-
xml_reader :author
|
32
|
-
xml_reader :depth, MeasurementWithXmlConstruct
|
33
|
-
end
|
34
|
-
|
35
|
-
class InheritedBookWithDepthWithXmlConstruct < Book
|
36
|
-
xml_reader :depth, MeasurementWithXmlConstruct
|
37
|
-
end
|
38
|
-
|
39
|
-
class TestXMLConstruct < ActiveSupport::TestCase
|
40
|
-
def test_is_deprecated
|
41
|
-
assert_deprecated do
|
42
|
-
MeasurementWithXmlConstruct.xml_construction_args
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_initialize_is_run
|
47
|
-
m = MeasurementWithXmlConstruct.from_xml('<measurement units="hundredths-meters">1130</measurement>')
|
48
|
-
assert_equal 11.3, m.value
|
49
|
-
assert_equal 'meters', m.units
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_initialize_is_run_for_nested_type
|
53
|
-
b = BookWithDepthWithXmlConstruct.from_xml(fixture(:book_with_depth))
|
54
|
-
assert_equal Measurement.new(11.3, 'meters'), b.depth
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_initialize_is_run_for_nested_type_with_inheritance
|
58
|
-
b = InheritedBookWithDepthWithXmlConstruct.from_xml(fixture(:book_with_depth))
|
59
|
-
assert_equal Measurement.new(11.3, 'meters'), b.depth
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_xml_name_uses_accessor_not_name
|
63
|
-
assert_nothing_raised do
|
64
|
-
Class.new do
|
65
|
-
include ROXML
|
66
|
-
|
67
|
-
xml_reader :bar, :from => '@Foo'
|
68
|
-
xml_reader :foo, :text => 'Foo'
|
69
|
-
xml_reader :baz, :from => '@Bar'
|
70
|
-
|
71
|
-
xml_construct_without_deprecation :baz, :bar, :foo
|
72
|
-
def initialize(baz, bar, foo)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|