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

Ticket #8798: test_case_to_fix_missing_method_collect_on_hash_error.patch

File test_case_to_fix_missing_method_collect_on_hash_error.patch, 1.9 kB (added by JasonRoelofs, 3 years ago)

Test case proving the applied patch works.

  • test/base_test.rb

    old new  
    1313    @people = [{ :id => 1, :name => 'Matz' }, { :id => 2, :name => 'David' }].to_xml(:root => 'people') 
    1414    @people_david = [{ :id => 2, :name => 'David' }].to_xml(:root => 'people') 
    1515    @addresses = [{ :id => 1, :street => '12345 Street' }].to_xml(:root => 'addresses') 
    16      
     16 
    1717    ActiveResource::HttpMock.respond_to do |mock| 
    1818      mock.get    "/people/1.xml",             {}, @matz 
    1919      mock.get    "/people/2.xml",             {}, @david 
     
    441441    matz = Person.find(1) 
    442442    assert_equal "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<person>\n  <name>Matz</name>\n  <id type=\"integer\">1</id>\n</person>\n", matz.to_xml 
    443443  end 
     444 
     445  def test_unspecified_collection_types 
     446  # Tests and data to prove that we've fixed the "undefined method 'collect!' for Hash" problem 
     447    @people_xml = <<XML 
     448<?xml version="1.0" encoding="UTF-8"?> 
     449<people> 
     450  <person> 
     451    <name>Matz</name> 
     452    <id type="integer">1</id> 
     453  </person> 
     454  <person> 
     455    <name>David</name> 
     456    <id type="integer">2</id> 
     457  </person> 
     458</people> 
     459XML 
     460 
     461    @people_david_xml = <<XML 
     462<?xml version="1.0" encoding="UTF-8"?> 
     463<people> 
     464  <person> 
     465    <name>David</name> 
     466    <id type="integer">2</id> 
     467  </person> 
     468</people> 
     469XML 
     470 
     471    ActiveResource::HttpMock.respond_to { |m|  
     472      m.get "/firms/1/people.xml", {}, @people_xml  
     473      m.get "/partners/1/people.xml", {}, @people_david_xml 
     474    } 
     475 
     476    people = Person.find(:all, :from => "/firms/1/people.xml") 
     477     
     478    assert_equal 2, people.size 
     479    assert_kind_of Person, people.first 
     480    assert_equal "Matz", people.first.name 
     481    assert_equal "David", people.last.name 
     482 
     483    people = Person.find(:all, :from => "/partners/1/people.xml") 
     484    assert_equal 1, people.size 
     485    assert_equal "David", people.first.name 
     486  end 
    444487end