fotonauts-facebooker 1.0.67
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +15 -0
- data/CHANGELOG.rdoc +24 -0
- data/COPYING.rdoc +19 -0
- data/Manifest.txt +152 -0
- data/README.rdoc +119 -0
- data/Rakefile +94 -0
- data/TODO.rdoc +4 -0
- data/examples/desktop_login.rb +14 -0
- data/facebooker.gemspec +45 -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 +332 -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/templates/xd_receiver_ssl.html +10 -0
- data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
- data/init.rb +26 -0
- data/install.rb +12 -0
- data/lib/facebooker.rb +275 -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 +60 -0
- data/lib/facebooker/admin.rb +42 -0
- data/lib/facebooker/application.rb +37 -0
- data/lib/facebooker/attachment.rb +51 -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/comment.rb +9 -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/family_relative_info.rb +7 -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/message_thread.rb +89 -0
- data/lib/facebooker/models/notifications.rb +17 -0
- data/lib/facebooker/models/page.rb +46 -0
- data/lib/facebooker/models/photo.rb +19 -0
- data/lib/facebooker/models/tag.rb +12 -0
- data/lib/facebooker/models/user.rb +751 -0
- data/lib/facebooker/models/video.rb +9 -0
- data/lib/facebooker/models/work_info.rb +10 -0
- data/lib/facebooker/parser.rb +970 -0
- data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
- data/lib/facebooker/rails/controller.rb +353 -0
- data/lib/facebooker/rails/cucumber.rb +28 -0
- data/lib/facebooker/rails/cucumber/world.rb +40 -0
- data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
- data/lib/facebooker/rails/extensions/rack_setup.rb +16 -0
- data/lib/facebooker/rails/extensions/routing.rb +15 -0
- data/lib/facebooker/rails/facebook_form_builder.rb +141 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
- data/lib/facebooker/rails/facebook_request_fix.rb +28 -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.rb +835 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +165 -0
- data/lib/facebooker/rails/helpers/stream_publish.rb +22 -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 +608 -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 +103 -0
- data/lib/facebooker/service/base_service.rb +19 -0
- data/lib/facebooker/service/curl_service.rb +44 -0
- data/lib/facebooker/service/net_http_service.rb +12 -0
- data/lib/facebooker/service/typhoeus_multi_service.rb +27 -0
- data/lib/facebooker/service/typhoeus_service.rb +17 -0
- data/lib/facebooker/session.rb +786 -0
- data/lib/facebooker/stream_post.rb +19 -0
- data/lib/facebooker/version.rb +9 -0
- data/lib/net/http_multipart_post.rb +123 -0
- data/lib/rack/facebook.rb +89 -0
- data/lib/rack/facebook_session.rb +21 -0
- data/lib/tasks/facebooker.rake +19 -0
- data/lib/tasks/facebooker.rb +2 -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 +191 -0
- data/test/facebooker/admin_test.rb +102 -0
- data/test/facebooker/application_test.rb +110 -0
- data/test/facebooker/attachment_test.rb +72 -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/page_test.rb +56 -0
- data/test/facebooker/models/photo_test.rb +16 -0
- data/test/facebooker/models/user_test.rb +1074 -0
- data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +25 -0
- data/test/facebooker/rails/facebook_url_rewriting_test.rb +76 -0
- data/test/facebooker/rails/integration_session_test.rb +13 -0
- data/test/facebooker/rails/publisher_test.rb +538 -0
- data/test/facebooker/rails_integration_test.rb +1543 -0
- data/test/facebooker/server_cache_test.rb +44 -0
- data/test/facebooker/service_test.rb +58 -0
- data/test/facebooker/session_test.rb +883 -0
- data/test/facebooker_test.rb +1263 -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_session_test.rb +34 -0
- data/test/rack/facebook_test.rb +73 -0
- data/test/rails_test_helper.rb +36 -0
- data/test/test_helper.rb +74 -0
- metadata +303 -0
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
2
|
+
require 'facebooker/rails/facebook_request_fix_2-3' if Rails.version >= '2.3'
|
3
|
+
class Facebooker::Rails::FacebookRequestFix23Test < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
7
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
8
|
+
if Rails.version < '2.3'
|
9
|
+
@request = ActionController::TestRequest.new({"fb_sig_is_ajax"=>"1"}, {}, nil)
|
10
|
+
|
11
|
+
else
|
12
|
+
@request = ActionController::TestRequest.new
|
13
|
+
@request.query_parameters[:fb_sig_is_ajax] = "1"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_xhr_when_is_ajax
|
18
|
+
assert @request.xhr?
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_xml_http_request_when_is_ajax
|
22
|
+
assert @request.xml_http_request?
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
2
|
+
|
3
|
+
class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@request = ActionController::TestRequest.new
|
7
|
+
@params = {}
|
8
|
+
@rewriter = ActionController::UrlRewriter.new(@request, @params)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_one_or_true_on_string_1
|
12
|
+
assert @rewriter.one_or_true( "1" )
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_one_or_true_on_string_0
|
16
|
+
assert !@rewriter.one_or_true( "0" )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_one_or_true_on_integer_1
|
20
|
+
assert @rewriter.one_or_true( 1 )
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_one_or_true_on_float_1
|
24
|
+
assert @rewriter.one_or_true( 1.0 )
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_one_or_true_on_true
|
28
|
+
assert @rewriter.one_or_true( true )
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_one_or_true_on_false
|
32
|
+
assert !@rewriter.one_or_true( false )
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_one_or_true_on_nil
|
36
|
+
assert !@rewriter.one_or_true( nil )
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def test_zero_or_false_on_blank
|
41
|
+
assert @rewriter.zero_or_false( "" )
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_zero_or_false_on_integer_0
|
45
|
+
assert @rewriter.zero_or_false( 0 )
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_zero_or_false_on_float_0
|
49
|
+
assert @rewriter.zero_or_false( 0.0 )
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_zero_or_false_on_string_0
|
53
|
+
assert @rewriter.zero_or_false( "0" )
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_zero_or_false_on_false
|
57
|
+
assert @rewriter.zero_or_false( false )
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_zero_or_false_on_nil
|
61
|
+
assert @rewriter.zero_or_false( nil )
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_zero_or_false_on_string_1
|
65
|
+
assert !@rewriter.zero_or_false( "1" )
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_zero_or_false_on_numeric_1
|
69
|
+
assert !@rewriter.zero_or_false( 1 )
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_zero_or_false_on_true
|
73
|
+
assert !@rewriter.zero_or_false( true )
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../lib/facebooker/rails/integration_session')
|
3
|
+
|
4
|
+
class Facebooker::Rails::IntegrationSessionTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_include_api_key_in_default_request_params
|
7
|
+
ENV['FACEBOOK_API_KEY'] = 'a key'
|
8
|
+
integration_session = Facebooker::Rails::IntegrationSession.new
|
9
|
+
integration_session.reset!
|
10
|
+
assert_equal 'a key', integration_session.default_request_params[ :fb_sig_api_key ]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,538 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
|
2
|
+
|
3
|
+
module SymbolHelper
|
4
|
+
def symbol_helper_loaded
|
5
|
+
true
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module ModuleHelper
|
10
|
+
def module_helper_loaded
|
11
|
+
true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
::RAILS_DEFAULT_LOGGER = Logger.new(STDOUT)
|
16
|
+
|
17
|
+
class TestPublisher < Facebooker::Rails::Publisher
|
18
|
+
|
19
|
+
helper :symbol
|
20
|
+
helper ModuleHelper
|
21
|
+
|
22
|
+
def action(f)
|
23
|
+
send_as :action
|
24
|
+
from f
|
25
|
+
title "Action Title"
|
26
|
+
end
|
27
|
+
|
28
|
+
def templatized_action(f)
|
29
|
+
send_as :templatized_action
|
30
|
+
from f
|
31
|
+
title_template "Templatized Action Title"
|
32
|
+
end
|
33
|
+
|
34
|
+
def story(to)
|
35
|
+
send_as :story
|
36
|
+
recipients to
|
37
|
+
title 'Story Title'
|
38
|
+
end
|
39
|
+
|
40
|
+
def notification(to,f)
|
41
|
+
send_as :notification
|
42
|
+
recipients to
|
43
|
+
from f
|
44
|
+
fbml "Not"
|
45
|
+
end
|
46
|
+
|
47
|
+
def email(to,f)
|
48
|
+
send_as :email
|
49
|
+
recipients to
|
50
|
+
from f
|
51
|
+
title "Email"
|
52
|
+
fbml 'text'
|
53
|
+
text fbml
|
54
|
+
end
|
55
|
+
|
56
|
+
def render_notification(to,f)
|
57
|
+
send_as :notification
|
58
|
+
recipients to
|
59
|
+
from f
|
60
|
+
fbml render(:inline=>"<%=module_helper_loaded%>")
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
def profile_update(to,f)
|
65
|
+
send_as :profile
|
66
|
+
recipients to
|
67
|
+
profile "profile"
|
68
|
+
profile_action "profile_action"
|
69
|
+
mobile_profile "mobile_profile"
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
def profile_update_with_profile_main(to,f)
|
74
|
+
send_as :profile
|
75
|
+
recipients to
|
76
|
+
from f
|
77
|
+
profile "profile"
|
78
|
+
profile_action "profile_action"
|
79
|
+
mobile_profile "mobile_profile"
|
80
|
+
profile_main "profile_main"
|
81
|
+
end
|
82
|
+
|
83
|
+
def ref_update(user)
|
84
|
+
send_as :ref
|
85
|
+
fbml "fbml"
|
86
|
+
handle "handle"
|
87
|
+
end
|
88
|
+
|
89
|
+
def user_action_template
|
90
|
+
one_line_story_template "{*actor*} did stuff with {*friend*}"
|
91
|
+
short_story_template "{*actor*} has a title {*friend*}", render(:inline=>"This is a test render")
|
92
|
+
full_story_template "{*actor*} did a lot","This is the full body",:img=>{:some_params=>true}
|
93
|
+
end
|
94
|
+
|
95
|
+
def simple_user_action_template
|
96
|
+
one_line_story_template "{*actor*} did stuff with {*friend*}"
|
97
|
+
end
|
98
|
+
|
99
|
+
def user_action_with_action_links_template
|
100
|
+
one_line_story_template "{*actor*} did stuff with {*friend*}"
|
101
|
+
short_story_template "{*actor*} has a title {*friend*}", render(:inline=>"This is a test render")
|
102
|
+
full_story_template "{*actor*} did a lot","This is the full body",:img=>{:some_params=>true}
|
103
|
+
action_links action_link("Source","HREF")
|
104
|
+
end
|
105
|
+
|
106
|
+
def user_action(user)
|
107
|
+
send_as :user_action
|
108
|
+
from user
|
109
|
+
data :friend=>"Mike"
|
110
|
+
end
|
111
|
+
|
112
|
+
def user_action_with_template_id(user)
|
113
|
+
send_as :user_action
|
114
|
+
from user
|
115
|
+
data :friend=>"Mike"
|
116
|
+
template_id 4
|
117
|
+
end
|
118
|
+
def user_action_with_story_size(user)
|
119
|
+
send_as :user_action
|
120
|
+
from user
|
121
|
+
story_size ONE_LINE
|
122
|
+
story_size FULL
|
123
|
+
story_size SHORT
|
124
|
+
data :friend=>"Mike"
|
125
|
+
end
|
126
|
+
def user_action_no_data(user)
|
127
|
+
send_as :user_action
|
128
|
+
from user
|
129
|
+
end
|
130
|
+
|
131
|
+
def no_send_as(to)
|
132
|
+
recipients to
|
133
|
+
end
|
134
|
+
|
135
|
+
def invalid_send_as(to)
|
136
|
+
send_as :fake
|
137
|
+
recipients to
|
138
|
+
end
|
139
|
+
|
140
|
+
def publish_post_to_own_stream(user)
|
141
|
+
send_as :publish_stream
|
142
|
+
from user
|
143
|
+
target user
|
144
|
+
attachment({:name => "Facebooker", :href => "http://www.exampple.com"})
|
145
|
+
message "Posting post to own stream"
|
146
|
+
action_links([{:text => "Action Link", :href => "http://www.example.com/action_link"}])
|
147
|
+
end
|
148
|
+
|
149
|
+
def publish_post_to_friends_stream(from, to)
|
150
|
+
send_as :publish_stream
|
151
|
+
from from
|
152
|
+
target to
|
153
|
+
attachment({:name => "Facebooker", :href => "http://www.exampple.com"})
|
154
|
+
message "Posting post to friends stream"
|
155
|
+
action_links([{:text => "Action Link", :href => "http://www.example.com/action_link"}])
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
160
|
+
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
161
|
+
|
162
|
+
def setup
|
163
|
+
super
|
164
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
165
|
+
@template = mock("facebook template")
|
166
|
+
FacebookTemplate.stubs(:register).returns(@template)
|
167
|
+
FacebookTemplate.clear_cache!
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_find_or_register_calls_find_cached
|
171
|
+
FacebookTemplate.expects(:find_cached).with(TestPublisher,"simple_user_action").returns(@template)
|
172
|
+
assert_equal FacebookTemplate.for_class_and_method(TestPublisher,"simple_user_action"),@template
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_find_cached_should_use_cached_if_it_exists
|
176
|
+
FacebookTemplate.cache(TestPublisher,"simple_user_action",@template)
|
177
|
+
assert_equal FacebookTemplate.find_cached(TestPublisher,"simple_user_action"), @template
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_find_cached_should_call_find_in_db_if_not_in_cache
|
182
|
+
FacebookTemplate.expects(:find_in_db).with(TestPublisher,"simple_user_action").returns(@template)
|
183
|
+
assert_equal FacebookTemplate.find_cached(TestPublisher,"simple_user_action"), @template
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_find_in_db_should_run_find
|
187
|
+
FacebookTemplate.expects(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
|
188
|
+
@template.stubs(:template_changed?).returns(false)
|
189
|
+
assert_equal FacebookTemplate.find_in_db(TestPublisher,"simple_user_action"), @template
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_find_in_db_should_register_if_not_found
|
193
|
+
FacebookTemplate.expects(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(nil)
|
194
|
+
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
195
|
+
FacebookTemplate.find_cached(TestPublisher,"simple_user_action")
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_find_in_db_should_check_for_change_if_found
|
200
|
+
FacebookTemplate.stubs(:find_by_template_name).returns(@template)
|
201
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
202
|
+
@template.expects(:template_changed?).with("MY CONTENT").returns(false)
|
203
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_find_in_db_should_re_register_if_changed
|
207
|
+
FacebookTemplate.stubs(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
|
208
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
209
|
+
@template.stubs(:template_changed?).returns(true)
|
210
|
+
@template.stubs(:destroy)
|
211
|
+
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
212
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
216
|
+
|
217
|
+
class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
218
|
+
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
219
|
+
|
220
|
+
def setup
|
221
|
+
super
|
222
|
+
|
223
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
224
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
225
|
+
|
226
|
+
@user = Facebooker::User.new
|
227
|
+
@user.id=4
|
228
|
+
@session = "session"
|
229
|
+
@user.stubs(:session).returns(@session)
|
230
|
+
end
|
231
|
+
|
232
|
+
def teardown
|
233
|
+
super
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_respond_to
|
237
|
+
assert TestPublisher.respond_to?(:create_action)
|
238
|
+
assert TestPublisher.respond_to?(:deliver_action)
|
239
|
+
assert TestPublisher.respond_to?(:register_action)
|
240
|
+
end
|
241
|
+
|
242
|
+
def test_create_action
|
243
|
+
action=TestPublisher.create_action(@user)
|
244
|
+
assert_equal Facebooker::Feed::Action,action.class
|
245
|
+
assert_equal "Action Title",action.title
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_deliver_action
|
249
|
+
@user.expects(:publish_action)
|
250
|
+
TestPublisher.deliver_action(@user)
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_create_story
|
254
|
+
action=TestPublisher.create_story(@user)
|
255
|
+
assert_equal Facebooker::Feed::Story,action.class
|
256
|
+
assert_equal "Story Title",action.title
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_deliver_story
|
260
|
+
@user.expects(:publish_story)
|
261
|
+
TestPublisher.deliver_story(@user)
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_create_notification
|
265
|
+
notification=TestPublisher.create_notification(12451752,@user)
|
266
|
+
assert_equal Facebooker::Rails::Publisher::Notification,notification.class
|
267
|
+
assert_equal "Not",notification.fbml
|
268
|
+
end
|
269
|
+
|
270
|
+
def test_deliver_notification
|
271
|
+
@session.expects(:send_notification)
|
272
|
+
TestPublisher.deliver_notification("12451752",@user)
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_create_email
|
276
|
+
email=TestPublisher.create_email("12451752",@user)
|
277
|
+
assert_equal Facebooker::Rails::Publisher::Email,email.class
|
278
|
+
assert_equal "Email",email.title
|
279
|
+
assert_equal "text",email.text
|
280
|
+
assert_equal "text",email.fbml
|
281
|
+
end
|
282
|
+
|
283
|
+
def test_deliver_email
|
284
|
+
@session.expects(:send_email)
|
285
|
+
TestPublisher.deliver_email("12451752",@user)
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_create_templatized_action
|
289
|
+
ta=TestPublisher.create_templatized_action(@user)
|
290
|
+
assert_equal Facebooker::Feed::TemplatizedAction,ta.class
|
291
|
+
assert_equal "Templatized Action Title",ta.title_template
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
def test_deliver_templatized_action
|
298
|
+
@user.expects(:publish_action)
|
299
|
+
TestPublisher.deliver_templatized_action(@user)
|
300
|
+
end
|
301
|
+
def test_create_profile_update
|
302
|
+
p=TestPublisher.create_profile_update(@user,@user)
|
303
|
+
assert_equal Facebooker::Rails::Publisher::Profile,p.class
|
304
|
+
assert_equal "profile",p.profile
|
305
|
+
assert_equal "profile_action",p.profile_action
|
306
|
+
assert_equal "mobile_profile",p.mobile_profile
|
307
|
+
end
|
308
|
+
def test_create_profile_update_with_profile_main
|
309
|
+
p=TestPublisher.create_profile_update_with_profile_main(@user,@user)
|
310
|
+
assert_equal Facebooker::Rails::Publisher::Profile,p.class
|
311
|
+
assert_equal "profile",p.profile
|
312
|
+
assert_equal "profile_action",p.profile_action
|
313
|
+
assert_equal "mobile_profile",p.mobile_profile
|
314
|
+
assert_equal "profile_main",p.profile_main
|
315
|
+
end
|
316
|
+
|
317
|
+
|
318
|
+
def test_deliver_profile
|
319
|
+
Facebooker::User.stubs(:new).returns(@user)
|
320
|
+
@user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action',nil)
|
321
|
+
TestPublisher.deliver_profile_update(@user,@user)
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_deliver_profile_with_main
|
325
|
+
Facebooker::User.stubs(:new).returns(@user)
|
326
|
+
@user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action','profile_main')
|
327
|
+
TestPublisher.deliver_profile_update_with_profile_main(@user,@user)
|
328
|
+
end
|
329
|
+
|
330
|
+
|
331
|
+
def test_create_ref_update
|
332
|
+
p=TestPublisher.create_ref_update(@user)
|
333
|
+
assert_equal Facebooker::Rails::Publisher::Ref,p.class
|
334
|
+
assert_equal "fbml",p.fbml
|
335
|
+
assert_equal "handle",p.handle
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_deliver_ref_update
|
339
|
+
Facebooker::Session.stubs(:create).returns(@session)
|
340
|
+
@server_cache="server_cache"
|
341
|
+
@session.expects(:server_cache).returns(@server_cache)
|
342
|
+
@server_cache.expects(:set_ref_handle).with("handle","fbml")
|
343
|
+
TestPublisher.deliver_ref_update(@user)
|
344
|
+
end
|
345
|
+
|
346
|
+
def test_register_user_action
|
347
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
|
348
|
+
TestPublisher.register_user_action
|
349
|
+
end
|
350
|
+
|
351
|
+
def test_register_should_deactivate_template_bundle_if_exists
|
352
|
+
@template = mock
|
353
|
+
@template.stubs(:bundle_id).returns(999)
|
354
|
+
@template.stubs(:bundle_id=)
|
355
|
+
@template.stubs(:save!)
|
356
|
+
@session = mock
|
357
|
+
@session.stubs(:register_template_bundle).returns(1000)
|
358
|
+
Facebooker::Session.stubs(:create).returns(@session)
|
359
|
+
Facebooker::Rails::Publisher::FacebookTemplate.stubs(:find_or_initialize_by_template_name).returns(@template)
|
360
|
+
@template.expects(:deactivate)
|
361
|
+
FacebookTemplate.register(TestPublisher, "simple_user_action")
|
362
|
+
end
|
363
|
+
|
364
|
+
def test_register_user_action_with_action_links
|
365
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
366
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
|
367
|
+
TestPublisher.register_user_action_with_action_links
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_create_user_action
|
371
|
+
@from_user = Facebooker::User.new
|
372
|
+
@session = Facebooker::Session.new("","")
|
373
|
+
@from_user.stubs(:session).returns(@session)
|
374
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
375
|
+
with(TestPublisher,'user_action').
|
376
|
+
returns(20309041537)
|
377
|
+
ua = TestPublisher.create_user_action(@from_user)
|
378
|
+
assert_equal "user_action", ua.template_name
|
379
|
+
end
|
380
|
+
def test_create_user_action_with_template_id
|
381
|
+
@from_user = Facebooker::User.new
|
382
|
+
@session = Facebooker::Session.new("","")
|
383
|
+
@from_user.stubs(:session).returns(@session)
|
384
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
385
|
+
with(TestPublisher,'user_action').never
|
386
|
+
ua = TestPublisher.create_user_action_with_template_id(@from_user)
|
387
|
+
assert_equal 4,ua.template_id
|
388
|
+
end
|
389
|
+
|
390
|
+
def test_publisher_user_action
|
391
|
+
@from_user = Facebooker::User.new
|
392
|
+
@session = Facebooker::Session.new("","")
|
393
|
+
@from_user.stubs(:session).returns(@session)
|
394
|
+
@session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil,nil)
|
395
|
+
|
396
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
397
|
+
with(TestPublisher, 'user_action').
|
398
|
+
returns(20309041537)
|
399
|
+
# pseudo_template = Struct.new(:bundle_id, :content_hash).new(20309041537, '')
|
400
|
+
# pseudo_template.expects(:matches_content?).returns(true)
|
401
|
+
# Facebooker::Rails::Publisher::FacebookTemplate.expects(:for).returns(pseudo_template)
|
402
|
+
TestPublisher.deliver_user_action(@from_user)
|
403
|
+
end
|
404
|
+
|
405
|
+
def test_publish_user_action_with_story_size
|
406
|
+
@from_user = Facebooker::User.new
|
407
|
+
@session = Facebooker::Session.new("","")
|
408
|
+
@from_user.stubs(:session).returns(@session)
|
409
|
+
@session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil,2)
|
410
|
+
|
411
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
412
|
+
with(TestPublisher, 'user_action_with_story_size').
|
413
|
+
returns(20309041537)
|
414
|
+
TestPublisher.deliver_user_action_with_story_size(@from_user)
|
415
|
+
|
416
|
+
end
|
417
|
+
|
418
|
+
def test_publishing_user_data_no_action_gives_nil_hash
|
419
|
+
@from_user = Facebooker::User.new
|
420
|
+
@session = Facebooker::Session.new("","")
|
421
|
+
@from_user.stubs(:session).returns(@session)
|
422
|
+
@session.expects(:publish_user_action).with(20309041537,{},nil,nil,nil)
|
423
|
+
|
424
|
+
Facebooker::Rails::Publisher::FacebookTemplate.stubs(:bundle_id_for_class_and_method).returns(20309041537)
|
425
|
+
TestPublisher.deliver_user_action_no_data(@from_user)
|
426
|
+
end
|
427
|
+
def test_no_sends_as_raises
|
428
|
+
assert_raises(Facebooker::Rails::Publisher::UnspecifiedBodyType) {
|
429
|
+
TestPublisher.deliver_no_send_as(@user)
|
430
|
+
}
|
431
|
+
end
|
432
|
+
|
433
|
+
def test_invalid_send_as_raises
|
434
|
+
assert_raises(Facebooker::Rails::Publisher::UnknownBodyType) {
|
435
|
+
TestPublisher.deliver_invalid_send_as(@user)
|
436
|
+
}
|
437
|
+
end
|
438
|
+
|
439
|
+
def test_publish_post_to_own_stream
|
440
|
+
@user = Facebooker::User.new
|
441
|
+
@user.expects(:publish_to).with(@user, has_entry(:attachment=>instance_of(Hash)))
|
442
|
+
|
443
|
+
TestPublisher.deliver_publish_post_to_own_stream(@user)
|
444
|
+
end
|
445
|
+
|
446
|
+
def test_publish_stream_sets_action_links
|
447
|
+
@user = Facebooker::User.new
|
448
|
+
stream_post = TestPublisher.create_publish_post_to_own_stream(@user)
|
449
|
+
assert_equal [{:text => "Action Link", :href => "http://www.example.com/action_link"}],stream_post.action_links
|
450
|
+
end
|
451
|
+
|
452
|
+
def test_publish_stream_sets_target
|
453
|
+
@user = Facebooker::User.new
|
454
|
+
stream_post = TestPublisher.create_publish_post_to_own_stream(@user)
|
455
|
+
assert_equal @user,stream_post.target
|
456
|
+
|
457
|
+
end
|
458
|
+
|
459
|
+
def test_publish_post_to_friends_stream
|
460
|
+
@from_user = Facebooker::User.new
|
461
|
+
@to_user = Facebooker::User.new
|
462
|
+
@from_user.expects(:publish_to).with(@to_user, has_entry(:action_links=>instance_of(Array)))
|
463
|
+
|
464
|
+
TestPublisher.deliver_publish_post_to_friends_stream(@from_user, @to_user)
|
465
|
+
end
|
466
|
+
|
467
|
+
def test_keeps_class_method_missing
|
468
|
+
assert_raises(NoMethodError) {
|
469
|
+
TestPublisher.fake
|
470
|
+
}
|
471
|
+
end
|
472
|
+
def test_keeps_instance_method_missing
|
473
|
+
assert_raises(NoMethodError) {
|
474
|
+
TestPublisher.new.fake
|
475
|
+
}
|
476
|
+
end
|
477
|
+
|
478
|
+
def test_image_urls
|
479
|
+
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
480
|
+
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
481
|
+
assert_equal('/images/image.png',string_image.src)
|
482
|
+
assert_equal('raw_string',string_image.href)
|
483
|
+
route_image = TestPublisher.new.image('image.png', {:controller => :pokes, :action => :do, :id => 1})
|
484
|
+
assert_equal('http://apps.facebook.com/mike/pokes/do/1',route_image.href)
|
485
|
+
end
|
486
|
+
|
487
|
+
def test_image_holder_equality
|
488
|
+
assert_equal TestPublisher::ImageHolder.new('image.png', 'raw_string'), TestPublisher::ImageHolder.new('image.png', 'raw_string')
|
489
|
+
end
|
490
|
+
|
491
|
+
def test_image_to_json_puts_src_first
|
492
|
+
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
493
|
+
assert_equal "{\"src\":\"/images/image.png\", \"href\":\"raw_string\"}",string_image.to_json
|
494
|
+
end
|
495
|
+
def test_action_link
|
496
|
+
assert_equal({:text=>"text", :href=>"href"}, TestPublisher.new.action_link("text","href"))
|
497
|
+
end
|
498
|
+
|
499
|
+
def test_default_url_options
|
500
|
+
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
501
|
+
assert_equal({:host=>"apps.facebook.com/mike"},TestPublisher.new.default_url_options)
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_recipients
|
505
|
+
tp=TestPublisher.new
|
506
|
+
tp.recipients "a"
|
507
|
+
assert_equal("a",tp.recipients)
|
508
|
+
end
|
509
|
+
|
510
|
+
def test_symbol_helper
|
511
|
+
assert TestPublisher.new.symbol_helper_loaded
|
512
|
+
end
|
513
|
+
def test_module_helper
|
514
|
+
assert TestPublisher.new.module_helper_loaded
|
515
|
+
end
|
516
|
+
|
517
|
+
def test_with_render
|
518
|
+
#normally Rails would do this for us
|
519
|
+
silence_warnings do
|
520
|
+
if ActionController::Base.respond_to?(:append_view_path)
|
521
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
522
|
+
end
|
523
|
+
notification=TestPublisher.create_render_notification(12451752,@user)
|
524
|
+
assert_equal "true",notification.fbml
|
525
|
+
end
|
526
|
+
end
|
527
|
+
|
528
|
+
def test_notification_as_announcement
|
529
|
+
#normally Rails would do this for us
|
530
|
+
silence_warnings do
|
531
|
+
if ActionController::Base.respond_to?(:append_view_path)
|
532
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
533
|
+
end
|
534
|
+
notification=TestPublisher.create_render_notification(12451752,nil)
|
535
|
+
assert_equal "true",notification.fbml
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|