Permalink
Browse files

Make the xml_serializer plugin handle namespaced models by using __ i…

…nstead of / as a separator

Note that this may break backwards compatibility for people already
handling this issue using a custom :name_proc to translate the /
to something else.
  • Loading branch information...
jeremyevans committed Apr 12, 2011
1 parent b717eaa commit 2a26ba6cd74c80165973ebcdfe0b77415fc8d591
Showing with 16 additions and 2 deletions.
  1. +3 −1 CHANGELOG
  2. +1 −1 lib/sequel/plugins/xml_serializer.rb
  3. +12 −0 spec/extensions/xml_serializer_spec.rb
View
@@ -1,8 +1,10 @@
=== HEAD
+* Make the xml_serializer plugin handle namespaced models by using __ instead of / as a separator (jeremyevans)
+
* Allow the :eager_grapher association proc to accept a single hash instead of 3 arguments (jfirebaugh)
-* Allow specifying a callback to customize eager loading at query time (jfirebaugh)
+* Allow specifying a callback to customize eager loading at query time (jfirebaugh, jeremyevans)
* Fix bug in the identity_map plugin for many_to_one associations when the association reflection hadn't been filled in yet (funny-falcon)
@@ -266,7 +266,7 @@ def to_xml(opts={})
name_proc = model.xml_serialize_name_proc(opts)
x = model.xml_builder(opts)
- x.send(name_proc[opts.fetch(:root_name, model.send(:underscore, model.name)).to_s]) do |x1|
+ x.send(name_proc[opts.fetch(:root_name, model.send(:underscore, model.name).gsub('/', '__')).to_s]) do |x1|
cols.each do |c|
attrs = {}
if types
@@ -36,6 +36,18 @@ class ::Album < Sequel::Model
Album.from_xml(@album.to_xml).should == @album
end
+ it "should round trip successfully for namespaced models" do
+ module XmlSerializerTest
+ class Artist < Sequel::Model
+ plugin :xml_serializer
+ columns :id, :name
+ @db_schema = {:id=>{:type=>:integer}, :name=>{:type=>:string}}
+ end
+ end
+ artist = XmlSerializerTest::Artist.load(:id=>2, :name=>'YJM')
+ XmlSerializerTest::Artist.from_xml(artist.to_xml).should == artist
+ end
+
it "should round trip successfully with empty strings" do
artist = Artist.load(:id=>2, :name=>'')
Artist.from_xml(artist.to_xml).should == artist

0 comments on commit 2a26ba6

Please sign in to comment.