taweili-facebooker 1.0.37
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/.autotest +15 -0
- data/CHANGELOG.rdoc +24 -0
- data/COPYING.rdoc +19 -0
- data/Manifest.txt +133 -0
- data/README.rdoc +104 -0
- data/Rakefile +85 -0
- data/TODO.rdoc +4 -0
- data/examples/desktop_login.rb +14 -0
- data/facebooker.gemspec +38 -0
- data/generators/facebook/facebook_generator.rb +14 -0
- data/generators/facebook/templates/config/facebooker.yml +49 -0
- data/generators/facebook/templates/public/javascripts/facebooker.js +83 -0
- data/generators/facebook_controller/USAGE +33 -0
- data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
- data/generators/facebook_controller/templates/controller.rb +7 -0
- data/generators/facebook_controller/templates/functional_test.rb +11 -0
- data/generators/facebook_controller/templates/helper.rb +2 -0
- data/generators/facebook_controller/templates/view.fbml.erb +2 -0
- data/generators/facebook_controller/templates/view.html.erb +2 -0
- data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
- data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
- data/generators/facebook_publisher/templates/publisher.rb +3 -0
- data/generators/facebook_scaffold/USAGE +27 -0
- data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
- data/generators/facebook_scaffold/templates/controller.rb +93 -0
- data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
- data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
- data/generators/facebook_scaffold/templates/helper.rb +2 -0
- data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
- data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
- data/generators/facebook_scaffold/templates/style.css +74 -0
- data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
- data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
- data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
- data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
- data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
- data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
- data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
- data/generators/publisher/publisher_generator.rb +14 -0
- data/generators/xd_receiver/templates/xd_receiver.html +10 -0
- data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
- data/init.rb +25 -0
- data/install.rb +12 -0
- data/lib/facebooker/adapters/adapter_base.rb +91 -0
- data/lib/facebooker/adapters/bebo_adapter.rb +77 -0
- data/lib/facebooker/adapters/facebook_adapter.rb +52 -0
- data/lib/facebooker/admin.rb +42 -0
- data/lib/facebooker/batch_request.rb +45 -0
- data/lib/facebooker/data.rb +57 -0
- data/lib/facebooker/feed.rb +78 -0
- data/lib/facebooker/logging.rb +44 -0
- data/lib/facebooker/mobile.rb +20 -0
- data/lib/facebooker/mock/service.rb +50 -0
- data/lib/facebooker/mock/session.rb +18 -0
- data/lib/facebooker/model.rb +139 -0
- data/lib/facebooker/models/affiliation.rb +10 -0
- data/lib/facebooker/models/album.rb +11 -0
- data/lib/facebooker/models/applicationproperties.rb +39 -0
- data/lib/facebooker/models/applicationrestrictions.rb +10 -0
- data/lib/facebooker/models/cookie.rb +10 -0
- data/lib/facebooker/models/education_info.rb +11 -0
- data/lib/facebooker/models/event.rb +28 -0
- data/lib/facebooker/models/friend_list.rb +16 -0
- data/lib/facebooker/models/group.rb +36 -0
- data/lib/facebooker/models/info_item.rb +10 -0
- data/lib/facebooker/models/info_section.rb +10 -0
- data/lib/facebooker/models/location.rb +8 -0
- data/lib/facebooker/models/notifications.rb +17 -0
- data/lib/facebooker/models/page.rb +28 -0
- data/lib/facebooker/models/photo.rb +19 -0
- data/lib/facebooker/models/tag.rb +12 -0
- data/lib/facebooker/models/user.rb +497 -0
- data/lib/facebooker/models/video.rb +9 -0
- data/lib/facebooker/models/work_info.rb +10 -0
- data/lib/facebooker/parser.rb +650 -0
- data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
- data/lib/facebooker/rails/controller.rb +337 -0
- data/lib/facebooker/rails/cucumber/world.rb +46 -0
- data/lib/facebooker/rails/cucumber.rb +28 -0
- data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
- data/lib/facebooker/rails/extensions/rack_setup.rb +6 -0
- data/lib/facebooker/rails/extensions/routing.rb +15 -0
- data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
- data/lib/facebooker/rails/facebook_request_fix.rb +30 -0
- data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
- data/lib/facebooker/rails/facebook_session_handling.rb +68 -0
- data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
- data/lib/facebooker/rails/facebook_url_rewriting.rb +60 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +118 -0
- data/lib/facebooker/rails/helpers.rb +780 -0
- data/lib/facebooker/rails/integration_session.rb +38 -0
- data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
- data/lib/facebooker/rails/publisher.rb +554 -0
- data/lib/facebooker/rails/routing.rb +49 -0
- data/lib/facebooker/rails/test_helpers.rb +68 -0
- data/lib/facebooker/rails/utilities.rb +22 -0
- data/lib/facebooker/server_cache.rb +24 -0
- data/lib/facebooker/service.rb +102 -0
- data/lib/facebooker/session.rb +606 -0
- data/lib/facebooker/version.rb +9 -0
- data/lib/facebooker.rb +180 -0
- data/lib/net/http_multipart_post.rb +123 -0
- data/lib/rack/facebook.rb +77 -0
- data/lib/tasks/facebooker.rake +18 -0
- data/lib/tasks/tunnel.rake +46 -0
- data/rails/init.rb +1 -0
- data/setup.rb +1585 -0
- data/templates/layout.erb +24 -0
- data/test/facebooker/adapters_test.rb +96 -0
- data/test/facebooker/admin_test.rb +102 -0
- data/test/facebooker/batch_request_test.rb +83 -0
- data/test/facebooker/data_test.rb +86 -0
- data/test/facebooker/logging_test.rb +43 -0
- data/test/facebooker/mobile_test.rb +45 -0
- data/test/facebooker/model_test.rb +133 -0
- data/test/facebooker/models/event_test.rb +15 -0
- data/test/facebooker/models/photo_test.rb +16 -0
- data/test/facebooker/models/user_test.rb +343 -0
- data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +24 -0
- data/test/facebooker/rails/facebook_url_rewriting_test.rb +39 -0
- data/test/facebooker/rails/publisher_test.rb +481 -0
- data/test/facebooker/rails_integration_test.rb +1398 -0
- data/test/facebooker/server_cache_test.rb +44 -0
- data/test/facebooker/session_test.rb +614 -0
- data/test/facebooker_test.rb +951 -0
- data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
- data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
- data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
- data/test/net/http_multipart_post_test.rb +52 -0
- data/test/rack/facebook_test.rb +61 -0
- data/test/rails_test_helper.rb +27 -0
- data/test/test_helper.rb +74 -0
- metadata +232 -0
@@ -0,0 +1,1398 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../rails_test_helper')
|
2
|
+
|
3
|
+
module FBConnectTestHelpers
|
4
|
+
def setup_fb_connect_cookies(params=cookie_hash_for_auth)
|
5
|
+
params.each {|k,v| @request.cookies[ENV['FACEBOOK_API_KEY']+k] = CGI::Cookie.new(ENV['FACEBOOK_API_KEY']+k,v)}
|
6
|
+
end
|
7
|
+
|
8
|
+
def expired_cookie_hash_for_auth
|
9
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.ago.to_i}"}
|
10
|
+
end
|
11
|
+
|
12
|
+
def cookie_hash_for_auth
|
13
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.from_now.to_i}"}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
class NoisyController < ActionController::Base
|
17
|
+
include Facebooker::Rails::Controller
|
18
|
+
def rescue_action(e) raise e end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class ControllerWhichRequiresExtendedPermissions< NoisyController
|
23
|
+
ensure_authenticated_to_facebook
|
24
|
+
before_filter :ensure_has_status_update
|
25
|
+
before_filter :ensure_has_photo_upload
|
26
|
+
before_filter :ensure_has_video_upload
|
27
|
+
before_filter :ensure_has_create_listing
|
28
|
+
def index
|
29
|
+
render :text => 'score!'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class FBConnectController < NoisyController
|
34
|
+
before_filter :create_facebook_session
|
35
|
+
def index
|
36
|
+
render :text => 'score!'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class ControllerWhichRequiresFacebookAuthentication < NoisyController
|
41
|
+
ensure_authenticated_to_facebook
|
42
|
+
def index
|
43
|
+
render :text => 'score!'
|
44
|
+
end
|
45
|
+
def link_test
|
46
|
+
options = {}
|
47
|
+
options[:canvas] = true if params[:canvas] == true
|
48
|
+
options[:canvas] = false if params[:canvas] == false
|
49
|
+
render :text=>url_for(options)
|
50
|
+
end
|
51
|
+
|
52
|
+
def named_route_test
|
53
|
+
render :text=>comments_url()
|
54
|
+
end
|
55
|
+
|
56
|
+
def image_test
|
57
|
+
render :inline=>"<%=image_tag 'image.png'%>"
|
58
|
+
end
|
59
|
+
|
60
|
+
def fb_params_test
|
61
|
+
render :text=>facebook_params['user']
|
62
|
+
end
|
63
|
+
|
64
|
+
def publisher_test
|
65
|
+
if wants_interface?
|
66
|
+
render :text=>"interface"
|
67
|
+
else
|
68
|
+
render :text=>"not interface"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def publisher_test_interface
|
73
|
+
render_publisher_interface("This is a test",false,true)
|
74
|
+
end
|
75
|
+
|
76
|
+
def publisher_test_response
|
77
|
+
ua=Facebooker::Rails::Publisher::UserAction.new
|
78
|
+
ua.data = {:params=>true}
|
79
|
+
ua.template_name = "template_name"
|
80
|
+
ua.template_id = 1234
|
81
|
+
render_publisher_response(ua)
|
82
|
+
end
|
83
|
+
|
84
|
+
def publisher_test_error
|
85
|
+
render_publisher_error("Title","Body")
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
class ControllerWhichRequiresApplicationInstallation < NoisyController
|
90
|
+
ensure_application_is_installed_by_facebook_user
|
91
|
+
def index
|
92
|
+
render :text => 'installed!'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
class FacebookController < ActionController::Base
|
96
|
+
def index
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class PlainOldRailsController < ActionController::Base
|
101
|
+
def index
|
102
|
+
end
|
103
|
+
def link_test
|
104
|
+
options = {}
|
105
|
+
options[:canvas] = true if params[:canvas] == true
|
106
|
+
options[:canvas] = false if params[:canvas] == false
|
107
|
+
render :text => url_for(options)
|
108
|
+
end
|
109
|
+
|
110
|
+
def named_route_test
|
111
|
+
render :text=>comments_url()
|
112
|
+
end
|
113
|
+
def canvas_false_test
|
114
|
+
render :text=>comments_url(:canvas=>false)
|
115
|
+
end
|
116
|
+
def canvas_true_test
|
117
|
+
render :text=>comments_url(:canvas=>true)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
class Test::Unit::TestCase
|
122
|
+
include Facebooker::Rails::TestHelpers
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
# you can't use asset_recognize, because it can't pass parameters in to the requests
|
127
|
+
class UrlRecognitionTests < Test::Unit::TestCase
|
128
|
+
def test_detects_in_canvas
|
129
|
+
if Rails.version < '2.3'
|
130
|
+
request = ActionController::TestRequest.new({"fb_sig_in_canvas"=>"1"}, {}, nil)
|
131
|
+
else
|
132
|
+
request = ActionController::TestRequest.new
|
133
|
+
request.query_parameters[:fb_sig_in_canvas] = "1"
|
134
|
+
end
|
135
|
+
request.path = "/"
|
136
|
+
ActionController::Routing::Routes.recognize(request)
|
137
|
+
assert_equal({"controller"=>"facebook","action"=>"index"},request.path_parameters)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_routes_when_not_in_canvas
|
141
|
+
if Rails.version < '2.3'
|
142
|
+
request = ActionController::TestRequest.new({}, {}, nil)
|
143
|
+
else
|
144
|
+
request = ActionController::TestRequest.new
|
145
|
+
end
|
146
|
+
request.path = "/"
|
147
|
+
ActionController::Routing::Routes.recognize(request)
|
148
|
+
assert_equal({"controller"=>"plain_old_rails","action"=>"index"},request.path_parameters)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class RailsIntegrationTestForFBConnect < Test::Unit::TestCase
|
153
|
+
include FBConnectTestHelpers
|
154
|
+
|
155
|
+
def setup
|
156
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
|
157
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
158
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
159
|
+
@controller = FBConnectController.new
|
160
|
+
@request = ActionController::TestRequest.new
|
161
|
+
@response = ActionController::TestResponse.new
|
162
|
+
@controller.stubs(:verify_signature).returns(true)
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_doesnt_set_cookie_but_facebook_session_is_available
|
167
|
+
setup_fb_connect_cookies
|
168
|
+
get :index
|
169
|
+
assert_not_nil @controller.facebook_session
|
170
|
+
assert_nil @response.cookies[:facebook_session]
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
class RailsIntegrationTestForNonFacebookControllers < Test::Unit::TestCase
|
176
|
+
def setup
|
177
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
|
178
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
179
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
180
|
+
@controller = PlainOldRailsController.new
|
181
|
+
@request = ActionController::TestRequest.new
|
182
|
+
@response = ActionController::TestResponse.new
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_url_for_links_to_callback_if_canvas_is_false_and_in_canvas
|
186
|
+
get :link_test
|
187
|
+
assert_match(/test.host/, @response.body)
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_named_route_doesnt_include_canvas_path_when_not_in_canvas
|
191
|
+
get :named_route_test
|
192
|
+
assert_equal "http://test.host/comments",@response.body
|
193
|
+
end
|
194
|
+
def test_named_route_includes_canvas_path_when_in_canvas
|
195
|
+
get :named_route_test, facebook_params
|
196
|
+
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_named_route_doesnt_include_canvas_path_when_in_canvas_with_canvas_equals_false
|
200
|
+
get :canvas_false_test, facebook_params
|
201
|
+
assert_equal "http://test.host/comments",@response.body
|
202
|
+
end
|
203
|
+
def test_named_route_does_include_canvas_path_when_not_in_canvas_with_canvas_equals_true
|
204
|
+
get :canvas_true_test
|
205
|
+
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
class RailsIntegrationTestForExtendedPermissions < Test::Unit::TestCase
|
211
|
+
def setup
|
212
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
213
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
214
|
+
@controller = ControllerWhichRequiresExtendedPermissions.new
|
215
|
+
@request = ActionController::TestRequest.new
|
216
|
+
@response = ActionController::TestResponse.new
|
217
|
+
@controller.stubs(:verify_signature).returns(true)
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_redirects_without_set_status
|
221
|
+
post :index, facebook_params
|
222
|
+
assert_response :success
|
223
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=status_update\" />", @response.body)
|
224
|
+
end
|
225
|
+
def test_redirects_without_photo_upload
|
226
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update")
|
227
|
+
assert_response :success
|
228
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=photo_upload\" />", @response.body)
|
229
|
+
end
|
230
|
+
def test_redirects_without_video_upload
|
231
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update,photo_upload")
|
232
|
+
assert_response :success
|
233
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=video_upload\" />", @response.body)
|
234
|
+
end
|
235
|
+
def test_redirects_without_create_listing
|
236
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update,photo_upload,video_upload")
|
237
|
+
assert_response :success
|
238
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=create_listing\" />", @response.body)
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_renders_with_permission
|
242
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update,photo_upload,create_listing,video_upload")
|
243
|
+
assert_response :success
|
244
|
+
assert_equal("score!", @response.body)
|
245
|
+
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
class RailsIntegrationTestForApplicationInstallation < Test::Unit::TestCase
|
250
|
+
def setup
|
251
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
252
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
253
|
+
@controller = ControllerWhichRequiresApplicationInstallation.new
|
254
|
+
@request = ActionController::TestRequest.new
|
255
|
+
@response = ActionController::TestResponse.new
|
256
|
+
@controller.stubs(:verify_signature).returns(true)
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_if_controller_requires_application_installation_unauthenticated_requests_will_redirect_to_install_page
|
260
|
+
get :index
|
261
|
+
assert_response :redirect
|
262
|
+
assert_equal("http://www.facebook.com/install.php?api_key=1234567&v=1.0", @response.headers['Location'])
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_if_controller_requires_application_installation_authenticated_requests_without_installation_will_redirect_to_install_page
|
266
|
+
get :index, facebook_params(:fb_sig_added => nil)
|
267
|
+
assert_response :success
|
268
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/install.php?api_key=1234567&v=1.0\" />", @response.body)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_if_controller_requires_application_installation_authenticated_requests_with_installation_will_render
|
272
|
+
get :index, facebook_params('fb_sig_added' => "1")
|
273
|
+
assert_response :success
|
274
|
+
assert_equal("installed!", @response.body)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
class RailsIntegrationTest < Test::Unit::TestCase
|
279
|
+
include FBConnectTestHelpers
|
280
|
+
def setup
|
281
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='root'
|
282
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
283
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
284
|
+
ActionController::Base.asset_host="http://root.example.com"
|
285
|
+
@controller = ControllerWhichRequiresFacebookAuthentication.new
|
286
|
+
@request = ActionController::TestRequest.new
|
287
|
+
@response = ActionController::TestResponse.new
|
288
|
+
@controller.stubs(:verify_signature).returns(true)
|
289
|
+
|
290
|
+
end
|
291
|
+
|
292
|
+
def test_named_route_includes_new_canvas_path_when_in_new_canvas
|
293
|
+
get :named_route_test, facebook_params("fb_sig_in_new_facebook"=>"1")
|
294
|
+
assert_equal "http://apps.facebook.com/root/comments",@response.body
|
295
|
+
end
|
296
|
+
|
297
|
+
def test_if_controller_requires_facebook_authentication_unauthenticated_requests_will_redirect
|
298
|
+
get :index
|
299
|
+
assert_response :redirect
|
300
|
+
assert_equal("http://www.facebook.com/login.php?api_key=1234567&v=1.0", @response.headers['Location'])
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_facebook_params_are_parsed_into_a_separate_hash
|
304
|
+
get :index, facebook_params(:fb_sig_user => '9')
|
305
|
+
assert_not_nil @controller.facebook_params['time']
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_facebook_params_convert_in_canvas_to_boolean
|
309
|
+
get :index, facebook_params
|
310
|
+
assert_equal(true, @controller.facebook_params['in_canvas'])
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_facebook_params_convert_added_to_boolean_false
|
314
|
+
get :index, facebook_params(:fb_sig_added => '0')
|
315
|
+
assert_equal(false, @controller.facebook_params['added'])
|
316
|
+
end
|
317
|
+
|
318
|
+
def test_facebook_params_convert_added_to_boolean_true
|
319
|
+
get :index, facebook_params('fb_sig_added' => "1")
|
320
|
+
assert_equal(true, @controller.facebook_params['added'])
|
321
|
+
end
|
322
|
+
|
323
|
+
def test_facebook_params_convert_expirey_into_nil
|
324
|
+
get :index, facebook_params(:fb_sig_expires => '0')
|
325
|
+
assert_nil(@controller.facebook_params['expires'])
|
326
|
+
end
|
327
|
+
|
328
|
+
def test_facebook_params_convert_expirey_into_time
|
329
|
+
get :index, facebook_params(:fb_sig_expires => 5.minutes.from_now.to_f)
|
330
|
+
assert_instance_of Time, @controller.facebook_params['expires']
|
331
|
+
end
|
332
|
+
|
333
|
+
def test_facebook_params_convert_friend_list_to_parsed_array_of_friend_ids
|
334
|
+
get :index, facebook_params(:fb_sig_friends => '1,2,3,4,5')
|
335
|
+
assert_kind_of(Array, @controller.facebook_params['friends'])
|
336
|
+
assert_equal(5, @controller.facebook_params['friends'].size)
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_session_can_be_resecured_from_facebook_params
|
340
|
+
get :index, facebook_params(:fb_sig_user => 10)
|
341
|
+
assert_equal(10, @controller.facebook_session.user.id)
|
342
|
+
end
|
343
|
+
|
344
|
+
def test_existing_secured_session_is_used_if_available
|
345
|
+
session = Facebooker::Session.create(Facebooker::Session.api_key, Facebooker::Session.secret_key)
|
346
|
+
session.secure_with!("session_key", "111", Time.now.to_i + 60)
|
347
|
+
get :index, facebook_params(:fb_sig_session_key => 'session_key', :fb_sig_user => '987'), {:facebook_session => session}
|
348
|
+
assert_equal(111, @controller.facebook_session.user.id)
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_facebook_params_used_if_existing_secured_session_key_does_not_match
|
352
|
+
session = Facebooker::Session.create(Facebooker::Session.api_key, Facebooker::Session.secret_key)
|
353
|
+
session.secure_with!("different session key", "111", Time.now.to_i + 60)
|
354
|
+
get :index, facebook_params(:fb_sig_session_key => '', :fb_sig_user => '123'), {:facebook_session => session}
|
355
|
+
assert_equal(123, @controller.facebook_session.user.id)
|
356
|
+
end
|
357
|
+
|
358
|
+
def test_existing_secured_session_is_NOT_used_if_available_and_facebook_params_session_key_is_nil_and_in_canvas
|
359
|
+
session = Facebooker::Session.create(Facebooker::Session.api_key, Facebooker::Session.secret_key)
|
360
|
+
session.secure_with!("session_key", "111", Time.now.to_i + 60)
|
361
|
+
session.secure_with!("a session key", "1111111", Time.now.to_i + 60)
|
362
|
+
get :index, facebook_params(:fb_sig_session_key => '', :fb_sig_user => '987'), {:facebook_session => session}
|
363
|
+
assert_equal(987, @controller.facebook_session.user.id)
|
364
|
+
end
|
365
|
+
|
366
|
+
def test_existing_secured_session_IS_used_if_available_and_facebook_params_session_key_is_nil_and_NOT_in_canvas
|
367
|
+
@contoller = PlainOldRailsController.new
|
368
|
+
session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY'])
|
369
|
+
session.secure_with!("a session key", "1111111", Time.now.to_i + 60)
|
370
|
+
get :index,{}, {:facebook_session => session}
|
371
|
+
|
372
|
+
assert_equal(1111111, @controller.facebook_session.user.id)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_session_can_be_secured_with_auth_token
|
376
|
+
auth_token = 'ohaiauthtokenhere111'
|
377
|
+
modified_params = facebook_params
|
378
|
+
modified_params.delete('fb_sig_session_key')
|
379
|
+
modified_params['auth_token'] = auth_token
|
380
|
+
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
381
|
+
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
|
383
|
+
flexmock(@controller).should_receive(:new_facebook_session).once.and_return(session).ordered
|
384
|
+
get :index, modified_params
|
385
|
+
end
|
386
|
+
|
387
|
+
def test_session_secured_with_auth_token_if_cookies_expired
|
388
|
+
auth_token = 'ohaiauthtokenhere111'
|
389
|
+
modified_params = facebook_params
|
390
|
+
modified_params.delete('fb_sig_session_key')
|
391
|
+
modified_params['auth_token'] = auth_token
|
392
|
+
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
393
|
+
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
|
395
|
+
flexmock(@controller).should_receive(:new_facebook_session).once.and_return(session).ordered
|
396
|
+
setup_fb_connect_cookies(expired_cookie_hash_for_auth)
|
397
|
+
get :index, modified_params
|
398
|
+
assert_equal(321, @controller.facebook_session.user.id)
|
399
|
+
end
|
400
|
+
|
401
|
+
def test_session_can_be_secured_with_cookies
|
402
|
+
setup_fb_connect_cookies
|
403
|
+
get :index
|
404
|
+
assert_equal(77777, @controller.facebook_session.user.id)
|
405
|
+
end
|
406
|
+
|
407
|
+
def test_session_does_NOT_secure_with_expired_cookies
|
408
|
+
setup_fb_connect_cookies(expired_cookie_hash_for_auth)
|
409
|
+
get :index
|
410
|
+
assert_nil(@controller.facebook_session)
|
411
|
+
end
|
412
|
+
|
413
|
+
def test_user_friends_can_be_populated_from_facebook_params_if_available
|
414
|
+
get :index, facebook_params(:fb_sig_friends => '1,2,3,4')
|
415
|
+
friends = @controller.facebook_session.user.friends
|
416
|
+
assert_not_nil(friends)
|
417
|
+
assert_equal(4, friends.size)
|
418
|
+
end
|
419
|
+
|
420
|
+
def test_fbml_redirect_tag_handles_hash_parameters_correctly
|
421
|
+
get :index, facebook_params
|
422
|
+
assert_equal "<fb:redirect url=\"http://apps.facebook.com/root/require_auth\" />", @controller.send(:fbml_redirect_tag, :action => :index,:canvas=>true)
|
423
|
+
end
|
424
|
+
|
425
|
+
def test_redirect_to_renders_fbml_redirect_tag_if_request_is_for_a_facebook_canvas
|
426
|
+
get :index, facebook_params(:fb_sig_user => nil)
|
427
|
+
assert_response :success
|
428
|
+
assert_equal("<fb:redirect url=\"http://www.facebook.com/login.php?api_key=1234567&v=1.0\" />", @response.body)
|
429
|
+
end
|
430
|
+
|
431
|
+
def test_redirect_to_renders_javascript_redirect_if_request_is_for_a_facebook_iframe
|
432
|
+
get :index, facebook_params(:fb_sig_user => nil, :fb_sig_in_iframe => 1)
|
433
|
+
assert_response :success
|
434
|
+
assert_match "javascript", @response.body
|
435
|
+
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
|
+
assert_match "http://www.facebook.com/login.php?api_key=1234567&v=1.0", @response.body
|
438
|
+
end
|
439
|
+
|
440
|
+
def test_url_for_links_to_canvas_if_canvas_is_true_and_not_in_canvas
|
441
|
+
get :link_test, facebook_params(:fb_sig_in_canvas=>0,:canvas=>true)
|
442
|
+
assert_match(/apps.facebook.com/, @response.body)
|
443
|
+
end
|
444
|
+
|
445
|
+
def test_includes_relative_url_root_when_linked_to_canvas
|
446
|
+
get :link_test,facebook_params(:fb_sig_in_canvas=>0,:canvas=>true)
|
447
|
+
assert_match(/root/,@response.body)
|
448
|
+
end
|
449
|
+
|
450
|
+
def test_url_for_links_to_callback_if_canvas_is_false_and_in_canvas
|
451
|
+
get :link_test,facebook_params(:fb_sig_in_canvas=>0,:canvas=>false)
|
452
|
+
assert_match(/test.host/,@response.body)
|
453
|
+
end
|
454
|
+
|
455
|
+
def test_url_for_doesnt_include_url_root_when_not_linked_to_canvas
|
456
|
+
get :link_test,facebook_params(:fb_sig_in_canvas=>0,:canvas=>false)
|
457
|
+
assert !@response.body.match(/root/)
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_url_for_links_to_canvas_if_canvas_is_not_set
|
461
|
+
get :link_test,facebook_params
|
462
|
+
assert_match(/apps.facebook.com/,@response.body)
|
463
|
+
end
|
464
|
+
|
465
|
+
def test_image_tag
|
466
|
+
get :image_test, facebook_params
|
467
|
+
assert_equal "<img alt=\"Image\" src=\"http://root.example.com/images/image.png\" />",@response.body
|
468
|
+
end
|
469
|
+
|
470
|
+
def test_wants_interface_is_available_and_detects_method
|
471
|
+
get :publisher_test, facebook_params(:method=>"publisher_getInterface")
|
472
|
+
assert_equal "interface",@response.body
|
473
|
+
end
|
474
|
+
def test_wants_interface_is_available_and_detects_not_interface
|
475
|
+
get :publisher_test, facebook_params(:method=>"publisher_getFeedStory")
|
476
|
+
assert_equal "not interface",@response.body
|
477
|
+
end
|
478
|
+
|
479
|
+
def test_publisher_test_error
|
480
|
+
get :publisher_test_error, facebook_params
|
481
|
+
assert_equal Facebooker.json_decode("{\"errorCode\": 1, \"errorTitle\": \"Title\", \"errorMessage\": \"Body\"}"), Facebooker.json_decode(@response.body)
|
482
|
+
end
|
483
|
+
|
484
|
+
def test_publisher_test_interface
|
485
|
+
get :publisher_test_interface, facebook_params
|
486
|
+
assert_equal Facebooker.json_decode("{\"method\": \"publisher_getInterface\", \"content\": {\"fbml\": \"This is a test\", \"publishEnabled\": false, \"commentEnabled\": true}}"), Facebooker.json_decode(@response.body)
|
487
|
+
end
|
488
|
+
|
489
|
+
def test_publisher_test_reponse
|
490
|
+
get :publisher_test_response, facebook_params
|
491
|
+
assert_equal Facebooker.json_decode("{\"method\": \"publisher_getFeedStory\", \"content\": {\"feed\": {\"template_data\": {\"params\": true}, \"template_id\": 1234}}}"), Facebooker.json_decode(@response.body)
|
492
|
+
|
493
|
+
end
|
494
|
+
|
495
|
+
private
|
496
|
+
|
497
|
+
def expired_cookie_hash_for_auth
|
498
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.ago.to_i}"}
|
499
|
+
end
|
500
|
+
|
501
|
+
def cookie_hash_for_auth
|
502
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.from_now.to_i}"}
|
503
|
+
end
|
504
|
+
|
505
|
+
end
|
506
|
+
|
507
|
+
|
508
|
+
class RailsSignatureTest < Test::Unit::TestCase
|
509
|
+
def setup
|
510
|
+
ENV['FACEBOOKER_RELATIVE_URL_ROOT'] ='root'
|
511
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
512
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
513
|
+
@controller = ControllerWhichRequiresFacebookAuthentication.new
|
514
|
+
@request = ActionController::TestRequest.new
|
515
|
+
@response = ActionController::TestResponse.new
|
516
|
+
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_should_raise_too_old_for_replayed_session
|
520
|
+
begin
|
521
|
+
get :fb_params_test, facebook_params('fb_sig_time' => Time.now.to_i - 49.hours)
|
522
|
+
fail "No SignatureTooOld raised"
|
523
|
+
rescue Facebooker::Session::SignatureTooOld=>e
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
def test_should_raise_on_bad_sig
|
528
|
+
begin
|
529
|
+
get :fb_params_test, facebook_params.merge('fb_sig' => 'incorrect')
|
530
|
+
fail "No IncorrectSignature raised"
|
531
|
+
rescue Facebooker::Session::IncorrectSignature=>e
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
def test_valid_signature
|
536
|
+
@controller.expects(:earliest_valid_session).returns(Time.at(1186588275.5988)-1)
|
537
|
+
get :fb_params_test, facebook_params
|
538
|
+
|
539
|
+
end
|
540
|
+
|
541
|
+
end
|
542
|
+
class RailsHelperTest < Test::Unit::TestCase
|
543
|
+
class HelperClass
|
544
|
+
include ActionView::Helpers::TextHelper
|
545
|
+
include ActionView::Helpers::CaptureHelper
|
546
|
+
include ActionView::Helpers::TagHelper
|
547
|
+
include ActionView::Helpers::AssetTagHelper
|
548
|
+
include ActionView::Helpers::JavaScriptHelper
|
549
|
+
include Facebooker::Rails::Helpers
|
550
|
+
attr_accessor :flash, :output_buffer
|
551
|
+
def initialize
|
552
|
+
@flash={}
|
553
|
+
@template = self
|
554
|
+
@content_for_test_param="Test Param"
|
555
|
+
@output_buffer = ""
|
556
|
+
end
|
557
|
+
#used for stubbing out the form builder
|
558
|
+
def url_for(arg)
|
559
|
+
arg
|
560
|
+
end
|
561
|
+
def request
|
562
|
+
ActionController::TestRequest.new
|
563
|
+
end
|
564
|
+
def fields_for(*args)
|
565
|
+
""
|
566
|
+
end
|
567
|
+
|
568
|
+
end
|
569
|
+
|
570
|
+
# used for capturing the contents of some of the helper tests
|
571
|
+
# this duplicates the rails template system
|
572
|
+
attr_accessor :_erbout
|
573
|
+
|
574
|
+
def setup
|
575
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='facebook'
|
576
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
577
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
578
|
+
|
579
|
+
@_erbout = ""
|
580
|
+
@h = HelperClass.new
|
581
|
+
#use an asset path where the canvas path equals the hostname to make sure we handle that case right
|
582
|
+
ActionController::Base.asset_host='http://facebook.host.com'
|
583
|
+
end
|
584
|
+
|
585
|
+
def test_fb_profile_pic
|
586
|
+
assert_equal "<fb:profile-pic uid=\"1234\"></fb:profile-pic>", @h.fb_profile_pic("1234")
|
587
|
+
end
|
588
|
+
|
589
|
+
def test_fb_profile_pic_with_valid_size
|
590
|
+
assert_equal "<fb:profile-pic size=\"small\" uid=\"1234\"></fb:profile-pic>", @h.fb_profile_pic("1234", :size => :small)
|
591
|
+
end
|
592
|
+
|
593
|
+
def test_fb_profile_pic_with_width_and_height
|
594
|
+
assert_equal "<fb:profile-pic height=\"200\" uid=\"1234\" width=\"100\"></fb:profile-pic>", @h.fb_profile_pic("1234", :width => 100, :height => 200)
|
595
|
+
end
|
596
|
+
|
597
|
+
def test_fb_profile_pic_with_invalid_size
|
598
|
+
assert_raises(ArgumentError) {@h.fb_profile_pic("1234", :size => :mediumm)}
|
599
|
+
end
|
600
|
+
|
601
|
+
def test_fb_photo
|
602
|
+
assert_equal "<fb:photo pid=\"1234\"></fb:photo>",@h.fb_photo("1234")
|
603
|
+
end
|
604
|
+
|
605
|
+
def test_fb_photo_with_object_responding_to_photo_id
|
606
|
+
photo = flexmock("photo", :photo_id => "5678")
|
607
|
+
assert_equal "<fb:photo pid=\"5678\"></fb:photo>", @h.fb_photo(photo)
|
608
|
+
end
|
609
|
+
|
610
|
+
def test_fb_photo_with_invalid_size
|
611
|
+
assert_raises(ArgumentError) {@h.fb_photo("1234", :size => :medium)}
|
612
|
+
end
|
613
|
+
|
614
|
+
def test_fb_photo_with_invalid_size_value
|
615
|
+
assert_raises(ArgumentError) {@h.fb_photo("1234", :size => :mediumm)}
|
616
|
+
end
|
617
|
+
|
618
|
+
def test_fb_photo_with_invalid_align_value
|
619
|
+
assert_raises(ArgumentError) {@h.fb_photo("1234", :align => :rightt)}
|
620
|
+
end
|
621
|
+
|
622
|
+
def test_fb_photo_with_valid_align_value
|
623
|
+
assert_equal "<fb:photo align=\"right\" pid=\"1234\"></fb:photo>",@h.fb_photo("1234", :align => :right)
|
624
|
+
end
|
625
|
+
|
626
|
+
def test_fb_photo_with_class
|
627
|
+
assert_equal "<fb:photo class=\"picky\" pid=\"1234\"></fb:photo>",@h.fb_photo("1234", :class => :picky)
|
628
|
+
end
|
629
|
+
def test_fb_photo_with_style
|
630
|
+
assert_equal "<fb:photo pid=\"1234\" style=\"some=css;put=here;\"></fb:photo>",@h.fb_photo("1234", :style => "some=css;put=here;")
|
631
|
+
end
|
632
|
+
|
633
|
+
def test_fb_prompt_permission_valid_no_callback
|
634
|
+
assert_equal "<fb:prompt-permission perms=\"email\">Can I email you?</fb:prompt-permission>",@h.fb_prompt_permission("email","Can I email you?")
|
635
|
+
end
|
636
|
+
|
637
|
+
def test_fb_prompt_permission_valid_with_callback
|
638
|
+
assert_equal "<fb:prompt-permission next_fbjs=\"do_stuff()\" perms=\"email\">a message</fb:prompt-permission>",@h.fb_prompt_permission("email","a message","do_stuff()")
|
639
|
+
end
|
640
|
+
|
641
|
+
def test_fb_prompt_permission_invalid_option
|
642
|
+
assert_raises(ArgumentError) {@h.fb_prompt_permission("invliad", "a message")}
|
643
|
+
|
644
|
+
end
|
645
|
+
|
646
|
+
def test_fb_add_profile_section
|
647
|
+
assert_equal "<fb:add-section-button section=\"profile\" />",@h.fb_add_profile_section
|
648
|
+
end
|
649
|
+
|
650
|
+
def test_fb_add_info_section
|
651
|
+
assert_equal "<fb:add-section-button section=\"info\" />",@h.fb_add_info_section
|
652
|
+
end
|
653
|
+
|
654
|
+
def test_fb_name_with_invalid_key_sizee
|
655
|
+
assert_raises(ArgumentError) {@h.fb_name(1234, :sizee => false)}
|
656
|
+
end
|
657
|
+
|
658
|
+
def test_fb_name
|
659
|
+
assert_equal "<fb:name uid=\"1234\"></fb:name>",@h.fb_name("1234")
|
660
|
+
end
|
661
|
+
|
662
|
+
def test_fb_name_with_transformed_key
|
663
|
+
assert_equal "<fb:name uid=\"1234\" useyou=\"true\"></fb:name>", @h.fb_name(1234, :use_you => true)
|
664
|
+
end
|
665
|
+
|
666
|
+
def test_fb_name_with_user_responding_to_facebook_id
|
667
|
+
user = flexmock("user", :facebook_id => "5678")
|
668
|
+
assert_equal "<fb:name uid=\"5678\"></fb:name>", @h.fb_name(user)
|
669
|
+
end
|
670
|
+
|
671
|
+
def test_fb_name_with_invalid_key_linkd
|
672
|
+
assert_raises(ArgumentError) {@h.fb_name(1234, :linkd => false)}
|
673
|
+
end
|
674
|
+
|
675
|
+
def test_fb_tabs
|
676
|
+
assert_equal "<fb:tabs></fb:tabs>", @h.fb_tabs{}
|
677
|
+
end
|
678
|
+
|
679
|
+
def test_fb_tab_item
|
680
|
+
assert_equal "<fb:tab-item href=\"http://www.google.com\" title=\"Google\" />", @h.fb_tab_item("Google", "http://www.google.com")
|
681
|
+
end
|
682
|
+
|
683
|
+
def test_fb_tab_item_raises_exception_for_invalid_option
|
684
|
+
assert_raises(ArgumentError) {@h.fb_tab_item("Google", "http://www.google.com", :alignn => :right)}
|
685
|
+
end
|
686
|
+
|
687
|
+
def test_fb_tab_item_raises_exception_for_invalid_align_value
|
688
|
+
assert_raises(ArgumentError) {@h.fb_tab_item("Google", "http://www.google.com", :align => :rightt)}
|
689
|
+
end
|
690
|
+
|
691
|
+
def test_fb_req_choice
|
692
|
+
assert_equal "<fb:req-choice label=\"label\" url=\"url\" />", @h.fb_req_choice("label","url")
|
693
|
+
end
|
694
|
+
|
695
|
+
def test_fb_multi_friend_selector
|
696
|
+
assert_equal "<fb:multi-friend-selector actiontext=\"This is a message\" max=\"20\" showborder=\"false\" />", @h.fb_multi_friend_selector("This is a message")
|
697
|
+
end
|
698
|
+
def test_fb_multi_friend_selector_with_options
|
699
|
+
assert_equal "<fb:multi-friend-selector actiontext=\"This is a message\" exclude_ids=\"1,2\" max=\"20\" showborder=\"false\" />", @h.fb_multi_friend_selector("This is a message",:exclude_ids=>"1,2")
|
700
|
+
end
|
701
|
+
|
702
|
+
def test_fb_title
|
703
|
+
assert_equal "<fb:title>This is the canvas page window title</fb:title>", @h.fb_title("This is the canvas page window title")
|
704
|
+
end
|
705
|
+
|
706
|
+
def test_fb_google_analytics
|
707
|
+
assert_equal "<fb:google-analytics uacct=\"UA-9999999-99\" />", @h.fb_google_analytics("UA-9999999-99")
|
708
|
+
end
|
709
|
+
|
710
|
+
def test_fb_if_is_user_with_single_object
|
711
|
+
user = flexmock("user", :facebook_id => "5678")
|
712
|
+
assert_equal "<fb:if-is-user uid=\"5678\"></fb:if-is-user>", @h.fb_if_is_user(user){}
|
713
|
+
end
|
714
|
+
|
715
|
+
def test_fb_if_is_user_with_array
|
716
|
+
user1 = flexmock("user", :facebook_id => "5678")
|
717
|
+
user2 = flexmock("user", :facebook_id => "1234")
|
718
|
+
assert_equal "<fb:if-is-user uid=\"5678,1234\"></fb:if-is-user>", @h.fb_if_is_user([user1,user2]){}
|
719
|
+
end
|
720
|
+
|
721
|
+
def test_fb_else
|
722
|
+
assert_equal "<fb:else></fb:else>", @h.fb_else{}
|
723
|
+
end
|
724
|
+
|
725
|
+
def test_fb_about_url
|
726
|
+
ENV["FACEBOOK_API_KEY"]="1234"
|
727
|
+
assert_equal "http://www.facebook.com/apps/application.php?api_key=1234", @h.fb_about_url
|
728
|
+
end
|
729
|
+
|
730
|
+
def test_fb_ref_with_url
|
731
|
+
assert_equal "<fb:ref url=\"A URL\" />", @h.fb_ref(:url => "A URL")
|
732
|
+
end
|
733
|
+
|
734
|
+
def test_fb_ref_with_handle
|
735
|
+
assert_equal "<fb:ref handle=\"A Handle\" />", @h.fb_ref(:handle => "A Handle")
|
736
|
+
end
|
737
|
+
|
738
|
+
def test_fb_ref_with_invalid_attribute
|
739
|
+
assert_raises(ArgumentError) {@h.fb_ref(:handlee => "A HANLDE")}
|
740
|
+
end
|
741
|
+
|
742
|
+
def test_fb_ref_with_handle_and_url
|
743
|
+
assert_raises(ArgumentError) {@h.fb_ref(:url => "URL", :handle => "HANDLE")}
|
744
|
+
end
|
745
|
+
|
746
|
+
def test_facebook_messages_notice
|
747
|
+
@h.flash[:notice]="A message"
|
748
|
+
assert_equal "<fb:success message=\"A message\" />",@h.facebook_messages
|
749
|
+
end
|
750
|
+
|
751
|
+
def test_facebook_messages_error
|
752
|
+
@h.flash[:error]="An error"
|
753
|
+
assert_equal "<fb:error message=\"An error\" />",@h.facebook_messages
|
754
|
+
end
|
755
|
+
def test_fb_wall_post
|
756
|
+
assert_equal "<fb:wallpost uid=\"1234\">A wall post</fb:wallpost>",@h.fb_wall_post("1234","A wall post")
|
757
|
+
end
|
758
|
+
|
759
|
+
def test_fb_pronoun
|
760
|
+
assert_equal "<fb:pronoun uid=\"1234\"></fb:pronoun>", @h.fb_pronoun(1234)
|
761
|
+
end
|
762
|
+
|
763
|
+
def test_fb_pronoun_with_transformed_key
|
764
|
+
assert_equal "<fb:pronoun uid=\"1234\" usethey=\"true\"></fb:pronoun>", @h.fb_pronoun(1234, :use_they => true)
|
765
|
+
end
|
766
|
+
|
767
|
+
def test_fb_pronoun_with_user_responding_to_facebook_id
|
768
|
+
user = flexmock("user", :facebook_id => "5678")
|
769
|
+
assert_equal "<fb:pronoun uid=\"5678\"></fb:pronoun>", @h.fb_pronoun(user)
|
770
|
+
end
|
771
|
+
|
772
|
+
def test_fb_pronoun_with_invalid_key
|
773
|
+
assert_raises(ArgumentError) {@h.fb_pronoun(1234, :posessive => true)}
|
774
|
+
end
|
775
|
+
|
776
|
+
def test_fb_wall
|
777
|
+
@h.expects(:capture).returns("wall content")
|
778
|
+
@h.fb_wall do
|
779
|
+
end
|
780
|
+
assert_equal "<fb:wall>wall content</fb:wall>",@h.output_buffer
|
781
|
+
end
|
782
|
+
|
783
|
+
def test_fb_multi_friend_request
|
784
|
+
@h.expects(:capture).returns("body")
|
785
|
+
@h.expects(:protect_against_forgery?).returns(false)
|
786
|
+
@h.expects(:fb_multi_friend_selector).returns("friend selector")
|
787
|
+
assert_equal "<fb:request-form action=\"action\" content=\"body\" invite=\"true\" method=\"post\" type=\"invite\">friend selector</fb:request-form>",
|
788
|
+
(@h.fb_multi_friend_request("invite","ignored","action") {})
|
789
|
+
end
|
790
|
+
|
791
|
+
def test_fb_multi_friend_request_with_protection_against_forgery
|
792
|
+
@h.expects(:capture).returns("body")
|
793
|
+
@h.expects(:protect_against_forgery?).returns(true)
|
794
|
+
@h.expects(:request_forgery_protection_token).returns('forgery_token')
|
795
|
+
@h.expects(:form_authenticity_token).returns('form_token')
|
796
|
+
|
797
|
+
@h.expects(:fb_multi_friend_selector).returns("friend selector")
|
798
|
+
assert_equal "<fb:request-form action=\"action\" content=\"body\" invite=\"true\" method=\"post\" type=\"invite\">friend selector<input name=\"forgery_token\" type=\"hidden\" value=\"form_token\" /></fb:request-form>",
|
799
|
+
(@h.fb_multi_friend_request("invite","ignored","action") {})
|
800
|
+
end
|
801
|
+
|
802
|
+
def test_fb_dialog
|
803
|
+
@h.expects(:capture).returns("dialog content")
|
804
|
+
@h.fb_dialog( "my_dialog", "1" ) do
|
805
|
+
end
|
806
|
+
assert_equal '<fb:dialog cancel_button="1" id="my_dialog">dialog content</fb:dialog>', @h.output_buffer
|
807
|
+
end
|
808
|
+
def test_fb_dialog_title
|
809
|
+
assert_equal '<fb:dialog-title>My Little Dialog</fb:dialog-title>', @h.fb_dialog_title("My Little Dialog")
|
810
|
+
end
|
811
|
+
def test_fb_dialog_content
|
812
|
+
@h.expects(:capture).returns("dialog content content")
|
813
|
+
@h.fb_dialog_content do
|
814
|
+
end
|
815
|
+
assert_equal '<fb:dialog-content>dialog content content</fb:dialog-content>', @h.output_buffer
|
816
|
+
end
|
817
|
+
def test_fb_dialog_button
|
818
|
+
assert_equal '<fb:dialog-button clickrewriteform="my_form" clickrewriteid="my_dialog" clickrewriteurl="http://www.some_url_here.com/dialog_return.php" type="submit" value="Yes" />',
|
819
|
+
@h.fb_dialog_button("submit", "Yes", {:clickrewriteurl => "http://www.some_url_here.com/dialog_return.php",
|
820
|
+
:clickrewriteid => "my_dialog", :clickrewriteform => "my_form" } )
|
821
|
+
end
|
822
|
+
|
823
|
+
def test_fb_request_form
|
824
|
+
@h.expects(:capture).returns("body")
|
825
|
+
@h.expects(:protect_against_forgery?).returns(false)
|
826
|
+
assert_equal "<fb:request-form action=\"action\" content=\"Test Param\" invite=\"true\" method=\"post\" type=\"invite\">body</fb:request-form>",
|
827
|
+
(@h.fb_request_form("invite","test_param","action") {})
|
828
|
+
end
|
829
|
+
|
830
|
+
def test_fb_request_form_with_protect_against_forgery
|
831
|
+
@h.expects(:capture).returns("body")
|
832
|
+
@h.expects(:protect_against_forgery?).returns(true)
|
833
|
+
@h.expects(:request_forgery_protection_token).returns('forgery_token')
|
834
|
+
@h.expects(:form_authenticity_token).returns('form_token')
|
835
|
+
assert_equal "<fb:request-form action=\"action\" content=\"Test Param\" invite=\"true\" method=\"post\" type=\"invite\">body<input name=\"forgery_token\" type=\"hidden\" value=\"form_token\" /></fb:request-form>",
|
836
|
+
(@h.fb_request_form("invite","test_param","action") {})
|
837
|
+
end
|
838
|
+
|
839
|
+
def test_fb_error_with_only_message
|
840
|
+
assert_equal "<fb:error message=\"Errors have occurred!!\" />", @h.fb_error("Errors have occurred!!")
|
841
|
+
end
|
842
|
+
|
843
|
+
def test_fb_error_with_message_and_text
|
844
|
+
assert_equal "<fb:error><fb:message>Errors have occurred!!</fb:message>Label can't be blank!!</fb:error>", @h.fb_error("Errors have occurred!!", "Label can't be blank!!")
|
845
|
+
end
|
846
|
+
|
847
|
+
def test_fb_explanation_with_only_message
|
848
|
+
assert_equal "<fb:explanation message=\"This is an explanation\" />", @h.fb_explanation("This is an explanation")
|
849
|
+
end
|
850
|
+
|
851
|
+
def test_fb_explanation_with_message_and_text
|
852
|
+
assert_equal "<fb:explanation><fb:message>This is an explanation</fb:message>You have a match</fb:explanation>", @h.fb_explanation("This is an explanation", "You have a match")
|
853
|
+
end
|
854
|
+
|
855
|
+
def test_fb_success_with_only_message
|
856
|
+
assert_equal "<fb:success message=\"Woot!!\" />", @h.fb_success("Woot!!")
|
857
|
+
end
|
858
|
+
|
859
|
+
def test_fb_success_with_message_and_text
|
860
|
+
assert_equal "<fb:success><fb:message>Woot!!</fb:message>You Rock!!</fb:success>", @h.fb_success("Woot!!", "You Rock!!")
|
861
|
+
end
|
862
|
+
|
863
|
+
def test_facebook_form_for
|
864
|
+
@h.expects(:protect_against_forgery?).returns(false)
|
865
|
+
form_body=@h.facebook_form_for(:model,:url=>"action") do
|
866
|
+
end
|
867
|
+
assert_equal "<fb:editor action=\"action\"></fb:editor>",form_body
|
868
|
+
end
|
869
|
+
|
870
|
+
def test_facebook_form_for_with_authenticity_token
|
871
|
+
@h.expects(:protect_against_forgery?).returns(true)
|
872
|
+
@h.expects(:request_forgery_protection_token).returns('forgery_token')
|
873
|
+
@h.expects(:form_authenticity_token).returns('form_token')
|
874
|
+
assert_equal "<fb:editor action=\"action\"><input name=\"forgery_token\" type=\"hidden\" value=\"form_token\" /></fb:editor>",
|
875
|
+
(@h.facebook_form_for(:model, :url => "action") {})
|
876
|
+
end
|
877
|
+
|
878
|
+
def test_fb_friend_selector
|
879
|
+
assert_equal("<fb:friend-selector />",@h.fb_friend_selector)
|
880
|
+
end
|
881
|
+
|
882
|
+
def test_fb_request_form_submit
|
883
|
+
assert_equal("<fb:request-form-submit />",@h.fb_request_form_submit)
|
884
|
+
end
|
885
|
+
|
886
|
+
def test_fb_request_form_submit_with_uid
|
887
|
+
assert_equal("<fb:request-form-submit uid=\"123456789\" />",@h.fb_request_form_submit({:uid => "123456789"}))
|
888
|
+
end
|
889
|
+
|
890
|
+
def test_fb_request_form_submit_with_label
|
891
|
+
assert_equal("<fb:request-form-submit label=\"Send Invite to Joel\" />",@h.fb_request_form_submit({:label => "Send Invite to Joel"}))
|
892
|
+
end
|
893
|
+
|
894
|
+
def test_fb_request_form_submit_with_uid_and_label
|
895
|
+
assert_equal("<fb:request-form-submit label=\"Send Invite to Joel\" uid=\"123456789\" />",@h.fb_request_form_submit({:uid =>"123456789", :label => "Send Invite to Joel"}))
|
896
|
+
end
|
897
|
+
|
898
|
+
def test_fb_action
|
899
|
+
assert_equal "<fb:action href=\"/growingpets/rub\">Rub my pet</fb:action>", @h.fb_action("Rub my pet", "/growingpets/rub")
|
900
|
+
end
|
901
|
+
|
902
|
+
def test_fb_help
|
903
|
+
assert_equal "<fb:help href=\"http://www.facebook.com/apps/application.php?id=6236036681\">Help</fb:help>", @h.fb_help("Help", "http://www.facebook.com/apps/application.php?id=6236036681")
|
904
|
+
end
|
905
|
+
|
906
|
+
def test_fb_create_button
|
907
|
+
assert_equal "<fb:create-button href=\"/growingpets/invite\">Invite Friends</fb:create-button>", @h.fb_create_button('Invite Friends', '/growingpets/invite')
|
908
|
+
end
|
909
|
+
|
910
|
+
def test_fb_comments_a_1
|
911
|
+
assert_equal "<fb:comments candelete=\"false\" canpost=\"true\" numposts=\"7\" showform=\"true\" xid=\"a:1\"></fb:comments>", @h.fb_comments("a:1",true,false,7,:showform=>true)
|
912
|
+
end
|
913
|
+
|
914
|
+
def test_fb_comments_xxx
|
915
|
+
assert_equal "<fb:comments candelete=\"false\" canpost=\"true\" numposts=\"4\" optional=\"false\" xid=\"xxx\"></fb:comments>", @h.fb_comments("xxx",true,false,4,:optional=>false)
|
916
|
+
end
|
917
|
+
|
918
|
+
def test_fb_comments_with_title
|
919
|
+
assert_equal "<fb:comments candelete=\"false\" canpost=\"true\" numposts=\"4\" optional=\"false\" xid=\"xxx\"><fb:title>TITLE</fb:title></fb:comments>", @h.fb_comments("xxx",true,false,4,:optional=>false, :title => "TITLE")
|
920
|
+
end
|
921
|
+
def test_fb_board
|
922
|
+
assert_equal "<fb:board optional=\"false\" xid=\"xxx\"></fb:board>", @h.fb_board("xxx",:optional => false)
|
923
|
+
end
|
924
|
+
def test_fb_board_with_title
|
925
|
+
assert_equal "<fb:board optional=\"false\" xid=\"xxx\"><fb:title>TITLE</fb:title></fb:board>", @h.fb_board("xxx",:optional=>false, :title => "TITLE")
|
926
|
+
end
|
927
|
+
|
928
|
+
def test_fb_dashboard
|
929
|
+
@h.expects(:capture).returns("dashboard content")
|
930
|
+
@h.fb_dashboard do
|
931
|
+
end
|
932
|
+
assert_equal "<fb:dashboard>dashboard content</fb:dashboard>", @h.output_buffer
|
933
|
+
end
|
934
|
+
def test_fb_dashboard_non_block
|
935
|
+
assert_equal "<fb:dashboard></fb:dashboard>", @h.fb_dashboard
|
936
|
+
end
|
937
|
+
|
938
|
+
def test_fb_wide
|
939
|
+
@h.expects(:capture).returns("wide profile content")
|
940
|
+
@h.fb_wide do
|
941
|
+
end
|
942
|
+
assert_equal "<fb:wide>wide profile content</fb:wide>", @h.output_buffer
|
943
|
+
end
|
944
|
+
|
945
|
+
def test_fb_narrow
|
946
|
+
@h.expects(:capture).returns("narrow profile content")
|
947
|
+
@h.fb_narrow do
|
948
|
+
end
|
949
|
+
assert_equal "<fb:narrow>narrow profile content</fb:narrow>", @h.output_buffer
|
950
|
+
end
|
951
|
+
|
952
|
+
def test_fb_login_button
|
953
|
+
assert_equal "<fb:login-button onlogin=\"somejs\"></fb:login-button>",@h.fb_login_button("somejs")
|
954
|
+
end
|
955
|
+
|
956
|
+
def test_init_fb_connect_no_features
|
957
|
+
assert ! @h.init_fb_connect.match(/XFBML/)
|
958
|
+
end
|
959
|
+
|
960
|
+
def test_init_fb_connect_with_features
|
961
|
+
assert @h.init_fb_connect("XFBML").match(/XFBML/)
|
962
|
+
end
|
963
|
+
|
964
|
+
def test_init_fb_connect_receiver_path
|
965
|
+
assert @h.init_fb_connect.match(/xd_receiver.html/)
|
966
|
+
end
|
967
|
+
|
968
|
+
def test_init_fb_connect_receiver_path_ssl
|
969
|
+
@h.instance_eval do
|
970
|
+
def request
|
971
|
+
ssl_request = ActionController::TestRequest.new
|
972
|
+
ssl_request.stubs(:ssl?).returns(true)
|
973
|
+
ssl_request
|
974
|
+
end
|
975
|
+
end
|
976
|
+
|
977
|
+
assert @h.init_fb_connect.match(/xd_receiver_ssl.html/)
|
978
|
+
end
|
979
|
+
|
980
|
+
def test_init_fb_connect_with_features_and_body
|
981
|
+
@h.expects(:capture).returns("Body Content")
|
982
|
+
|
983
|
+
__in_erb_template = true
|
984
|
+
|
985
|
+
@h.init_fb_connect("XFBML") do
|
986
|
+
end
|
987
|
+
assert @h.output_buffer =~ /Body Content/
|
988
|
+
end
|
989
|
+
|
990
|
+
def test_init_fb_connect_no_options
|
991
|
+
assert ! @h.init_fb_connect.match(/Element.observe\(window,'load',/)
|
992
|
+
end
|
993
|
+
|
994
|
+
def test_init_fb_connect_with_options_js_jquery
|
995
|
+
assert ! @h.init_fb_connect(:js => :jquery).match(/\$\(document\).ready\(/)
|
996
|
+
end
|
997
|
+
|
998
|
+
def test_init_fb_connect_with_features_and_options_js_jquery
|
999
|
+
assert @h.init_fb_connect("XFBML", :js => :jquery).match(/XFBML.*/)
|
1000
|
+
assert @h.init_fb_connect("XFBML", :js => :jquery).match(/\$\(document\).ready\(/)
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def test_init_fb_connect_without_options_app_settings
|
1004
|
+
assert @h.init_fb_connect().match(/, \{\}\)/)
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
def test_init_fb_connect_with_options_app_settings
|
1008
|
+
assert @h.init_fb_connect(:app_settings => "{foo: bar}").match(/, \{foo: bar\}\)/)
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
|
1012
|
+
def test_fb_login_and_redirect
|
1013
|
+
assert_equal @h.fb_login_and_redirect("/path"),"<fb:login-button onlogin=\"window.location.href = "/path";\"></fb:login-button>"
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
def test_fb_logout_link
|
1017
|
+
assert_equal @h.fb_logout_link("Logout","My URL"),"<a href=\"#\" onclick=\"FB.Connect.logoutAndRedirect("My URL");; return false;\">Logout</a>"
|
1018
|
+
end
|
1019
|
+
def test_fb_user_action
|
1020
|
+
action = Facebooker::Rails::Publisher::UserAction.new
|
1021
|
+
assert_equal @h.fb_user_action(action,"message","prompt"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", {\"value\": \"message\"});"
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
|
1025
|
+
def test_fb_connect_javascript_tag
|
1026
|
+
silence_warnings do
|
1027
|
+
assert_equal "<script src=\"http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php\" type=\"text/javascript\"></script>",
|
1028
|
+
@h.fb_connect_javascript_tag
|
1029
|
+
end
|
1030
|
+
end
|
1031
|
+
|
1032
|
+
def test_fb_connect_javascript_tag_ssl
|
1033
|
+
@h.instance_eval do
|
1034
|
+
def request
|
1035
|
+
ssl_request = ActionController::TestRequest.new
|
1036
|
+
ssl_request.stubs(:ssl?).returns(true)
|
1037
|
+
ssl_request
|
1038
|
+
end
|
1039
|
+
end
|
1040
|
+
|
1041
|
+
silence_warnings do
|
1042
|
+
assert_equal "<script src=\"https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php\" type=\"text/javascript\"></script>",
|
1043
|
+
@h.fb_connect_javascript_tag
|
1044
|
+
end
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
def test_fb_container
|
1048
|
+
@h.expects(:capture).returns("Inner Stuff")
|
1049
|
+
@h.fb_container(:condition=>"somejs") do
|
1050
|
+
end
|
1051
|
+
assert_equal "<fb:container condition=\"somejs\">Inner Stuff</fb:container>",@h.output_buffer
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
def test_fb_eventlink
|
1055
|
+
assert_equal '<fb:eventlink eid="21150032416"></fb:eventlink>',@h.fb_eventlink("21150032416")
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
def test_fb_grouplink
|
1059
|
+
assert_equal '<fb:grouplink gid="2541896821"></fb:grouplink>',@h.fb_grouplink("2541896821")
|
1060
|
+
end
|
1061
|
+
|
1062
|
+
def test_fb_serverfbml
|
1063
|
+
@h.expects(:capture).returns("Inner Stuff")
|
1064
|
+
@h.fb_serverfbml(:condition=>"somejs") do
|
1065
|
+
end
|
1066
|
+
assert_equal "<fb:serverfbml condition=\"somejs\">Inner Stuff</fb:serverfbml>",@h.output_buffer
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
def test_fb_share_button
|
1070
|
+
assert_equal "<fb:share-button class=\"url\" href=\"http://www.elevatedrails.com\"></fb:share-button>",@h.fb_share_button("http://www.elevatedrails.com")
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
def test_fb_unconnected_friends_count_without_condition
|
1074
|
+
assert_equal "<fb:unconnected-friends-count></fb:unconnected-friends-count>",@h.fb_unconnected_friends_count
|
1075
|
+
end
|
1076
|
+
|
1077
|
+
def test_fb_user_status
|
1078
|
+
user=flexmock("user", :facebook_id => "5678")
|
1079
|
+
assert_equal '<fb:user-status linked="false" uid="5678"></fb:user-status>',@h.fb_user_status(user,false)
|
1080
|
+
end
|
1081
|
+
|
1082
|
+
def test_fb_time
|
1083
|
+
time = Time.now
|
1084
|
+
assert_equal %Q{<fb:time preposition="true" t="#{time.to_i}" tz="America/New York" />}, @h.fb_time(time, :tz => 'America/New York', :preposition => true)
|
1085
|
+
end
|
1086
|
+
|
1087
|
+
def test_fb_time_defaults
|
1088
|
+
time = Time.now
|
1089
|
+
assert_equal %Q{<fb:time t="#{time.to_i}" />}, @h.fb_time(time)
|
1090
|
+
end
|
1091
|
+
end
|
1092
|
+
class TestModel
|
1093
|
+
attr_accessor :name,:facebook_id
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
class RailsFacebookFormbuilderTest < Test::Unit::TestCase
|
1097
|
+
class TestTemplate
|
1098
|
+
include ActionView::Helpers::TextHelper
|
1099
|
+
include ActionView::Helpers::CaptureHelper
|
1100
|
+
include ActionView::Helpers::TagHelper
|
1101
|
+
include Facebooker::Rails::Helpers
|
1102
|
+
attr_accessor :output_buffer
|
1103
|
+
def initialize
|
1104
|
+
@output_buffer=""
|
1105
|
+
end
|
1106
|
+
end
|
1107
|
+
def setup
|
1108
|
+
@_erbout = ""
|
1109
|
+
@test_model = TestModel.new
|
1110
|
+
@test_model.name="Mike"
|
1111
|
+
@template = TestTemplate.new
|
1112
|
+
@proc = Proc.new {}
|
1113
|
+
@form_builder = Facebooker::Rails::FacebookFormBuilder.new(:test_model,@test_model,@template,{},@proc)
|
1114
|
+
def @form_builder._erbout
|
1115
|
+
""
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
def test_text_field
|
1121
|
+
assert_equal "<fb:editor-text id=\"test_model_name\" label=\"Name\" name=\"test_model[name]\" value=\"Mike\"></fb:editor-text>",
|
1122
|
+
@form_builder.text_field(:name)
|
1123
|
+
end
|
1124
|
+
def test_text_area
|
1125
|
+
assert_equal "<fb:editor-textarea id=\"test_model_name\" label=\"Name\" name=\"test_model[name]\">Mike</fb:editor-textarea>",
|
1126
|
+
@form_builder.text_area(:name)
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
def test_default_name_and_id
|
1130
|
+
assert_equal "<fb:editor-text id=\"different_id\" label=\"Name\" name=\"different_name\" value=\"Mike\"></fb:editor-text>",
|
1131
|
+
@form_builder.text_field(:name, {:name => 'different_name', :id => 'different_id'})
|
1132
|
+
end
|
1133
|
+
|
1134
|
+
def test_collection_typeahead
|
1135
|
+
flexmock(@form_builder) do |fb|
|
1136
|
+
fb.should_receive(:collection_typeahead_internal).with(:name,["ABC"],:size,:to_s,{})
|
1137
|
+
end
|
1138
|
+
@form_builder.collection_typeahead(:name,["ABC"],:size,:to_s)
|
1139
|
+
end
|
1140
|
+
|
1141
|
+
def test_collection_typeahead_internal
|
1142
|
+
assert_equal "<fb:typeahead-input id=\"test_model_name\" name=\"test_model[name]\" value=\"Mike\"><fb:typeahead-option value=\"3\">ABC</fb:typeahead-option></fb:typeahead-input>",
|
1143
|
+
@form_builder.collection_typeahead_internal(:name,["ABC"],:size,:to_s)
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
def test_buttons
|
1147
|
+
@form_builder.expects(:create_button).with(:first).returns("first")
|
1148
|
+
@form_builder.expects(:create_button).with(:second).returns("second")
|
1149
|
+
@template.expects(:content_tag).with("fb:editor-buttonset","firstsecond")
|
1150
|
+
@form_builder.buttons(:first,:second)
|
1151
|
+
end
|
1152
|
+
|
1153
|
+
def test_create_button
|
1154
|
+
assert_equal "<fb:editor-button name=\"commit\" value=\"first\"></fb:editor-button>",@form_builder.create_button(:first)
|
1155
|
+
end
|
1156
|
+
|
1157
|
+
def test_custom
|
1158
|
+
@template.expects(:password_field).returns("password_field")
|
1159
|
+
assert_equal "<fb:editor-custom label=\"Name\">password_field</fb:editor-custom>",@form_builder.password_field(:name)
|
1160
|
+
end
|
1161
|
+
|
1162
|
+
def test_text
|
1163
|
+
assert_equal "<fb:editor-custom label=\"custom\">Mike</fb:editor-custom>",@form_builder.text("Mike",:label=>"custom")
|
1164
|
+
end
|
1165
|
+
|
1166
|
+
def test_multi_friend_input
|
1167
|
+
assert_equal "<fb:editor-custom label=\"Friends\"><fb:multi-friend-input></fb:multi-friend-input></fb:editor-custom>",@form_builder.multi_friend_input
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
|
1171
|
+
end
|
1172
|
+
|
1173
|
+
class RailsPrettyErrorsTest < Test::Unit::TestCase
|
1174
|
+
class ControllerWhichFails < ActionController::Base
|
1175
|
+
def pass
|
1176
|
+
render :text=>''
|
1177
|
+
end
|
1178
|
+
def fail
|
1179
|
+
raise "I'm failing"
|
1180
|
+
end
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
def setup
|
1184
|
+
Facebooker.apply_configuration('api_key'=>"1234", 'secret_key'=>"34278",'canvas_page_name'=>'mike','pretty_errors'=>true)
|
1185
|
+
@controller = ControllerWhichFails.new
|
1186
|
+
@request = ActionController::TestRequest.new
|
1187
|
+
@response = ActionController::TestResponse.new
|
1188
|
+
end
|
1189
|
+
|
1190
|
+
def test_pretty_errors_disabled_success
|
1191
|
+
post :pass, facebook_params
|
1192
|
+
assert_response 200
|
1193
|
+
end
|
1194
|
+
|
1195
|
+
def test_pretty_errors_disabled_error
|
1196
|
+
Facebooker.apply_configuration('api_key'=>"1234", 'secret_key'=>"34278",'canvas_page_name'=>'mike','pretty_errors'=>false)
|
1197
|
+
silence_warnings do
|
1198
|
+
post :fail, facebook_params
|
1199
|
+
end
|
1200
|
+
assert_response :error
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
def test_pretty_errors_enabled_success
|
1204
|
+
post :pass, facebook_params
|
1205
|
+
assert_response 200
|
1206
|
+
end
|
1207
|
+
def test_pretty_errors_enabled_error
|
1208
|
+
silence_warnings do
|
1209
|
+
post :fail, facebook_params
|
1210
|
+
end
|
1211
|
+
assert_response 200
|
1212
|
+
end
|
1213
|
+
end
|
1214
|
+
|
1215
|
+
class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
|
1216
|
+
class UrlHelperExtensionsClass
|
1217
|
+
include ActionView::Helpers::UrlHelper
|
1218
|
+
include ActionView::Helpers::TagHelper
|
1219
|
+
def initialize(controller)
|
1220
|
+
@controller = controller
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
def protect_against_forgery?
|
1224
|
+
false
|
1225
|
+
end
|
1226
|
+
|
1227
|
+
def request_comes_from_facebook?
|
1228
|
+
@request_comes_from_facebook
|
1229
|
+
end
|
1230
|
+
|
1231
|
+
def request_comes_from_facebook=(val)
|
1232
|
+
@request_comes_from_facebook = val
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
end
|
1236
|
+
class UrlHelperExtensionsController < NoisyController
|
1237
|
+
def index
|
1238
|
+
render :nothing => true
|
1239
|
+
end
|
1240
|
+
def do_it
|
1241
|
+
render :nothing => true
|
1242
|
+
end
|
1243
|
+
end
|
1244
|
+
|
1245
|
+
class FacebookRequest < ActionController::TestRequest
|
1246
|
+
end
|
1247
|
+
|
1248
|
+
def setup
|
1249
|
+
@controller = UrlHelperExtensionsController.new
|
1250
|
+
@request = FacebookRequest.new
|
1251
|
+
@response = ActionController::TestResponse.new
|
1252
|
+
|
1253
|
+
@u = UrlHelperExtensionsClass.new(@controller)
|
1254
|
+
@u.request_comes_from_facebook = true
|
1255
|
+
|
1256
|
+
@non_canvas_u = UrlHelperExtensionsClass.new(@controller)
|
1257
|
+
@non_canvas_u.request_comes_from_facebook = false
|
1258
|
+
|
1259
|
+
@label = "Testing"
|
1260
|
+
@url = "test.host"
|
1261
|
+
@prompt = "Are you sure?"
|
1262
|
+
@default_title = "Please Confirm"
|
1263
|
+
@title = "Confirm Request"
|
1264
|
+
@style = {:color => 'black', :background => 'white'}
|
1265
|
+
@verbose_style = "{background: 'white', color: 'black'}"
|
1266
|
+
@default_okay = "Okay"
|
1267
|
+
@default_cancel = "Cancel"
|
1268
|
+
@default_style = "" #"'width','200px'"
|
1269
|
+
end
|
1270
|
+
|
1271
|
+
def test_link_to
|
1272
|
+
assert_equal "<a href=\"#{@url}\">Testing</a>", @u.link_to(@label, @url)
|
1273
|
+
end
|
1274
|
+
|
1275
|
+
def test_link_to_with_popup
|
1276
|
+
assert_raises(ActionView::ActionViewError) {@u.link_to(@label,@url, :popup=>true)}
|
1277
|
+
end
|
1278
|
+
|
1279
|
+
def test_link_to_with_confirm
|
1280
|
+
assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
|
1281
|
+
"var a=this;dlg.onconfirm = function() { " +
|
1282
|
+
"document.setLocation(a.getHref()); };return false;\">#{@label}</a>",
|
1283
|
+
@u.link_to(@label, @url, :confirm => @prompt) )
|
1284
|
+
end
|
1285
|
+
def test_link_to_with_confirm_with_title
|
1286
|
+
assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
|
1287
|
+
"var a=this;dlg.onconfirm = function() { " +
|
1288
|
+
"document.setLocation(a.getHref()); };return false;\">#{@label}</a>",
|
1289
|
+
@u.link_to(@label, @url, :confirm => {:title=>@title,:content=>@prompt}) )
|
1290
|
+
end
|
1291
|
+
def test_link_to_with_confirm_with_title_and_style
|
1292
|
+
assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@verbose_style});"+
|
1293
|
+
"var a=this;dlg.onconfirm = function() { " +
|
1294
|
+
"document.setLocation(a.getHref()); };return false;\">#{@label}</a>",
|
1295
|
+
@u.link_to(@label, @url, :confirm => {:title=>@title,:content=>@prompt}.merge!(@style)) )
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
def test_link_to_with_method
|
1299
|
+
assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var a=this;var f = document.createElement('form'); f.setStyle('display','none'); "+
|
1300
|
+
"a.getParentNode().appendChild(f); f.setMethod('POST'); f.setAction(a.getHref());" +
|
1301
|
+
"var m = document.createElement('input'); m.setType('hidden'); "+
|
1302
|
+
"m.setName('_method'); m.setValue('delete'); f.appendChild(m);"+
|
1303
|
+
"f.submit();return false;\">#{@label}</a>", @u.link_to(@label,@url, :method=>:delete))
|
1304
|
+
end
|
1305
|
+
|
1306
|
+
def test_link_to_with_confirm_and_method
|
1307
|
+
assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
|
1308
|
+
"var a=this;dlg.onconfirm = function() { " +
|
1309
|
+
"var f = document.createElement('form'); f.setStyle('display','none'); "+
|
1310
|
+
"a.getParentNode().appendChild(f); f.setMethod('POST'); f.setAction(a.getHref());" +
|
1311
|
+
"var m = document.createElement('input'); m.setType('hidden'); "+
|
1312
|
+
"m.setName('_method'); m.setValue('delete'); f.appendChild(m);"+
|
1313
|
+
"f.submit(); };return false;\">#{@label}</a>", @u.link_to(@label,@url, :confirm=>@prompt, :method=>:delete) )
|
1314
|
+
end
|
1315
|
+
def test_link_to_with_confirm_and_method_for_non_canvas_page
|
1316
|
+
assert_dom_equal( "<a href=\"#{@url}\" onclick=\"if (confirm(\'#{@prompt}\')) { var f = document.createElement('form'); f.style.display = 'none'; "+
|
1317
|
+
"this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var m = document.createElement('input'); "+
|
1318
|
+
"m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); "+
|
1319
|
+
"f.appendChild(m);f.submit(); };return false;\">#{@label}</a>",
|
1320
|
+
@non_canvas_u.link_to(@label,@url, :confirm=>@prompt, :method=>:delete) )
|
1321
|
+
end
|
1322
|
+
|
1323
|
+
def test_button_to
|
1324
|
+
assert_equal "<form method=\"post\" action=\"#{@url}\" class=\"button-to\"><div>" +
|
1325
|
+
"<input type=\"submit\" value=\"#{@label}\" /></div></form>", @u.button_to(@label,@url)
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
def test_button_to_with_confirm
|
1329
|
+
assert_equal "<form method=\"post\" action=\"#{@url}\" class=\"button-to\"><div>" +
|
1330
|
+
"<input onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
|
1331
|
+
"var a=this;dlg.onconfirm = function() { "+
|
1332
|
+
"a.getForm().submit(); };return false;\" type=\"submit\" value=\"#{@label}\" /></div></form>",
|
1333
|
+
@u.button_to(@label,@url, :confirm=>@prompt)
|
1334
|
+
end
|
1335
|
+
def test_button_to_with_confirm_for_non_canvas_page
|
1336
|
+
assert_equal "<form method=\"post\" action=\"#{@url}\" class=\"button-to\"><div>"+
|
1337
|
+
"<input onclick=\"return confirm(\'#{@prompt}\');\" type=\"submit\" value=\"#{@label}\" /></div></form>",
|
1338
|
+
@non_canvas_u.button_to(@label,@url, :confirm=>@prompt)
|
1339
|
+
end
|
1340
|
+
|
1341
|
+
def test_link_to_unless_with_true
|
1342
|
+
assert_equal @label, @u.link_to_unless(true,@label,@url)
|
1343
|
+
end
|
1344
|
+
def test_link_to_unless_with_false
|
1345
|
+
assert_equal @u.link_to(@label,@url), @u.link_to_unless(false,@label,@url)
|
1346
|
+
end
|
1347
|
+
|
1348
|
+
def test_link_to_if_with_true
|
1349
|
+
assert_equal @u.link_to(@label,@url), @u.link_to_if(true,@label,@url)
|
1350
|
+
end
|
1351
|
+
def test_link_to_if_with_false
|
1352
|
+
assert_equal @label, @u.link_to_if(false,@label,@url)
|
1353
|
+
end
|
1354
|
+
|
1355
|
+
end
|
1356
|
+
|
1357
|
+
class RailsRequestFormatTest < Test::Unit::TestCase
|
1358
|
+
class FacebookController < NoisyController
|
1359
|
+
def index
|
1360
|
+
respond_to do |format|
|
1361
|
+
format.html { render :text => 'html' }
|
1362
|
+
format.fbml { render :text => 'fbml' }
|
1363
|
+
format.fbjs { render :text => 'fbjs' }
|
1364
|
+
end
|
1365
|
+
end
|
1366
|
+
end
|
1367
|
+
|
1368
|
+
def setup
|
1369
|
+
ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
|
1370
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
1371
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
1372
|
+
@controller = FacebookController.new
|
1373
|
+
@request = ActionController::TestRequest.new
|
1374
|
+
@response = ActionController::TestResponse.new
|
1375
|
+
@controller.stubs(:verify_signature).returns(true)
|
1376
|
+
end
|
1377
|
+
|
1378
|
+
def test_responds_to_html_without_canvas
|
1379
|
+
get :index
|
1380
|
+
assert_equal 'html', @response.body
|
1381
|
+
end
|
1382
|
+
|
1383
|
+
def test_responds_to_fbml_in_canvas
|
1384
|
+
get :index, facebook_params(:fb_sig_in_canvas => '1')
|
1385
|
+
assert_equal 'fbml', @response.body
|
1386
|
+
end
|
1387
|
+
|
1388
|
+
def test_responds_to_fbjs_when_is_ajax
|
1389
|
+
get :index, facebook_params(:fb_sig_is_ajax => '1')
|
1390
|
+
assert_equal 'fbjs', @response.body
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
def test_responds_to_html_when_iframe
|
1394
|
+
get :index, facebook_params(:fb_sig_in_iframe => '1')
|
1395
|
+
assert_equal 'html', @response.body
|
1396
|
+
end
|
1397
|
+
|
1398
|
+
end
|