facebooker-fbg1 1.0.61.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (154) hide show
  1. data/.autotest +15 -0
  2. data/CHANGELOG.rdoc +24 -0
  3. data/COPYING.rdoc +19 -0
  4. data/Manifest.txt +150 -0
  5. data/README.rdoc +119 -0
  6. data/Rakefile +94 -0
  7. data/TODO.rdoc +4 -0
  8. data/examples/desktop_login.rb +14 -0
  9. data/facebooker.gemspec +42 -0
  10. data/generators/facebook/facebook_generator.rb +14 -0
  11. data/generators/facebook/templates/config/facebooker.yml +49 -0
  12. data/generators/facebook/templates/public/javascripts/facebooker.js +332 -0
  13. data/generators/facebook_controller/USAGE +33 -0
  14. data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
  15. data/generators/facebook_controller/templates/controller.rb +7 -0
  16. data/generators/facebook_controller/templates/functional_test.rb +11 -0
  17. data/generators/facebook_controller/templates/helper.rb +2 -0
  18. data/generators/facebook_controller/templates/view.fbml.erb +2 -0
  19. data/generators/facebook_controller/templates/view.html.erb +2 -0
  20. data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
  21. data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
  22. data/generators/facebook_publisher/templates/publisher.rb +3 -0
  23. data/generators/facebook_scaffold/USAGE +27 -0
  24. data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
  25. data/generators/facebook_scaffold/templates/controller.rb +93 -0
  26. data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
  27. data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
  28. data/generators/facebook_scaffold/templates/helper.rb +2 -0
  29. data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
  30. data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
  31. data/generators/facebook_scaffold/templates/style.css +74 -0
  32. data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
  33. data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
  34. data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
  35. data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
  36. data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
  37. data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
  38. data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
  39. data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
  40. data/generators/publisher/publisher_generator.rb +14 -0
  41. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  42. data/generators/xd_receiver/templates/xd_receiver_ssl.html +10 -0
  43. data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
  44. data/init.rb +26 -0
  45. data/install.rb +12 -0
  46. data/lib/facebooker.rb +254 -0
  47. data/lib/facebooker/adapters/adapter_base.rb +91 -0
  48. data/lib/facebooker/adapters/bebo_adapter.rb +77 -0
  49. data/lib/facebooker/adapters/facebook_adapter.rb +60 -0
  50. data/lib/facebooker/admin.rb +42 -0
  51. data/lib/facebooker/application.rb +13 -0
  52. data/lib/facebooker/attachment.rb +51 -0
  53. data/lib/facebooker/batch_request.rb +45 -0
  54. data/lib/facebooker/data.rb +57 -0
  55. data/lib/facebooker/feed.rb +78 -0
  56. data/lib/facebooker/logging.rb +44 -0
  57. data/lib/facebooker/mobile.rb +20 -0
  58. data/lib/facebooker/mock/service.rb +50 -0
  59. data/lib/facebooker/mock/session.rb +18 -0
  60. data/lib/facebooker/model.rb +139 -0
  61. data/lib/facebooker/models/affiliation.rb +10 -0
  62. data/lib/facebooker/models/album.rb +11 -0
  63. data/lib/facebooker/models/applicationproperties.rb +39 -0
  64. data/lib/facebooker/models/applicationrestrictions.rb +10 -0
  65. data/lib/facebooker/models/cookie.rb +10 -0
  66. data/lib/facebooker/models/education_info.rb +11 -0
  67. data/lib/facebooker/models/event.rb +28 -0
  68. data/lib/facebooker/models/family_relative_info.rb +7 -0
  69. data/lib/facebooker/models/friend_list.rb +16 -0
  70. data/lib/facebooker/models/group.rb +36 -0
  71. data/lib/facebooker/models/info_item.rb +10 -0
  72. data/lib/facebooker/models/info_section.rb +10 -0
  73. data/lib/facebooker/models/location.rb +8 -0
  74. data/lib/facebooker/models/notifications.rb +17 -0
  75. data/lib/facebooker/models/page.rb +44 -0
  76. data/lib/facebooker/models/photo.rb +19 -0
  77. data/lib/facebooker/models/tag.rb +12 -0
  78. data/lib/facebooker/models/user.rb +575 -0
  79. data/lib/facebooker/models/video.rb +9 -0
  80. data/lib/facebooker/models/work_info.rb +10 -0
  81. data/lib/facebooker/parser.rb +724 -0
  82. data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
  83. data/lib/facebooker/rails/controller.rb +372 -0
  84. data/lib/facebooker/rails/cucumber.rb +28 -0
  85. data/lib/facebooker/rails/cucumber/world.rb +40 -0
  86. data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
  87. data/lib/facebooker/rails/extensions/rack_setup.rb +14 -0
  88. data/lib/facebooker/rails/extensions/routing.rb +15 -0
  89. data/lib/facebooker/rails/facebook_form_builder.rb +141 -0
  90. data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
  91. data/lib/facebooker/rails/facebook_request_fix.rb +28 -0
  92. data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
  93. data/lib/facebooker/rails/facebook_session_handling.rb +68 -0
  94. data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
  95. data/lib/facebooker/rails/facebook_url_rewriting.rb +60 -0
  96. data/lib/facebooker/rails/helpers.rb +834 -0
  97. data/lib/facebooker/rails/helpers/fb_connect.rb +133 -0
  98. data/lib/facebooker/rails/helpers/stream_publish.rb +22 -0
  99. data/lib/facebooker/rails/integration_session.rb +38 -0
  100. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  101. data/lib/facebooker/rails/publisher.rb +599 -0
  102. data/lib/facebooker/rails/routing.rb +49 -0
  103. data/lib/facebooker/rails/test_helpers.rb +68 -0
  104. data/lib/facebooker/rails/utilities.rb +22 -0
  105. data/lib/facebooker/server_cache.rb +24 -0
  106. data/lib/facebooker/service.rb +102 -0
  107. data/lib/facebooker/service/base_service.rb +19 -0
  108. data/lib/facebooker/service/curl_service.rb +44 -0
  109. data/lib/facebooker/service/net_http_service.rb +12 -0
  110. data/lib/facebooker/service/typhoeus_multi_service.rb +27 -0
  111. data/lib/facebooker/service/typhoeus_service.rb +17 -0
  112. data/lib/facebooker/session.rb +732 -0
  113. data/lib/facebooker/stream_post.rb +19 -0
  114. data/lib/facebooker/version.rb +9 -0
  115. data/lib/net/http_multipart_post.rb +123 -0
  116. data/lib/rack/facebook.rb +89 -0
  117. data/lib/rack/facebook_session.rb +21 -0
  118. data/lib/tasks/facebooker.rake +18 -0
  119. data/lib/tasks/facebooker.rb +2 -0
  120. data/lib/tasks/tunnel.rake +46 -0
  121. data/rails/init.rb +1 -0
  122. data/setup.rb +1585 -0
  123. data/templates/layout.erb +24 -0
  124. data/test/facebooker/adapters_test.rb +191 -0
  125. data/test/facebooker/admin_test.rb +102 -0
  126. data/test/facebooker/application_test.rb +41 -0
  127. data/test/facebooker/attachment_test.rb +72 -0
  128. data/test/facebooker/batch_request_test.rb +83 -0
  129. data/test/facebooker/data_test.rb +86 -0
  130. data/test/facebooker/logging_test.rb +43 -0
  131. data/test/facebooker/mobile_test.rb +45 -0
  132. data/test/facebooker/model_test.rb +133 -0
  133. data/test/facebooker/models/event_test.rb +15 -0
  134. data/test/facebooker/models/page_test.rb +51 -0
  135. data/test/facebooker/models/photo_test.rb +16 -0
  136. data/test/facebooker/models/user_test.rb +430 -0
  137. data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +25 -0
  138. data/test/facebooker/rails/facebook_url_rewriting_test.rb +76 -0
  139. data/test/facebooker/rails/integration_session_test.rb +13 -0
  140. data/test/facebooker/rails/publisher_test.rb +532 -0
  141. data/test/facebooker/rails_integration_test.rb +1534 -0
  142. data/test/facebooker/server_cache_test.rb +44 -0
  143. data/test/facebooker/service_test.rb +58 -0
  144. data/test/facebooker/session_test.rb +883 -0
  145. data/test/facebooker_test.rb +951 -0
  146. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  147. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  148. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  149. data/test/net/http_multipart_post_test.rb +52 -0
  150. data/test/rack/facebook_session_test.rb +34 -0
  151. data/test/rack/facebook_test.rb +73 -0
  152. data/test/rails_test_helper.rb +36 -0
  153. data/test/test_helper.rb +74 -0
  154. metadata +272 -0
@@ -0,0 +1,31 @@
1
+ module Facebooker::Rails::BackwardsCompatibleParamChecks
2
+
3
+ def one_or_true( value )
4
+ case value
5
+ when String then
6
+ value == "1"
7
+ when Numeric then
8
+ value.to_f == 1.0
9
+ when TrueClass then
10
+ true
11
+ else
12
+ false
13
+ end
14
+ end
15
+
16
+ def zero_or_false( value )
17
+ case value
18
+ when String then
19
+ value.empty? || value == "0"
20
+ when Numeric then
21
+ value.to_f == 0.0
22
+ when FalseClass then
23
+ true
24
+ when NilClass then
25
+ true
26
+ else
27
+ false
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,372 @@
1
+ require 'facebooker'
2
+ require 'facebooker/rails/profile_publisher_extensions'
3
+ module Facebooker
4
+ module Rails
5
+ module Controller
6
+ include Facebooker::Rails::BackwardsCompatibleParamChecks
7
+ include Facebooker::Rails::ProfilePublisherExtensions
8
+ def self.included(controller)
9
+ controller.extend(ClassMethods)
10
+ controller.before_filter :set_facebook_request_format
11
+ controller.helper_attr :facebook_session_parameters
12
+ controller.helper_method :request_comes_from_facebook?
13
+ end
14
+
15
+ def initialize *args
16
+ @facebook_session = nil
17
+ @installation_required = nil
18
+ super
19
+ end
20
+
21
+ def facebook_session
22
+ @facebook_session
23
+ end
24
+
25
+ def facebook_session_parameters
26
+ {:fb_sig_session_key=>params[:fb_sig_session_key]}
27
+ end
28
+
29
+ def create_facebook_session
30
+ secure_with_facebook_params! || secure_with_connect_js! || secure_with_cookies! || secure_with_token!
31
+ end
32
+
33
+ #this is used to proxy a connection through a rails app so the facebook secret key is not needed
34
+ #iphone apps use this
35
+ def create_facebook_session_with_secret
36
+ secure_with_session_secret!
37
+ end
38
+
39
+ def set_facebook_session
40
+ # first, see if we already have a session
41
+ session_set = session_already_secured?
42
+ # if not, see if we can load it from the environment
43
+ unless session_set
44
+ session_set = create_facebook_session
45
+ session[:facebook_session] = @facebook_session if session_set
46
+ end
47
+ if session_set
48
+ capture_facebook_friends_if_available!
49
+ Session.current = facebook_session
50
+ end
51
+ return session_set
52
+ end
53
+
54
+
55
+ def facebook_params
56
+ @facebook_params ||= verified_facebook_params
57
+ end
58
+
59
+ # Redirects the top window to the given url if the content is in an iframe, otherwise performs
60
+ # a normal redirect_to call.
61
+ def top_redirect_to(*args)
62
+ if request_is_facebook_iframe?
63
+ @redirect_url = url_for(*args)
64
+ render :layout => false, :inline => <<-HTML
65
+ <html><head>
66
+ <script type="text/javascript">
67
+ window.top.location.href = <%= @redirect_url.to_json -%>;
68
+ </script>
69
+ <noscript>
70
+ <meta http-equiv="refresh" content="0;url=<%=h @redirect_url %>" />
71
+ <meta http-equiv="window-target" content="_top" />
72
+ </noscript>
73
+ </head></html>
74
+ HTML
75
+ else
76
+ redirect_to(*args)
77
+ end
78
+ end
79
+
80
+ def redirect_to(*args)
81
+ if request_is_for_a_facebook_canvas? and !request_is_facebook_tab?
82
+ render :text => fbml_redirect_tag(*args)
83
+ else
84
+ super
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def session_already_secured?
91
+ (@facebook_session = session[:facebook_session]) && session[:facebook_session].secured? if valid_session_key_in_session?
92
+ end
93
+
94
+ def user_has_deauthorized_application?
95
+ # if we're inside the facebook session and there is no session key,
96
+ # that means the user revoked our access
97
+ # we don't want to keep using the old expired key from the cookie.
98
+ request_comes_from_facebook? and params[:fb_sig_session_key].blank?
99
+ end
100
+
101
+ def clear_facebook_session_information
102
+ session[:facebook_session] = nil
103
+ @facebook_session=nil
104
+ end
105
+
106
+ def valid_session_key_in_session?
107
+ #before we access the facebook_params, make sure we have the parameters
108
+ #otherwise we will blow up trying to access the secure parameters
109
+ if user_has_deauthorized_application?
110
+ clear_facebook_session_information
111
+ false
112
+ else
113
+ !session[:facebook_session].blank? && (params[:fb_sig_session_key].blank? || session[:facebook_session].session_key == facebook_params[:session_key])
114
+ end
115
+ end
116
+
117
+ def clear_fb_cookies!
118
+ domain_cookie_tag = "base_domain_#{Facebooker.api_key}"
119
+ cookie_domain = ".#{cookies[domain_cookie_tag]}" if cookies[domain_cookie_tag]
120
+ fb_cookie_names.each {|name| cookies.delete(name, :domain=>cookie_domain)}
121
+ cookies.delete Facebooker.api_key
122
+ end
123
+
124
+ def fb_cookie_prefix
125
+ Facebooker.api_key+"_"
126
+ end
127
+
128
+ def fb_cookie_names
129
+ fb_cookie_names = cookies.keys.select{|k| k && k.starts_with?(fb_cookie_prefix)}
130
+ end
131
+
132
+ def secure_with_connect_js!
133
+ cookie_str = cookies["fbs_#{Facebooker.api_key}"]
134
+ return unless cookie_str
135
+ parsed = {}
136
+ cookie_str = cookie_str[1..-2] # get rid of quotes
137
+ cookie_str.split('&').each do |kv|
138
+ pair = kv.split('=')
139
+ parsed[pair[0]] = pair[1]
140
+ end
141
+ return unless parsed['session_key'] && parsed['uid'] && parsed['expires'] && parsed['secret'] && parsed['sig']
142
+ expected_sig = parsed['sig']
143
+ parsed.delete 'sig'
144
+ verify_signature(parsed, expected_sig, true)
145
+
146
+ @facebook_session = new_facebook_session
147
+ @facebook_session.secure_with!(parsed['session_key'],parsed['uid'],parsed['expires'],parsed['secret'])
148
+ @facebook_session
149
+ end
150
+
151
+ def secure_with_cookies!
152
+ parsed = {}
153
+
154
+ fb_cookie_names.each { |key| parsed[key[fb_cookie_prefix.size,key.size]] = cookies[key] }
155
+
156
+ #returning gracefully if the cookies aren't set or have expired
157
+ return unless parsed['session_key'] && parsed['user'] && parsed['expires'] && parsed['ss']
158
+ return unless (Time.at(parsed['expires'].to_s.to_f) > Time.now) || (parsed['expires'] == "0")
159
+ #if we have the unexpired cookies, we'll throw an exception if the sig doesn't verify
160
+ verify_signature(parsed,cookies[Facebooker.api_key], true)
161
+
162
+ @facebook_session = new_facebook_session
163
+ @facebook_session.secure_with!(parsed['session_key'],parsed['user'],parsed['expires'],parsed['ss'])
164
+ @facebook_session
165
+ end
166
+
167
+ def secure_with_token!
168
+ if params['auth_token']
169
+ @facebook_session = new_facebook_session
170
+ @facebook_session.auth_token = params['auth_token']
171
+ @facebook_session.secure!
172
+ @facebook_session
173
+ end
174
+ end
175
+
176
+ def secure_with_session_secret!
177
+ if params['auth_token']
178
+ @facebook_session = new_facebook_session
179
+ @facebook_session.auth_token = params['auth_token']
180
+ @facebook_session.secure_with_session_secret!
181
+ @facebook_session
182
+ end
183
+ end
184
+
185
+ def secure_with_facebook_params!
186
+ return unless request_comes_from_facebook?
187
+
188
+ if ['user', 'session_key'].all? {|element| facebook_params[element]}
189
+ @facebook_session = new_facebook_session
190
+ @facebook_session.secure_with!(facebook_params['session_key'], facebook_params['user'], facebook_params['expires'])
191
+ @facebook_session
192
+ end
193
+ end
194
+
195
+ #override to specify where the user should be sent after logging in
196
+ def after_facebook_login_url
197
+ nil
198
+ end
199
+
200
+ def default_after_facebook_login_url
201
+ omit_keys = ["_method", "format"]
202
+ options = (params||{}).clone
203
+ options = options.reject{|k,v| k.to_s.match(/^fb_sig/) or omit_keys.include?(k.to_s)}
204
+ options = options.merge({:only_path => false})
205
+ url_for(options)
206
+ end
207
+
208
+ def create_new_facebook_session_and_redirect!
209
+ session[:facebook_session] = new_facebook_session
210
+ next_url = after_facebook_login_url || default_after_facebook_login_url
211
+ top_redirect_to session[:facebook_session].login_url({:next => next_url, :canvas=>params[:fb_sig_in_canvas]}) unless @installation_required
212
+ false
213
+ end
214
+
215
+ def new_facebook_session
216
+ Facebooker::Session.create(Facebooker.api_key, Facebooker.secret_key)
217
+ end
218
+
219
+ def capture_facebook_friends_if_available!
220
+ return unless request_comes_from_facebook?
221
+ if friends = facebook_params['friends']
222
+ facebook_session.user.friends = friends.map do |friend_uid|
223
+ User.new(friend_uid, facebook_session)
224
+ end
225
+ end
226
+ end
227
+
228
+ def verified_facebook_params
229
+ facebook_sig_params = params.inject({}) do |collection, pair|
230
+ collection[pair.first.sub(/^fb_sig_/, '')] = pair.last if pair.first[0,7] == 'fb_sig_'
231
+ collection
232
+ end
233
+ verify_signature(facebook_sig_params,params['fb_sig'])
234
+
235
+ facebook_sig_params.inject(HashWithIndifferentAccess.new) do |collection, pair|
236
+ collection[pair.first] = facebook_parameter_conversions[pair.first].call(pair.last)
237
+ collection
238
+ end
239
+ end
240
+
241
+ def earliest_valid_session
242
+ 48.hours.ago
243
+ end
244
+
245
+ def verify_signature(facebook_sig_params,expected_signature,force=false)
246
+ # Don't verify the signature if rack has already done so.
247
+ unless ::Rails.version >= "2.3" and ActionController::Dispatcher.middleware.include? Rack::Facebook and !force
248
+ raw_string = facebook_sig_params.map{ |*args| args.join('=') }.sort.join
249
+ actual_sig = Digest::MD5.hexdigest([raw_string, Facebooker::Session.secret_key].join)
250
+ raise Facebooker::Session::IncorrectSignature if actual_sig != expected_signature
251
+ end
252
+ raise Facebooker::Session::SignatureTooOld if facebook_sig_params['time'] && Time.at(facebook_sig_params['time'].to_f) < earliest_valid_session
253
+ true
254
+ end
255
+
256
+ def facebook_parameter_conversions
257
+ @facebook_parameter_conversions ||= Hash.new do |hash, key|
258
+ lambda{|value| value}
259
+ end.merge(
260
+ 'time' => lambda{|value| Time.at(value.to_f)},
261
+ 'in_canvas' => lambda{|value| one_or_true(value)},
262
+ 'added' => lambda{|value| one_or_true(value)},
263
+ 'expires' => lambda{|value| zero_or_false(value) ? nil : Time.at(value.to_f)},
264
+ 'friends' => lambda{|value| value.split(/,/)}
265
+ )
266
+ end
267
+
268
+ def fbml_redirect_tag(url)
269
+ "<fb:redirect url=\"#{url_for(url)}\" />"
270
+ end
271
+
272
+ def request_comes_from_facebook?
273
+ request_is_for_a_facebook_canvas? || request_is_facebook_ajax? || request_is_fb_ping?
274
+ end
275
+
276
+ def request_is_fb_ping?
277
+ !params['fb_sig'].blank?
278
+ end
279
+
280
+ def request_is_for_a_facebook_canvas?
281
+ !params['fb_sig_in_canvas'].blank?
282
+ end
283
+
284
+ def request_is_facebook_tab?
285
+ !params["fb_sig_in_profile_tab"].blank?
286
+ end
287
+
288
+ def request_is_facebook_iframe?
289
+ !params["fb_sig_in_iframe"].blank?
290
+ end
291
+
292
+ def request_is_facebook_ajax?
293
+ one_or_true(params["fb_sig_is_mockajax"]) || one_or_true(params["fb_sig_is_ajax"])
294
+ end
295
+
296
+ def xml_http_request?
297
+ request_is_facebook_ajax? || super
298
+ end
299
+
300
+ def application_is_installed?
301
+ facebook_params['added']
302
+ end
303
+
304
+ def ensure_has_status_update
305
+ has_extended_permission?("status_update") || application_needs_permission("status_update")
306
+ end
307
+ def ensure_has_photo_upload
308
+ has_extended_permission?("photo_upload") || application_needs_permission("photo_upload")
309
+ end
310
+ def ensure_has_video_upload
311
+ has_extended_permission?("video_upload") || application_needs_permission("video_upload")
312
+ end
313
+ def ensure_has_create_listing
314
+ has_extended_permission?("create_listing") || application_needs_permission("create_listing")
315
+ end
316
+ def ensure_has_create_event
317
+ has_extended_permission?("create_event") || application_needs_permission("create_event")
318
+ end
319
+
320
+ def application_needs_permission(perm)
321
+ top_redirect_to(facebook_session.permission_url(perm))
322
+ end
323
+
324
+ def has_extended_permission?(perm)
325
+ params["fb_sig_ext_perms"] and params["fb_sig_ext_perms"].include?(perm)
326
+ end
327
+
328
+ def ensure_authenticated_to_facebook
329
+ set_facebook_session || create_new_facebook_session_and_redirect!
330
+ end
331
+
332
+ def ensure_application_is_installed_by_facebook_user
333
+ @installation_required = true
334
+ returning ensure_authenticated_to_facebook && application_is_installed? do |authenticated_and_installed|
335
+ application_is_not_installed_by_facebook_user unless authenticated_and_installed
336
+ end
337
+ end
338
+
339
+ def application_is_not_installed_by_facebook_user
340
+ next_url = after_facebook_login_url || default_after_facebook_login_url
341
+ top_redirect_to session[:facebook_session].install_url({:next => next_url})
342
+ end
343
+
344
+ def set_facebook_request_format
345
+ if request_is_facebook_ajax?
346
+ request.format = :fbjs
347
+ elsif request_comes_from_facebook? && !request_is_facebook_iframe?
348
+ request.format = :fbml
349
+ end
350
+ end
351
+
352
+
353
+ module ClassMethods
354
+ #
355
+ # Creates a filter which reqires a user to have already authenticated to
356
+ # Facebook before executing actions. Accepts the same optional options hash which
357
+ # before_filter and after_filter accept.
358
+ def ensure_authenticated_to_facebook(options = {})
359
+ before_filter :ensure_authenticated_to_facebook, options
360
+ end
361
+
362
+ def ensure_application_is_installed_by_facebook_user(options = {})
363
+ before_filter :ensure_application_is_installed_by_facebook_user, options
364
+ end
365
+
366
+ def request_comes_from_facebook?
367
+ request_is_for_a_facebook_canvas? || request_is_facebook_ajax?
368
+ end
369
+ end
370
+ end
371
+ end
372
+ end
@@ -0,0 +1,28 @@
1
+ require 'facebooker/rails/cucumber/world'
2
+ require 'facebooker/mock/session'
3
+ require 'facebooker/mock/service'
4
+
5
+ Facebooker::MockService.fixture_path = File.join(RAILS_ROOT, 'features', 'support', 'facebook')
6
+
7
+ module Facebooker
8
+ class << self
9
+ # prevent Facebooker from adding canvas name as prefix to URLs
10
+ def request_for_canvas(arg)
11
+ yield
12
+ end
13
+ end
14
+
15
+ module Rails
16
+ module Controller
17
+ # prevent Facebooker from rendering fb:redirect
18
+ def redirect_to(*args)
19
+ super
20
+ end
21
+
22
+ # Return the mock session
23
+ def new_facebook_session
24
+ Facebooker::MockSession.create
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ require 'cucumber/rails/world'
2
+ require 'facebooker/rails/integration_session'
3
+
4
+ module Facebooker
5
+ module Rails
6
+ module Cucumber
7
+ def open_session
8
+ session = Facebooker::Rails::IntegrationSession.new
9
+
10
+ # delegate the fixture accessors back to the test instance
11
+ extras = Module.new { attr_accessor :delegate, :test_result }
12
+ if self.class.respond_to?(:fixture_table_names)
13
+ self.class.fixture_table_names.each do |table_name|
14
+ name = table_name.tr(".", "_")
15
+ next unless respond_to?(name)
16
+ extras.__send__(:define_method, name) { |*args| delegate.send(name, *args) }
17
+ end
18
+ end
19
+
20
+ # delegate add_assertion to the test case
21
+ extras.__send__(:define_method, :add_assertion) { test_result.add_assertion }
22
+ session.extend(extras)
23
+ session.delegate = self
24
+ session.test_result = @_result
25
+
26
+ yield session if block_given?
27
+ session
28
+ end
29
+
30
+ def without_canvas
31
+ in_canvas = @integration_session.canvas
32
+ @integration_session.canvas = false
33
+ yield
34
+ @integration_session.canvas = in_canvas
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ World(Facebooker::Rails::Cucumber)