forked from andreyberya/xml-mapping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritance_test.rb
50 lines (39 loc) · 1.03 KB
/
inheritance_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require File.dirname(__FILE__)+"/tests_init"
require 'test/unit'
require 'xml/mapping'
require 'xml/xxpath_methods'
class Base
attr_accessor :baseinit
def initialize(p)
self.baseinit = p
end
end
class Derived < Base
include XML::Mapping
text_node :mytext, "mytext"
end
class Derived2 < Base
include XML::Mapping
text_node :baseinit, "baseinit"
end
# test that tries to reproduce ticket #4783
class InheritanceTest < Test::Unit::TestCase
def test_inheritance_simple
d = Derived.new "foo"
assert_equal "foo", d.baseinit
d.mytext = "hello"
dxml=d.save_to_xml
assert_equal "hello", dxml.first_xpath("mytext").text
d2 = Derived.load_from_xml(dxml)
assert_nil d2.baseinit
assert_equal "hello", d2.mytext
end
def test_inheritance_superclass_initializing_mappedattr
d = Derived2.new "foo"
assert_equal "foo", d.baseinit
dxml=d.save_to_xml
assert_equal "foo", dxml.first_xpath("baseinit").text
d2 = Derived2.load_from_xml(dxml)
assert_equal "foo", d2.baseinit
end
end