facebooker 1.0.31 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +7 -0
- data/Manifest.txt +5 -0
- data/README.rdoc +9 -0
- data/facebooker.gemspec +8 -9
- data/generators/facebook/templates/public/javascripts/facebooker.js +10 -16
- data/init.rb +4 -1
- data/install.rb +1 -1
- data/lib/facebooker.rb +75 -20
- data/lib/facebooker/adapters/bebo_adapter.rb +9 -9
- data/lib/facebooker/data.rb +14 -14
- data/lib/facebooker/models/page.rb +16 -0
- data/lib/facebooker/models/photo.rb +7 -0
- data/lib/facebooker/models/user.rb +75 -28
- data/lib/facebooker/parser.rb +187 -127
- data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
- data/lib/facebooker/rails/controller.rb +30 -7
- data/lib/facebooker/rails/extensions/rack_setup.rb +5 -1
- data/lib/facebooker/rails/facebook_request_fix.rb +5 -5
- data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
- data/lib/facebooker/rails/facebook_url_rewriting.rb +7 -2
- data/lib/facebooker/rails/helpers.rb +29 -5
- data/lib/facebooker/rails/helpers/fb_connect.rb +14 -5
- data/lib/facebooker/rails/publisher.rb +26 -12
- data/lib/facebooker/service.rb +64 -56
- data/lib/facebooker/session.rb +56 -22
- data/lib/facebooker/version.rb +1 -1
- data/lib/rack/facebook.rb +26 -14
- data/lib/tasks/tunnel.rake +1 -1
- data/test/facebooker/adapters_test.rb +78 -0
- data/test/facebooker/data_test.rb +14 -14
- data/test/facebooker/models/page_test.rb +46 -0
- data/test/facebooker/models/photo_test.rb +16 -0
- data/test/facebooker/models/user_test.rb +83 -48
- data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +25 -0
- data/test/facebooker/rails/facebook_url_rewriting_test.rb +39 -0
- data/test/facebooker/rails/publisher_test.rb +5 -1
- data/test/facebooker/rails_integration_test.rb +52 -8
- data/test/facebooker/service_test.rb +58 -0
- data/test/facebooker/session_test.rb +106 -92
- data/test/facebooker_test.rb +2 -2
- data/test/rack/facebook_test.rb +4 -4
- data/test/test_helper.rb +10 -3
- metadata +14 -4
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
|
2
2
|
require 'active_support'
|
3
3
|
|
4
4
|
class Facebooker::UserTest < Test::Unit::TestCase
|
5
|
-
|
5
|
+
|
6
6
|
def setup
|
7
7
|
@session = Facebooker::Session.create('apikey', 'secretkey')
|
8
8
|
@user = Facebooker::User.new(1234, @session)
|
@@ -10,19 +10,24 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
10
10
|
ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
|
11
11
|
ENV['FACEBOOK_API_KEY'] = '1234567'
|
12
12
|
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
13
|
-
|
13
|
+
|
14
14
|
@user.friends = [@other_user]
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_has_permission
|
18
18
|
expect_http_posts_with_responses(has_app_permission_response_xml)
|
19
|
-
assert @user.has_permission?("status_update")
|
19
|
+
assert @user.has_permission?("status_update")
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
|
+
def test_has_permissions
|
23
|
+
expect_http_posts_with_responses(has_app_permission_response_xml, has_app_permission_response_xml)
|
24
|
+
assert @user.has_permissions?(["status_update", "read_stream"])
|
25
|
+
end
|
26
|
+
|
22
27
|
def test_can_ask_user_if_he_or_she_is_friends_with_another_user
|
23
28
|
assert(@user.friends_with?(@other_user))
|
24
29
|
end
|
25
|
-
|
30
|
+
|
26
31
|
def test_can_ask_user_if_he_or_she_is_friends_with_another_user_by_user_id
|
27
32
|
assert(@user.friends_with?(@other_user.id))
|
28
33
|
end
|
@@ -35,14 +40,14 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
35
40
|
def test_uid_is_always_an_integer
|
36
41
|
assert_equal 1234, Facebooker::User.new(:uid => "1234").uid
|
37
42
|
assert_equal 1234, Facebooker::User.new(:id => "1234").uid
|
38
|
-
|
43
|
+
|
39
44
|
assert_equal 1234, Facebooker::User.new(:uid => "1234").id
|
40
45
|
assert_equal 1234, Facebooker::User.new(:id => "1234").id
|
41
|
-
|
46
|
+
|
42
47
|
assert_equal 1234, Facebooker::User.new(:uid => "1234").facebook_id
|
43
48
|
assert_equal 1234, Facebooker::User.new(:id => "1234").facebook_id
|
44
49
|
end
|
45
|
-
|
50
|
+
|
46
51
|
def test_cast_to_friend_list_id_with_nil
|
47
52
|
assert_nil @user.cast_to_friend_list_id(nil)
|
48
53
|
end
|
@@ -56,7 +61,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
56
61
|
def test_cast_to_friend_list_id_with_friend_list
|
57
62
|
assert_equal 199,@user.cast_to_friend_list_id(Facebooker::FriendList.new(:flid=>199,:name=>"Work"))
|
58
63
|
end
|
59
|
-
|
64
|
+
|
60
65
|
def test_cast_to_friend_list_id_with_invalid_string_raises
|
61
66
|
@user.expects(:friend_lists).returns([Facebooker::FriendList.new(:flid=>1,:name=>"Not Picked")])
|
62
67
|
assert_nil @user.cast_to_friend_list_id("Something")
|
@@ -64,7 +69,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
64
69
|
rescue Facebooker::Session::InvalidFriendList
|
65
70
|
nil
|
66
71
|
end
|
67
|
-
|
72
|
+
|
68
73
|
def test_can_create_from_current_session
|
69
74
|
Facebooker::Session.expects(:current).returns("current")
|
70
75
|
user=Facebooker::User.new(1)
|
@@ -74,7 +79,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
74
79
|
def test_raises_when_no_session_bound
|
75
80
|
assert_raises(Facebooker::Model::UnboundSessionException) { Facebooker::User.new(1, nil).populate }
|
76
81
|
end
|
77
|
-
|
82
|
+
|
78
83
|
def test_can_set_mobile_fbml
|
79
84
|
@user.expects(:set_profile_fbml).with(nil,"test",nil,nil)
|
80
85
|
@user.mobile_fbml="test"
|
@@ -87,52 +92,69 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
87
92
|
@user.expects(:set_profile_fbml).with("test",nil,nil,nil)
|
88
93
|
@user.profile_fbml="test"
|
89
94
|
end
|
90
|
-
|
95
|
+
|
91
96
|
def test_can_set_profile_main
|
92
97
|
@user.expects(:set_profile_fbml).with(nil,nil,nil,"test")
|
93
98
|
@user.profile_main="test"
|
94
99
|
end
|
95
|
-
|
100
|
+
|
96
101
|
def test_can_call_set_profile_fbml
|
97
102
|
@session.expects(:post).with('facebook.profile.setFBML', {:uid=>1234,:profile=>"profile",:profile_action=>"action",:mobile_profile=>"mobile"},false)
|
98
103
|
@user.set_profile_fbml("profile","mobile","action")
|
99
104
|
end
|
100
|
-
|
105
|
+
|
101
106
|
def test_can_call_set_profile_fbml_with_profile_main
|
102
107
|
@session.expects(:post).with('facebook.profile.setFBML', {:uid=>1234,:profile=>"profile",:profile_action=>"action",:mobile_profile=>"mobile", :profile_main => 'profile_main'},false)
|
103
108
|
@user.set_profile_fbml("profile","mobile","action",'profile_main')
|
104
109
|
end
|
105
|
-
|
110
|
+
|
106
111
|
def test_can_get_profile_photos
|
107
112
|
@user.expects(:profile_photos)
|
108
113
|
@user.profile_photos
|
109
114
|
end
|
110
|
-
|
115
|
+
|
111
116
|
def test_can_set_cookie
|
112
117
|
@user.expects(:set_cookie).with('name', 'value')
|
113
118
|
@user.set_cookie('name', 'value')
|
114
119
|
end
|
115
|
-
|
120
|
+
|
116
121
|
def test_can_get_cookies
|
117
122
|
@user.expects(:get_cookies).with('name')
|
118
123
|
@user.get_cookies('name')
|
119
124
|
end
|
120
|
-
|
125
|
+
|
121
126
|
def test_get_profile_photos
|
122
127
|
@user = Facebooker::User.new(548871286, @session)
|
123
|
-
expect_http_posts_with_responses(example_profile_photos_get_xml)
|
128
|
+
expect_http_posts_with_responses(example_profile_photos_get_xml)
|
124
129
|
photos = @user.profile_photos
|
125
130
|
assert_equal "2357384227378429949", photos.first.aid
|
126
131
|
end
|
132
|
+
|
133
|
+
def test_publish_to
|
134
|
+
@user = Facebooker::User.new(548871286, @session)
|
135
|
+
expect_http_posts_with_responses(example_profile_publish_to_get_xml)
|
136
|
+
@user.publish_to(@other_user, :message => 'i love you man')
|
137
|
+
end
|
138
|
+
def test_publish_to_converts_attachment_to_json
|
139
|
+
@user = Facebooker::User.new(548871286, @session)
|
140
|
+
@user.session.expects(:post).with("facebook.stream.publish",has_entry(:attachment=>instance_of(String)))
|
141
|
+
@user.publish_to(@other_user, :message => 'i love you man',:attachment=>{:a=>"b"})
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_comment_on
|
145
|
+
@user = Facebooker::User.new(548871286, @session)
|
146
|
+
expect_http_posts_with_responses(example_comment_on_response)
|
147
|
+
assert_equal('703826862_78463536863', @user.comment_on('703826862_78463536862', :message => 'that was hilarious!'))
|
148
|
+
end
|
127
149
|
|
128
150
|
def test_can_send_email
|
129
151
|
@user.expects(:send_email).with("subject", "body text")
|
130
152
|
@user.send_email("subject", "body text")
|
131
|
-
|
153
|
+
|
132
154
|
@user.expects(:send_email).with("subject", nil, "body fbml")
|
133
155
|
@user.send_email("subject", nil, "body fbml")
|
134
156
|
end
|
135
|
-
|
157
|
+
|
136
158
|
def test_doesnt_post_to_facebook_when_assigning_status
|
137
159
|
@session.expects(:post).never
|
138
160
|
@user.status="my status"
|
@@ -141,7 +163,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
141
163
|
@session.expects(:post).with('facebook.users.setStatus', {:status=>"my status",:status_includes_verb=>1, :uid => @user.uid}, false)
|
142
164
|
@user.set_status("my status")
|
143
165
|
end
|
144
|
-
|
166
|
+
|
145
167
|
def test_get_events
|
146
168
|
@user = Facebooker::User.new(9507801, @session)
|
147
169
|
expect_http_posts_with_responses(example_events_get_xml)
|
@@ -158,33 +180,33 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
158
180
|
@session.expects(:post).never
|
159
181
|
assert_equal 1,@user.events.first.eid
|
160
182
|
end
|
161
|
-
|
162
|
-
|
183
|
+
|
184
|
+
|
163
185
|
def test_to_s
|
164
186
|
assert_equal("1234",@user.to_s)
|
165
187
|
end
|
166
|
-
|
188
|
+
|
167
189
|
def test_equality_with_same_id
|
168
190
|
assert_equal @user, @user.dup
|
169
191
|
assert_equal @user, Facebooker::User.new(:id => @user.id)
|
170
192
|
end
|
171
|
-
|
193
|
+
|
172
194
|
def test_not_equal_to_differnt_class
|
173
195
|
assert_not_equal @user, flexmock(:id => @user.id)
|
174
196
|
end
|
175
|
-
|
197
|
+
|
176
198
|
def test_hash_email
|
177
199
|
assert_equal "4228600737_c96da02bba97aedfd26136e980ae3761", Facebooker::User.hash_email("mary@example.com")
|
178
200
|
end
|
179
201
|
def test_hash_email_not_normalized
|
180
202
|
assert_equal "4228600737_c96da02bba97aedfd26136e980ae3761", Facebooker::User.hash_email(" MaRy@example.com ")
|
181
203
|
end
|
182
|
-
|
204
|
+
|
183
205
|
def test_register_with_array
|
184
206
|
expect_http_posts_with_responses(register_response_xml)
|
185
207
|
assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.register([{:email=>"mary@example.com",:account_id=>1}])
|
186
208
|
end
|
187
|
-
|
209
|
+
|
188
210
|
def test_unregister_with_array
|
189
211
|
expect_http_posts_with_responses(unregister_response_xml)
|
190
212
|
assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.unregister(["4228600737_c96da02bba97aedfd26136e980ae3761"])
|
@@ -194,7 +216,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
194
216
|
expect_http_posts_with_responses(unregister_response_xml)
|
195
217
|
assert_equal ["mary@example.com"],Facebooker::User.unregister_emails(["mary@example.com"])
|
196
218
|
end
|
197
|
-
|
219
|
+
|
198
220
|
def test_register_with_array_raises_if_not_all_success
|
199
221
|
expect_http_posts_with_responses(register_response_xml)
|
200
222
|
assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.register([{:email=>"mary@example.com",:account_id=>1},{:email=>"mike@example.com",:account_id=>2}])
|
@@ -202,7 +224,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
202
224
|
rescue Facebooker::Session::UserRegistrationFailed => e
|
203
225
|
assert_equal({:email=>"mike@example.com",:account_id=>2},e.failed_users.first)
|
204
226
|
end
|
205
|
-
|
227
|
+
|
206
228
|
def test_unregister_with_array_raises_if_not_all_success
|
207
229
|
expect_http_posts_with_responses(unregister_response_xml)
|
208
230
|
assert_equal ["4228600737_c96da02bba97aedfd26136e980ae3761"],Facebooker::User.unregister(["4228600737_c96da02bba97aedfd26136e980ae3761","3587916587_791214eb452bf4de30e957d65a0234d4"])
|
@@ -219,19 +241,19 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
219
241
|
assert_equal("mike@example.com",e.failed_users.first)
|
220
242
|
end
|
221
243
|
|
222
|
-
|
244
|
+
|
223
245
|
def test_get_locale
|
224
246
|
@user = Facebooker::User.new(9507801, @session)
|
225
247
|
expect_http_posts_with_responses(example_users_get_info_xml)
|
226
248
|
assert_equal "en_US", @user.locale
|
227
249
|
end
|
228
|
-
|
250
|
+
|
229
251
|
def test_get_profile_url
|
230
252
|
@user = Facebooker::User.new(8055, @session)
|
231
253
|
expect_http_posts_with_responses(example_users_get_info_xml)
|
232
254
|
assert_equal "http://www.facebook.com/profile.php?id=8055", @user.profile_url
|
233
255
|
end
|
234
|
-
|
256
|
+
|
235
257
|
private
|
236
258
|
def example_profile_photos_get_xml
|
237
259
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
@@ -262,7 +284,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
262
284
|
</photo>
|
263
285
|
</photos_get_response>"
|
264
286
|
end
|
265
|
-
|
287
|
+
|
266
288
|
def example_events_get_xml
|
267
289
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
268
290
|
<events_get_response xmlns=\"http://api.facebook.com/1.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd\" list=\"true\">
|
@@ -294,31 +316,31 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
294
316
|
</event>
|
295
317
|
</events_get_response>"
|
296
318
|
end
|
297
|
-
|
319
|
+
|
298
320
|
def example_users_get_info_xml
|
299
321
|
<<-XML
|
300
322
|
<?xml version="1.0" encoding="UTF-8"?> <users_getInfo_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true"> <user> <uid>8055</uid> <about_me>This field perpetuates the glorification of the ego. Also, it has a character limit.</about_me> <activities>Here: facebook, etc. There: Glee Club, a capella, teaching.</activities> <affiliations list="true"> <affiliation> <nid>50453093</nid> <name>Facebook Developers</name> <type>work</type> <status/> <year/> </affiliation> </affiliations> <birthday>November 3</birthday> <books>The Brothers K, GEB, Ken Wilber, Zen and the Art, Fitzgerald, The Emporer's New Mind, The Wonderful Story of Henry Sugar</books> <current_location> <city>Palo Alto</city> <state>CA</state> <country>United States</country> <zip>94303</zip> </current_location> <education_history list="true"> <education_info> <name>Harvard</name> <year>2003</year> <concentrations list="true"> <concentration>Applied Mathematics</concentration> <concentration>Computer Science</concentration> </concentrations> </education_info> </education_history> <first_name>Dave</first_name> <hometown_location> <city>York</city> <state>PA</state> <country>United States</country> </hometown_location> <hs_info> <hs1_name>Central York High School</hs1_name> <hs2_name/> <grad_year>1999</grad_year> <hs1_id>21846</hs1_id> <hs2_id>0</hs2_id> </hs_info> <is_app_user>1</is_app_user> <has_added_app>1</has_added_app> <interests>coffee, computers, the funny, architecture, code breaking,snowboarding, philosophy, soccer, talking to strangers</interests> <last_name>Fetterman</last_name> <locale>en_US</locale> <meeting_for list="true"> <seeking>Friendship</seeking> </meeting_for> <meeting_sex list="true"> <sex>female</sex> </meeting_sex> <movies>Tommy Boy, Billy Madison, Fight Club, Dirty Work, Meet the Parents, My Blue Heaven, Office Space </movies> <music>New Found Glory, Daft Punk, Weezer, The Crystal Method, Rage, the KLF, Green Day, Live, Coldplay, Panic at the Disco, Family Force 5</music> <name>Dave Fetterman</name> <notes_count>0</notes_count> <pic>http://photos-055.facebook.com/ip007/profile3/1271/65/s8055_39735.jpg</pic> <pic_big>http://photos-055.facebook.com/ip007/profile3/1271/65/n8055_39735.jpg</pic_big> <pic_small>http://photos-055.facebook.com/ip007/profile3/1271/65/t8055_39735.jpg</pic_small> <pic_square>http://photos-055.facebook.com/ip007/profile3/1271/65/q8055_39735.jpg</pic_square> <political>Moderate</political> <profile_update_time>1170414620</profile_update_time> <profile_url>http://www.facebook.com/profile.php?id=8055</profile_url> <quotes/> <relationship_status>In a Relationship</relationship_status> <religion/> <sex>male</sex> <significant_other_id xsi:nil="true"/> <status> <message>Fast Company, November issue, page 84</message> <time>1193075616</time> </status> <timezone>-8</timezone> <tv>cf. Bob Trahan</tv> <wall_count>121</wall_count> <work_history list="true"> <work_info> <location> <city>Palo Alto</city> <state>CA</state> <country>United States</country> </location> <company_name>Facebook</company_name> <position>Software Engineer</position> <description>Tech Lead, Facebook Platform</description> <start_date>2006-01</start_date> <end_date/> </work_info> </work_history> </user> </users_getInfo_response>
|
301
323
|
XML
|
302
324
|
end
|
303
|
-
|
325
|
+
|
304
326
|
def register_response_xml
|
305
327
|
<<-XML
|
306
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
307
|
-
<connect_registerUsers_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/facebook.xsd" list="true">
|
308
|
-
<connect_registerUsers_response_elt>4228600737_c96da02bba97aedfd26136e980ae3761</connect_registerUsers_response_elt>
|
328
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
329
|
+
<connect_registerUsers_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/facebook.xsd" list="true">
|
330
|
+
<connect_registerUsers_response_elt>4228600737_c96da02bba97aedfd26136e980ae3761</connect_registerUsers_response_elt>
|
309
331
|
</connect_registerUsers_response>
|
310
332
|
XML
|
311
333
|
end
|
312
|
-
|
334
|
+
|
313
335
|
def unregister_response_xml
|
314
336
|
<<-XML
|
315
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
316
|
-
<connect_unregisterUsers_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/facebook.xsd" list="true">
|
317
|
-
<connect_unregisterUsers_response_elt>4228600737_c96da02bba97aedfd26136e980ae3761</connect_unregisterUsers_response_elt>
|
337
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
338
|
+
<connect_unregisterUsers_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/facebook.xsd" list="true">
|
339
|
+
<connect_unregisterUsers_response_elt>4228600737_c96da02bba97aedfd26136e980ae3761</connect_unregisterUsers_response_elt>
|
318
340
|
</connect_unregisterUsers_response>
|
319
341
|
XML
|
320
|
-
end
|
321
|
-
|
342
|
+
end
|
343
|
+
|
322
344
|
def has_app_permission_response_xml
|
323
345
|
<<-XML
|
324
346
|
<?xml version="1.0" encoding="UTF-8"?>
|
@@ -327,5 +349,18 @@ class Facebooker::UserTest < Test::Unit::TestCase
|
|
327
349
|
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</users_hasAppPermission_response>
|
328
350
|
XML
|
329
351
|
end
|
330
|
-
|
352
|
+
|
353
|
+
def example_profile_publish_to_get_xml
|
354
|
+
<<-eoxml
|
355
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
356
|
+
<stream_publish_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">703826862_78463536862</stream_publish_response>
|
357
|
+
eoxml
|
358
|
+
end
|
359
|
+
|
360
|
+
def example_comment_on_response
|
361
|
+
<<-eoxml
|
362
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
363
|
+
<stream_addComment_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">703826862_78463536863</stream_addComment_response>
|
364
|
+
eoxml
|
365
|
+
end
|
331
366
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
2
|
+
require 'facebooker/rails/facebook_request_fix_2-3' if Rails.version >= '2.3'
|
3
|
+
class Facebooker::Rails::FacebookRequestFix23Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
7
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
8
|
+
if Rails.version < '2.3'
|
9
|
+
@request = ActionController::TestRequest.new({"fb_sig_is_ajax"=>"1"}, {}, nil)
|
10
|
+
|
11
|
+
else
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@request.query_parameters[:fb_sig_is_ajax] = "1"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_xhr_when_is_ajax
|
18
|
+
assert @request.xhr?
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_xml_http_request_when_is_ajax
|
22
|
+
assert @request.xml_http_request?
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
2
|
+
|
3
|
+
class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@request = ActionController::TestRequest.new
|
7
|
+
@params = {}
|
8
|
+
@rewriter = ActionController::UrlRewriter.new(@request, @params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_one_or_true_on_string_1
|
12
|
+
assert @rewriter.one_or_true( "1" )
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_one_or_true_on_string_0
|
16
|
+
assert !@rewriter.one_or_true( "0" )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_one_or_true_on_integer_1
|
20
|
+
assert @rewriter.one_or_true( 1 )
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_one_or_true_on_float_1
|
24
|
+
assert @rewriter.one_or_true( 1.0 )
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_one_or_true_on_true
|
28
|
+
assert @rewriter.one_or_true( true )
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_one_or_true_on_false
|
32
|
+
assert !@rewriter.one_or_true( false )
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_one_or_true_on_nil
|
36
|
+
assert !@rewriter.one_or_true( nil )
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -427,6 +427,10 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
|
427
427
|
assert_equal('http://apps.facebook.com/mike/pokes/do/1',route_image.href)
|
428
428
|
end
|
429
429
|
|
430
|
+
def test_image_holder_equality
|
431
|
+
assert_equal TestPublisher::ImageHolder.new('image.png', 'raw_string'), TestPublisher::ImageHolder.new('image.png', 'raw_string')
|
432
|
+
end
|
433
|
+
|
430
434
|
def test_image_to_json_puts_src_first
|
431
435
|
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
432
436
|
assert_equal "{\"src\":\"/images/image.png\", \"href\":\"raw_string\"}",string_image.to_json
|
@@ -437,7 +441,7 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
|
437
441
|
|
438
442
|
def test_default_url_options
|
439
443
|
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
440
|
-
assert_equal({:host=>"apps.facebook.com/mike"},TestPublisher.default_url_options)
|
444
|
+
assert_equal({:host=>"apps.facebook.com/mike"},TestPublisher.new.default_url_options)
|
441
445
|
end
|
442
446
|
|
443
447
|
def test_recipients
|
@@ -37,6 +37,13 @@ class FBConnectController < NoisyController
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
class FBConnectControllerProxy < NoisyController
|
41
|
+
before_filter :create_facebook_session_with_secret
|
42
|
+
def index
|
43
|
+
render :text => 'score!'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
40
47
|
class ControllerWhichRequiresFacebookAuthentication < NoisyController
|
41
48
|
ensure_authenticated_to_facebook
|
42
49
|
def index
|
@@ -259,13 +266,13 @@ class RailsIntegrationTestForApplicationInstallation < Test::Unit::TestCase
|
|
259
266
|
def test_if_controller_requires_application_installation_unauthenticated_requests_will_redirect_to_install_page
|
260
267
|
get :index
|
261
268
|
assert_response :redirect
|
262
|
-
assert_equal("http://www.facebook.com/install.php?api_key=1234567&v=1.0", @response.headers['Location'])
|
269
|
+
assert_equal("http://www.facebook.com/install.php?api_key=1234567&v=1.0&next=http%3A%2F%2Ftest.host%2Frequire_install", @response.headers['Location'])
|
263
270
|
end
|
264
271
|
|
265
272
|
def test_if_controller_requires_application_installation_authenticated_requests_without_installation_will_redirect_to_install_page
|
266
273
|
get :index, facebook_params(:fb_sig_added => nil)
|
267
274
|
assert_response :success
|
268
|
-
|
275
|
+
assert(@response.body =~ /fb:redirect/)
|
269
276
|
end
|
270
277
|
|
271
278
|
def test_if_controller_requires_application_installation_authenticated_requests_with_installation_will_render
|
@@ -297,7 +304,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
297
304
|
def test_if_controller_requires_facebook_authentication_unauthenticated_requests_will_redirect
|
298
305
|
get :index
|
299
306
|
assert_response :redirect
|
300
|
-
assert_equal("http://www.facebook.com/login.php?api_key=1234567&v=1.0", @response.headers['Location'])
|
307
|
+
assert_equal("http://www.facebook.com/login.php?api_key=1234567&v=1.0&next=http%3A%2F%2Ftest.host%2Frequire_auth", @response.headers['Location'])
|
301
308
|
end
|
302
309
|
|
303
310
|
def test_facebook_params_are_parsed_into_a_separate_hash
|
@@ -372,6 +379,20 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
372
379
|
assert_equal(1111111, @controller.facebook_session.user.id)
|
373
380
|
end
|
374
381
|
|
382
|
+
def test_session_can_be_secured_with_secret
|
383
|
+
@controller = FBConnectControllerProxy.new
|
384
|
+
auth_token = 'ohaiauthtokenhere111'
|
385
|
+
modified_params = facebook_params
|
386
|
+
modified_params.delete('fb_sig_session_key')
|
387
|
+
modified_params['auth_token'] = auth_token
|
388
|
+
modified_params['generate_session_secret'] = true
|
389
|
+
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
390
|
+
session_params = { 'session_key' => '123', 'uid' => '321' }
|
391
|
+
session_mock.should_receive(:post).with('facebook.auth.getSession', :auth_token => auth_token, :generate_session_secret => "1").once.and_return(session_params).ordered
|
392
|
+
flexmock(@controller).should_receive(:new_facebook_session).once.and_return(session).ordered
|
393
|
+
get :index, modified_params
|
394
|
+
end
|
395
|
+
|
375
396
|
def test_session_can_be_secured_with_auth_token
|
376
397
|
auth_token = 'ohaiauthtokenhere111'
|
377
398
|
modified_params = facebook_params
|
@@ -379,7 +400,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
379
400
|
modified_params['auth_token'] = auth_token
|
380
401
|
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
381
402
|
session_params = { 'session_key' => '123', 'uid' => '321' }
|
382
|
-
session_mock.should_receive(:post).with('facebook.auth.getSession', :auth_token => auth_token).once.and_return(session_params).ordered
|
403
|
+
session_mock.should_receive(:post).with('facebook.auth.getSession', :auth_token => auth_token, :generate_session_secret => "0").once.and_return(session_params).ordered
|
383
404
|
flexmock(@controller).should_receive(:new_facebook_session).once.and_return(session).ordered
|
384
405
|
get :index, modified_params
|
385
406
|
end
|
@@ -391,7 +412,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
391
412
|
modified_params['auth_token'] = auth_token
|
392
413
|
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
393
414
|
session_params = { 'session_key' => '123', 'uid' => '321' }
|
394
|
-
session_mock.should_receive(:post).with('facebook.auth.getSession', :auth_token => auth_token).once.and_return(session_params).ordered
|
415
|
+
session_mock.should_receive(:post).with('facebook.auth.getSession', :auth_token => auth_token, :generate_session_secret => "0").once.and_return(session_params).ordered
|
395
416
|
flexmock(@controller).should_receive(:new_facebook_session).once.and_return(session).ordered
|
396
417
|
setup_fb_connect_cookies(expired_cookie_hash_for_auth)
|
397
418
|
get :index, modified_params
|
@@ -425,7 +446,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
425
446
|
def test_redirect_to_renders_fbml_redirect_tag_if_request_is_for_a_facebook_canvas
|
426
447
|
get :index, facebook_params(:fb_sig_user => nil)
|
427
448
|
assert_response :success
|
428
|
-
|
449
|
+
assert @response.body =~ /fb:redirect/
|
429
450
|
end
|
430
451
|
|
431
452
|
def test_redirect_to_renders_javascript_redirect_if_request_is_for_a_facebook_iframe
|
@@ -433,7 +454,6 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
433
454
|
assert_response :success
|
434
455
|
assert_match "javascript", @response.body
|
435
456
|
assert_match "http-equiv", @response.body
|
436
|
-
assert_match "http://www.facebook.com/login.php?api_key=1234567&v=1.0".to_json, @response.body
|
437
457
|
assert_match "http://www.facebook.com/login.php?api_key=1234567&v=1.0", @response.body
|
438
458
|
end
|
439
459
|
|
@@ -643,6 +663,22 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
643
663
|
|
644
664
|
end
|
645
665
|
|
666
|
+
def test_fb_prompt_permissions_valid_no_callback
|
667
|
+
assert_equal "<fb:prompt-permission perms=\"publish_stream,read_stream\">Can I read and write your streams?</fb:prompt-permission>",
|
668
|
+
@h.fb_prompt_permissions(['publish_stream', 'read_stream'],"Can I read and write your streams?")
|
669
|
+
end
|
670
|
+
|
671
|
+
def test_fb_prompt_permissions_valid_with_callback
|
672
|
+
assert_equal "<fb:prompt-permission next_fbjs=\"do_stuff()\" perms=\"publish_stream,read_stream\">Can I read and write your streams?</fb:prompt-permission>",
|
673
|
+
@h.fb_prompt_permissions(['publish_stream', 'read_stream'],"Can I read and write your streams?", "do_stuff()")
|
674
|
+
end
|
675
|
+
|
676
|
+
def test_fb_prompt_permissions_invalid_option
|
677
|
+
assert_raises(ArgumentError) {@h.fb_prompt_permissions(["invliad", "read_stream"], "a message")}
|
678
|
+
|
679
|
+
end
|
680
|
+
|
681
|
+
|
646
682
|
def test_fb_add_profile_section
|
647
683
|
assert_equal "<fb:add-section-button section=\"profile\" />",@h.fb_add_profile_section
|
648
684
|
end
|
@@ -1000,6 +1036,14 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
1000
1036
|
assert @h.init_fb_connect("XFBML", :js => :jquery).match(/\$\(document\).ready\(/)
|
1001
1037
|
end
|
1002
1038
|
|
1039
|
+
def test_init_fb_connect_without_options_app_settings
|
1040
|
+
assert @h.init_fb_connect().match(/, \{\}\)/)
|
1041
|
+
end
|
1042
|
+
|
1043
|
+
def test_init_fb_connect_with_options_app_settings
|
1044
|
+
assert @h.init_fb_connect(:app_settings => "{foo: bar}").match(/, \{foo: bar\}\)/)
|
1045
|
+
end
|
1046
|
+
|
1003
1047
|
|
1004
1048
|
def test_fb_login_and_redirect
|
1005
1049
|
assert_equal @h.fb_login_and_redirect("/path"),"<fb:login-button onlogin=\"window.location.href = "/path";\"></fb:login-button>"
|
@@ -1010,7 +1054,7 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
1010
1054
|
end
|
1011
1055
|
def test_fb_user_action
|
1012
1056
|
action = Facebooker::Rails::Publisher::UserAction.new
|
1013
|
-
assert_equal @h.fb_user_action(action,"message","prompt"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", \"message\");"
|
1057
|
+
assert_equal @h.fb_user_action(action,"message","prompt"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", {\"value\": \"message\"});"
|
1014
1058
|
end
|
1015
1059
|
|
1016
1060
|
|