Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7307: xml_serialization_ignores_undefined_methods_200701221649.diff

File xml_serialization_ignores_undefined_methods_200701221649.diff, 1.1 kB (added by jwilger, 2 years ago)

patch to ignore undefined methods passed in :methods option to #to_xml

  • test/xml_serialization_test.rb

    old new  
    5353    assert_no_match %r{<age},     @xml 
    5454    assert_match %r{<created-at}, @xml 
    5555  end 
     56   
     57  def test_should_not_try_to_serialize_methods_that_are_not_defined 
     58    assert_nothing_raised( NoMethodError ) do 
     59      Contact.new.to_xml( :methods => [ :i_do_not_exist ] ) 
     60    end 
     61  end 
    5662end 
    5763 
    5864class DefaultXmlSerializationTest < Test::Unit::TestCase 
  • lib/active_record/xml_serialization.rb

    old new  
    160160    end 
    161161 
    162162    def serializable_method_attributes 
    163       Array(options[:methods]).collect { |name| MethodAttribute.new(name.to_s, @record) } 
     163      valid_methods = Array(options[:methods]).reject { |name| !@record.respond_to? name } 
     164      valid_methods.collect { |name| MethodAttribute.new(name.to_s, @record) } 
    164165    end 
    165166 
    166167