PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/friendster_on_rails/test/model_test.rb

http://friendster-rails-api.googlecode.com/
Ruby | 153 lines | 127 code | 16 blank | 10 comment | 0 complexity | 398ca58c028c080a39230c2fef207768 MD5 | raw file
  1. ##
  2. # Copyright 2008 Friendster Inc Licensed under the Apache License, Version 2.0 (the "License");
  3. # you may not use this file except in compliance with the License.
  4. # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  5. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  6. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  7. # See the License for the specific language governing permissions and limitations under the License.
  8. ##
  9. require File.dirname(__FILE__) + "/test_helper"
  10. require "test/unit"
  11. require "rubygems"
  12. require "mocha"
  13. class ModelTest < Test::Unit::TestCase
  14. def test_acts_as_friendster_user_is_present
  15. assert @model.class.respond_to?(:acts_as_friendster_user)
  16. end
  17. def test_friendster_extensions_are_present
  18. assert @model.respond_to?(:friendster_api_key)
  19. assert @model.respond_to?(:friendster_api_secret)
  20. assert @model.respond_to?(:friendster_session)
  21. assert @model.respond_to?(:friendster_session=)
  22. Friendster::Rails::ModelExtensions::ActsAsFriendsterUser::FIELDS.each do |field|
  23. assert @model.respond_to?(field), "Any model that acts_as_friendster_user should respond to '#{field}'"
  24. end
  25. assert @model.class.respond_to?(:find_or_create_by_friendster_session)
  26. end
  27. def test_friendster_properties_dispatched_to_internal_session
  28. # allow session to be used
  29. @model.friendster_session.expects(:is_session_enabled? ).at_least_once.returns(true)
  30. @model.friendster_session.expects(:get_responce).at_least_once.returns @dummy_users_getInfo_response
  31. # try a bunch of fields
  32. assert_equal "57519", @model.uid, "Uid should be consistent with the users_getInfo response XML"
  33. assert_equal "Single", @model.relationship_status, "Relationship status should be consistent with the users_getInfo response XML"
  34. assert_equal "Wicked, The Best of Julia Child", @model.favorites.books, "Books should be consistent with the users_getInfo response XML"
  35. assert_equal "Hervey", @model.first_name, "First name should be consistent with the users_getInfo response XML"
  36. end
  37. def setup
  38. @model = DummyModel.allocate # TODO: how do we properly test model instances that don't have database backing?
  39. @dummy_users_getInfo_response = <<-EOF
  40. <?xml version="1.0" encoding="UTF-8"?>
  41. <user_response xmlns="http://api.friendster.com/v1/"
  42. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  43. xsi:schemaLocation="http://api.friendster.com/v1/
  44. http://api.friendster.com/v1/friendster.xsd" list="true">
  45. <user>
  46. <uid>57519</uid>
  47. <first_name>Hervey</first_name>
  48. <last_name>Herrera</last_name>
  49. <gender>Male</gender>
  50. <member_since>
  51. <year>2003</year>
  52. <month>03</month>
  53. <day>17</day>
  54. </member_since>
  55. <relationship_status>Single</relationship_status>
  56. <interested_in>
  57. <interest>Dating Men</interest>
  58. <interest>Dating Women</interest>
  59. <interest>Friends</interest>
  60. <interest>Activity Partners</interest>
  61. </interested_in>
  62. <birthday>
  63. <year>1984</year>
  64. <month>04</month>
  65. <day>07</day>
  66. </birthday>
  67. <location>
  68. <country>US</country>
  69. <state>CA</state>
  70. <city>Beverly Hills</city>
  71. <zip></zip>
  72. </location>
  73. <hometown>Chihuahua, MX</hometown>
  74. <occupation>Sathsma Hound Chihuahua, you eeediot!!!</occupation>
  75. <companies>Corona, Sears chuchu</companies>
  76. <hobbies_and_interests>
  77. Cookin',Hog jowels, Chocolate covered raisins, Rubber nipples, Wax paper,
  78. Unwashed lederhosen, $1 Million, Killing the Taco Bell Dog: NO quiero Taco Bell!!!
  79. </hobbies_and_interests>
  80. <affiliations>Corona Beer, Dos Equis Beer</affiliations>
  81. <college_list>
  82. <college>
  83. <name>Northern Mindanao State Institute of Science and Technology</name>
  84. <region>Agusan del Norte</region>
  85. <country>Philippines</country>
  86. <city></city>
  87. <year_start>2002</year_start>
  88. <year_end>0000</year_end>
  89. <major>major</major>
  90. <degree>4</degree>
  91. <course>course</course>
  92. </college>
  93. <college>
  94. <name>Antioch University-Los Angeles</name>
  95. <region>California</region>
  96. <country>United States</country>
  97. <city></city>
  98. <year_start>1995</year_start>
  99. <year_end>2000</year_end>
  100. <major>PHYSICS</major>
  101. <degree>4</degree>
  102. <course></course>
  103. </college>
  104. </college_list>
  105. <school_list>
  106. <school>
  107. <name>Anglo Chinese Junior College</name>
  108. <region></region>
  109. <country>Singapore</country>
  110. <city></city>
  111. <year_start>2001</year_start>
  112. <year_end>0000</year_end>
  113. <major></major>
  114. <degree>0</degree>
  115. <course></course>
  116. </school>
  117. </school_list>
  118. <school_other>University of Mexico at Colima</school_other>
  119. <favorites>
  120. <books>Wicked, The Best of Julia Child</books>
  121. <movies>Casablanca, Jaws, Music & Lyrics, Flushed Away, Scooby</movies>
  122. <music>Sugar Ray, Smashmouth,</music>
  123. <tv_shows>Ren&Stimpy Show you fooooool! CSI Miami</tv_shows>
  124. </favorites>
  125. <about_me>
  126. There is nothing to write about me.
  127. </about_me>
  128. <want_to_meet>Michael Arrington. Bill Gates. God.</want_to_meet>
  129. </user>
  130. </user_response>
  131. EOF
  132. end
  133. end