Permalink
Browse files

test cases for record.to_xml [#458 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
Neeraj Singh authored and josevalim committed Apr 29, 2010
1 parent 34908e4 commit 883f27aa9a6fae5194400bb8f00e343dcb610270
@@ -95,6 +95,14 @@ def setup
assert_match %r{<awesome type=\"boolean\">false</awesome>}, @contact.to_xml
end
+ test "should serialize array" do
+ assert_match %r{<social type=\"array\">\s*<social>twitter</social>\s*<social>github</social>\s*</social>}, @contact.to_xml(:methods => :social)
+ end
+
+ test "should serialize hash" do
+ assert_match %r{<network>\s*<git type=\"symbol\">github</git>\s*</network>}, @contact.to_xml(:methods => :network)
+ end
+
test "should serialize yaml" do
assert_match %r{<preferences type=\"yaml\">--- !ruby/object:OpenStruct \ntable:\s*:name: John\n</preferences>}, @contact.to_xml
end
@@ -3,6 +3,14 @@ class Contact
attr_accessor :id, :name, :age, :created_at, :awesome, :preferences
+ def social
+ %w(twitter github)
+ end
+
+ def network
+ {:git => :github}
+ end
+
def initialize(options = {})
options.each { |name, value| send("#{name}=", value) }
end
@@ -234,4 +234,12 @@ def test_should_has_many_array_elements_should_include_type_when_different_from_
assert types.include?('StiPost')
end
+ def test_should_produce_xml_for_methods_returning_array
+ xml = authors(:david).to_xml(:methods => :social)
+ array = Hash.from_xml(xml)['author']['social']
+ assert_equal 2, array.size
+ assert array.include? 'twitter'
+ assert array.include? 'github'
+ end
+
end
@@ -104,6 +104,10 @@ def label
"#{id}-#{name}"
end
+ def social
+ %w(twitter github)
+ end
+
private
def log_before_adding(object)
@post_log << "before_adding#{object.id || '<new>'}"

0 comments on commit 883f27a

Please sign in to comment.