taweili-facebooker 1.0.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.autotest +15 -0
- data/CHANGELOG.rdoc +24 -0
- data/COPYING.rdoc +19 -0
- data/Manifest.txt +133 -0
- data/README.rdoc +104 -0
- data/Rakefile +85 -0
- data/TODO.rdoc +4 -0
- data/examples/desktop_login.rb +14 -0
- data/facebooker.gemspec +38 -0
- data/generators/facebook/facebook_generator.rb +14 -0
- data/generators/facebook/templates/config/facebooker.yml +49 -0
- data/generators/facebook/templates/public/javascripts/facebooker.js +83 -0
- data/generators/facebook_controller/USAGE +33 -0
- data/generators/facebook_controller/facebook_controller_generator.rb +40 -0
- data/generators/facebook_controller/templates/controller.rb +7 -0
- data/generators/facebook_controller/templates/functional_test.rb +11 -0
- data/generators/facebook_controller/templates/helper.rb +2 -0
- data/generators/facebook_controller/templates/view.fbml.erb +2 -0
- data/generators/facebook_controller/templates/view.html.erb +2 -0
- data/generators/facebook_publisher/facebook_publisher_generator.rb +14 -0
- data/generators/facebook_publisher/templates/create_facebook_templates.rb +15 -0
- data/generators/facebook_publisher/templates/publisher.rb +3 -0
- data/generators/facebook_scaffold/USAGE +27 -0
- data/generators/facebook_scaffold/facebook_scaffold_generator.rb +118 -0
- data/generators/facebook_scaffold/templates/controller.rb +93 -0
- data/generators/facebook_scaffold/templates/facebook_style.css +2579 -0
- data/generators/facebook_scaffold/templates/functional_test.rb +89 -0
- data/generators/facebook_scaffold/templates/helper.rb +2 -0
- data/generators/facebook_scaffold/templates/layout.fbml.erb +6 -0
- data/generators/facebook_scaffold/templates/layout.html.erb +17 -0
- data/generators/facebook_scaffold/templates/style.css +74 -0
- data/generators/facebook_scaffold/templates/view_edit.fbml.erb +13 -0
- data/generators/facebook_scaffold/templates/view_edit.html.erb +18 -0
- data/generators/facebook_scaffold/templates/view_index.fbml.erb +24 -0
- data/generators/facebook_scaffold/templates/view_index.html.erb +24 -0
- data/generators/facebook_scaffold/templates/view_new.fbml.erb +12 -0
- data/generators/facebook_scaffold/templates/view_new.html.erb +17 -0
- data/generators/facebook_scaffold/templates/view_show.fbml.erb +10 -0
- data/generators/facebook_scaffold/templates/view_show.html.erb +10 -0
- data/generators/publisher/publisher_generator.rb +14 -0
- data/generators/xd_receiver/templates/xd_receiver.html +10 -0
- data/generators/xd_receiver/xd_receiver_generator.rb +10 -0
- data/init.rb +25 -0
- data/install.rb +12 -0
- data/lib/facebooker/adapters/adapter_base.rb +91 -0
- data/lib/facebooker/adapters/bebo_adapter.rb +77 -0
- data/lib/facebooker/adapters/facebook_adapter.rb +52 -0
- data/lib/facebooker/admin.rb +42 -0
- data/lib/facebooker/batch_request.rb +45 -0
- data/lib/facebooker/data.rb +57 -0
- data/lib/facebooker/feed.rb +78 -0
- data/lib/facebooker/logging.rb +44 -0
- data/lib/facebooker/mobile.rb +20 -0
- data/lib/facebooker/mock/service.rb +50 -0
- data/lib/facebooker/mock/session.rb +18 -0
- data/lib/facebooker/model.rb +139 -0
- data/lib/facebooker/models/affiliation.rb +10 -0
- data/lib/facebooker/models/album.rb +11 -0
- data/lib/facebooker/models/applicationproperties.rb +39 -0
- data/lib/facebooker/models/applicationrestrictions.rb +10 -0
- data/lib/facebooker/models/cookie.rb +10 -0
- data/lib/facebooker/models/education_info.rb +11 -0
- data/lib/facebooker/models/event.rb +28 -0
- data/lib/facebooker/models/friend_list.rb +16 -0
- data/lib/facebooker/models/group.rb +36 -0
- data/lib/facebooker/models/info_item.rb +10 -0
- data/lib/facebooker/models/info_section.rb +10 -0
- data/lib/facebooker/models/location.rb +8 -0
- data/lib/facebooker/models/notifications.rb +17 -0
- data/lib/facebooker/models/page.rb +28 -0
- data/lib/facebooker/models/photo.rb +19 -0
- data/lib/facebooker/models/tag.rb +12 -0
- data/lib/facebooker/models/user.rb +497 -0
- data/lib/facebooker/models/video.rb +9 -0
- data/lib/facebooker/models/work_info.rb +10 -0
- data/lib/facebooker/parser.rb +650 -0
- data/lib/facebooker/rails/backwards_compatible_param_checks.rb +31 -0
- data/lib/facebooker/rails/controller.rb +337 -0
- data/lib/facebooker/rails/cucumber/world.rb +46 -0
- data/lib/facebooker/rails/cucumber.rb +28 -0
- data/lib/facebooker/rails/extensions/action_controller.rb +48 -0
- data/lib/facebooker/rails/extensions/rack_setup.rb +6 -0
- data/lib/facebooker/rails/extensions/routing.rb +15 -0
- data/lib/facebooker/rails/facebook_form_builder.rb +112 -0
- data/lib/facebooker/rails/facebook_pretty_errors.rb +22 -0
- data/lib/facebooker/rails/facebook_request_fix.rb +30 -0
- data/lib/facebooker/rails/facebook_request_fix_2-3.rb +31 -0
- data/lib/facebooker/rails/facebook_session_handling.rb +68 -0
- data/lib/facebooker/rails/facebook_url_helper.rb +192 -0
- data/lib/facebooker/rails/facebook_url_rewriting.rb +60 -0
- data/lib/facebooker/rails/helpers/fb_connect.rb +118 -0
- data/lib/facebooker/rails/helpers.rb +780 -0
- data/lib/facebooker/rails/integration_session.rb +38 -0
- data/lib/facebooker/rails/profile_publisher_extensions.rb +42 -0
- data/lib/facebooker/rails/publisher.rb +554 -0
- data/lib/facebooker/rails/routing.rb +49 -0
- data/lib/facebooker/rails/test_helpers.rb +68 -0
- data/lib/facebooker/rails/utilities.rb +22 -0
- data/lib/facebooker/server_cache.rb +24 -0
- data/lib/facebooker/service.rb +102 -0
- data/lib/facebooker/session.rb +606 -0
- data/lib/facebooker/version.rb +9 -0
- data/lib/facebooker.rb +180 -0
- data/lib/net/http_multipart_post.rb +123 -0
- data/lib/rack/facebook.rb +77 -0
- data/lib/tasks/facebooker.rake +18 -0
- data/lib/tasks/tunnel.rake +46 -0
- data/rails/init.rb +1 -0
- data/setup.rb +1585 -0
- data/templates/layout.erb +24 -0
- data/test/facebooker/adapters_test.rb +96 -0
- data/test/facebooker/admin_test.rb +102 -0
- data/test/facebooker/batch_request_test.rb +83 -0
- data/test/facebooker/data_test.rb +86 -0
- data/test/facebooker/logging_test.rb +43 -0
- data/test/facebooker/mobile_test.rb +45 -0
- data/test/facebooker/model_test.rb +133 -0
- data/test/facebooker/models/event_test.rb +15 -0
- data/test/facebooker/models/photo_test.rb +16 -0
- data/test/facebooker/models/user_test.rb +343 -0
- data/test/facebooker/rails/facebook_request_fix_2-3_test.rb +24 -0
- data/test/facebooker/rails/facebook_url_rewriting_test.rb +39 -0
- data/test/facebooker/rails/publisher_test.rb +481 -0
- data/test/facebooker/rails_integration_test.rb +1398 -0
- data/test/facebooker/server_cache_test.rb +44 -0
- data/test/facebooker/session_test.rb +614 -0
- data/test/facebooker_test.rb +951 -0
- data/test/fixtures/multipart_post_body_with_only_parameters.txt +33 -0
- data/test/fixtures/multipart_post_body_with_single_file.txt +38 -0
- data/test/fixtures/multipart_post_body_with_single_file_that_has_nil_key.txt +38 -0
- data/test/net/http_multipart_post_test.rb +52 -0
- data/test/rack/facebook_test.rb +61 -0
- data/test/rails_test_helper.rb +27 -0
- data/test/test_helper.rb +74 -0
- metadata +232 -0
@@ -0,0 +1,481 @@
|
|
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
|
+
end
|
141
|
+
|
142
|
+
class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
|
143
|
+
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
144
|
+
include Facebooker::Rails::TestHelpers
|
145
|
+
|
146
|
+
def setup
|
147
|
+
super
|
148
|
+
@template = mock("facebook template")
|
149
|
+
FacebookTemplate.stubs(:register).returns(@template)
|
150
|
+
FacebookTemplate.clear_cache!
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_find_or_register_calls_find_cached
|
154
|
+
FacebookTemplate.expects(:find_cached).with(TestPublisher,"simple_user_action").returns(@template)
|
155
|
+
assert_equal FacebookTemplate.for_class_and_method(TestPublisher,"simple_user_action"),@template
|
156
|
+
end
|
157
|
+
|
158
|
+
def test_find_cached_should_use_cached_if_it_exists
|
159
|
+
FacebookTemplate.cache(TestPublisher,"simple_user_action",@template)
|
160
|
+
assert_equal FacebookTemplate.find_cached(TestPublisher,"simple_user_action"), @template
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_find_cached_should_call_find_in_db_if_not_in_cache
|
165
|
+
FacebookTemplate.expects(:find_in_db).with(TestPublisher,"simple_user_action").returns(@template)
|
166
|
+
assert_equal FacebookTemplate.find_cached(TestPublisher,"simple_user_action"), @template
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_find_in_db_should_run_find
|
170
|
+
FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
|
171
|
+
@template.stubs(:template_changed?).returns(false)
|
172
|
+
assert_equal FacebookTemplate.find_in_db(TestPublisher,"simple_user_action"), @template
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_find_in_db_should_register_if_not_found
|
176
|
+
FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(nil)
|
177
|
+
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
178
|
+
FacebookTemplate.find_cached(TestPublisher,"simple_user_action")
|
179
|
+
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_find_in_db_should_check_for_change_if_found
|
183
|
+
FacebookTemplate.stubs(:find_by_template_name).returns(@template)
|
184
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
185
|
+
@template.expects(:template_changed?).with("MY CONTENT").returns(false)
|
186
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_find_in_db_should_destroy_old_record_if_changed
|
190
|
+
FacebookTemplate.stubs(:find_by_template_name).returns(@template)
|
191
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
192
|
+
@template.stubs(:template_changed?).returns(true)
|
193
|
+
@template.expects(:destroy)
|
194
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_find_in_db_should_re_register_if_changed
|
198
|
+
FacebookTemplate.stubs(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
|
199
|
+
FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
|
200
|
+
@template.stubs(:template_changed?).returns(true)
|
201
|
+
@template.stubs(:destroy)
|
202
|
+
FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
|
203
|
+
FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
|
208
|
+
FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
|
209
|
+
|
210
|
+
def setup
|
211
|
+
super
|
212
|
+
|
213
|
+
ENV['FACEBOOK_API_KEY'] = '1234567'
|
214
|
+
ENV['FACEBOOK_SECRET_KEY'] = '7654321'
|
215
|
+
|
216
|
+
@user = Facebooker::User.new
|
217
|
+
@user.id=4
|
218
|
+
@session = "session"
|
219
|
+
@user.stubs(:session).returns(@session)
|
220
|
+
end
|
221
|
+
|
222
|
+
def teardown
|
223
|
+
super
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_create_action
|
227
|
+
action=TestPublisher.create_action(@user)
|
228
|
+
assert_equal Facebooker::Feed::Action,action.class
|
229
|
+
assert_equal "Action Title",action.title
|
230
|
+
end
|
231
|
+
|
232
|
+
def test_deliver_action
|
233
|
+
@user.expects(:publish_action)
|
234
|
+
TestPublisher.deliver_action(@user)
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_create_story
|
238
|
+
action=TestPublisher.create_story(@user)
|
239
|
+
assert_equal Facebooker::Feed::Story,action.class
|
240
|
+
assert_equal "Story Title",action.title
|
241
|
+
end
|
242
|
+
|
243
|
+
def test_deliver_story
|
244
|
+
@user.expects(:publish_story)
|
245
|
+
TestPublisher.deliver_story(@user)
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_create_notification
|
249
|
+
notification=TestPublisher.create_notification(12451752,@user)
|
250
|
+
assert_equal Facebooker::Rails::Publisher::Notification,notification.class
|
251
|
+
assert_equal "Not",notification.fbml
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_deliver_notification
|
255
|
+
@session.expects(:send_notification)
|
256
|
+
TestPublisher.deliver_notification("12451752",@user)
|
257
|
+
end
|
258
|
+
|
259
|
+
def test_create_email
|
260
|
+
email=TestPublisher.create_email("12451752",@user)
|
261
|
+
assert_equal Facebooker::Rails::Publisher::Email,email.class
|
262
|
+
assert_equal "Email",email.title
|
263
|
+
assert_equal "text",email.text
|
264
|
+
assert_equal "text",email.fbml
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_deliver_email
|
268
|
+
@session.expects(:send_email)
|
269
|
+
TestPublisher.deliver_email("12451752",@user)
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_create_templatized_action
|
273
|
+
ta=TestPublisher.create_templatized_action(@user)
|
274
|
+
assert_equal Facebooker::Feed::TemplatizedAction,ta.class
|
275
|
+
assert_equal "Templatized Action Title",ta.title_template
|
276
|
+
|
277
|
+
end
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
def test_deliver_templatized_action
|
282
|
+
@user.expects(:publish_action)
|
283
|
+
TestPublisher.deliver_templatized_action(@user)
|
284
|
+
end
|
285
|
+
def test_create_profile_update
|
286
|
+
p=TestPublisher.create_profile_update(@user,@user)
|
287
|
+
assert_equal Facebooker::Rails::Publisher::Profile,p.class
|
288
|
+
assert_equal "profile",p.profile
|
289
|
+
assert_equal "profile_action",p.profile_action
|
290
|
+
assert_equal "mobile_profile",p.mobile_profile
|
291
|
+
end
|
292
|
+
def test_create_profile_update_with_profile_main
|
293
|
+
p=TestPublisher.create_profile_update_with_profile_main(@user,@user)
|
294
|
+
assert_equal Facebooker::Rails::Publisher::Profile,p.class
|
295
|
+
assert_equal "profile",p.profile
|
296
|
+
assert_equal "profile_action",p.profile_action
|
297
|
+
assert_equal "mobile_profile",p.mobile_profile
|
298
|
+
assert_equal "profile_main",p.profile_main
|
299
|
+
end
|
300
|
+
|
301
|
+
|
302
|
+
def test_deliver_profile
|
303
|
+
Facebooker::User.stubs(:new).returns(@user)
|
304
|
+
@user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action',nil)
|
305
|
+
TestPublisher.deliver_profile_update(@user,@user)
|
306
|
+
end
|
307
|
+
|
308
|
+
def test_deliver_profile_with_main
|
309
|
+
Facebooker::User.stubs(:new).returns(@user)
|
310
|
+
@user.expects(:set_profile_fbml).with('profile', 'mobile_profile', 'profile_action','profile_main')
|
311
|
+
TestPublisher.deliver_profile_update_with_profile_main(@user,@user)
|
312
|
+
end
|
313
|
+
|
314
|
+
|
315
|
+
def test_create_ref_update
|
316
|
+
p=TestPublisher.create_ref_update(@user)
|
317
|
+
assert_equal Facebooker::Rails::Publisher::Ref,p.class
|
318
|
+
assert_equal "fbml",p.fbml
|
319
|
+
assert_equal "handle",p.handle
|
320
|
+
end
|
321
|
+
|
322
|
+
def test_deliver_ref_update
|
323
|
+
Facebooker::Session.stubs(:create).returns(@session)
|
324
|
+
@server_cache="server_cache"
|
325
|
+
@session.expects(:server_cache).returns(@server_cache)
|
326
|
+
@server_cache.expects(:set_ref_handle).with("handle","fbml")
|
327
|
+
TestPublisher.deliver_ref_update(@user)
|
328
|
+
end
|
329
|
+
|
330
|
+
def test_register_user_action
|
331
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
|
332
|
+
TestPublisher.register_user_action
|
333
|
+
end
|
334
|
+
def test_register_user_action_with_action_links
|
335
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
336
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
|
337
|
+
TestPublisher.register_user_action_with_action_links
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_create_user_action
|
341
|
+
@from_user = Facebooker::User.new
|
342
|
+
@session = Facebooker::Session.new("","")
|
343
|
+
@from_user.stubs(:session).returns(@session)
|
344
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
345
|
+
with(TestPublisher,'user_action').
|
346
|
+
returns(20309041537)
|
347
|
+
ua = TestPublisher.create_user_action(@from_user)
|
348
|
+
assert_equal "user_action", ua.template_name
|
349
|
+
end
|
350
|
+
def test_create_user_action_with_template_id
|
351
|
+
@from_user = Facebooker::User.new
|
352
|
+
@session = Facebooker::Session.new("","")
|
353
|
+
@from_user.stubs(:session).returns(@session)
|
354
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
355
|
+
with(TestPublisher,'user_action').never
|
356
|
+
ua = TestPublisher.create_user_action_with_template_id(@from_user)
|
357
|
+
assert_equal 4,ua.template_id
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_publisher_user_action
|
361
|
+
@from_user = Facebooker::User.new
|
362
|
+
@session = Facebooker::Session.new("","")
|
363
|
+
@from_user.stubs(:session).returns(@session)
|
364
|
+
@session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil,nil)
|
365
|
+
|
366
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
367
|
+
with(TestPublisher, 'user_action').
|
368
|
+
returns(20309041537)
|
369
|
+
# pseudo_template = Struct.new(:bundle_id, :content_hash).new(20309041537, '')
|
370
|
+
# pseudo_template.expects(:matches_content?).returns(true)
|
371
|
+
# Facebooker::Rails::Publisher::FacebookTemplate.expects(:for).returns(pseudo_template)
|
372
|
+
TestPublisher.deliver_user_action(@from_user)
|
373
|
+
end
|
374
|
+
|
375
|
+
def test_publish_user_action_with_story_size
|
376
|
+
@from_user = Facebooker::User.new
|
377
|
+
@session = Facebooker::Session.new("","")
|
378
|
+
@from_user.stubs(:session).returns(@session)
|
379
|
+
@session.expects(:publish_user_action).with(20309041537,{:friend=>"Mike"},nil,nil,2)
|
380
|
+
|
381
|
+
Facebooker::Rails::Publisher::FacebookTemplate.expects(:bundle_id_for_class_and_method).
|
382
|
+
with(TestPublisher, 'user_action_with_story_size').
|
383
|
+
returns(20309041537)
|
384
|
+
TestPublisher.deliver_user_action_with_story_size(@from_user)
|
385
|
+
|
386
|
+
end
|
387
|
+
|
388
|
+
def test_publishing_user_data_no_action_gives_nil_hash
|
389
|
+
@from_user = Facebooker::User.new
|
390
|
+
@session = Facebooker::Session.new("","")
|
391
|
+
@from_user.stubs(:session).returns(@session)
|
392
|
+
@session.expects(:publish_user_action).with(20309041537,{},nil,nil,nil)
|
393
|
+
|
394
|
+
Facebooker::Rails::Publisher::FacebookTemplate.stubs(:bundle_id_for_class_and_method).returns(20309041537)
|
395
|
+
TestPublisher.deliver_user_action_no_data(@from_user)
|
396
|
+
end
|
397
|
+
def test_no_sends_as_raises
|
398
|
+
assert_raises(Facebooker::Rails::Publisher::UnspecifiedBodyType) {
|
399
|
+
TestPublisher.deliver_no_send_as(@user)
|
400
|
+
}
|
401
|
+
end
|
402
|
+
|
403
|
+
def test_invalid_send_as_raises
|
404
|
+
assert_raises(Facebooker::Rails::Publisher::UnknownBodyType) {
|
405
|
+
TestPublisher.deliver_invalid_send_as(@user)
|
406
|
+
}
|
407
|
+
end
|
408
|
+
|
409
|
+
|
410
|
+
def test_keeps_class_method_missing
|
411
|
+
assert_raises(NoMethodError) {
|
412
|
+
TestPublisher.fake
|
413
|
+
}
|
414
|
+
end
|
415
|
+
def test_keeps_instance_method_missing
|
416
|
+
assert_raises(NoMethodError) {
|
417
|
+
TestPublisher.new.fake
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
421
|
+
def test_image_urls
|
422
|
+
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
423
|
+
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
424
|
+
assert_equal('/images/image.png',string_image.src)
|
425
|
+
assert_equal('raw_string',string_image.href)
|
426
|
+
route_image = TestPublisher.new.image('image.png', {:controller => :pokes, :action => :do, :id => 1})
|
427
|
+
assert_equal('http://apps.facebook.com/mike/pokes/do/1',route_image.href)
|
428
|
+
end
|
429
|
+
|
430
|
+
def test_image_holder_equality
|
431
|
+
assert_equal TestPublisher::ImageHolder.new('image.png', 'raw_string'), TestPublisher::ImageHolder.new('image.png', 'raw_string')
|
432
|
+
end
|
433
|
+
|
434
|
+
def test_image_to_json_puts_src_first
|
435
|
+
string_image = TestPublisher.new.image('image.png', 'raw_string')
|
436
|
+
assert_equal "{\"src\":\"/images/image.png\", \"href\":\"raw_string\"}",string_image.to_json
|
437
|
+
end
|
438
|
+
def test_action_link
|
439
|
+
assert_equal({:text=>"text", :href=>"href"}, TestPublisher.new.action_link("text","href"))
|
440
|
+
end
|
441
|
+
|
442
|
+
def test_default_url_options
|
443
|
+
Facebooker.expects(:facebook_path_prefix).returns("/mike")
|
444
|
+
assert_equal({:host=>"apps.facebook.com/mike"},TestPublisher.default_url_options)
|
445
|
+
end
|
446
|
+
|
447
|
+
def test_recipients
|
448
|
+
tp=TestPublisher.new
|
449
|
+
tp.recipients "a"
|
450
|
+
assert_equal("a",tp.recipients)
|
451
|
+
end
|
452
|
+
|
453
|
+
def test_symbol_helper
|
454
|
+
assert TestPublisher.new.symbol_helper_loaded
|
455
|
+
end
|
456
|
+
def test_module_helper
|
457
|
+
assert TestPublisher.new.module_helper_loaded
|
458
|
+
end
|
459
|
+
|
460
|
+
def test_with_render
|
461
|
+
#normally Rails would do this for us
|
462
|
+
silence_warnings do
|
463
|
+
if ActionController::Base.respond_to?(:append_view_path)
|
464
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
465
|
+
end
|
466
|
+
notification=TestPublisher.create_render_notification(12451752,@user)
|
467
|
+
assert_equal "true",notification.fbml
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
def test_notification_as_announcement
|
472
|
+
#normally Rails would do this for us
|
473
|
+
silence_warnings do
|
474
|
+
if ActionController::Base.respond_to?(:append_view_path)
|
475
|
+
ActionController::Base.append_view_path("./test/../../app/views")
|
476
|
+
end
|
477
|
+
notification=TestPublisher.create_render_notification(12451752,nil)
|
478
|
+
assert_equal "true",notification.fbml
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|