aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/test')
-rw-r--r--activemodel/test/cases/serializeration/xml_serialization_test.rb15
-rw-r--r--activemodel/test/models/contact.rb8
2 files changed, 21 insertions, 2 deletions
diff --git a/activemodel/test/cases/serializeration/xml_serialization_test.rb b/activemodel/test/cases/serializeration/xml_serialization_test.rb
index 6340aad531..3ba826a8d0 100644
--- a/activemodel/test/cases/serializeration/xml_serialization_test.rb
+++ b/activemodel/test/cases/serializeration/xml_serialization_test.rb
@@ -1,6 +1,7 @@
require 'cases/helper'
require 'models/contact'
require 'active_support/core_ext/object/instance_variables'
+require 'ostruct'
class Contact
extend ActiveModel::Naming
@@ -23,7 +24,9 @@ class XmlSerializationTest < ActiveModel::TestCase
@contact.age = 25
@contact.created_at = Time.utc(2006, 8, 1)
@contact.awesome = false
- @contact.preferences = { :gem => 'ruby' }
+ customer = OpenStruct.new
+ customer.name = "John"
+ @contact.preferences = customer
end
test "should serialize default root" do
@@ -92,8 +95,16 @@ class XmlSerializationTest < ActiveModel::TestCase
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\">--- \n:gem: ruby\n</preferences>}, @contact.to_xml
+ assert_match %r{<preferences type=\"yaml\">--- !ruby/object:OpenStruct \ntable:\s*:name: John\n</preferences>}, @contact.to_xml
end
test "should call proc on object" do
diff --git a/activemodel/test/models/contact.rb b/activemodel/test/models/contact.rb
index a9009fbdef..605e435f39 100644
--- a/activemodel/test/models/contact.rb
+++ b/activemodel/test/models/contact.rb
@@ -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