| | 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> |
|---|
| | 459 | XML |
|---|
| | 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> |
|---|
| | 469 | XML |
|---|
| | 470 | |
|---|
| | 471 | @problematic = <<XML |
|---|
| | 472 | <?xml version="1.0" encoding="UTF-8"?> |
|---|
| | 473 | <account> |
|---|
| | 474 | <id type="integer">1</id> |
|---|
| | 475 | <account-number>1234</account-number> |
|---|
| | 476 | <name>Checking</name> |
|---|
| | 477 | <txactions> |
|---|
| | 478 | <txaction> |
|---|
| | 479 | <date>2007-05-03</date> |
|---|
| | 480 | <amount>-89.72</amount> |
|---|
| | 481 | <merchant> |
|---|
| | 482 | <name>Berkeley Bowl</name> <rating>Fan</rating> |
|---|
| | 483 | </merchant> |
|---|
| | 484 | </txaction> |
|---|
| | 485 | </txactions> |
|---|
| | 486 | </account> |
|---|
| | 487 | XML |
|---|
| | 488 | |
|---|
| | 489 | ActiveResource::HttpMock.respond_to { |m| |
|---|
| | 490 | m.get "/firms/1/people.xml", {}, @people_xml |
|---|
| | 491 | m.get "/partners/1/people.xml", {}, @people_david_xml |
|---|
| | 492 | m.get "/problems/1/people.xml", {}, @problematic |
|---|
| | 493 | } |
|---|
| | 494 | |
|---|
| | 495 | people = Person.find(:all, :from => "/firms/1/people.xml") |
|---|
| | 496 | |
|---|
| | 497 | assert_equal 2, people.size |
|---|
| | 498 | assert_kind_of Person, people.first |
|---|
| | 499 | assert_equal "Matz", people.first.name |
|---|
| | 500 | assert_equal "David", people.last.name |
|---|
| | 501 | |
|---|
| | 502 | people = Person.find(:all, :from => "/partners/1/people.xml") |
|---|
| | 503 | assert_equal 1, people.size |
|---|
| | 504 | assert_equal "David", people.first.name |
|---|
| | 505 | |
|---|
| | 506 | got = Person.find(:all, :from => "/problems/1/people.xml") |
|---|
| | 507 | assert_equal "Checking", got.name |
|---|
| | 508 | assert_equal "-89.72", got.txactions.txaction.amount |
|---|
| | 509 | end |
|---|