/friendster_on_rails/test/model_test.rb
Ruby | 153 lines | 127 code | 16 blank | 10 comment | 0 complexity | 398ca58c028c080a39230c2fef207768 MD5 | raw file
- ##
- # Copyright 2008 Friendster Inc Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
- # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
- # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and limitations under the License.
- ##
- require File.dirname(__FILE__) + "/test_helper"
- require "test/unit"
- require "rubygems"
- require "mocha"
- class ModelTest < Test::Unit::TestCase
-
- def test_acts_as_friendster_user_is_present
-
- assert @model.class.respond_to?(:acts_as_friendster_user)
- end
-
- def test_friendster_extensions_are_present
-
- assert @model.respond_to?(:friendster_api_key)
- assert @model.respond_to?(:friendster_api_secret)
- assert @model.respond_to?(:friendster_session)
- assert @model.respond_to?(:friendster_session=)
-
- Friendster::Rails::ModelExtensions::ActsAsFriendsterUser::FIELDS.each do |field|
- assert @model.respond_to?(field), "Any model that acts_as_friendster_user should respond to '#{field}'"
- end
-
- assert @model.class.respond_to?(:find_or_create_by_friendster_session)
- end
-
- def test_friendster_properties_dispatched_to_internal_session
-
- # allow session to be used
-
- @model.friendster_session.expects(:is_session_enabled? ).at_least_once.returns(true)
-
- @model.friendster_session.expects(:get_responce).at_least_once.returns @dummy_users_getInfo_response
-
- # try a bunch of fields
- assert_equal "57519", @model.uid, "Uid should be consistent with the users_getInfo response XML"
- assert_equal "Single", @model.relationship_status, "Relationship status should be consistent with the users_getInfo response XML"
- assert_equal "Wicked, The Best of Julia Child", @model.favorites.books, "Books should be consistent with the users_getInfo response XML"
- assert_equal "Hervey", @model.first_name, "First name should be consistent with the users_getInfo response XML"
- end
-
-
- def setup
- @model = DummyModel.allocate # TODO: how do we properly test model instances that don't have database backing?
-
- @dummy_users_getInfo_response = <<-EOF
- <?xml version="1.0" encoding="UTF-8"?>
- <user_response xmlns="http://api.friendster.com/v1/"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://api.friendster.com/v1/
- http://api.friendster.com/v1/friendster.xsd" list="true">
- <user>
- <uid>57519</uid>
- <first_name>Hervey</first_name>
- <last_name>Herrera</last_name>
- <gender>Male</gender>
- <member_since>
- <year>2003</year>
- <month>03</month>
- <day>17</day>
- </member_since>
- <relationship_status>Single</relationship_status>
- <interested_in>
- <interest>Dating Men</interest>
- <interest>Dating Women</interest>
- <interest>Friends</interest>
- <interest>Activity Partners</interest>
- </interested_in>
- <birthday>
- <year>1984</year>
- <month>04</month>
- <day>07</day>
- </birthday>
- <location>
- <country>US</country>
- <state>CA</state>
- <city>Beverly Hills</city>
- <zip></zip>
- </location>
- <hometown>Chihuahua, MX</hometown>
- <occupation>Sathsma Hound Chihuahua, you eeediot!!!</occupation>
- <companies>Corona, Sears chuchu</companies>
- <hobbies_and_interests>
- Cookin',Hog jowels, Chocolate covered raisins, Rubber nipples, Wax paper,
- Unwashed lederhosen, $1 Million, Killing the Taco Bell Dog: NO quiero Taco Bell!!!
- </hobbies_and_interests>
- <affiliations>Corona Beer, Dos Equis Beer</affiliations>
- <college_list>
- <college>
- <name>Northern Mindanao State Institute of Science and Technology</name>
- <region>Agusan del Norte</region>
- <country>Philippines</country>
- <city></city>
- <year_start>2002</year_start>
- <year_end>0000</year_end>
- <major>major</major>
- <degree>4</degree>
- <course>course</course>
- </college>
- <college>
- <name>Antioch University-Los Angeles</name>
- <region>California</region>
- <country>United States</country>
- <city></city>
- <year_start>1995</year_start>
- <year_end>2000</year_end>
- <major>PHYSICS</major>
- <degree>4</degree>
- <course></course>
- </college>
- </college_list>
- <school_list>
- <school>
- <name>Anglo Chinese Junior College</name>
- <region></region>
- <country>Singapore</country>
- <city></city>
- <year_start>2001</year_start>
- <year_end>0000</year_end>
- <major></major>
- <degree>0</degree>
- <course></course>
- </school>
- </school_list>
- <school_other>University of Mexico at Colima</school_other>
- <favorites>
- <books>Wicked, The Best of Julia Child</books>
- <movies>Casablanca, Jaws, Music & Lyrics, Flushed Away, Scooby</movies>
- <music>Sugar Ray, Smashmouth,</music>
- <tv_shows>Ren&Stimpy Show you fooooool! CSI Miami</tv_shows>
- </favorites>
- <about_me>
- There is nothing to write about me.
- </about_me>
- <want_to_meet>Michael Arrington. Bill Gates. God.</want_to_meet>
- </user>
- </user_response>
- EOF
-
-
- end
-
- end