facebooker-fbg 1.0.59a

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/.autotest +15 -0
  2. data/CHANGELOG.rdoc +24 -0
  3. data/COPYING.rdoc +19 -0
  4. data/Manifest.txt +149 -0
  5. data/README.rdoc +119 -0
  6. data/Rakefile +94 -0
  7. data/TODO.rdoc +4 -0
  8. data/examples/desktop_login.rb +14 -0
  9. data/facebooker.gemspec +42 -0
  10. data/generators/facebook/facebook_generator.rb +14 -0
  11. data/generators/facebook/templates/config/facebooker.yml +49 -0
  12. data/generators/facebook/templates/public/javascripts/facebooker.js +332 -0
  13. data/generators/facebook_controller/USAGE +33 -0
  14. data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
  15. data/generators/facebook_controller/templates/controller.rb +7 -0
  16. data/generators/facebook_controller/templates/functional_test.rb +11 -0
  17. data/generators/facebook_controller/templates/helper.rb +2 -0
  18. data/generators/facebook_controller/templates/view.fbml.erb +2 -0
  19. data/generators/facebook_controller/templates/view.html.erb +2 -0
  20. data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
  21. data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
  22. data/generators/facebook_publisher/templates/publisher.rb +3 -0
  23. data/generators/facebook_scaffold/USAGE +27 -0
  24. data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
  25. data/generators/facebook_scaffold/templates/controller.rb +93 -0
  26. data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
  27. data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
  28. data/generators/facebook_scaffold/templates/helper.rb +2 -0
  29. data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
  30. data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
  31. data/generators/facebook_scaffold/templates/style.css +74 -0
  32. data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
  33. data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
  34. data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
  35. data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
  36. data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
  37. data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
  38. data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
  39. data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
  40. data/generators/publisher/publisher_generator.rb +14 -0
  41. data/generators/xd_receiver/templates/xd_receiver.html +10 -0
  42. data/generators/xd_receiver/templates/xd_receiver_ssl.html +10 -0
  43. data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
  44. data/init.rb +26 -0
  45. data/install.rb +12 -0
  46. data/lib/facebooker.rb +254 -0
  47. data/lib/facebooker/adapters/adapter_base.rb +91 -0
  48. data/lib/facebooker/adapters/bebo_adapter.rb +77 -0
  49. data/lib/facebooker/adapters/facebook_adapter.rb +60 -0
  50. data/lib/facebooker/admin.rb +42 -0
  51. data/lib/facebooker/application.rb +13 -0
  52. data/lib/facebooker/attachment.rb +51 -0
  53. data/lib/facebooker/batch_request.rb +45 -0
  54. data/lib/facebooker/data.rb +57 -0
  55. data/lib/facebooker/feed.rb +78 -0
  56. data/lib/facebooker/logging.rb +44 -0
  57. data/lib/facebooker/mobile.rb +20 -0
  58. data/lib/facebooker/mock/service.rb +50 -0
  59. data/lib/facebooker/mock/session.rb +18 -0
  60. data/lib/facebooker/model.rb +139 -0
  61. data/lib/facebooker/models/affiliation.rb +10 -0
  62. data/lib/facebooker/models/album.rb +11 -0
  63. data/lib/facebooker/models/applicationproperties.rb +39 -0
  64. data/lib/facebooker/models/applicationrestrictions.rb +10 -0
  65. data/lib/facebooker/models/cookie.rb +10 -0
  66. data/lib/facebooker/models/education_info.rb +11 -0
  67. data/lib/facebooker/models/event.rb +28 -0
  68. data/lib/facebooker/models/family_relative_info.rb +7 -0
  69. data/lib/facebooker/models/friend_list.rb +16 -0
  70. data/lib/facebooker/models/group.rb +36 -0
  71. data/lib/facebooker/models/info_item.rb +10 -0
  72. data/lib/facebooker/models/info_section.rb +10 -0
  73. data/lib/facebooker/models/location.rb +8 -0
  74. data/lib/facebooker/models/notifications.rb +17 -0
  75. data/lib/facebooker/models/page.rb +44 -0
  76. data/lib/facebooker/models/photo.rb +19 -0
  77. data/lib/facebooker/models/tag.rb +12 -0
  78. data/lib/facebooker/models/user.rb +575 -0
  79. data/lib/facebooker/models/video.rb +9 -0
  80. data/lib/facebooker/models/work_info.rb +10 -0
  81. data/lib/facebooker/parser.rb +724 -0
  82. data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
  83. data/lib/facebooker/rails/controller.rb +372 -0
  84. data/lib/facebooker/rails/cucumber.rb +28 -0
  85. data/lib/facebooker/rails/cucumber/world.rb +40 -0
  86. data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
  87. data/lib/facebooker/rails/extensions/rack_setup.rb +14 -0
  88. data/lib/facebooker/rails/extensions/routing.rb +15 -0
  89. data/lib/facebooker/rails/facebook_form_builder.rb +141 -0
  90. data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
  91. data/lib/facebooker/rails/facebook_request_fix.rb +28 -0
  92. data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
  93. data/lib/facebooker/rails/facebook_session_handling.rb +68 -0
  94. data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
  95. data/lib/facebooker/rails/facebook_url_rewriting.rb +60 -0
  96. data/lib/facebooker/rails/helpers.rb +829 -0
  97. data/lib/facebooker/rails/helpers/fb_connect.rb +144 -0
  98. data/lib/facebooker/rails/integration_session.rb +38 -0
  99. data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
  100. data/lib/facebooker/rails/publisher.rb +599 -0
  101. data/lib/facebooker/rails/routing.rb +49 -0
  102. data/lib/facebooker/rails/test_helpers.rb +68 -0
  103. data/lib/facebooker/rails/utilities.rb +22 -0
  104. data/lib/facebooker/server_cache.rb +24 -0
  105. data/lib/facebooker/service.rb +102 -0
  106. data/lib/facebooker/service/base_service.rb +19 -0
  107. data/lib/facebooker/service/curl_service.rb +44 -0
  108. data/lib/facebooker/service/net_http_service.rb +12 -0
  109. data/lib/facebooker/service/typhoeus_multi_service.rb +27 -0
  110. data/lib/facebooker/service/typhoeus_service.rb +17 -0
  111. data/lib/facebooker/session.rb +732 -0
  112. data/lib/facebooker/stream_post.rb +19 -0
  113. data/lib/facebooker/version.rb +9 -0
  114. data/lib/net/http_multipart_post.rb +123 -0
  115. data/lib/rack/facebook.rb +89 -0
  116. data/lib/rack/facebook_session.rb +21 -0
  117. data/lib/tasks/facebooker.rake +18 -0
  118. data/lib/tasks/facebooker.rb +2 -0
  119. data/lib/tasks/tunnel.rake +46 -0
  120. data/rails/init.rb +1 -0
  121. data/setup.rb +1585 -0
  122. data/templates/layout.erb +24 -0
  123. data/test/facebooker/adapters_test.rb +191 -0
  124. data/test/facebooker/admin_test.rb +102 -0
  125. data/test/facebooker/application_test.rb +41 -0
  126. data/test/facebooker/attachment_test.rb +72 -0
  127. data/test/facebooker/batch_request_test.rb +83 -0
  128. data/test/facebooker/data_test.rb +86 -0
  129. data/test/facebooker/logging_test.rb +43 -0
  130. data/test/facebooker/mobile_test.rb +45 -0
  131. data/test/facebooker/model_test.rb +133 -0
  132. data/test/facebooker/models/event_test.rb +15 -0
  133. data/test/facebooker/models/page_test.rb +51 -0
  134. data/test/facebooker/models/photo_test.rb +16 -0
  135. data/test/facebooker/models/user_test.rb +430 -0
  136. data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +25 -0
  137. data/test/facebooker/rails/facebook_url_rewriting_test.rb +76 -0
  138. data/test/facebooker/rails/integration_session_test.rb +13 -0
  139. data/test/facebooker/rails/publisher_test.rb +532 -0
  140. data/test/facebooker/rails_integration_test.rb +1524 -0
  141. data/test/facebooker/server_cache_test.rb +44 -0
  142. data/test/facebooker/service_test.rb +58 -0
  143. data/test/facebooker/session_test.rb +883 -0
  144. data/test/facebooker_test.rb +951 -0
  145. data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
  146. data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
  147. data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
  148. data/test/net/http_multipart_post_test.rb +52 -0
  149. data/test/rack/facebook_session_test.rb +34 -0
  150. data/test/rack/facebook_test.rb +73 -0
  151. data/test/rails_test_helper.rb +35 -0
  152. data/test/test_helper.rb +74 -0
  153. metadata +271 -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,532 @@
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_create_action
237
+ action=TestPublisher.create_action(@user)
238
+ assert_equal Facebooker::Feed::Action,action.class
239
+ assert_equal "Action Title",action.title
240
+ end
241
+
242
+ def test_deliver_action
243
+ @user.expects(:publish_action)
244
+ TestPublisher.deliver_action(@user)
245
+ end
246
+
247
+ def test_create_story
248
+ action=TestPublisher.create_story(@user)
249
+ assert_equal Facebooker::Feed::Story,action.class
250
+ assert_equal "Story Title",action.title
251
+ end
252
+
253
+ def test_deliver_story
254
+ @user.expects(:publish_story)
255
+ TestPublisher.deliver_story(@user)
256
+ end
257
+
258
+ def test_create_notification
259
+ notification=TestPublisher.create_notification(12451752,@user)
260
+ assert_equal Facebooker::Rails::Publisher::Notification,notification.class
261
+ assert_equal "Not",notification.fbml
262
+ end
263
+
264
+ def test_deliver_notification
265
+ @session.expects(:send_notification)
266
+ TestPublisher.deliver_notification("12451752",@user)
267
+ end
268
+
269
+ def test_create_email
270
+ email=TestPublisher.create_email("12451752",@user)
271
+ assert_equal Facebooker::Rails::Publisher::Email,email.class
272
+ assert_equal "Email",email.title
273
+ assert_equal "text",email.text
274
+ assert_equal "text",email.fbml
275
+ end
276
+
277
+ def test_deliver_email
278
+ @session.expects(:send_email)
279
+ TestPublisher.deliver_email("12451752",@user)
280
+ end
281
+
282
+ def test_create_templatized_action
283
+ ta=TestPublisher.create_templatized_action(@user)
284
+ assert_equal Facebooker::Feed::TemplatizedAction,ta.class
285
+ assert_equal "Templatized Action Title",ta.title_template
286
+
287
+ end
288
+
289
+
290
+
291
+ def test_deliver_templatized_action
292
+ @user.expects(:publish_action)
293
+ TestPublisher.deliver_templatized_action(@user)
294
+ end
295
+ def test_create_profile_update
296
+ p=TestPublisher.create_profile_update(@user,@user)
297
+ assert_equal Facebooker::Rails::Publisher::Profile,p.class
298
+ assert_equal "profile",p.profile
299
+ assert_equal "profile_action",p.profile_action
300
+ assert_equal "mobile_profile",p.mobile_profile
301
+ end
302
+ def test_create_profile_update_with_profile_main
303
+ p=TestPublisher.create_profile_update_with_profile_main(@user,@user)
304
+ assert_equal Facebooker::Rails::Publisher::Profile,p.class
305
+ assert_equal "profile",p.profile
306
+ assert_equal "profile_action",p.profile_action
307
+ assert_equal "mobile_profile",p.mobile_profile
308
+ assert_equal "profile_main",p.profile_main
309
+ end
310
+
311
+
312
+ def test_deliver_profile
313
+ Facebooker::User.stubs(:new).returns(@user)
314
+ @user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action',nil)
315
+ TestPublisher.deliver_profile_update(@user,@user)
316
+ end
317
+
318
+ def test_deliver_profile_with_main
319
+ Facebooker::User.stubs(:new).returns(@user)
320
+ @user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action','profile_main')
321
+ TestPublisher.deliver_profile_update_with_profile_main(@user,@user)
322
+ end
323
+
324
+
325
+ def test_create_ref_update
326
+ p=TestPublisher.create_ref_update(@user)
327
+ assert_equal Facebooker::Rails::Publisher::Ref,p.class
328
+ assert_equal "fbml",p.fbml
329
+ assert_equal "handle",p.handle
330
+ end
331
+
332
+ def test_deliver_ref_update
333
+ Facebooker::Session.stubs(:create).returns(@session)
334
+ @server_cache="server_cache"
335
+ @session.expects(:server_cache).returns(@server_cache)
336
+ @server_cache.expects(:set_ref_handle).with("handle","fbml")
337
+ TestPublisher.deliver_ref_update(@user)
338
+ end
339
+
340
+ def test_register_user_action
341
+ Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
342
+ TestPublisher.register_user_action
343
+ end
344
+
345
+ def test_register_should_deactivate_template_bundle_if_exists
346
+ @template = mock
347
+ @template.stubs(:bundle_id).returns(999)
348
+ @template.stubs(:bundle_id=)
349
+ @template.stubs(:save!)
350
+ @session = mock
351
+ @session.stubs(:register_template_bundle).returns(1000)
352
+ Facebooker::Session.stubs(:create).returns(@session)
353
+ Facebooker::Rails::Publisher::FacebookTemplate.stubs(:find_or_initialize_by_template_name).returns(@template)
354
+ @template.expects(:deactivate)
355
+ FacebookTemplate.register(TestPublisher, "simple_user_action")
356
+ end
357
+
358
+ def test_register_user_action_with_action_links
359
+ ActionController::Base.append_view_path("./test/../../app/views")
360
+ Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
361
+ TestPublisher.register_user_action_with_action_links
362
+ end
363
+
364
+ def test_create_user_action
365
+ @from_user = Facebooker::User.new
366
+ @session = Facebooker::Session.new("","")
367
+ @from_user.stubs(:session).returns(@session)
368
+ Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
369
+ with(TestPublisher,'user_action').
370
+ returns(20309041537)
371
+ ua = TestPublisher.create_user_action(@from_user)
372
+ assert_equal "user_action", ua.template_name
373
+ end
374
+ def test_create_user_action_with_template_id
375
+ @from_user = Facebooker::User.new
376
+ @session = Facebooker::Session.new("","")
377
+ @from_user.stubs(:session).returns(@session)
378
+ Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
379
+ with(TestPublisher,'user_action').never
380
+ ua = TestPublisher.create_user_action_with_template_id(@from_user)
381
+ assert_equal 4,ua.template_id
382
+ end
383
+
384
+ def test_publisher_user_action
385
+ @from_user = Facebooker::User.new
386
+ @session = Facebooker::Session.new("","")
387
+ @from_user.stubs(:session).returns(@session)
388
+ @session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil,nil)
389
+
390
+ Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
391
+ with(TestPublisher, 'user_action').
392
+ returns(20309041537)
393
+ # pseudo_template = Struct.new(:bundle_id, :content_hash).new(20309041537, '')
394
+ # pseudo_template.expects(:matches_content?).returns(true)
395
+ # Facebooker::Rails::Publisher::FacebookTemplate.expects(:for).returns(pseudo_template)
396
+ TestPublisher.deliver_user_action(@from_user)
397
+ end
398
+
399
+ def test_publish_user_action_with_story_size
400
+ @from_user = Facebooker::User.new
401
+ @session = Facebooker::Session.new("","")
402
+ @from_user.stubs(:session).returns(@session)
403
+ @session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil,2)
404
+
405
+ Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
406
+ with(TestPublisher, 'user_action_with_story_size').
407
+ returns(20309041537)
408
+ TestPublisher.deliver_user_action_with_story_size(@from_user)
409
+
410
+ end
411
+
412
+ def test_publishing_user_data_no_action_gives_nil_hash
413
+ @from_user = Facebooker::User.new
414
+ @session = Facebooker::Session.new("","")
415
+ @from_user.stubs(:session).returns(@session)
416
+ @session.expects(:publish_user_action).with(20309041537,{},nil,nil,nil)
417
+
418
+ Facebooker::Rails::Publisher::FacebookTemplate.stubs(:bundle_id_for_class_and_method).returns(20309041537)
419
+ TestPublisher.deliver_user_action_no_data(@from_user)
420
+ end
421
+ def test_no_sends_as_raises
422
+ assert_raises(Facebooker::Rails::Publisher::UnspecifiedBodyType) {
423
+ TestPublisher.deliver_no_send_as(@user)
424
+ }
425
+ end
426
+
427
+ def test_invalid_send_as_raises
428
+ assert_raises(Facebooker::Rails::Publisher::UnknownBodyType) {
429
+ TestPublisher.deliver_invalid_send_as(@user)
430
+ }
431
+ end
432
+
433
+ def test_publish_post_to_own_stream
434
+ @user = Facebooker::User.new
435
+ @user.expects(:publish_to).with(@user, has_entry(:attachment=>instance_of(Hash)))
436
+
437
+ TestPublisher.deliver_publish_post_to_own_stream(@user)
438
+ end
439
+
440
+ def test_publish_stream_sets_action_links
441
+ @user = Facebooker::User.new
442
+ stream_post = TestPublisher.create_publish_post_to_own_stream(@user)
443
+ assert_equal [{:text => "Action Link", :href => "http://www.example.com/action_link"}],stream_post.action_links
444
+ end
445
+
446
+ def test_publish_stream_sets_target
447
+ @user = Facebooker::User.new
448
+ stream_post = TestPublisher.create_publish_post_to_own_stream(@user)
449
+ assert_equal @user,stream_post.target
450
+
451
+ end
452
+
453
+ def test_publish_post_to_friends_stream
454
+ @from_user = Facebooker::User.new
455
+ @to_user = Facebooker::User.new
456
+ @from_user.expects(:publish_to).with(@to_user, has_entry(:action_links=>instance_of(Array)))
457
+
458
+ TestPublisher.deliver_publish_post_to_friends_stream(@from_user, @to_user)
459
+ end
460
+
461
+ def test_keeps_class_method_missing
462
+ assert_raises(NoMethodError) {
463
+ TestPublisher.fake
464
+ }
465
+ end
466
+ def test_keeps_instance_method_missing
467
+ assert_raises(NoMethodError) {
468
+ TestPublisher.new.fake
469
+ }
470
+ end
471
+
472
+ def test_image_urls
473
+ Facebooker.expects(:facebook_path_prefix).returns("/mike")
474
+ string_image = TestPublisher.new.image('image.png', 'raw_string')
475
+ assert_equal('/images/image.png',string_image.src)
476
+ assert_equal('raw_string',string_image.href)
477
+ route_image = TestPublisher.new.image('image.png', {:controller => :pokes, :action => :do, :id => 1})
478
+ assert_equal('http://apps.facebook.com/mike/pokes/do/1',route_image.href)
479
+ end
480
+
481
+ def test_image_holder_equality
482
+ assert_equal TestPublisher::ImageHolder.new('image.png', 'raw_string'), TestPublisher::ImageHolder.new('image.png', 'raw_string')
483
+ end
484
+
485
+ def test_image_to_json_puts_src_first
486
+ string_image = TestPublisher.new.image('image.png', 'raw_string')
487
+ assert_equal "{\"src\":\"/images/image.png\", \"href\":\"raw_string\"}",string_image.to_json
488
+ end
489
+ def test_action_link
490
+ assert_equal({:text=>"text", :href=>"href"}, TestPublisher.new.action_link("text","href"))
491
+ end
492
+
493
+ def test_default_url_options
494
+ Facebooker.expects(:facebook_path_prefix).returns("/mike")
495
+ assert_equal({:host=>"apps.facebook.com/mike"},TestPublisher.new.default_url_options)
496
+ end
497
+
498
+ def test_recipients
499
+ tp=TestPublisher.new
500
+ tp.recipients "a"
501
+ assert_equal("a",tp.recipients)
502
+ end
503
+
504
+ def test_symbol_helper
505
+ assert TestPublisher.new.symbol_helper_loaded
506
+ end
507
+ def test_module_helper
508
+ assert TestPublisher.new.module_helper_loaded
509
+ end
510
+
511
+ def test_with_render
512
+ #normally Rails would do this for us
513
+ silence_warnings do
514
+ if ActionController::Base.respond_to?(:append_view_path)
515
+ ActionController::Base.append_view_path("./test/../../app/views")
516
+ end
517
+ notification=TestPublisher.create_render_notification(12451752,@user)
518
+ assert_equal "true",notification.fbml
519
+ end
520
+ end
521
+
522
+ def test_notification_as_announcement
523
+ #normally Rails would do this for us
524
+ silence_warnings do
525
+ if ActionController::Base.respond_to?(:append_view_path)
526
+ ActionController::Base.append_view_path("./test/../../app/views")
527
+ end
528
+ notification=TestPublisher.create_render_notification(12451752,nil)
529
+ assert_equal "true",notification.fbml
530
+ end
531
+ end
532
+ end