Empact-roxml 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/roxml/extensions.rb
CHANGED
@@ -2,29 +2,6 @@ module ROXML
|
|
2
2
|
module CoreExtensions
|
3
3
|
module Array #:nodoc:all
|
4
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
5
|
def apply_to(val)
|
29
6
|
# Only makes sense for arrays of blocks... maybe better outside Array...
|
30
7
|
inject(val) {|val, block| block.call(val) }
|
@@ -7,7 +7,7 @@ module ActiveSupport # :nodoc:all
|
|
7
7
|
module Deprecation
|
8
8
|
class << self
|
9
9
|
def warn_with_internals_exclusion(message = nil, callstack = caller)
|
10
|
-
warn_without_internals_exclusion(message, callstack.reject {|line| line =~ /\/roxml(-[\d\.]+)?\/lib\// })
|
10
|
+
warn_without_internals_exclusion(message, callstack.reject {|line| line =~ /\/roxml(-[\d\.]+)?\/lib\// || line.include?('lib/roxml.rb') })
|
11
11
|
end
|
12
12
|
alias_method_chain :warn, :internals_exclusion
|
13
13
|
|
@@ -2,20 +2,5 @@ require File.join(File.dirname(__FILE__), 'string/conversions')
|
|
2
2
|
require File.join(File.dirname(__FILE__), 'string/iterators')
|
3
3
|
|
4
4
|
class String #:nodoc:
|
5
|
-
include ROXML::CoreExtensions::String::Conversions
|
6
5
|
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
6
|
end
|
@@ -1,41 +1,3 @@
|
|
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
1
|
class String
|
40
2
|
def between(separator, &block)
|
41
3
|
split(separator).collect(&block).join(separator)
|
@@ -1,60 +1,25 @@
|
|
1
1
|
module ROXML
|
2
|
-
HASH_KEYS = [:attrs, :key, :value].freeze
|
3
|
-
TYPE_KEYS = [:attr, :text, :hash, :content].freeze
|
4
|
-
|
5
2
|
class HashDefinition # :nodoc:
|
6
3
|
attr_reader :key, :value
|
7
4
|
attr_accessor :wrapper
|
8
5
|
|
9
6
|
def initialize(opts)
|
10
|
-
|
11
|
-
raise ArgumentError, "Invalid Hash description keys: #{invalid_keys.join(', ')}"
|
12
|
-
end
|
7
|
+
opts.assert_valid_keys(:key, :value)
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
@key = to_hash_args(opts, :from => "@#{opts[:attrs][0]}")
|
17
|
-
@value = to_hash_args(opts, :from => "@#{opts[:attrs][1]}")
|
18
|
-
else
|
19
|
-
@key = to_hash_args opts, fetch_element(opts, :key)
|
20
|
-
@value = to_hash_args opts, fetch_element(opts, :value)
|
21
|
-
end
|
9
|
+
@key = Definition.new(nil, to_definition_options(opts, :key))
|
10
|
+
@value = Definition.new(nil, to_definition_options(opts, :value))
|
22
11
|
end
|
23
12
|
|
24
13
|
private
|
25
|
-
def
|
14
|
+
def to_definition_options(opts, what)
|
26
15
|
case opts[what]
|
27
16
|
when Hash
|
28
|
-
|
29
|
-
ActiveSupport::Deprecation.warn(":as => {:key => {Type => 'name'} ... } is going away in 3.0. Use explicit :key => {:from => 'name', :as => Type} instead.")
|
30
|
-
type = opts[what].keys.first
|
31
|
-
case type
|
32
|
-
when :attr
|
33
|
-
{:from => "@#{opts[what][type]}"}
|
34
|
-
when :text
|
35
|
-
{:from => opts[what][type]}
|
36
|
-
else
|
37
|
-
{:as => type, :from => opts[what][type]}
|
38
|
-
end
|
39
|
-
else
|
40
|
-
opts[what]
|
41
|
-
end
|
17
|
+
opts[what]
|
42
18
|
when String, Symbol
|
43
19
|
{:from => opts[what]}
|
44
20
|
else
|
45
21
|
raise ArgumentError, "unrecognized hash parameter: #{what} => #{opts[what]}"
|
46
22
|
end
|
47
23
|
end
|
48
|
-
|
49
|
-
def to_hash_args(args, opts)
|
50
|
-
args = [args] unless args.is_a? Array
|
51
|
-
|
52
|
-
if args.one? && !(args.first.keys & HASH_KEYS).empty?
|
53
|
-
Definition.new(nil, opts)
|
54
|
-
else
|
55
|
-
opts = args.extract_options!
|
56
|
-
raise opts.inspect
|
57
|
-
end
|
58
|
-
end
|
59
24
|
end
|
60
25
|
end
|
data/lib/roxml/xml/references.rb
CHANGED
@@ -6,7 +6,7 @@ module ROXML
|
|
6
6
|
# Internal base class that represents an XML - Class binding.
|
7
7
|
#
|
8
8
|
class XMLRef # :nodoc:
|
9
|
-
delegate :required?, :array?, :blocks, :accessor, :
|
9
|
+
delegate :required?, :array?, :blocks, :accessor, :default, :to => :opts
|
10
10
|
|
11
11
|
def initialize(opts, instance)
|
12
12
|
@opts = opts
|
@@ -48,8 +48,9 @@ module ROXML
|
|
48
48
|
attr_reader :opts
|
49
49
|
|
50
50
|
def conventionize(what)
|
51
|
-
|
52
|
-
|
51
|
+
convention ||= @instance.class.respond_to?(:roxml_naming_convention) && @instance.class.roxml_naming_convention
|
52
|
+
if !what.blank? && convention.respond_to?(:call)
|
53
|
+
URI.unescape(convention.call(URI.escape(what, /\/|::/)))
|
53
54
|
else
|
54
55
|
what
|
55
56
|
end
|
@@ -120,7 +121,7 @@ module ROXML
|
|
120
121
|
# Updates the attribute in the given XML block to
|
121
122
|
# the value provided.
|
122
123
|
def write_xml(xml, value)
|
123
|
-
xml.attributes[name] = value.to_s
|
124
|
+
xml.attributes[name] = value.to_s
|
124
125
|
end
|
125
126
|
|
126
127
|
def fetch_value(xml)
|
@@ -179,7 +180,7 @@ module ROXML
|
|
179
180
|
nodes_in(xml) do |nodes|
|
180
181
|
if array?
|
181
182
|
nodes.collect do |e|
|
182
|
-
e.content.strip
|
183
|
+
e.content.strip
|
183
184
|
end
|
184
185
|
else
|
185
186
|
nodes.first.content
|
@@ -190,9 +191,9 @@ module ROXML
|
|
190
191
|
|
191
192
|
def add(dest, value)
|
192
193
|
if cdata?
|
193
|
-
dest.child_add(XML::Node.new_cdata(value.to_s
|
194
|
+
dest.child_add(XML::Node.new_cdata(value.to_s))
|
194
195
|
else
|
195
|
-
dest.content = value.to_s
|
196
|
+
dest.content = value.to_s
|
196
197
|
end
|
197
198
|
end
|
198
199
|
end
|
@@ -231,7 +232,7 @@ module ROXML
|
|
231
232
|
super(kvp)
|
232
233
|
end
|
233
234
|
end
|
234
|
-
vals
|
235
|
+
to_hash(vals) if vals
|
235
236
|
end
|
236
237
|
|
237
238
|
def freeze(vals)
|
@@ -242,6 +243,17 @@ module ROXML
|
|
242
243
|
vals
|
243
244
|
end
|
244
245
|
end
|
246
|
+
|
247
|
+
def to_hash(array)
|
248
|
+
hash = array.inject({}) do |result, (k, v)|
|
249
|
+
result[k] ||= []
|
250
|
+
result[k] << v
|
251
|
+
result
|
252
|
+
end
|
253
|
+
hash.each_pair do |k, v|
|
254
|
+
hash[k] = v.first if v.one?
|
255
|
+
end
|
256
|
+
end
|
245
257
|
end
|
246
258
|
|
247
259
|
class XMLObjectRef < XMLTextRef # :nodoc:
|
data/roxml.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{roxml}
|
5
|
-
s.version = "2.5.
|
5
|
+
s.version = "2.5.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Ben Woosley", "Zak Mandhro", "Anders Engstrom", "Russ Olsen"]
|
9
|
-
s.date = %q{2009-03-
|
9
|
+
s.date = %q{2009-03-12}
|
10
10
|
s.description = %q{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.}
|
11
11
|
s.email = %q{ben.woosley@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.rdoc"]
|
13
|
-
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "config/website.yml", "examples/active_record.rb", "examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/library.rb", "examples/posts.rb", "examples/twitter.rb", "examples/xml/active_record.xml", "examples/xml/amazon.xml", "examples/xml/current_weather.xml", "examples/xml/dashed_elements.xml", "examples/xml/posts.xml", "examples/xml/twitter.xml", "lib/roxml.rb", "lib/roxml/definition.rb", "lib/roxml/extensions.rb", "lib/roxml/extensions/
|
13
|
+
s.files = ["History.txt", "MIT-LICENSE", "Manifest.txt", "README.rdoc", "Rakefile", "TODO", "config/website.yml", "examples/active_record.rb", "examples/amazon.rb", "examples/current_weather.rb", "examples/dashed_elements.rb", "examples/library.rb", "examples/posts.rb", "examples/twitter.rb", "examples/xml/active_record.xml", "examples/xml/amazon.xml", "examples/xml/current_weather.xml", "examples/xml/dashed_elements.xml", "examples/xml/posts.xml", "examples/xml/twitter.xml", "lib/roxml.rb", "lib/roxml/definition.rb", "lib/roxml/extensions.rb", "lib/roxml/extensions/array.rb", "lib/roxml/extensions/array/conversions.rb", "lib/roxml/extensions/deprecation.rb", "lib/roxml/extensions/string.rb", "lib/roxml/extensions/string/conversions.rb", "lib/roxml/extensions/string/iterators.rb", "lib/roxml/hash_definition.rb", "lib/roxml/xml.rb", "lib/roxml/xml/parsers/libxml.rb", "lib/roxml/xml/parsers/rexml.rb", "lib/roxml/xml/references.rb", "roxml.gemspec", "spec/definition_spec.rb", "spec/examples/active_record_spec.rb", "spec/examples/amazon_spec.rb", "spec/examples/current_weather_spec.rb", "spec/examples/dashed_elements_spec.rb", "spec/examples/library_spec.rb", "spec/examples/post_spec.rb", "spec/examples/twitter_spec.rb", "spec/roxml_spec.rb", "spec/shared_specs.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/xml/parser_spec.rb", "tasks/rspec.rake", "tasks/test.rake", "test/bugs/rexml_bugs.rb", "test/fixtures/book_malformed.xml", "test/fixtures/book_pair.xml", "test/fixtures/book_text_with_attribute.xml", "test/fixtures/book_valid.xml", "test/fixtures/book_with_authors.xml", "test/fixtures/book_with_contributions.xml", "test/fixtures/book_with_contributors.xml", "test/fixtures/book_with_contributors_attrs.xml", "test/fixtures/book_with_default_namespace.xml", "test/fixtures/book_with_depth.xml", "test/fixtures/book_with_octal_pages.xml", "test/fixtures/book_with_publisher.xml", "test/fixtures/book_with_wrapped_attr.xml", "test/fixtures/dictionary_of_attr_name_clashes.xml", "test/fixtures/dictionary_of_attrs.xml", "test/fixtures/dictionary_of_guarded_names.xml", "test/fixtures/dictionary_of_mixeds.xml", "test/fixtures/dictionary_of_name_clashes.xml", "test/fixtures/dictionary_of_names.xml", "test/fixtures/dictionary_of_texts.xml", "test/fixtures/library.xml", "test/fixtures/library_uppercase.xml", "test/fixtures/muffins.xml", "test/fixtures/nameless_ageless_youth.xml", "test/fixtures/node_with_attr_name_conflicts.xml", "test/fixtures/node_with_name_conflicts.xml", "test/fixtures/numerology.xml", "test/fixtures/person.xml", "test/fixtures/person_with_guarded_mothers.xml", "test/fixtures/person_with_mothers.xml", "test/mocks/dictionaries.rb", "test/mocks/mocks.rb", "test/test_helper.rb", "test/unit/definition_test.rb", "test/unit/deprecations_test.rb", "test/unit/to_xml_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_convention_test.rb", "test/unit/xml_hash_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_name_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_text_test.rb", "vendor/override_rake_task/README", "vendor/override_rake_task/init.rb", "vendor/override_rake_task/install.rb", "vendor/override_rake_task/lib/override_rake_task.rb", "website/index.html"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://roxml.rubyforge.org}
|
16
16
|
s.rdoc_options = ["--main", "README.rdoc"]
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.rubyforge_project = %q{roxml}
|
19
19
|
s.rubygems_version = %q{1.3.1}
|
20
20
|
s.summary = %q{Ruby Object to XML mapping library}
|
21
|
-
s.test_files = ["test/unit/
|
21
|
+
s.test_files = ["test/unit/xml_convention_test.rb", "test/unit/xml_object_test.rb", "test/unit/xml_required_test.rb", "test/unit/xml_bool_test.rb", "test/unit/xml_name_test.rb", "test/unit/definition_test.rb", "test/unit/xml_namespace_test.rb", "test/unit/deprecations_test.rb", "test/unit/xml_text_test.rb", "test/unit/xml_block_test.rb", "test/unit/xml_attribute_test.rb", "test/unit/xml_initialize_test.rb", "test/unit/xml_hash_test.rb", "test/unit/to_xml_test.rb"]
|
22
22
|
|
23
23
|
if s.respond_to? :specification_version then
|
24
24
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/spec/definition_spec.rb
CHANGED
@@ -17,141 +17,132 @@ describe ROXML::Definition do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe "
|
21
|
-
it "should
|
22
|
-
@
|
20
|
+
describe "DateTime reference", :shared => true do
|
21
|
+
it "should return nil on empty string" do
|
22
|
+
@subject.blocks.first.call(" ").should be_nil
|
23
23
|
end
|
24
24
|
|
25
|
-
it "should
|
26
|
-
|
27
|
-
{@opts.hash.value.type => @opts.hash.value.name}.should == @hash_args[:value]
|
25
|
+
it "should return a time version of the string" do
|
26
|
+
@subject.blocks.first.call("12:05pm, September 3rd, 1970").to_s == "1970-09-03T12:05:00+00:00"
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
context "when passed an array of values" do
|
30
|
+
it "should timify all of them" do
|
31
|
+
@subject.blocks.first.call(["12:05pm, September 3rd, 1970", "3:00pm, May 22, 1700"]).map(&:to_s).should == ["1970-09-03T12:05:00+00:00", "1700-05-22T15:00:00+00:00"]
|
32
|
+
end
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
describe "
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
ROXML::Definition.new(:author, :content).content?.should be_true
|
40
|
-
end
|
36
|
+
describe "Date reference", :shared => true do
|
37
|
+
it "should return nil on empty string" do
|
38
|
+
@subject.blocks.first.call(" ").should be_nil
|
39
|
+
end
|
41
40
|
|
42
|
-
|
41
|
+
it "should return a time version of the string" do
|
42
|
+
@subject.blocks.first.call("September 3rd, 1970").to_s == "1970-09-03"
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
it "
|
47
|
-
|
48
|
-
opts.array?.should be_true
|
49
|
-
opts.type.should == :text
|
45
|
+
context "when passed an array of values" do
|
46
|
+
it "should timify all of them" do
|
47
|
+
@subject.blocks.first.call(["September 3rd, 1970", "1776-07-04"]).map(&:to_s).should == ["1970-09-03", "1776-07-04"]
|
50
48
|
end
|
49
|
+
end
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
it "should unescape xml entities" do
|
53
|
+
ROXML::Definition.new(:questions, :as => []).to_ref(RoxmlObject.new).value_in(%{
|
54
|
+
<xml>
|
55
|
+
<question>"Wickard & Filburn" ></question>
|
56
|
+
<question> < McCulloch & Maryland?</question>
|
57
|
+
</xml>
|
58
|
+
}).should == ["\"Wickard & Filburn\" >", "< McCulloch & Maryland?"]
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "attr name" do
|
62
|
+
context "when ending with '_at'" do
|
63
|
+
context "and without an :as argument" do
|
64
|
+
before(:all) do
|
65
|
+
@subject = ROXML::Definition.new(:time_at)
|
66
|
+
end
|
67
|
+
it_should_behave_like "DateTime reference"
|
56
68
|
end
|
69
|
+
end
|
57
70
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
context "when ending with '_on'" do
|
72
|
+
context "and without an :as argument" do
|
73
|
+
before(:all) do
|
74
|
+
@subject = ROXML::Definition.new(:created_on)
|
75
|
+
end
|
76
|
+
it_should_behave_like "Date reference"
|
62
77
|
end
|
78
|
+
end
|
79
|
+
end
|
63
80
|
|
64
|
-
|
65
|
-
|
81
|
+
describe ":as" do
|
82
|
+
describe "=> []" do
|
83
|
+
it "should means array of texts" do
|
84
|
+
opts = ROXML::Definition.new(:authors, :as => [])
|
66
85
|
opts.array?.should be_true
|
67
|
-
opts.type.should ==
|
86
|
+
opts.type.should == :text
|
68
87
|
end
|
69
88
|
end
|
70
89
|
|
71
|
-
describe "
|
72
|
-
|
73
|
-
|
74
|
-
@opts = ROXML::Definition.new(:attributes, {:key => {:attr => :name},
|
75
|
-
:value => :value})
|
76
|
-
@hash_args = {:key => {:attr => 'name'},
|
77
|
-
:value => {:text => 'value'}}
|
78
|
-
end
|
79
|
-
|
80
|
-
it_should_behave_like "hash options declaration"
|
90
|
+
describe "=> RoxmlClass" do
|
91
|
+
class RoxmlClass
|
92
|
+
include ROXML
|
81
93
|
end
|
82
94
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
:value => {String => 'value'}})
|
87
|
-
@hash_args = {:key => {:text => 'name'}, :value => {:text => 'value'}}
|
88
|
-
end
|
89
|
-
|
90
|
-
it_should_behave_like "hash options declaration"
|
95
|
+
it "should store type" do
|
96
|
+
opts = ROXML::Definition.new(:name, :as => RoxmlClass)
|
97
|
+
opts.type.should == RoxmlClass
|
91
98
|
end
|
99
|
+
end
|
92
100
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
@hash_args = {:key => {:attr => 'name'}, :value => {:text => '.'}}
|
101
|
+
describe "=> NonRoxmlClassWithFromXmlDefined" do
|
102
|
+
class OctalInteger
|
103
|
+
def self.from_xml(val)
|
104
|
+
new(Integer(val.content))
|
98
105
|
end
|
99
|
-
|
100
|
-
it_should_behave_like "hash options declaration"
|
101
106
|
end
|
102
107
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
@opts = ROXML::Definition.new(:attributes, {:attrs => [:name, :value]})
|
107
|
-
end
|
108
|
-
|
109
|
-
it_should_behave_like "hash options declaration"
|
110
|
-
|
111
|
-
describe "with options" do
|
112
|
-
before do
|
113
|
-
@hash_args = {:key => {:attr => 'dt'}, :value => {:attr => 'dd'}}
|
114
|
-
@opts = ROXML::Definition.new(:definitions, {:attrs => [:dt, :dd]},
|
115
|
-
:in => 'definitions')
|
116
|
-
end
|
117
|
-
|
118
|
-
it_should_behave_like "hash options declaration"
|
119
|
-
|
120
|
-
it "should not interfere with options" do
|
121
|
-
@opts.wrapper.should == 'definitions'
|
122
|
-
end
|
123
|
-
end
|
108
|
+
it "should accept type" do
|
109
|
+
opts = ROXML::Definition.new(:name, :as => OctalInteger)
|
110
|
+
opts.type.should == OctalInteger
|
124
111
|
end
|
125
112
|
end
|
126
|
-
end
|
127
113
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
end
|
132
|
-
|
133
|
-
describe "=> []" do
|
134
|
-
it "should means array of texts" do
|
135
|
-
opts = ROXML::Definition.new(:authors, :as => [])
|
136
|
-
opts.array?.should be_true
|
137
|
-
opts.type.should == :text
|
114
|
+
describe "=> NonRoxmlClass" do
|
115
|
+
it "should fail with a warning" do
|
116
|
+
proc { ROXML::Definition.new(:authors, :as => Module) }.should raise_error(ArgumentError)
|
138
117
|
end
|
118
|
+
end
|
139
119
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
<question>"Wickard & Filburn" ></question>
|
144
|
-
<question> < McCulloch & Maryland?</question>
|
145
|
-
</xml>
|
146
|
-
}).should == ["\"Wickard & Filburn\" >", "< McCulloch & Maryland?"]
|
120
|
+
describe "=> [NonRoxmlClass]" do
|
121
|
+
it "should raise" do
|
122
|
+
proc { ROXML::Definition.new(:authors, :as => [Module]) }.should raise_error(ArgumentError)
|
147
123
|
end
|
148
124
|
end
|
149
125
|
|
150
126
|
describe "=> {}" do
|
127
|
+
describe "hash options declaration", :shared => true do
|
128
|
+
it "should represent a hash" do
|
129
|
+
@opts.hash?.should be_true
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should have hash definition" do
|
133
|
+
{@opts.hash.key.type => @opts.hash.key.name}.should == @hash_args[:key]
|
134
|
+
{@opts.hash.value.type => @opts.hash.value.name}.should == @hash_args[:value]
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should not represent an array" do
|
138
|
+
@opts.array?.should be_false
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
151
142
|
describe "hash with attr key and text val" do
|
152
143
|
before do
|
153
|
-
@opts = ROXML::Definition.new(:attributes, :as => {:key =>
|
154
|
-
:value =>
|
144
|
+
@opts = ROXML::Definition.new(:attributes, :as => {:key => '@name',
|
145
|
+
:value => 'value'})
|
155
146
|
@hash_args = {:key => {:attr => 'name'},
|
156
147
|
:value => {:text => 'value'}}
|
157
148
|
end
|
@@ -161,8 +152,8 @@ describe ROXML::Definition do
|
|
161
152
|
|
162
153
|
describe "hash with String class for type" do
|
163
154
|
before do
|
164
|
-
@opts = ROXML::Definition.new(:attributes, :as => {:key =>
|
165
|
-
:value =>
|
155
|
+
@opts = ROXML::Definition.new(:attributes, :as => {:key => 'name',
|
156
|
+
:value => 'value'})
|
166
157
|
@hash_args = {:key => {:text => 'name'}, :value => {:text => 'value'}}
|
167
158
|
end
|
168
159
|
|
@@ -171,7 +162,7 @@ describe ROXML::Definition do
|
|
171
162
|
|
172
163
|
describe "hash with attr key and content val" do
|
173
164
|
before do
|
174
|
-
@opts = ROXML::Definition.new(:attributes, :as => {:key =>
|
165
|
+
@opts = ROXML::Definition.new(:attributes, :as => {:key => '@name',
|
175
166
|
:value => :content})
|
176
167
|
@hash_args = {:key => {:attr => 'name'}, :value => {:text => '.'}}
|
177
168
|
end
|
@@ -179,27 +170,14 @@ describe ROXML::Definition do
|
|
179
170
|
it_should_behave_like "hash options declaration"
|
180
171
|
end
|
181
172
|
|
182
|
-
describe "hash
|
173
|
+
describe "hash with names as keys and content vals" do
|
183
174
|
before do
|
184
|
-
@
|
185
|
-
|
175
|
+
@opts = ROXML::Definition.new(:attributes, :as => {:key => :name,
|
176
|
+
:value => :content})
|
177
|
+
@hash_args = {:key => {:text => '*'}, :value => {:text => '.'}}
|
186
178
|
end
|
187
179
|
|
188
180
|
it_should_behave_like "hash options declaration"
|
189
|
-
|
190
|
-
describe "with options" do
|
191
|
-
before do
|
192
|
-
@hash_args = {:key => {:attr => 'dt'}, :value => {:attr => 'dd'}}
|
193
|
-
@opts = ROXML::Definition.new(:definitions, :as => {:attrs => [:dt, :dd]},
|
194
|
-
:in => 'definitions')
|
195
|
-
end
|
196
|
-
|
197
|
-
it_should_behave_like "hash options declaration"
|
198
|
-
|
199
|
-
it "should not interfere with options" do
|
200
|
-
@opts.wrapper.should == 'definitions'
|
201
|
-
end
|
202
|
-
end
|
203
181
|
end
|
204
182
|
end
|
205
183
|
|
@@ -221,8 +199,11 @@ describe ROXML::Definition do
|
|
221
199
|
|
222
200
|
it "should have no blocks without a shorthand" do
|
223
201
|
ROXML::Definition.new(:count).blocks.should be_empty
|
224
|
-
|
225
|
-
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should raise on unknown :as" do
|
205
|
+
proc { ROXML::Definition.new(:count, :as => :bogus) }.should raise_error(ArgumentError)
|
206
|
+
proc { ROXML::Definition.new(:count, :as => :foat) }.should raise_error(ArgumentError)
|
226
207
|
end
|
227
208
|
|
228
209
|
describe "block shorthand type declaration", :shared => true do
|
@@ -236,7 +217,11 @@ describe ROXML::Definition do
|
|
236
217
|
end
|
237
218
|
end
|
238
219
|
|
239
|
-
describe "
|
220
|
+
describe "Integer" do
|
221
|
+
before do
|
222
|
+
@definition = ROXML::Definition.new(:intvalue, :as => Integer)
|
223
|
+
end
|
224
|
+
|
240
225
|
it_should_behave_like "block shorthand type declaration"
|
241
226
|
|
242
227
|
it "should translate text to integers" do
|
@@ -258,25 +243,11 @@ describe ROXML::Definition do
|
|
258
243
|
end
|
259
244
|
end
|
260
245
|
|
261
|
-
describe "
|
262
|
-
before do
|
263
|
-
@definition = ROXML::Definition.new(:intvalue, :as => Integer)
|
264
|
-
end
|
265
|
-
|
266
|
-
it_should_behave_like ":as => Integer"
|
267
|
-
end
|
268
|
-
|
269
|
-
describe ":integer" do
|
246
|
+
describe "Float" do
|
270
247
|
before do
|
271
|
-
@definition = ROXML::Definition.new(:
|
248
|
+
@definition = ROXML::Definition.new(:floatvalue, :as => Float)
|
272
249
|
end
|
273
250
|
|
274
|
-
it_should_behave_like ":as => Integer"
|
275
|
-
|
276
|
-
it "should be deprecated"
|
277
|
-
end
|
278
|
-
|
279
|
-
describe ":as => Float", :shared => true do
|
280
251
|
it_should_behave_like "block shorthand type declaration"
|
281
252
|
|
282
253
|
it "should translate text to float" do
|
@@ -296,24 +267,6 @@ describe ROXML::Definition do
|
|
296
267
|
end
|
297
268
|
end
|
298
269
|
|
299
|
-
describe ":float" do
|
300
|
-
before do
|
301
|
-
@definition = ROXML::Definition.new(:floatvalue, :as => :float)
|
302
|
-
end
|
303
|
-
|
304
|
-
it_should_behave_like ":as => Float"
|
305
|
-
|
306
|
-
it "should be deprecated"
|
307
|
-
end
|
308
|
-
|
309
|
-
describe "Float" do
|
310
|
-
before do
|
311
|
-
@definition = ROXML::Definition.new(:floatvalue, :as => Float)
|
312
|
-
end
|
313
|
-
|
314
|
-
it_should_behave_like ":as => Float"
|
315
|
-
end
|
316
|
-
|
317
270
|
describe "BigDecimal" do
|
318
271
|
before do
|
319
272
|
@definition = ROXML::Definition.new(:decimalvalue, :as => BigDecimal)
|
@@ -408,35 +361,17 @@ describe ROXML::Definition do
|
|
408
361
|
end
|
409
362
|
|
410
363
|
describe "Date" do
|
411
|
-
|
412
|
-
ROXML::Definition.new(:
|
413
|
-
end
|
414
|
-
|
415
|
-
it "should return a time version of the string" do
|
416
|
-
ROXML::Definition.new(:datevalue, :as => Date).blocks.first.call("September 3rd, 1970").to_s == "1970-09-03"
|
417
|
-
end
|
418
|
-
|
419
|
-
context "when passed an array of values" do
|
420
|
-
it "should timify all of them" do
|
421
|
-
ROXML::Definition.new(:datevalue, :as => Date).blocks.first.call(["September 3rd, 1970", "1776-07-04"]).map(&:to_s).should == ["1970-09-03", "1776-07-04"]
|
422
|
-
end
|
364
|
+
before do
|
365
|
+
@subject = ROXML::Definition.new(:datevalue, :as => Date)
|
423
366
|
end
|
367
|
+
it_should_behave_like "Date reference"
|
424
368
|
end
|
425
369
|
|
426
370
|
describe "DateTime" do
|
427
|
-
|
428
|
-
ROXML::Definition.new(:
|
429
|
-
end
|
430
|
-
|
431
|
-
it "should return a time version of the string" do
|
432
|
-
ROXML::Definition.new(:datevalue, :as => DateTime).blocks.first.call("12:05pm, September 3rd, 1970").to_s == "1970-09-03T12:05:00+00:00"
|
433
|
-
end
|
434
|
-
|
435
|
-
context "when passed an array of values" do
|
436
|
-
it "should timify all of them" do
|
437
|
-
ROXML::Definition.new(:datevalue, :as => DateTime).blocks.first.call(["12:05pm, September 3rd, 1970", "3:00pm, May 22, 1700"]).map(&:to_s).should == ["1970-09-03T12:05:00+00:00", "1700-05-22T15:00:00+00:00"]
|
438
|
-
end
|
371
|
+
before do
|
372
|
+
@subject = ROXML::Definition.new(:datevalue, :as => DateTime)
|
439
373
|
end
|
374
|
+
it_should_behave_like "DateTime reference"
|
440
375
|
end
|
441
376
|
|
442
377
|
it "should prohibit multiple shorthands" do
|
@@ -481,19 +416,11 @@ describe ROXML::Definition do
|
|
481
416
|
end
|
482
417
|
|
483
418
|
it_should_behave_like "attribute reference"
|
484
|
-
|
485
|
-
describe "and with :attr" do
|
486
|
-
before do
|
487
|
-
@opts = ROXML::Definition.new(:attr_name, :attr, :from => '@attr_name')
|
488
|
-
end
|
489
|
-
|
490
|
-
it_should_behave_like "attribute reference"
|
491
|
-
it "should be deprecated"
|
492
|
-
end
|
493
419
|
end
|
494
420
|
|
495
421
|
describe ":content" do
|
496
422
|
it "should be recognized" do
|
423
|
+
ROXML::Definition.new(:author).content?.should be_false
|
497
424
|
ROXML::Definition.new(:author, :from => :content).content?.should == true
|
498
425
|
end
|
499
426
|
|
@@ -521,13 +448,13 @@ describe ROXML::Definition do
|
|
521
448
|
|
522
449
|
describe "boolean option", :shared => true do
|
523
450
|
it "should be recognized" do
|
524
|
-
ROXML::Definition.new(:author, :content, @option => true).respond_to?(:"#{@option}?")
|
525
|
-
ROXML::Definition.new(:author, :content, @option => true).send(:"#{@option}?").should be_true
|
526
|
-
ROXML::Definition.new(:author, :content, @option => false).send(:"#{@option}?").should be_false
|
451
|
+
ROXML::Definition.new(:author, :from => :content, @option => true).respond_to?(:"#{@option}?")
|
452
|
+
ROXML::Definition.new(:author, :from => :content, @option => true).send(:"#{@option}?").should be_true
|
453
|
+
ROXML::Definition.new(:author, :from => :content, @option => false).send(:"#{@option}?").should be_false
|
527
454
|
end
|
528
455
|
|
529
456
|
it "should default to false" do
|
530
|
-
ROXML::Definition.new(:author, :content).send(:"#{@option}?").should be_false
|
457
|
+
ROXML::Definition.new(:author, :from => :content).send(:"#{@option}?").should be_false
|
531
458
|
end
|
532
459
|
end
|
533
460
|
|
@@ -539,8 +466,8 @@ describe ROXML::Definition do
|
|
539
466
|
it_should_behave_like "boolean option"
|
540
467
|
|
541
468
|
it "should not be allowed together with :else" do
|
542
|
-
proc { ROXML::Definition.new(:author, :content, :required => true, :else => 'Johnny') }.should raise_error(ArgumentError)
|
543
|
-
proc { ROXML::Definition.new(:author, :content, :required => false, :else => 'Johnny') }.should_not raise_error
|
469
|
+
proc { ROXML::Definition.new(:author, :from => :content, :required => true, :else => 'Johnny') }.should raise_error(ArgumentError)
|
470
|
+
proc { ROXML::Definition.new(:author, :from => :content, :required => false, :else => 'Johnny') }.should_not raise_error
|
544
471
|
end
|
545
472
|
end
|
546
473
|
|