Sha256: 3bd398dff49801429c42a5721cfeff03c815c2a642f86a505a8a7201ad90b916
Contents?: true
Size: 1.54 KB
Versions: 2
Compression:
Stored size: 1.54 KB
Contents
require 'test/unit' require 'ostruct' $:.unshift File.dirname(__FILE__) + "/../lib/" require 'model_xml' class TestStruct < OpenStruct include ModelXML end class ModelXMLTest < Test::Unit::TestCase def setup @t = TestStruct.new :foo => 1, :bar => 2 end def test_class_simple TestStruct.instance_eval do model_xml_reset! model_xml :foo end assert_equal [[:foo]], TestStruct.model_xml_generator.field_sets res = '<?xml version="1.0" encoding="UTF-8"?> <teststruct> <foo>1</foo> </teststruct> ' assert_equal res, @t.to_xml end def test_block_notation TestStruct.instance_eval do model_xml_reset! model_xml do foo bar end end assert_equal [[:foo, :bar]], TestStruct.model_xml_generator.field_sets res = '<?xml version="1.0" encoding="UTF-8"?> <teststruct> <foo>1</foo> <bar>2</bar> </teststruct> ' assert_equal res, @t.to_xml end def test_inline_procs TestStruct.instance_eval do model_xml_reset! model_xml do foo bar foobar Proc.new {|obj| obj.foo + obj.bar} end end res = '<?xml version="1.0" encoding="UTF-8"?> <teststruct> <foo>1</foo> <bar>2</bar> <foobar>3</foobar> </teststruct> ' assert_equal res, @t.to_xml end def test_skip_instruct TestStruct.instance_eval do model_xml_reset! model_xml :foo, :bar end res = '<?xml version="1.0"?> <teststruct> <foo>1</foo> <bar>2</bar> </teststruct> ' assert_equal res, @t.to_xml(:skip_instruct => true) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
model_xml-1.0.1 | test/test_model_xml.rb |
model_xml-1.0.0 | test/test_model_xml.rb |