facebooker 1.0.13 → 1.0.18
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/Manifest.txt +29 -16
- data/Rakefile +9 -2
- data/generators/facebook/templates/public/javascripts/facebooker.js +1 -8
- data/init.rb +3 -1
- data/lib/facebooker.rb +4 -2
- data/lib/facebooker/adapters/facebook_adapter.rb +4 -0
- data/lib/facebooker/admin.rb +2 -2
- 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 +3 -3
- data/lib/facebooker/models/applicationrestrictions.rb +10 -0
- data/lib/facebooker/models/user.rb +35 -3
- data/lib/facebooker/models/user.rb.orig +396 -0
- data/lib/facebooker/models/user.rb.rej +17 -0
- data/lib/facebooker/models/video.rb +9 -0
- data/lib/facebooker/parser.rb +22 -1
- data/lib/facebooker/rails/controller.rb +34 -12
- data/lib/facebooker/rails/cucumber.rb +28 -0
- data/lib/facebooker/rails/cucumber/world.rb +46 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +19 -11
- data/lib/facebooker/rails/helpers.rb +203 -122
- data/lib/facebooker/rails/helpers/fb_connect.rb +56 -5
- data/lib/facebooker/rails/integration_session.rb +38 -0
- data/lib/facebooker/rails/publisher.rb +15 -2
- data/lib/facebooker/rails/test_helpers.rb +11 -26
- data/lib/facebooker/service.rb +6 -3
- data/lib/facebooker/session.rb +24 -2
- data/lib/facebooker/session.rb.orig +564 -0
- data/lib/facebooker/session.rb.rej +29 -0
- data/lib/facebooker/version.rb +1 -1
- data/lib/tasks/tunnel.rake +2 -2
- data/test/{adapters_test.rb → facebooker/adapters_test.rb} +2 -4
- data/test/{facebook_admin_test.rb → facebooker/admin_test.rb} +2 -2
- data/test/{batch_request_test.rb → facebooker/batch_request_test.rb} +3 -2
- data/test/{facebook_data_test.rb → facebooker/data_test.rb} +2 -2
- data/test/{logging_test.rb → facebooker/logging_test.rb} +3 -3
- data/test/facebooker/mobile_test.rb +45 -0
- data/test/{model_test.rb → facebooker/model_test.rb} +36 -4
- data/test/{event_test.rb → facebooker/models/event_test.rb} +2 -2
- data/test/{user_test.rb → facebooker/models/user_test.rb} +10 -5
- data/test/{publisher_test.rb → facebooker/rails/publisher_test.rb} +12 -18
- data/test/{rails_integration_test.rb → facebooker/rails_integration_test.rb} +347 -272
- data/test/{facebook_cache_test.rb → facebooker/server_cache_test.rb} +1 -1
- data/test/{session_test.rb → facebooker/session_test.rb} +3 -2
- data/test/facebooker_test.rb +19 -1
- data/test/{http_multipart_post_test.rb → net/http_multipart_post_test.rb} +2 -4
- data/test/rails_test_helper.rb +11 -0
- data/test/test_helper.rb +8 -2
- metadata +45 -32
- data/lib/facebooker/rails/facebook_asset_path.rb +0 -18
@@ -0,0 +1,29 @@
|
|
1
|
+
***************
|
2
|
+
*** 211,223 ****
|
3
|
+
end
|
4
|
+
|
5
|
+
def users_standard(user_ids, fields=[])
|
6
|
+
- post("facebook.users.getStandardInfo",:uids=>user_ids.join(","),:fields=>User.user_fields(fields)) do |users|
|
7
|
+
users.map { |u| User.new(u)}
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def users(user_ids, fields=[])
|
12
|
+
- post("facebook.users.getInfo",:uids=>user_ids.join(","),:fields=>User.standard_fields(fields)) do |users|
|
13
|
+
users.map { |u| User.new(u)}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
--- 211,223 ----
|
17
|
+
end
|
18
|
+
|
19
|
+
def users_standard(user_ids, fields=[])
|
20
|
+
+ post("facebook.users.getStandardInfo",:uids=>user_ids.join(","),:fields=>User.standard_fields(fields)) do |users|
|
21
|
+
users.map { |u| User.new(u)}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def users(user_ids, fields=[])
|
26
|
+
+ post("facebook.users.getInfo",:uids=>user_ids.join(","),:fields=>User.user_fields(fields)) do |users|
|
27
|
+
users.map { |u| User.new(u)}
|
28
|
+
end
|
29
|
+
end
|
data/lib/facebooker/version.rb
CHANGED
data/lib/tasks/tunnel.rake
CHANGED
@@ -7,13 +7,13 @@ namespace :facebooker do
|
|
7
7
|
desc "Create a reverse ssh tunnel from a public server to a private development server."
|
8
8
|
task :start => [ :environment, :config ] do
|
9
9
|
puts @notification
|
10
|
-
|
10
|
+
system @ssh_command
|
11
11
|
end
|
12
12
|
|
13
13
|
desc "Create a reverse ssh tunnel in the background. Requires ssh keys to be setup."
|
14
14
|
task :background_start => [ :environment, :config ] do
|
15
15
|
puts @notification
|
16
|
-
|
16
|
+
system "#{@ssh_command} > /dev/null 2>&1 &"
|
17
17
|
end
|
18
18
|
|
19
19
|
# Adapted from Evan Weaver: http://blog.evanweaver.com/articles/2007/07/13/developing-a-facebook-app-locally/
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
require 'facebooker'
|
3
|
-
class SessionTest < Test::Unit::TestCase
|
4
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
5
2
|
|
3
|
+
class Facebooker::SessionTest < Test::Unit::TestCase
|
6
4
|
def setup
|
7
5
|
ENV['FACEBOOK_API_KEY'] = '1234567'
|
8
6
|
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class Facebooker::AdminTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
6
|
Facebooker.use_curl=false
|
@@ -1,5 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::BatchRequestTest < Test::Unit::TestCase
|
3
4
|
|
4
5
|
def setup
|
5
6
|
@proc_called=false
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
2
|
|
3
|
-
class
|
3
|
+
class Facebooker::DataTest < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
6
|
#make sure we use net::http since that's what the tests expect
|
@@ -1,7 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
require 'logger'
|
2
3
|
|
3
|
-
|
4
|
-
class LoggingTest < Test::Unit::TestCase
|
4
|
+
class Facebooker::LoggingTest < Test::Unit::TestCase
|
5
5
|
def setup
|
6
6
|
super
|
7
7
|
Facebooker.logger = Logger.new(STDERR)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
+
|
3
|
+
class Facebooker::MobileTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@session = Facebooker::Session.create('apikey', 'secretkey')
|
6
|
+
@user = Facebooker::User.new(1234, @session)
|
7
|
+
Facebooker.use_curl=false
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_can_send
|
11
|
+
expect_http_posts_with_responses(example_can_send_xml)
|
12
|
+
assert(@session.mobile.can_send(@user))
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_send
|
16
|
+
expect_http_posts_with_responses(example_send_xml)
|
17
|
+
assert(@session.mobile.send(@user, "Some sort of message"))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def example_can_send_xml
|
22
|
+
<<-XML
|
23
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
24
|
+
<sms_canSend_response
|
25
|
+
xmlns="http://api.facebook.com/1.0/"
|
26
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
27
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
28
|
+
0
|
29
|
+
</sms_canSend_response>
|
30
|
+
XML
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_send_xml
|
34
|
+
<<-XML
|
35
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
36
|
+
<sms_send_response
|
37
|
+
xmlns="http://api.facebook.com/1.0/"
|
38
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
39
|
+
xsi:schemaLocation="http://api.facebook.com/1.0/http://api.facebook.com/1.0/facebook.xsd">
|
40
|
+
0
|
41
|
+
</sms_send_response>
|
42
|
+
XML
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
require 'rubygems'
|
3
|
-
require 'flexmock/test_unit'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
4
2
|
|
5
|
-
class
|
3
|
+
class Facebooker::ModelTest < Test::Unit::TestCase
|
6
4
|
|
7
5
|
class ComplexThing
|
8
6
|
include Facebooker::Model
|
@@ -87,5 +85,39 @@ class TestFacebooker < Test::Unit::TestCase
|
|
87
85
|
t.first_name
|
88
86
|
}
|
89
87
|
end
|
88
|
+
|
89
|
+
def test_populate_from_hash_e_should_call_a_setter_for_a_key
|
90
|
+
t = PopulatingThing.new
|
91
|
+
flexmock(t).should_receive('mykey=').with('a value')
|
92
|
+
t.populate_from_hash!({ :mykey => 'a value' })
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_populate_from_hash_e_should_call_a_setter_for_a_key_if_the_value_is_false
|
96
|
+
t = PopulatingThing.new
|
97
|
+
flexmock(t).should_receive('mykey=').with(false)
|
98
|
+
t.populate_from_hash!({ :mykey => false })
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_populate_from_hash_e_should_call_not_a_setter_for_a_key_if_the_value_is_nil
|
102
|
+
t = PopulatingThing.new
|
103
|
+
flexmock(t).should_receive('mykey=').never
|
104
|
+
t.populate_from_hash!({ :mykey => nil })
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_populate_from_hash_should_check_for_an_empty_hash
|
108
|
+
t = PopulatingThing.new
|
109
|
+
hash = {}
|
110
|
+
flexmock(hash).should_receive('empty?')
|
111
|
+
t.populate_from_hash!(hash)
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_populate_from_hash_should_check_for_a_nil_param
|
115
|
+
t = PopulatingThing.new
|
116
|
+
hash = nil
|
117
|
+
assert_nothing_raised do
|
118
|
+
t.populate_from_hash!(hash)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
90
122
|
end
|
91
123
|
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
2
|
|
3
|
-
class EventTest< Test::Unit::TestCase
|
3
|
+
class Facebooker::EventTest < Test::Unit::TestCase
|
4
4
|
def test_attendance_will_query_for_event_when_asked_for_full_event_object
|
5
5
|
session = flexmock("a session object")
|
6
6
|
eid = 123
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
require '
|
3
|
-
require 'flexmock/test_unit'
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
|
2
|
+
require 'active_support'
|
4
3
|
|
5
|
-
class UserTest < Test::Unit::TestCase
|
4
|
+
class Facebooker::UserTest < Test::Unit::TestCase
|
6
5
|
|
7
6
|
def setup
|
8
7
|
@session = Facebooker::Session.create('apikey', 'secretkey')
|
@@ -165,8 +164,13 @@ class UserTest < Test::Unit::TestCase
|
|
165
164
|
assert_equal("1234",@user.to_s)
|
166
165
|
end
|
167
166
|
|
168
|
-
def
|
167
|
+
def test_equality_with_same_id
|
169
168
|
assert_equal @user, @user.dup
|
169
|
+
assert_equal @user, Facebooker::User.new(:id => @user.id)
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_not_equal_to_differnt_class
|
173
|
+
assert_not_equal @user, flexmock(:id => @user.id)
|
170
174
|
end
|
171
175
|
|
172
176
|
def test_hash_email
|
@@ -287,4 +291,5 @@ class UserTest < Test::Unit::TestCase
|
|
287
291
|
xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd">1</users_hasAppPermission_response>
|
288
292
|
XML
|
289
293
|
end
|
294
|
+
|
290
295
|
end
|
@@ -1,15 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
require 'rubygems'
|
3
|
-
require 'flexmock/test_unit'
|
4
|
-
require 'action_controller'
|
5
|
-
require 'action_controller/test_process'
|
6
|
-
require 'active_record'
|
7
|
-
require File.dirname(__FILE__)+'/../init'
|
8
|
-
require 'facebooker/rails/controller'
|
9
|
-
require 'facebooker/rails/helpers/fb_connect'
|
10
|
-
require 'facebooker/rails/helpers'
|
11
|
-
require 'facebooker/rails/publisher'
|
12
|
-
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
13
2
|
|
14
3
|
module SymbolHelper
|
15
4
|
def symbol_helper_loaded
|
@@ -143,7 +132,7 @@ class TestPublisher < Facebooker::Rails::Publisher
|
|
143
132
|
|
144
133
|
end
|
145
134
|
|
146
|
-
class FacebookTemplateTest < Test::Unit::TestCase
|
135
|
+
class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
147
136
|
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
148
137
|
|
149
138
|
def setup
|
@@ -207,7 +196,7 @@ class FacebookTemplateTest < Test::Unit::TestCase
|
|
207
196
|
end
|
208
197
|
end
|
209
198
|
|
210
|
-
class PublisherTest < Test::Unit::TestCase
|
199
|
+
class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
211
200
|
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
212
201
|
|
213
202
|
def setup
|
@@ -410,12 +399,17 @@ class PublisherTest < Test::Unit::TestCase
|
|
410
399
|
|
411
400
|
def test_image_urls
|
412
401
|
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
413
|
-
|
414
|
-
|
415
|
-
assert_equal(
|
416
|
-
|
402
|
+
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
403
|
+
assert_equal('/images/image.png',string_image.src)
|
404
|
+
assert_equal('raw_string',string_image.href)
|
405
|
+
route_image = TestPublisher.new.image('image.png', {:controller => :pokes, :action => :do, :id => 1})
|
406
|
+
assert_equal('http://apps.facebook.com/mike/pokes/do/1',route_image.href)
|
417
407
|
end
|
418
408
|
|
409
|
+
def test_image_to_json_puts_src_first
|
410
|
+
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
411
|
+
assert_equal "{\"src\":\"/images/image.png\", \"href\":\"raw_string\"}",string_image.to_json
|
412
|
+
end
|
419
413
|
def test_action_link
|
420
414
|
assert_equal({:text=>"text", :href=>"href"}, TestPublisher.new.action_link("text","href"))
|
421
415
|
end
|
@@ -1,187 +1,212 @@
|
|
1
|
-
require File.dirname(__FILE__) + '
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../rails_test_helper')
|
2
|
+
|
3
|
+
ActionController::Routing::Routes.draw do |map|
|
4
|
+
map.connect '', :controller=>"facebook",:conditions=>{:canvas=>true}
|
5
|
+
map.connect '', :controller=>"plain_old_rails"
|
6
|
+
map.resources :comments, :controller=>"plain_old_rails"
|
7
|
+
map.connect 'require_auth/:action', :controller => "controller_which_requires_facebook_authentication"
|
8
|
+
map.connect 'require_install/:action', :controller => "controller_which_requires_application_installation"
|
9
|
+
map.connect ':controller/:action/:id', :controller => "plain_old_rails"
|
10
|
+
end
|
11
|
+
|
12
|
+
module FBConnectTestHelpers
|
13
|
+
def setup_fb_connect_cookies(params=cookie_hash_for_auth)
|
14
|
+
params.each {|k,v| @request.cookies[ENV['FACEBOOK_API_KEY']+k] = CGI::Cookie.new(ENV['FACEBOOK_API_KEY']+k,v)}
|
15
|
+
end
|
16
|
+
|
17
|
+
def expired_cookie_hash_for_auth
|
18
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.ago.to_i}"}
|
19
|
+
end
|
20
|
+
|
21
|
+
def cookie_hash_for_auth
|
22
|
+
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.from_now.to_i}"}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
class NoisyController < ActionController::Base
|
26
|
+
include Facebooker::Rails::Controller
|
27
|
+
def rescue_action(e) raise e end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
class ControllerWhichRequiresExtendedPermissions< NoisyController
|
32
|
+
ensure_authenticated_to_facebook
|
33
|
+
before_filter :ensure_has_status_update
|
34
|
+
before_filter :ensure_has_photo_upload
|
35
|
+
before_filter :ensure_has_video_upload
|
36
|
+
before_filter :ensure_has_create_listing
|
37
|
+
def index
|
38
|
+
render :text => 'score!'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class FBConnectController < NoisyController
|
43
|
+
before_filter :create_facebook_session
|
44
|
+
def index
|
45
|
+
render :text => 'score!'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class ControllerWhichRequiresFacebookAuthentication < NoisyController
|
50
|
+
ensure_authenticated_to_facebook
|
51
|
+
def index
|
52
|
+
render :text => 'score!'
|
53
|
+
end
|
54
|
+
def link_test
|
55
|
+
options = {}
|
56
|
+
options[:canvas] = true if params[:canvas] == true
|
57
|
+
options[:canvas] = false if params[:canvas] == false
|
58
|
+
render :text=>url_for(options)
|
59
|
+
end
|
20
60
|
|
21
|
-
|
22
|
-
|
23
|
-
def rescue_action(e) raise e end
|
61
|
+
def named_route_test
|
62
|
+
render :text=>comments_url()
|
24
63
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
before_filter :ensure_has_photo_upload
|
29
|
-
before_filter :ensure_has_create_listing
|
30
|
-
def index
|
31
|
-
render :text => 'score!'
|
32
|
-
end
|
64
|
+
|
65
|
+
def image_test
|
66
|
+
render :inline=>"<%=image_tag 'image.png'%>"
|
33
67
|
end
|
34
68
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
render :text=>url_for(options)
|
45
|
-
end
|
46
|
-
|
47
|
-
def named_route_test
|
48
|
-
render :text=>comments_url()
|
49
|
-
end
|
50
|
-
|
51
|
-
def image_test
|
52
|
-
render :inline=>"<%=image_tag 'image.png'%>"
|
53
|
-
end
|
54
|
-
|
55
|
-
def fb_params_test
|
56
|
-
render :text=>facebook_params['user']
|
57
|
-
end
|
58
|
-
|
59
|
-
def publisher_test
|
60
|
-
if wants_interface?
|
61
|
-
render :text=>"interface"
|
62
|
-
else
|
63
|
-
render :text=>"not interface"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def publisher_test_interface
|
68
|
-
render_publisher_interface("This is a test",false,true)
|
69
|
-
end
|
70
|
-
|
71
|
-
def publisher_test_response
|
72
|
-
ua=Facebooker::Rails::Publisher::UserAction.new
|
73
|
-
ua.data = {:params=>true}
|
74
|
-
ua.template_name = "template_name"
|
75
|
-
ua.template_id = 1234
|
76
|
-
render_publisher_response(ua)
|
77
|
-
end
|
78
|
-
|
79
|
-
def publisher_test_error
|
80
|
-
render_publisher_error("Title","Body")
|
69
|
+
def fb_params_test
|
70
|
+
render :text=>facebook_params['user']
|
71
|
+
end
|
72
|
+
|
73
|
+
def publisher_test
|
74
|
+
if wants_interface?
|
75
|
+
render :text=>"interface"
|
76
|
+
else
|
77
|
+
render :text=>"not interface"
|
81
78
|
end
|
82
|
-
|
83
79
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
render :text => 'installed!'
|
88
|
-
end
|
80
|
+
|
81
|
+
def publisher_test_interface
|
82
|
+
render_publisher_interface("This is a test",false,true)
|
89
83
|
end
|
90
|
-
|
91
|
-
|
92
|
-
|
84
|
+
|
85
|
+
def publisher_test_response
|
86
|
+
ua=Facebooker::Rails::Publisher::UserAction.new
|
87
|
+
ua.data = {:params=>true}
|
88
|
+
ua.template_name = "template_name"
|
89
|
+
ua.template_id = 1234
|
90
|
+
render_publisher_response(ua)
|
93
91
|
end
|
94
92
|
|
95
|
-
|
96
|
-
|
97
|
-
end
|
98
|
-
def link_test
|
99
|
-
options = {}
|
100
|
-
options[:canvas] = true if params[:canvas] == true
|
101
|
-
options[:canvas] = false if params[:canvas] == false
|
102
|
-
render :text => url_for(options)
|
103
|
-
end
|
104
|
-
|
105
|
-
def named_route_test
|
106
|
-
render :text=>comments_url()
|
107
|
-
end
|
108
|
-
def canvas_false_test
|
109
|
-
render :text=>comments_url(:canvas=>false)
|
110
|
-
end
|
111
|
-
def canvas_true_test
|
112
|
-
render :text=>comments_url(:canvas=>true)
|
113
|
-
end
|
93
|
+
def publisher_test_error
|
94
|
+
render_publisher_error("Title","Body")
|
114
95
|
end
|
115
96
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
97
|
+
end
|
98
|
+
class ControllerWhichRequiresApplicationInstallation < NoisyController
|
99
|
+
ensure_application_is_installed_by_facebook_user
|
100
|
+
def index
|
101
|
+
render :text => 'installed!'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
class FacebookController < ActionController::Base
|
105
|
+
def index
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
class PlainOldRailsController < ActionController::Base
|
110
|
+
def index
|
111
|
+
end
|
112
|
+
def link_test
|
113
|
+
options = {}
|
114
|
+
options[:canvas] = true if params[:canvas] == true
|
115
|
+
options[:canvas] = false if params[:canvas] == false
|
116
|
+
render :text => url_for(options)
|
123
117
|
end
|
124
118
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
119
|
+
def named_route_test
|
120
|
+
render :text=>comments_url()
|
121
|
+
end
|
122
|
+
def canvas_false_test
|
123
|
+
render :text=>comments_url(:canvas=>false)
|
124
|
+
end
|
125
|
+
def canvas_true_test
|
126
|
+
render :text=>comments_url(:canvas=>true)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
class Test::Unit::TestCase
|
131
|
+
include Facebooker::Rails::TestHelpers
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
# you can't use asset_recognize, because it can't pass parameters in to the requests
|
136
|
+
class UrlRecognitionTests < Test::Unit::TestCase
|
137
|
+
def test_detects_in_canvas
|
138
|
+
request = ActionController::TestRequest.new({"fb_sig_in_canvas"=>"1"}, {}, nil)
|
139
|
+
request.path = "/"
|
140
|
+
ActionController::Routing::Routes.recognize(request)
|
141
|
+
assert_equal({"controller"=>"facebook","action"=>"index"},request.path_parameters)
|
140
142
|
end
|
141
143
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
@response = ActionController::TestResponse.new
|
150
|
-
end
|
144
|
+
def test_routes_when_not_in_canvas
|
145
|
+
request = ActionController::TestRequest.new({}, {}, nil)
|
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
151
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
get :canvas_true_test, example_rails_params
|
172
|
-
assert_equal "http://apps.facebook.com/facebook_app_name/comments",@response.body
|
173
|
-
end
|
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]
|
174
171
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
182
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
|
183
206
|
end
|
184
207
|
|
208
|
+
end
|
209
|
+
|
185
210
|
class RailsIntegrationTestForExtendedPermissions < Test::Unit::TestCase
|
186
211
|
def setup
|
187
212
|
ENV['FACEBOOK_API_KEY'] = '1234567'
|
@@ -193,32 +218,32 @@ class RailsIntegrationTestForExtendedPermissions < Test::Unit::TestCase
|
|
193
218
|
end
|
194
219
|
|
195
220
|
def test_redirects_without_set_status
|
196
|
-
post :index,
|
221
|
+
post :index, facebook_params
|
197
222
|
assert_response :success
|
198
223
|
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=status_update\" />", @response.body)
|
199
224
|
end
|
200
225
|
def test_redirects_without_photo_upload
|
201
|
-
post :index,
|
226
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update")
|
202
227
|
assert_response :success
|
203
228
|
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=photo_upload\" />", @response.body)
|
204
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
|
205
235
|
def test_redirects_without_create_listing
|
206
|
-
post :index,
|
236
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update,photo_upload,video_upload")
|
207
237
|
assert_response :success
|
208
238
|
assert_equal("<fb:redirect url=\"http://www.facebook.com/authorize.php?api_key=1234567&v=1.0&ext_perm=create_listing\" />", @response.body)
|
209
239
|
end
|
210
240
|
|
211
241
|
def test_renders_with_permission
|
212
|
-
post :index,
|
242
|
+
post :index, facebook_params(:fb_sig_ext_perms=>"status_update,photo_upload,create_listing,video_upload")
|
213
243
|
assert_response :success
|
214
244
|
assert_equal("score!", @response.body)
|
215
245
|
|
216
246
|
end
|
217
|
-
private
|
218
|
-
def example_rails_params_including_fb
|
219
|
-
{"fb_sig_time"=>"1186588275.5988", "fb_sig"=>"7371a6400329b229f800a5ecafe03b0a", "action"=>"index", "fb_sig_in_canvas"=>"1", "fb_sig_session_key"=>"c452b5d5d60cbd0a0da82021-744961110", "controller"=>"controller_which_requires_facebook_authentication", "fb_sig_expires"=>"0", "fb_sig_friends"=>"417358,702720,1001170,1530839,3300204,3501584,6217936,9627766,9700907,22701786,33902768,38914148,67400422,135301144,157200364,500103523,500104930,500870819,502149612,502664898,502694695,502852293,502985816,503254091,504510130,504611551,505421674,509229747,511075237,512548373,512830487,517893818,517961878,518890403,523589362,523826914,525812984,531555098,535310228,539339781,541137089,549405288,552706617,564393355,564481279,567640762,568091401,570201702,571469972,573863097,574415114,575543081,578129427,578520568,582262836,582561201,586550659,591631962,592318318,596269347,596663221,597405464,599764847,602995438,606661367,609761260,610544224,620049417,626087078,628803637,632686250,641422291,646763898,649678032,649925863,653288975,654395451,659079771,661794253,665861872,668960554,672481514,675399151,678427115,685772348,686821151,687686894,688506532,689275123,695551670,710631572,710766439,712406081,715741469,718976395,719246649,722747311,725327717,725683968,725831016,727580320,734151780,734595181,737944528,748881410,752244947,763868412,768578853,776596978,789728437,873695441", "fb_sig_added"=>"0", "fb_sig_api_key"=>"b6c9c857ac543ca806f4d3187cd05e09", "fb_sig_user"=>"744961110", "fb_sig_profile_update_time"=>"1180712453"}
|
220
|
-
end
|
221
|
-
|
222
247
|
end
|
223
248
|
|
224
249
|
class RailsIntegrationTestForApplicationInstallation < Test::Unit::TestCase
|
@@ -238,24 +263,20 @@ class RailsIntegrationTestForApplicationInstallation < Test::Unit::TestCase
|
|
238
263
|
end
|
239
264
|
|
240
265
|
def test_if_controller_requires_application_installation_authenticated_requests_without_installation_will_redirect_to_install_page
|
241
|
-
get :index,
|
266
|
+
get :index, facebook_params(:fb_sig_added => nil)
|
242
267
|
assert_response :success
|
243
268
|
assert_equal("<fb:redirect url=\"http://www.facebook.com/install.php?api_key=1234567&v=1.0\" />", @response.body)
|
244
269
|
end
|
245
270
|
|
246
271
|
def test_if_controller_requires_application_installation_authenticated_requests_with_installation_will_render
|
247
|
-
get :index,
|
272
|
+
get :index, facebook_params('fb_sig_added' => "1")
|
248
273
|
assert_response :success
|
249
274
|
assert_equal("installed!", @response.body)
|
250
275
|
end
|
251
|
-
|
252
|
-
private
|
253
|
-
def example_rails_params_including_fb
|
254
|
-
{"fb_sig_time"=>"1186588275.5988", "fb_sig"=>"7371a6400329b229f800a5ecafe03b0a", "action"=>"index", "fb_sig_in_canvas"=>"1", "fb_sig_session_key"=>"c452b5d5d60cbd0a0da82021-744961110", "controller"=>"controller_which_requires_facebook_authentication", "fb_sig_expires"=>"0", "fb_sig_friends"=>"417358,702720,1001170,1530839,3300204,3501584,6217936,9627766,9700907,22701786,33902768,38914148,67400422,135301144,157200364,500103523,500104930,500870819,502149612,502664898,502694695,502852293,502985816,503254091,504510130,504611551,505421674,509229747,511075237,512548373,512830487,517893818,517961878,518890403,523589362,523826914,525812984,531555098,535310228,539339781,541137089,549405288,552706617,564393355,564481279,567640762,568091401,570201702,571469972,573863097,574415114,575543081,578129427,578520568,582262836,582561201,586550659,591631962,592318318,596269347,596663221,597405464,599764847,602995438,606661367,609761260,610544224,620049417,626087078,628803637,632686250,641422291,646763898,649678032,649925863,653288975,654395451,659079771,661794253,665861872,668960554,672481514,675399151,678427115,685772348,686821151,687686894,688506532,689275123,695551670,710631572,710766439,712406081,715741469,718976395,719246649,722747311,725327717,725683968,725831016,727580320,734151780,734595181,737944528,748881410,752244947,763868412,768578853,776596978,789728437,873695441", "fb_sig_added"=>"0", "fb_sig_api_key"=>"b6c9c857ac543ca806f4d3187cd05e09", "fb_sig_user"=>"744961110", "fb_sig_profile_update_time"=>"1180712453"}
|
255
|
-
end
|
256
276
|
end
|
257
277
|
|
258
278
|
class RailsIntegrationTest < Test::Unit::TestCase
|
279
|
+
include FBConnectTestHelpers
|
259
280
|
def setup
|
260
281
|
ENV['FACEBOOK_CANVAS_PATH'] ='root'
|
261
282
|
ENV['FACEBOOK_API_KEY'] = '1234567'
|
@@ -269,7 +290,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
269
290
|
end
|
270
291
|
|
271
292
|
def test_named_route_includes_new_canvas_path_when_in_new_canvas
|
272
|
-
get :named_route_test,
|
293
|
+
get :named_route_test, facebook_params("fb_sig_in_new_facebook"=>"1")
|
273
294
|
assert_equal "http://apps.facebook.com/root/comments",@response.body
|
274
295
|
end
|
275
296
|
|
@@ -280,67 +301,66 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
280
301
|
end
|
281
302
|
|
282
303
|
def test_facebook_params_are_parsed_into_a_separate_hash
|
283
|
-
get :index,
|
284
|
-
|
285
|
-
assert_equal([8, 8], [facebook_params['time'].day, facebook_params['time'].mon])
|
304
|
+
get :index, facebook_params(:fb_sig_user => '9')
|
305
|
+
assert_not_nil @controller.facebook_params['time']
|
286
306
|
end
|
287
307
|
|
288
308
|
def test_facebook_params_convert_in_canvas_to_boolean
|
289
|
-
get :index,
|
309
|
+
get :index, facebook_params
|
290
310
|
assert_equal(true, @controller.facebook_params['in_canvas'])
|
291
311
|
end
|
292
312
|
|
293
313
|
def test_facebook_params_convert_added_to_boolean_false
|
294
|
-
get :index,
|
314
|
+
get :index, facebook_params(:fb_sig_added => '0')
|
295
315
|
assert_equal(false, @controller.facebook_params['added'])
|
296
316
|
end
|
297
317
|
|
298
318
|
def test_facebook_params_convert_added_to_boolean_true
|
299
|
-
get :index,
|
319
|
+
get :index, facebook_params('fb_sig_added' => "1")
|
300
320
|
assert_equal(true, @controller.facebook_params['added'])
|
301
321
|
end
|
302
322
|
|
303
|
-
def
|
304
|
-
get :index,
|
323
|
+
def test_facebook_params_convert_expirey_into_nil
|
324
|
+
get :index, facebook_params(:fb_sig_expires => '0')
|
305
325
|
assert_nil(@controller.facebook_params['expires'])
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
get :index,
|
310
|
-
|
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']
|
311
331
|
end
|
312
332
|
|
313
333
|
def test_facebook_params_convert_friend_list_to_parsed_array_of_friend_ids
|
314
|
-
get :index,
|
334
|
+
get :index, facebook_params(:fb_sig_friends => '1,2,3,4,5')
|
315
335
|
assert_kind_of(Array, @controller.facebook_params['friends'])
|
316
|
-
assert_equal(
|
336
|
+
assert_equal(5, @controller.facebook_params['friends'].size)
|
317
337
|
end
|
318
338
|
|
319
339
|
def test_session_can_be_resecured_from_facebook_params
|
320
|
-
get :index,
|
321
|
-
assert_equal(
|
340
|
+
get :index, facebook_params(:fb_sig_user => 10)
|
341
|
+
assert_equal(10, @controller.facebook_session.user.id)
|
322
342
|
end
|
323
343
|
|
324
344
|
def test_existing_secured_session_is_used_if_available
|
325
|
-
session = Facebooker::Session.create(
|
326
|
-
session.secure_with!("
|
327
|
-
get :index,
|
328
|
-
assert_equal(
|
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)
|
329
349
|
end
|
330
350
|
|
331
351
|
def test_facebook_params_used_if_existing_secured_session_key_does_not_match
|
332
|
-
session = Facebooker::Session.create(
|
333
|
-
session.secure_with!("
|
334
|
-
get :index,
|
335
|
-
assert_equal(
|
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)
|
336
356
|
end
|
337
357
|
|
338
358
|
def test_existing_secured_session_is_NOT_used_if_available_and_facebook_params_session_key_is_nil_and_in_canvas
|
339
|
-
session = Facebooker::Session.create(
|
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)
|
340
361
|
session.secure_with!("a session key", "1111111", Time.now.to_i + 60)
|
341
|
-
get :index,
|
342
|
-
|
343
|
-
assert_equal(744961110, @controller.facebook_session.user.id)
|
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)
|
344
364
|
end
|
345
365
|
|
346
366
|
def test_existing_secured_session_IS_used_if_available_and_facebook_params_session_key_is_nil_and_NOT_in_canvas
|
@@ -354,7 +374,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
354
374
|
|
355
375
|
def test_session_can_be_secured_with_auth_token
|
356
376
|
auth_token = 'ohaiauthtokenhere111'
|
357
|
-
modified_params =
|
377
|
+
modified_params = facebook_params
|
358
378
|
modified_params.delete('fb_sig_session_key')
|
359
379
|
modified_params['auth_token'] = auth_token
|
360
380
|
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
@@ -366,106 +386,104 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
366
386
|
|
367
387
|
def test_session_secured_with_auth_token_if_cookies_expired
|
368
388
|
auth_token = 'ohaiauthtokenhere111'
|
369
|
-
modified_params =
|
389
|
+
modified_params = facebook_params
|
370
390
|
modified_params.delete('fb_sig_session_key')
|
371
391
|
modified_params['auth_token'] = auth_token
|
372
392
|
session_mock = flexmock(session = Facebooker::Session.create(ENV['FACEBOOK_API_KEY'], ENV['FACEBOOK_SECRET_KEY']))
|
373
393
|
session_params = { 'session_key' => '123', 'uid' => '321' }
|
374
394
|
session_mock.should_receive(:post).with('facebook.auth.getSession', :auth_token => auth_token).once.and_return(session_params).ordered
|
375
395
|
flexmock(@controller).should_receive(:new_facebook_session).once.and_return(session).ordered
|
376
|
-
expired_cookie_hash_for_auth
|
396
|
+
setup_fb_connect_cookies(expired_cookie_hash_for_auth)
|
377
397
|
get :index, modified_params
|
378
398
|
assert_equal(321, @controller.facebook_session.user.id)
|
379
399
|
end
|
380
400
|
|
381
401
|
def test_session_can_be_secured_with_cookies
|
382
|
-
|
383
|
-
get :index
|
402
|
+
setup_fb_connect_cookies
|
403
|
+
get :index
|
384
404
|
assert_equal(77777, @controller.facebook_session.user.id)
|
385
405
|
end
|
386
406
|
|
387
407
|
def test_session_does_NOT_secure_with_expired_cookies
|
388
|
-
expired_cookie_hash_for_auth
|
389
|
-
get :index
|
408
|
+
setup_fb_connect_cookies(expired_cookie_hash_for_auth)
|
409
|
+
get :index
|
390
410
|
assert_nil(@controller.facebook_session)
|
391
411
|
end
|
392
412
|
|
393
413
|
def test_user_friends_can_be_populated_from_facebook_params_if_available
|
394
|
-
get :index,
|
395
|
-
|
396
|
-
|
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)
|
397
418
|
end
|
398
419
|
|
399
420
|
def test_fbml_redirect_tag_handles_hash_parameters_correctly
|
400
|
-
get :index,
|
421
|
+
get :index, facebook_params
|
401
422
|
assert_equal "<fb:redirect url=\"http://apps.facebook.com/root/require_auth\" />", @controller.send(:fbml_redirect_tag, :action => :index,:canvas=>true)
|
402
423
|
end
|
403
424
|
|
404
425
|
def test_redirect_to_renders_fbml_redirect_tag_if_request_is_for_a_facebook_canvas
|
405
|
-
get :index,
|
426
|
+
get :index, facebook_params(:fb_sig_user => nil)
|
406
427
|
assert_response :success
|
407
428
|
assert_equal("<fb:redirect url=\"http://www.facebook.com/login.php?api_key=1234567&v=1.0\" />", @response.body)
|
408
429
|
end
|
409
430
|
|
410
431
|
def test_url_for_links_to_canvas_if_canvas_is_true_and_not_in_canvas
|
411
|
-
get :link_test,
|
432
|
+
get :link_test, facebook_params(:fb_sig_in_canvas=>0,:canvas=>true)
|
412
433
|
assert_match /apps.facebook.com/,@response.body
|
413
434
|
end
|
414
435
|
|
415
436
|
def test_includes_relative_url_root_when_linked_to_canvas
|
416
|
-
get :link_test,
|
437
|
+
get :link_test,facebook_params(:fb_sig_in_canvas=>0,:canvas=>true)
|
417
438
|
assert_match /root/,@response.body
|
418
439
|
end
|
419
440
|
|
420
441
|
def test_url_for_links_to_callback_if_canvas_is_false_and_in_canvas
|
421
|
-
get :link_test,
|
442
|
+
get :link_test,facebook_params(:fb_sig_in_canvas=>0,:canvas=>false)
|
422
443
|
assert_match /test.host/,@response.body
|
423
444
|
end
|
424
445
|
|
425
446
|
def test_url_for_doesnt_include_url_root_when_not_linked_to_canvas
|
426
|
-
get :link_test,
|
447
|
+
get :link_test,facebook_params(:fb_sig_in_canvas=>0,:canvas=>false)
|
427
448
|
assert !@response.body.match(/root/)
|
428
449
|
end
|
429
450
|
|
430
451
|
def test_url_for_links_to_canvas_if_canvas_is_not_set
|
431
|
-
get :link_test,
|
452
|
+
get :link_test,facebook_params
|
432
453
|
assert_match /apps.facebook.com/,@response.body
|
433
454
|
end
|
434
455
|
|
435
456
|
def test_image_tag
|
436
|
-
get :image_test,
|
457
|
+
get :image_test, facebook_params
|
437
458
|
assert_equal "<img alt=\"Image\" src=\"http://root.example.com/images/image.png\" />",@response.body
|
438
459
|
end
|
439
460
|
|
440
461
|
def test_wants_interface_is_available_and_detects_method
|
441
|
-
get :publisher_test,
|
462
|
+
get :publisher_test, facebook_params(:method=>"publisher_getInterface")
|
442
463
|
assert_equal "interface",@response.body
|
443
464
|
end
|
444
465
|
def test_wants_interface_is_available_and_detects_not_interface
|
445
|
-
get :publisher_test,
|
466
|
+
get :publisher_test, facebook_params(:method=>"publisher_getFeedStory")
|
446
467
|
assert_equal "not interface",@response.body
|
447
468
|
end
|
448
469
|
|
449
470
|
def test_publisher_test_error
|
450
|
-
get :publisher_test_error,
|
451
|
-
assert_equal
|
471
|
+
get :publisher_test_error, facebook_params
|
472
|
+
assert_equal Facebooker.json_decode("{\"errorCode\": 1, \"errorTitle\": \"Title\", \"errorMessage\": \"Body\"}"), Facebooker.json_decode(@response.body)
|
452
473
|
end
|
453
474
|
|
454
475
|
def test_publisher_test_interface
|
455
|
-
get :publisher_test_interface,
|
456
|
-
assert_equal
|
476
|
+
get :publisher_test_interface, facebook_params
|
477
|
+
assert_equal Facebooker.json_decode("{\"method\": \"publisher_getInterface\", \"content\": {\"fbml\": \"This is a test\", \"publishEnabled\": false, \"commentEnabled\": true}}"), Facebooker.json_decode(@response.body)
|
457
478
|
end
|
458
479
|
|
459
480
|
def test_publisher_test_reponse
|
460
|
-
get :publisher_test_response,
|
461
|
-
assert_equal
|
481
|
+
get :publisher_test_response, facebook_params
|
482
|
+
assert_equal Facebooker.json_decode("{\"method\": \"publisher_getFeedStory\", \"content\": {\"feed\": {\"template_data\": {\"params\": true}, \"template_id\": 1234}}}"), Facebooker.json_decode(@response.body)
|
462
483
|
|
463
484
|
end
|
464
485
|
|
465
486
|
private
|
466
|
-
def example_rails_params_for_fb_connect
|
467
|
-
{"action"=>"index", "controller"=>"controller_which_requires_facebook_authentication"}
|
468
|
-
end
|
469
487
|
|
470
488
|
def expired_cookie_hash_for_auth
|
471
489
|
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.ago.to_i}"}
|
@@ -475,13 +493,6 @@ class RailsIntegrationTest < Test::Unit::TestCase
|
|
475
493
|
{"_ss" => "not_used", "_session_key"=> "whatever", "_user"=>"77777", "_expires"=>"#{1.day.from_now.to_i}"}
|
476
494
|
end
|
477
495
|
|
478
|
-
def example_rails_params_including_fb_for_user_not_logged_into_application
|
479
|
-
{"fb_sig_time"=>"1186588275.5988", "fb_sig"=>"7371a6400329b229f800a5ecafe03b0a", "action"=>"index", "fb_sig_in_canvas"=>"1", "controller"=>"controller_which_requires_facebook_authentication", "fb_sig_added"=>"0", "fb_sig_api_key"=>"b6c9c857ac543ca806f4d3187cd05e09"}
|
480
|
-
end
|
481
|
-
|
482
|
-
def example_rails_params_including_fb
|
483
|
-
{"fb_sig_time"=>"1186588275.5988", "fb_sig"=>"7371a6400329b229f800a5ecafe03b0a", "action"=>"index", "fb_sig_in_canvas"=>"1", "fb_sig_session_key"=>"c452b5d5d60cbd0a0da82021-744961110", "controller"=>"controller_which_requires_facebook_authentication", "fb_sig_expires"=>"0", "fb_sig_friends"=>"417358,702720,1001170,1530839,3300204,3501584,6217936,9627766,9700907,22701786,33902768,38914148,67400422,135301144,157200364,500103523,500104930,500870819,502149612,502664898,502694695,502852293,502985816,503254091,504510130,504611551,505421674,509229747,511075237,512548373,512830487,517893818,517961878,518890403,523589362,523826914,525812984,531555098,535310228,539339781,541137089,549405288,552706617,564393355,564481279,567640762,568091401,570201702,571469972,573863097,574415114,575543081,578129427,578520568,582262836,582561201,586550659,591631962,592318318,596269347,596663221,597405464,599764847,602995438,606661367,609761260,610544224,620049417,626087078,628803637,632686250,641422291,646763898,649678032,649925863,653288975,654395451,659079771,661794253,665861872,668960554,672481514,675399151,678427115,685772348,686821151,687686894,688506532,689275123,695551670,710631572,710766439,712406081,715741469,718976395,719246649,722747311,725327717,725683968,725831016,727580320,734151780,734595181,737944528,748881410,752244947,763868412,768578853,776596978,789728437,873695441", "fb_sig_added"=>"0", "fb_sig_api_key"=>"b6c9c857ac543ca806f4d3187cd05e09", "fb_sig_user"=>"744961110", "fb_sig_profile_update_time"=>"1180712453"}
|
484
|
-
end
|
485
496
|
end
|
486
497
|
|
487
498
|
|
@@ -498,7 +509,7 @@ class RailsSignatureTest < Test::Unit::TestCase
|
|
498
509
|
|
499
510
|
def test_should_raise_too_old_for_replayed_session
|
500
511
|
begin
|
501
|
-
get :fb_params_test,
|
512
|
+
get :fb_params_test, facebook_params('fb_sig_time' => Time.now.to_i - 49.hours)
|
502
513
|
fail "No SignatureTooOld raised"
|
503
514
|
rescue Facebooker::Session::SignatureTooOld=>e
|
504
515
|
end
|
@@ -506,7 +517,7 @@ class RailsSignatureTest < Test::Unit::TestCase
|
|
506
517
|
|
507
518
|
def test_should_raise_on_bad_sig
|
508
519
|
begin
|
509
|
-
get :fb_params_test,
|
520
|
+
get :fb_params_test, facebook_params.merge('fb_sig' => 'incorrect')
|
510
521
|
fail "No IncorrectSignature raised"
|
511
522
|
rescue Facebooker::Session::IncorrectSignature=>e
|
512
523
|
end
|
@@ -514,14 +525,10 @@ class RailsSignatureTest < Test::Unit::TestCase
|
|
514
525
|
|
515
526
|
def test_valid_signature
|
516
527
|
@controller.expects(:earliest_valid_session).returns(Time.at(1186588275.5988)-1)
|
517
|
-
get :fb_params_test,
|
528
|
+
get :fb_params_test, facebook_params
|
518
529
|
|
519
530
|
end
|
520
531
|
|
521
|
-
def example_rails_params_including_fb(options={})
|
522
|
-
{"fb_sig_time"=>"1186588275.5988", "fb_sig"=>"8d9e9dd2cb0742a5a2bfe35563134585", "action"=>"index", "fb_sig_in_canvas"=>"1", "fb_sig_session_key"=>"c452b5d5d60cbd0a0da82021-744961110", "controller"=>"controller_which_requires_facebook_authentication", "fb_sig_expires"=>"0", "fb_sig_friends"=>"417358,702720,1001170,1530839,3300204,3501584,6217936,9627766,9700907,22701786,33902768,38914148,67400422,135301144,157200364,500103523,500104930,500870819,502149612,502664898,502694695,502852293,502985816,503254091,504510130,504611551,505421674,509229747,511075237,512548373,512830487,517893818,517961878,518890403,523589362,523826914,525812984,531555098,535310228,539339781,541137089,549405288,552706617,564393355,564481279,567640762,568091401,570201702,571469972,573863097,574415114,575543081,578129427,578520568,582262836,582561201,586550659,591631962,592318318,596269347,596663221,597405464,599764847,602995438,606661367,609761260,610544224,620049417,626087078,628803637,632686250,641422291,646763898,649678032,649925863,653288975,654395451,659079771,661794253,665861872,668960554,672481514,675399151,678427115,685772348,686821151,687686894,688506532,689275123,695551670,710631572,710766439,712406081,715741469,718976395,719246649,722747311,725327717,725683968,725831016,727580320,734151780,734595181,737944528,748881410,752244947,763868412,768578853,776596978,789728437,873695441", "fb_sig_added"=>"0", "fb_sig_api_key"=>"b6c9c857ac543ca806f4d3187cd05e09", "fb_sig_user"=>"744961110", "fb_sig_profile_update_time"=>"1180712453"}.merge(options)
|
523
|
-
end
|
524
|
-
|
525
532
|
end
|
526
533
|
class RailsHelperTest < Test::Unit::TestCase
|
527
534
|
class HelperClass
|
@@ -939,6 +946,23 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
939
946
|
assert @h.init_fb_connect("XFBML").match(/XFBML/)
|
940
947
|
end
|
941
948
|
|
949
|
+
def test_init_fb_connect_with_features_and_body
|
950
|
+
@h.expects(:capture).returns("Body Content")
|
951
|
+
|
952
|
+
@h.init_fb_connect("XFBML") do
|
953
|
+
end
|
954
|
+
assert @h.output_buffer =~ /Body Content/
|
955
|
+
end
|
956
|
+
|
957
|
+
def test_fb_login_and_redirect
|
958
|
+
assert_equal @h.fb_login_and_redirect("/path"),"<fb:login-button onlogin=\"window.location.href = "/path";\"></fb:login-button>"
|
959
|
+
end
|
960
|
+
|
961
|
+
def test_fb_logout_link
|
962
|
+
assert_equal @h.fb_logout_link("Logout","My URL"),"<a href=\"#\" onclick=\"FB.Connect.logoutAndRedirect("My URL");; return false;\">Logout</a>"
|
963
|
+
end
|
964
|
+
|
965
|
+
|
942
966
|
def test_fb_connect_javascript_tag
|
943
967
|
assert_equal "<script src=\"http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php\" type=\"text/javascript\"></script>",
|
944
968
|
@h.fb_connect_javascript_tag
|
@@ -978,6 +1002,16 @@ class RailsHelperTest < Test::Unit::TestCase
|
|
978
1002
|
user=flexmock("user", :facebook_id => "5678")
|
979
1003
|
assert_equal '<fb:user-status linked="false" uid="5678"></fb:user-status>',@h.fb_user_status(user,false)
|
980
1004
|
end
|
1005
|
+
|
1006
|
+
def test_fb_time
|
1007
|
+
time = Time.now
|
1008
|
+
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)
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
def test_fb_time_defaults
|
1012
|
+
time = Time.now
|
1013
|
+
assert_equal %Q{<fb:time t="#{time.to_i}" />}, @h.fb_time(time)
|
1014
|
+
end
|
981
1015
|
end
|
982
1016
|
class TestModel
|
983
1017
|
attr_accessor :name,:facebook_id
|
@@ -1061,32 +1095,43 @@ class RailsFacebookFormbuilderTest < Test::Unit::TestCase
|
|
1061
1095
|
end
|
1062
1096
|
|
1063
1097
|
class RailsPrettyErrorsTest < Test::Unit::TestCase
|
1098
|
+
class ControllerWhichFails < ActionController::Base
|
1099
|
+
def pass
|
1100
|
+
render :text=>''
|
1101
|
+
end
|
1102
|
+
def fail
|
1103
|
+
raise "I'm failing"
|
1104
|
+
end
|
1105
|
+
end
|
1106
|
+
|
1064
1107
|
def setup
|
1065
|
-
ENV['FACEBOOK_API_KEY'] = '1234567'
|
1066
|
-
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
1067
1108
|
@controller = ControllerWhichFails.new
|
1068
1109
|
@request = ActionController::TestRequest.new
|
1069
1110
|
@response = ActionController::TestResponse.new
|
1070
|
-
@controller.stubs(:verify_signature).returns(true)
|
1071
1111
|
end
|
1072
1112
|
|
1073
|
-
def
|
1074
|
-
Facebooker.facebooker_config.stubs(:pretty_errors).returns(false)
|
1075
|
-
post :pass,
|
1076
|
-
assert_response
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
post :fail, example_rails_params_including_fb
|
1113
|
+
def test_pretty_errors_disabled_success
|
1114
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(false)
|
1115
|
+
post :pass, facebook_params
|
1116
|
+
assert_response 200
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
def test_pretty_errors_disabled_error
|
1120
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(false)
|
1121
|
+
post :fail, facebook_params
|
1083
1122
|
assert_response :error
|
1084
1123
|
end
|
1085
|
-
private
|
1086
|
-
def example_rails_params_including_fb
|
1087
|
-
{"fb_sig_time"=>"1186588275.5988", "fb_sig"=>"7371a6400329b229f800a5ecafe03b0a", "action"=>"index", "fb_sig_in_canvas"=>"1", "fb_sig_session_key"=>"c452b5d5d60cbd0a0da82021-744961110", "controller"=>"controller_which_requires_facebook_authentication", "fb_sig_expires"=>"0", "fb_sig_friends"=>"417358,702720,1001170,1530839,3300204,3501584,6217936,9627766,9700907,22701786,33902768,38914148,67400422,135301144,157200364,500103523,500104930,500870819,502149612,502664898,502694695,502852293,502985816,503254091,504510130,504611551,505421674,509229747,511075237,512548373,512830487,517893818,517961878,518890403,523589362,523826914,525812984,531555098,535310228,539339781,541137089,549405288,552706617,564393355,564481279,567640762,568091401,570201702,571469972,573863097,574415114,575543081,578129427,578520568,582262836,582561201,586550659,591631962,592318318,596269347,596663221,597405464,599764847,602995438,606661367,609761260,610544224,620049417,626087078,628803637,632686250,641422291,646763898,649678032,649925863,653288975,654395451,659079771,661794253,665861872,668960554,672481514,675399151,678427115,685772348,686821151,687686894,688506532,689275123,695551670,710631572,710766439,712406081,715741469,718976395,719246649,722747311,725327717,725683968,725831016,727580320,734151780,734595181,737944528,748881410,752244947,763868412,768578853,776596978,789728437,873695441", "fb_sig_added"=>"0", "fb_sig_api_key"=>"b6c9c857ac543ca806f4d3187cd05e09", "fb_sig_user"=>"744961110", "fb_sig_profile_update_time"=>"1180712453"}
|
1088
|
-
end
|
1089
1124
|
|
1125
|
+
def test_pretty_errors_enabled_success
|
1126
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(true)
|
1127
|
+
post :pass, facebook_params
|
1128
|
+
assert_response 200
|
1129
|
+
end
|
1130
|
+
def test_pretty_errors_enabled_error
|
1131
|
+
Facebooker.facebooker_config.stubs(:[]).with('pretty_errors').returns(true)
|
1132
|
+
post :fail, facebook_params
|
1133
|
+
assert_response 200
|
1134
|
+
end
|
1090
1135
|
end
|
1091
1136
|
|
1092
1137
|
class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
|
@@ -1231,7 +1276,37 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
|
|
1231
1276
|
|
1232
1277
|
end
|
1233
1278
|
|
1279
|
+
class RailsRequestFormatTest < Test::Unit::TestCase
|
1280
|
+
class FacebookController < NoisyController
|
1281
|
+
def index
|
1282
|
+
respond_to do |format|
|
1283
|
+
format.html { render :text => 'html' }
|
1284
|
+
format.fbml { render :text => 'fbml' }
|
1285
|
+
format.fbjs { render :text => 'fbjs' }
|
1286
|
+
end
|
1287
|
+
end
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
def setup
|
1291
|
+
@controller = FacebookController.new
|
1292
|
+
@request = ActionController::TestRequest.new
|
1293
|
+
@response = ActionController::TestResponse.new
|
1294
|
+
@controller.stubs(:verify_signature).returns(true)
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
def test_responds_to_html_without_canvas
|
1298
|
+
get :index
|
1299
|
+
assert_equal 'html', @response.body
|
1300
|
+
end
|
1301
|
+
|
1302
|
+
def test_responds_to_fbml_in_canvas
|
1303
|
+
get :index, facebook_params(:fb_sig_in_canvas => '1')
|
1304
|
+
assert_equal 'fbml', @response.body
|
1305
|
+
end
|
1234
1306
|
|
1235
|
-
|
1236
|
-
|
1307
|
+
def test_responds_to_fbjs_when_is_ajax
|
1308
|
+
get :index, facebook_params(:fb_sig_is_ajax => '1')
|
1309
|
+
assert_equal 'fbjs', @response.body
|
1310
|
+
end
|
1311
|
+
|
1237
1312
|
end
|