require File.dirname(__FILE__) + '/../../spec_helper' require File.dirname(__FILE__) + '/../spec_helper_tables' unless metaclass.class_variable_defined? :@@set_up_demo_tables require 'active_resource' describe "Sequel::Serializer" do describe "to_fos_xml method adds options to skip instructions, dasherize, and only for" do it "single sequel model" do add_test_table_data({:id=>1,:'goofy name col' => 123}) data = TestTable.first mock(data).to_xml({:dasherize=>false, :skip_instruct=>true, :only=>[]}) data.to_fos_xml end it "an array of sequel models" do add_test_table_data({:id=>1,:'goofy name col' => 123}) data = [TestTable.first] mock(data).to_xml({:dasherize=>false, :skip_instruct=>true, :only=>[]}) data.to_fos_xml end end it "to_xml works with references to aliased columns" do add_test_table_data({:id=>1,:'goofy name col' => 123}) TestTable.column_alias :'nice_name', :'goofy name col' TestTable.first.to_fos_xml(:only => :nice_name).should equal_xml( %{ 123 } ) end it "to_fos_xml with many to one assoc" do Dude.o_to_n :horses, :class=>:Horse, :prefix => 'dude' Dude.first.to_fos_xml(:only=> :name, :include=> :horses).should equal_xml( %{ dano pinto silver }) end it "to_xml with many to one assoc" do Horse.n_to_o :dude, :class=>:Dude, :prefix=>'dude' Horse.first.to_fos_xml(:only=> [:name], :include=> :dude).should equal_xml( %{ pinto dano }) end it "to_xml with array of horses" do Horse.n_to_o :dude, :class=>:Dude, :prefix=>'dude' Horse.all.to_fos_xml(:only=> [:name], :include=> :dude).should equal_xml( %{ pinto dano silver dano } ) end it "converts to ActiveResource::Base from xml" do class Dudeman < ActiveResource::Base; self.site = ""; end hash = Hash.from_xml( Dude.first.to_xml(:only=> :name, :include=> :horses) ) dudeman = Dudeman.new( hash.values.first ) dudeman.name.should == 'dano' dudeman.horses.size.should == 2 dudeman.horses.first.name == 'pinto' end end # it "creates sql model from xml" do # hash = Hash.from_xml( Dude.first.to_xml(:only=> :name, :include=> :horses) ) # d = Dude.new(hash.values.first) # end # it "can take the flatten option to flatten associations" do # Horse.n_to_o :dude, :class=>:Dude, :prefix=>'dude' # # Horse.all.to_xml(:flatten=>true, :only=> [:name], :include=> :dude).should equal_xml( # %{ # # # pinto # dano # # # } ) # end