Empact-roxml 2.5.1 → 2.5.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.
- data/History.txt +25 -0
- data/Manifest.txt +0 -4
- data/README.rdoc +12 -2
- data/examples/posts.rb +1 -1
- data/examples/twitter.rb +1 -1
- data/lib/roxml.rb +59 -149
- data/lib/roxml/definition.rb +60 -150
- data/lib/roxml/extensions.rb +4 -1
- data/lib/roxml/extensions/array/conversions.rb +0 -23
- data/lib/roxml/extensions/deprecation.rb +1 -1
- data/lib/roxml/extensions/string.rb +0 -15
- data/lib/roxml/extensions/string/conversions.rb +0 -38
- data/lib/roxml/hash_definition.rb +5 -40
- data/lib/roxml/xml/references.rb +20 -8
- data/roxml.gemspec +4 -4
- data/spec/definition_spec.rb +120 -193
- data/spec/examples/library_spec.rb +8 -3
- data/spec/examples/post_spec.rb +1 -1
- data/spec/roxml_spec.rb +14 -14
- data/test/bugs/rexml_bugs.rb +1 -1
- data/test/mocks/dictionaries.rb +8 -7
- data/test/mocks/mocks.rb +19 -19
- data/test/test_helper.rb +1 -0
- data/test/unit/definition_test.rb +22 -96
- data/test/unit/deprecations_test.rb +1 -74
- data/test/unit/to_xml_test.rb +6 -6
- 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 +2 -2
- data/test/unit/xml_object_test.rb +5 -5
- data/test/unit/xml_required_test.rb +1 -1
- data/test/unit/xml_text_test.rb +2 -2
- metadata +12 -17
- data/lib/roxml/extensions/active_support.rb +0 -54
- data/spec/string_spec.rb +0 -15
- data/test/release/dependencies_test.rb +0 -32
- data/test/unit/xml_construct_test.rb +0 -77
@@ -22,13 +22,18 @@ describe Library do
|
|
22
22
|
|
23
23
|
context "when written to a file" do
|
24
24
|
before :all do
|
25
|
+
@path = "spec/examples/library.xml"
|
25
26
|
@doc = ROXML::XML::Document.new
|
26
27
|
@doc.root = @lib.to_xml
|
27
|
-
@doc.save(
|
28
|
+
@doc.save(@path)
|
28
29
|
end
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
after :all do
|
32
|
+
FileUtils.rm @path
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be contain the expected xml" do
|
36
|
+
ROXML::XML::Parser.parse(File.read(@path)).to_s.should == ROXML::XML::Parser.parse(%{<?xml version="1.0"?><library><NAME><![CDATA[Favorite Books]]></NAME><novel ISBN='0201710897'><title>The PickAxe</title><description><![CDATA[Best Ruby book out there!]]></description><author>David Thomas, Andrew Hunt, Dave Thomas</author><publisher><name>Addison Wesley Longman, Inc.</name></publisher></novel></library>}).to_s
|
32
37
|
end
|
33
38
|
|
34
39
|
it "should be re-parsable via .from_xml" do
|
data/spec/examples/post_spec.rb
CHANGED
data/spec/roxml_spec.rb
CHANGED
@@ -53,8 +53,8 @@ describe ROXML, "#xml" do
|
|
53
53
|
xml_name :book
|
54
54
|
xml_reader :isbn, :from => :attr
|
55
55
|
xml_reader :title
|
56
|
-
xml_reader :description, DescriptionReadonly
|
57
|
-
xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions"
|
56
|
+
xml_reader :description, :as => DescriptionReadonly
|
57
|
+
xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions"
|
58
58
|
end
|
59
59
|
|
60
60
|
class BookWithContributionsReadonly
|
@@ -63,8 +63,8 @@ describe ROXML, "#xml" do
|
|
63
63
|
xml_name :book
|
64
64
|
xml_reader :isbn, :from => :attr, :frozen => true
|
65
65
|
xml_reader :title, :frozen => true
|
66
|
-
xml_reader :description, DescriptionReadonly, :frozen => true
|
67
|
-
xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions", :frozen => true
|
66
|
+
xml_reader :description, :as => DescriptionReadonly, :frozen => true
|
67
|
+
xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions", :frozen => true
|
68
68
|
end
|
69
69
|
|
70
70
|
before do
|
@@ -106,7 +106,7 @@ describe ROXML, "#xml" do
|
|
106
106
|
include ROXML
|
107
107
|
|
108
108
|
xml_accessor :pages_with_as, :as => Integer, :to_xml => proc {|val| sprintf("%#o", val) }, :required => true
|
109
|
-
xml_accessor :pages_with_type, OctalInteger, :required => true
|
109
|
+
xml_accessor :pages_with_type, :as => OctalInteger, :required => true
|
110
110
|
end
|
111
111
|
|
112
112
|
# to_xml_test :book_with_octal_pages
|
@@ -148,7 +148,7 @@ describe ROXML, "#xml" do
|
|
148
148
|
class BookWithOctalPagesType
|
149
149
|
include ROXML
|
150
150
|
|
151
|
-
xml_accessor :pages, OctalInteger, :required => true
|
151
|
+
xml_accessor :pages, :as => OctalInteger, :required => true
|
152
152
|
end
|
153
153
|
|
154
154
|
it "should apply filtering on input" do
|
@@ -216,7 +216,7 @@ describe ROXML, "#xml" do
|
|
216
216
|
xml_reader :isbn, :from => :attr
|
217
217
|
xml_reader :title
|
218
218
|
xml_reader :description
|
219
|
-
xml_reader :contributors, [Contributor]
|
219
|
+
xml_reader :contributors, :as => [Contributor]
|
220
220
|
end
|
221
221
|
|
222
222
|
it "should look for elements :in the plural of name" do
|
@@ -239,7 +239,7 @@ describe ROXML, "#xml" do
|
|
239
239
|
include ROXML
|
240
240
|
|
241
241
|
xml_name :dictionary
|
242
|
-
xml_reader :definitions, {:key => :name,
|
242
|
+
xml_reader :definitions, :as => {:key => :name,
|
243
243
|
:value => :content}, :in => :definitions
|
244
244
|
end
|
245
245
|
|
@@ -247,7 +247,7 @@ describe ROXML, "#xml" do
|
|
247
247
|
include ROXML
|
248
248
|
|
249
249
|
xml_name :dictionary
|
250
|
-
xml_reader :definitions, {:key => :name,
|
250
|
+
xml_reader :definitions, :as => {:key => :name,
|
251
251
|
:value => :content}, :in => :definitions, :frozen => true
|
252
252
|
end
|
253
253
|
|
@@ -274,11 +274,11 @@ describe ROXML, "inheritance" do
|
|
274
274
|
class Book
|
275
275
|
include ROXML
|
276
276
|
|
277
|
-
xml_accessor :isbn, :
|
277
|
+
xml_accessor :isbn, :from => '@ISBN'
|
278
278
|
xml_reader :title
|
279
|
-
xml_reader :description, :
|
279
|
+
xml_reader :description, :cdata => true
|
280
280
|
xml_reader :author
|
281
|
-
xml_accessor :pages, :
|
281
|
+
xml_accessor :pages, :from => 'pagecount', :as => Integer
|
282
282
|
end
|
283
283
|
|
284
284
|
class Measurement
|
@@ -315,7 +315,7 @@ describe ROXML, "inheritance" do
|
|
315
315
|
end
|
316
316
|
|
317
317
|
class InheritedBookWithDepth < Book
|
318
|
-
xml_reader :depth, Measurement
|
318
|
+
xml_reader :depth, :as => Measurement
|
319
319
|
end
|
320
320
|
|
321
321
|
before do
|
@@ -362,7 +362,7 @@ describe ROXML, "inheritance" do
|
|
362
362
|
|
363
363
|
it "should include parent's attributes added after declaration" do
|
364
364
|
Book.class_eval do
|
365
|
-
xml_reader :publisher, :
|
365
|
+
xml_reader :publisher, :required => true
|
366
366
|
end
|
367
367
|
|
368
368
|
book = InheritedBookWithDepth.from_xml(@book_xml)
|
data/test/bugs/rexml_bugs.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
|
-
class RexmlBugs <
|
3
|
+
class RexmlBugs < ActiveSupport::TestCase
|
4
4
|
def test_that_some_illegal_chars_are_parsed_without_complaint
|
5
5
|
p "REXML ignores illegal ']]>' brackets in xml content"
|
6
6
|
assert_nothing_raised do
|
data/test/mocks/dictionaries.rb
CHANGED
@@ -4,14 +4,15 @@ class DictionaryOfAttrs
|
|
4
4
|
include ROXML
|
5
5
|
|
6
6
|
xml_name :dictionary
|
7
|
-
xml_reader :definitions,
|
7
|
+
xml_reader :definitions, :as => {:key => '@dt',
|
8
|
+
:value => '@dd'}, :in => :definitions
|
8
9
|
end
|
9
10
|
|
10
11
|
class DictionaryOfTexts
|
11
12
|
include ROXML
|
12
13
|
|
13
14
|
xml_name :dictionary
|
14
|
-
xml_reader :definitions, {:key => :word,
|
15
|
+
xml_reader :definitions, :as => {:key => :word,
|
15
16
|
:value => :meaning}
|
16
17
|
end
|
17
18
|
|
@@ -19,7 +20,7 @@ class DictionaryOfMixeds
|
|
19
20
|
include ROXML
|
20
21
|
|
21
22
|
xml_name :dictionary
|
22
|
-
xml_reader :definitions,
|
23
|
+
xml_reader :definitions, :as => {:key => '@word',
|
23
24
|
:value => :content}
|
24
25
|
end
|
25
26
|
|
@@ -27,7 +28,7 @@ class DictionaryOfNames
|
|
27
28
|
include ROXML
|
28
29
|
|
29
30
|
xml_name :dictionary
|
30
|
-
xml_reader :definitions, {:key => :name,
|
31
|
+
xml_reader :definitions, :as => {:key => :name,
|
31
32
|
:value => :content}
|
32
33
|
end
|
33
34
|
|
@@ -35,7 +36,7 @@ class DictionaryOfGuardedNames
|
|
35
36
|
include ROXML
|
36
37
|
|
37
38
|
xml_name :dictionary
|
38
|
-
xml_reader :definitions, {:key => :name,
|
39
|
+
xml_reader :definitions, :as => {:key => :name,
|
39
40
|
:value => :content}, :in => :definitions
|
40
41
|
end
|
41
42
|
|
@@ -43,7 +44,7 @@ class DictionaryOfNameClashes
|
|
43
44
|
include ROXML
|
44
45
|
|
45
46
|
xml_name :dictionary
|
46
|
-
xml_reader :definitions, {:key => 'name',
|
47
|
+
xml_reader :definitions, :as => {:key => 'name',
|
47
48
|
:value => 'content'}, :from => :definition
|
48
49
|
end
|
49
50
|
|
@@ -51,6 +52,6 @@ class DictionaryOfAttrNameClashes
|
|
51
52
|
include ROXML
|
52
53
|
|
53
54
|
xml_name :dictionary
|
54
|
-
xml_reader :definitions,
|
55
|
+
xml_reader :definitions, :as => {:key => '@name',
|
55
56
|
:value => 'content'}, :from => :definition
|
56
57
|
end
|
data/test/mocks/mocks.rb
CHANGED
@@ -15,7 +15,7 @@ end
|
|
15
15
|
class Numerology
|
16
16
|
include ROXML
|
17
17
|
|
18
|
-
xml_reader :predictions, {:
|
18
|
+
xml_reader :predictions, :as => {:key => '@number', :value => '@meaning'} do |k, v|
|
19
19
|
[Integer(k), v]
|
20
20
|
end
|
21
21
|
end
|
@@ -41,7 +41,7 @@ class Book
|
|
41
41
|
xml_reader :title
|
42
42
|
xml_reader :description, :cdata => true
|
43
43
|
xml_reader :author
|
44
|
-
xml_accessor :pages, :
|
44
|
+
xml_accessor :pages, :from => 'pagecount', :as => Integer
|
45
45
|
end
|
46
46
|
|
47
47
|
class BookWithRequired
|
@@ -49,8 +49,8 @@ class BookWithRequired
|
|
49
49
|
|
50
50
|
xml_accessor :isbn, :from => '@ISBN', :required => true
|
51
51
|
xml_reader :title, :required => true
|
52
|
-
xml_reader :contributors, [Contributor], :in => 'contributor_array', :required => true
|
53
|
-
xml_reader :contributor_hash, {:
|
52
|
+
xml_reader :contributors, :as => [Contributor], :in => 'contributor_array', :required => true
|
53
|
+
xml_reader :contributor_hash, :as => {:key => '@role', :value => '@name'},
|
54
54
|
:from => 'contributor', :in => 'contributor_hash', :required => true
|
55
55
|
end
|
56
56
|
|
@@ -107,7 +107,7 @@ class BookWithDepth
|
|
107
107
|
xml_reader :title
|
108
108
|
xml_reader :description, :cdata => true
|
109
109
|
xml_reader :author
|
110
|
-
xml_reader :depth, Measurement
|
110
|
+
xml_reader :depth, :as => Measurement
|
111
111
|
end
|
112
112
|
|
113
113
|
class Author
|
@@ -124,7 +124,7 @@ class BookWithAuthors
|
|
124
124
|
xml_reader :isbn, :from => '@ISBN'
|
125
125
|
xml_reader :title
|
126
126
|
xml_reader :description, :cdata => true
|
127
|
-
xml_reader :authors, []
|
127
|
+
xml_reader :authors, :as => []
|
128
128
|
end
|
129
129
|
|
130
130
|
class BookWithAuthorTextAttribute
|
@@ -134,7 +134,7 @@ class BookWithAuthorTextAttribute
|
|
134
134
|
xml_reader :isbn, :from => '@ISBN'
|
135
135
|
xml_reader :title
|
136
136
|
xml_reader :description, :cdata => true
|
137
|
-
xml_reader :author, Author
|
137
|
+
xml_reader :author, :as => Author
|
138
138
|
end
|
139
139
|
|
140
140
|
class BookWithContributions
|
@@ -144,7 +144,7 @@ class BookWithContributions
|
|
144
144
|
xml_reader :isbn, :from => :attr
|
145
145
|
xml_reader :title
|
146
146
|
xml_reader :description
|
147
|
-
xml_reader :contributions, [Contributor], :from => 'contributor', :in => "contributions"
|
147
|
+
xml_reader :contributions, :as => [Contributor], :from => 'contributor', :in => "contributions"
|
148
148
|
end
|
149
149
|
|
150
150
|
class BookWithContributors
|
@@ -154,7 +154,7 @@ class BookWithContributors
|
|
154
154
|
xml_reader :isbn, :from => :attr
|
155
155
|
xml_reader :title
|
156
156
|
xml_reader :description
|
157
|
-
xml_reader :contributors, [Contributor]
|
157
|
+
xml_reader :contributors, :as => [Contributor]
|
158
158
|
end
|
159
159
|
|
160
160
|
class WriteableBookWithContributors
|
@@ -164,7 +164,7 @@ class WriteableBookWithContributors
|
|
164
164
|
xml_accessor :isbn, :from => :attr
|
165
165
|
xml_accessor :title
|
166
166
|
xml_accessor :description
|
167
|
-
xml_accessor :contributors, [Contributor]
|
167
|
+
xml_accessor :contributors, :as => [Contributor]
|
168
168
|
end
|
169
169
|
|
170
170
|
class NamelessBook
|
@@ -173,7 +173,7 @@ class NamelessBook
|
|
173
173
|
xml_reader :isbn, :from => :attr
|
174
174
|
xml_reader :title
|
175
175
|
xml_reader :description
|
176
|
-
xml_reader :contributors, [Contributor]
|
176
|
+
xml_reader :contributors, :as => [Contributor]
|
177
177
|
end
|
178
178
|
|
179
179
|
class Publisher
|
@@ -189,7 +189,7 @@ class BookWithPublisher
|
|
189
189
|
xml_reader :isbn, :from => :attr
|
190
190
|
xml_reader :title
|
191
191
|
xml_reader :description
|
192
|
-
xml_reader :publisher, Publisher
|
192
|
+
xml_reader :publisher, :as => Publisher
|
193
193
|
end
|
194
194
|
|
195
195
|
class BookPair
|
@@ -199,14 +199,14 @@ class BookPair
|
|
199
199
|
xml_reader :title
|
200
200
|
xml_reader :description
|
201
201
|
xml_reader :author
|
202
|
-
xml_reader :book, Book
|
202
|
+
xml_reader :book, :as => Book
|
203
203
|
end
|
204
204
|
|
205
205
|
class Library
|
206
206
|
include ROXML
|
207
207
|
|
208
208
|
xml_reader :name
|
209
|
-
xml_reader :books, [BookWithContributions]
|
209
|
+
xml_reader :books, :as => [BookWithContributions]
|
210
210
|
end
|
211
211
|
|
212
212
|
class UppercaseLibrary
|
@@ -214,14 +214,14 @@ class UppercaseLibrary
|
|
214
214
|
|
215
215
|
xml_name :library
|
216
216
|
xml_reader :name, :from => 'NAME'
|
217
|
-
xml_reader :books, [BookWithContributions], :from => 'BOOK'
|
217
|
+
xml_reader :books, :as => [BookWithContributions], :from => 'BOOK'
|
218
218
|
end
|
219
219
|
|
220
220
|
class LibraryWithBooksOfUnderivableName
|
221
221
|
include ROXML
|
222
222
|
|
223
223
|
xml_accessor :name
|
224
|
-
xml_reader :novels, [NamelessBook]
|
224
|
+
xml_reader :novels, :as => [NamelessBook]
|
225
225
|
end
|
226
226
|
|
227
227
|
class NodeWithNameConflicts
|
@@ -259,7 +259,7 @@ class PersonWithMother
|
|
259
259
|
|
260
260
|
xml_name :person
|
261
261
|
xml_reader :name
|
262
|
-
xml_reader :mother, PersonWithMother, :from => 'mother'
|
262
|
+
xml_reader :mother, :as => PersonWithMother, :from => 'mother'
|
263
263
|
end
|
264
264
|
|
265
265
|
class PersonWithGuardedMother
|
@@ -267,7 +267,7 @@ class PersonWithGuardedMother
|
|
267
267
|
|
268
268
|
xml_name :person
|
269
269
|
xml_reader :name
|
270
|
-
xml_reader :mother, PersonWithGuardedMother, :from => :person, :in => :mother
|
270
|
+
xml_reader :mother, :as => PersonWithGuardedMother, :from => :person, :in => :mother
|
271
271
|
end
|
272
272
|
|
273
273
|
class PersonWithMotherOrMissing
|
@@ -275,5 +275,5 @@ class PersonWithMotherOrMissing
|
|
275
275
|
|
276
276
|
xml_reader :age, :from => :attr, :else => 21
|
277
277
|
xml_reader :name, :else => 'Anonymous'
|
278
|
-
xml_reader :mother
|
278
|
+
xml_reader :mother,:as => PersonWithMotherOrMissing, :else => Person.blank
|
279
279
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
2
2
|
|
3
|
-
class TestDefinition <
|
3
|
+
class TestDefinition < ActiveSupport::TestCase
|
4
4
|
def assert_hash(opts, kvp)
|
5
5
|
assert opts.hash?
|
6
6
|
assert !opts.array?
|
@@ -8,36 +8,18 @@ class TestDefinition < Test::Unit::TestCase
|
|
8
8
|
opts.hash.value.type => opts.hash.value.name}
|
9
9
|
end
|
10
10
|
|
11
|
-
def test_text_in_array_means_as_array_for_text
|
12
|
-
opts = ROXML::Definition.new(:authors, [:text])
|
13
|
-
assert opts.array?
|
14
|
-
assert_equal :text, opts.type
|
15
|
-
end
|
16
|
-
|
17
11
|
def test_empty_array_means_as_array_for_text
|
18
|
-
opts = ROXML::Definition.new(:authors, [])
|
12
|
+
opts = ROXML::Definition.new(:authors, :as => [])
|
19
13
|
assert opts.array?
|
20
14
|
assert_equal :text, opts.type
|
21
15
|
end
|
22
16
|
|
23
17
|
def test_attr_in_array_means_as_array_for_attr
|
24
|
-
opts = ROXML::Definition.new(:authors, [:attr
|
18
|
+
opts = ROXML::Definition.new(:authors, :as => [], :from => :attr)
|
25
19
|
assert opts.array?
|
26
20
|
assert_equal :attr, opts.type
|
27
21
|
end
|
28
22
|
|
29
|
-
def test_object_in_array_means_as_array_for_object
|
30
|
-
opts = ROXML::Definition.new(:authors, [Hash])
|
31
|
-
assert opts.array?
|
32
|
-
assert_equal Hash, opts.type
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_literal_as_array_is_deprecated
|
36
|
-
assert_deprecated do
|
37
|
-
assert ROXML::Definition.new(:authors, :as => :array).array?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
23
|
def test_block_shorthand_in_array_means_array
|
42
24
|
opts = ROXML::Definition.new(:intarray, :as => [Integer])
|
43
25
|
assert opts.array?
|
@@ -61,30 +43,30 @@ class TestDefinition < Test::Unit::TestCase
|
|
61
43
|
end
|
62
44
|
|
63
45
|
def test_hash_of_attrs
|
64
|
-
opts = ROXML::Definition.new(:attributes, {:
|
46
|
+
opts = ROXML::Definition.new(:attributes, :as => {:key => '@name', :value => '@value'})
|
65
47
|
assert_hash(opts, :attr => 'name', :attr => 'value')
|
66
48
|
end
|
67
49
|
|
68
50
|
def test_hash_with_attr_key_and_text_val
|
69
|
-
opts = ROXML::Definition.new(:attributes,
|
51
|
+
opts = ROXML::Definition.new(:attributes, :as => {:key => '@name',
|
70
52
|
:value => :value})
|
71
53
|
assert_hash(opts, :attr => 'name', :text => 'value')
|
72
54
|
end
|
73
55
|
|
74
56
|
def test_hash_with_string_class_for_type
|
75
|
-
opts = ROXML::Definition.new(:attributes,
|
76
|
-
:value =>
|
57
|
+
opts = ROXML::Definition.new(:attributes, :as => {:key => 'name',
|
58
|
+
:value => 'value'})
|
77
59
|
assert_hash(opts, :text => 'name', :text => 'value')
|
78
60
|
end
|
79
61
|
|
80
62
|
def test_hash_with_attr_key_and_content_val
|
81
|
-
opts = ROXML::Definition.new(:attributes,
|
63
|
+
opts = ROXML::Definition.new(:attributes, :as => {:key => '@name',
|
82
64
|
:value => :content})
|
83
65
|
assert_hash(opts, :attr => 'name', :text => '.')
|
84
66
|
end
|
85
67
|
|
86
68
|
def test_hash_with_options
|
87
|
-
opts = ROXML::Definition.new(:definitions, {:
|
69
|
+
opts = ROXML::Definition.new(:definitions, :as => {:key => '@dt', :value => '@dd'},
|
88
70
|
:in => :definitions, :from => 'definition')
|
89
71
|
assert_hash(opts, :attr => 'dt', :attr => 'dd')
|
90
72
|
assert_equal 'definition', opts.hash.wrapper
|
@@ -92,12 +74,6 @@ class TestDefinition < Test::Unit::TestCase
|
|
92
74
|
|
93
75
|
def test_no_block_shorthand_means_no_block
|
94
76
|
assert ROXML::Definition.new(:count).blocks.empty?
|
95
|
-
assert_deprecated do
|
96
|
-
assert ROXML::Definition.new(:count, :as => :intager).blocks.empty?
|
97
|
-
end
|
98
|
-
assert_deprecated do
|
99
|
-
assert ROXML::Definition.new(:count, :as => :foat).blocks.empty?
|
100
|
-
end
|
101
77
|
end
|
102
78
|
|
103
79
|
def test_block_integer_shorthand
|
@@ -133,15 +109,6 @@ class TestDefinition < Test::Unit::TestCase
|
|
133
109
|
assert_equal 2, ROXML::Definition.new(:count, :as => Float) {|val| val.object_id }.blocks.size
|
134
110
|
end
|
135
111
|
|
136
|
-
def test_symbol_shorthands_are_deprecated
|
137
|
-
assert_deprecated do
|
138
|
-
ROXML::Definition.new(:junk, :as => :integer)
|
139
|
-
end
|
140
|
-
assert_deprecated do
|
141
|
-
ROXML::Definition.new(:junk, :as => :float)
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
112
|
def test_block_shorthand_supports_bool
|
146
113
|
assert_equal true, ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call("1")
|
147
114
|
assert_equal [true, false, nil], ROXML::Definition.new(:floatvalue, :as => :bool).blocks.first.call(["TrUe", "0", "328"])
|
@@ -196,27 +163,12 @@ class TestDefinition < Test::Unit::TestCase
|
|
196
163
|
assert ROXML::Definition.new(:manufacturer, :cdata => true).cdata?
|
197
164
|
end
|
198
165
|
|
199
|
-
def test_as_cdata_is_deprecated
|
200
|
-
assert_deprecated do
|
201
|
-
assert ROXML::Definition.new(:manufacturer, :as => :cdata).cdata?
|
202
|
-
end
|
203
|
-
assert_deprecated do
|
204
|
-
assert ROXML::Definition.new(:manufacturer, :as => [Integer, :cdata]).cdata?
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
166
|
def test_as_supports_generic_roxml_types
|
209
167
|
assert_equal RoxmlObject, ROXML::Definition.new(:type, :as => RoxmlObject).type
|
210
|
-
assert_deprecated do
|
211
|
-
assert_equal RoxmlObject, ROXML::Definition.new(:type, RoxmlObject).type
|
212
|
-
end
|
213
168
|
end
|
214
169
|
|
215
170
|
def test_as_supports_generic_roxml_types_in_arrays
|
216
171
|
assert_equal RoxmlObject, ROXML::Definition.new(:types, :as => [RoxmlObject]).type
|
217
|
-
assert_deprecated do
|
218
|
-
assert_equal RoxmlObject, ROXML::Definition.new(:types, [RoxmlObject]).type
|
219
|
-
end
|
220
172
|
end
|
221
173
|
|
222
174
|
def test_default_works
|
@@ -227,14 +179,6 @@ class TestDefinition < Test::Unit::TestCase
|
|
227
179
|
def test_default_works_for_arrays
|
228
180
|
opts = ROXML::Definition.new(:missing, :as => [])
|
229
181
|
assert_equal [], opts.to_ref(RoxmlObject.new).value_in(ROXML::XML::Parser.parse('<xml></xml>'))
|
230
|
-
assert_deprecated do
|
231
|
-
opts = ROXML::Definition.new(:missing, [])
|
232
|
-
assert_equal [], opts.to_ref(RoxmlObject.new).value_in(ROXML::XML::Parser.parse('<xml></xml>'))
|
233
|
-
end
|
234
|
-
assert_deprecated do
|
235
|
-
opts = ROXML::Definition.new(:missing, :as => :array)
|
236
|
-
assert_equal [], opts.to_ref(RoxmlObject.new).value_in(ROXML::XML::Parser.parse('<xml></xml>'))
|
237
|
-
end
|
238
182
|
end
|
239
183
|
|
240
184
|
def test_default_works_for_recursive_objects
|
@@ -248,20 +192,16 @@ class TestDefinition < Test::Unit::TestCase
|
|
248
192
|
end
|
249
193
|
|
250
194
|
def test_content_is_a_recognized_type
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
assert_equal :text, opts.type
|
256
|
-
end
|
195
|
+
opts = ROXML::Definition.new(:author, :from => :content)
|
196
|
+
assert opts.content?
|
197
|
+
assert_equal '.', opts.name
|
198
|
+
assert_equal :text, opts.type
|
257
199
|
end
|
258
200
|
|
259
201
|
def test_content_symbol_as_target_is_translated_to_string
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
assert_equal :attr, opts.type
|
264
|
-
end
|
202
|
+
opts = ROXML::Definition.new(:content, :from => :attr)
|
203
|
+
assert_equal 'content', opts.name
|
204
|
+
assert_equal :attr, opts.type
|
265
205
|
end
|
266
206
|
|
267
207
|
def test_attr_is_accepted_as_from
|
@@ -270,39 +210,25 @@ class TestDefinition < Test::Unit::TestCase
|
|
270
210
|
end
|
271
211
|
|
272
212
|
def test_attr_is_a_recognized_type
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
assert_equal :attr, opts.type
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
def test_name_ending_with_on_warns_of_coming_date_default
|
281
|
-
assert_deprecated do
|
282
|
-
assert_equal :text, ROXML::Definition.new(:created_at).type
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
def test_name_ending_with_at_warns_of_coming_datetime_default
|
287
|
-
assert_deprecated do
|
288
|
-
assert_equal :text, ROXML::Definition.new(:created_on).type
|
289
|
-
end
|
213
|
+
opts = ROXML::Definition.new(:author, :from => :attr)
|
214
|
+
assert_equal 'author', opts.name
|
215
|
+
assert_equal :attr, opts.type
|
290
216
|
end
|
291
217
|
end
|
292
218
|
|
293
219
|
class RecursiveObject
|
294
220
|
include ROXML
|
295
221
|
|
296
|
-
xml_reader :next, RecursiveObject, :else => true
|
222
|
+
xml_reader :next, :as => RecursiveObject, :else => true
|
297
223
|
end
|
298
224
|
|
299
225
|
class RoxmlObject
|
300
226
|
include ROXML
|
301
227
|
end
|
302
228
|
|
303
|
-
class HashDefinitionTest <
|
229
|
+
class HashDefinitionTest < ActiveSupport::TestCase
|
304
230
|
def test_content_detected_as_from
|
305
|
-
opts = ROXML::Definition.new(:hash, {:key => :content, :value => :name})
|
231
|
+
opts = ROXML::Definition.new(:hash, :as => {:key => :content, :value => :name})
|
306
232
|
assert_equal '.', opts.hash.key.name
|
307
233
|
assert_equal :text, opts.hash.key.type
|
308
234
|
end
|