facebooker 1.0.44 → 1.0.48

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,11 +3,13 @@ module Facebooker
3
3
  module Helpers
4
4
  module FbConnect
5
5
 
6
- def fb_connect_javascript_tag
6
+ def fb_connect_javascript_tag(options = {})
7
+ lang = "/#{options[:lang]}" if options[:lang]
8
+ # dont use the javascript_include_tag helper since it adds a .js at the end
7
9
  if request.ssl?
8
- javascript_include_tag "https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
10
+ "<script src=\"https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php#{lang}\" type=\"text/javascript\"></script>"
9
11
  else
10
- javascript_include_tag "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
12
+ "<script src=\"http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php#{lang}\" type=\"text/javascript\"></script>"
11
13
  end
12
14
  end
13
15
 
@@ -101,10 +101,14 @@ module Facebooker
101
101
  @controller = PublisherController.new(self)
102
102
  end
103
103
 
104
- def default_url_options
104
+ def self.default_url_options
105
105
  {:host => Facebooker.canvas_server_base + Facebooker.facebook_path_prefix}
106
106
  end
107
107
 
108
+ def default_url_options
109
+ self.class.default_url_options
110
+ end
111
+
108
112
  # use facebook options everywhere
109
113
  def request_comes_from_facebook?
110
114
  true
@@ -126,6 +130,13 @@ module Facebooker
126
130
  end
127
131
  end
128
132
 
133
+ def deactivate
134
+ Facebooker::Session.create.deactivate_template_bundle_by_id(self.bundle_id)
135
+ return true
136
+ rescue Facebooker::Session::TemplateBundleInvalid => e
137
+ return false
138
+ end
139
+
129
140
 
130
141
 
131
142
  class << self
@@ -134,6 +145,7 @@ module Facebooker
134
145
  publisher = setup_publisher(klass,method)
135
146
  template_id = Facebooker::Session.create.register_template_bundle(publisher.one_line_story_templates,publisher.short_story_templates,publisher.full_story_template,publisher.action_links)
136
147
  template = find_or_initialize_by_template_name(template_name(klass,method))
148
+ template.deactivate if template.bundle_id # deactivate old templates to avoid exceeding templates/app limit
137
149
  template.bundle_id = template_id
138
150
  template.content_hash = hashed_content(klass,method) if template.respond_to?(:content_hash)
139
151
  template.save!
@@ -162,12 +174,8 @@ module Facebooker
162
174
 
163
175
  def find_in_db(klass,method)
164
176
  template = find_by_template_name(template_name(klass,method))
165
- if template and template.template_changed?(hashed_content(klass,method))
166
- template.destroy
167
- template = nil
168
- end
169
177
 
170
- if template.nil?
178
+ if template.nil? || template.template_changed?(hashed_content(klass, method))
171
179
  template = register(klass,method)
172
180
  end
173
181
  template
@@ -189,7 +197,7 @@ module Facebooker
189
197
  end
190
198
 
191
199
  def template_name(klass,method)
192
- "#{klass.name}::#{method}"
200
+ "#{Facebooker.api_key}: #{klass.name}::#{method}"
193
201
  end
194
202
  end
195
203
  end
@@ -462,6 +470,13 @@ module Facebooker
462
470
  ActionController::Routing::Routes.named_routes.install(self.master_helper_module)
463
471
  include self.master_helper_module
464
472
  class <<self
473
+
474
+ def register_all_templates_on_all_applications
475
+ Facebooker.with_all_applications do
476
+ puts "Registering templates for #{Facebooker.api_key}"
477
+ register_all_templates
478
+ end
479
+ end
465
480
 
466
481
  def register_all_templates
467
482
  all_templates = instance_methods.grep(/_template$/) - %w(short_story_template full_story_template one_line_story_template)
@@ -472,6 +487,15 @@ module Facebooker
472
487
  end
473
488
  end
474
489
 
490
+ def unregister_inactive_templates
491
+ session = Facebooker::Session.create
492
+ active_template_ids = FacebookTemplate.all.map(&:bundle_id)
493
+ all_template_ids = session.active_template_bundles.map {|t| t["template_bundle_id"]}
494
+ (all_template_ids - active_template_ids).each do |template_bundle_id|
495
+ session.deactivate_template_bundle_by_id(template_bundle_id)
496
+ end
497
+ end
498
+
475
499
  def method_missing(name,*args)
476
500
  should_send = false
477
501
  method = ''
@@ -6,6 +6,7 @@ class Facebooker::Service::BaseService
6
6
  def post_params(params)
7
7
  post_params = {}
8
8
  params.each do |k,v|
9
+ k = k.to_s unless k.is_a?(String)
9
10
  if Array === v || Hash === v
10
11
  post_params[k] = Facebooker.json_encode(v)
11
12
  else
@@ -15,4 +16,4 @@ class Facebooker::Service::BaseService
15
16
  post_params
16
17
  end
17
18
 
18
- end
19
+ end
@@ -2,11 +2,12 @@ require 'curb'
2
2
  Facebooker.use_curl = true
3
3
  class Facebooker::Service::CurlService < Facebooker::Service::BaseService
4
4
  def post_form(url,params,multipart=false)
5
- response = Curl::Easy.http_post(url.to_s, *to_curb_params(params)) do |c|
5
+ curl = Curl::Easy.new(url.to_s) do |c|
6
6
  c.multipart_form_post = multipart
7
7
  c.timeout = Facebooker.timeout
8
8
  end
9
- response.body_str
9
+ curl.http_post(*to_curb_params(params))
10
+ curl.body_str
10
11
  end
11
12
 
12
13
  def post_multipart_form(url,params)
@@ -100,11 +100,11 @@ module Facebooker
100
100
 
101
101
  def login_url(options={})
102
102
  options = default_login_url_options.merge(options)
103
- "#{Facebooker.login_url_base(@api_key)}#{login_url_optional_parameters(options)}"
103
+ "#{Facebooker.login_url_base}#{login_url_optional_parameters(options)}"
104
104
  end
105
105
 
106
106
  def install_url(options={})
107
- "#{Facebooker.install_url_base(@api_key)}#{install_url_optional_parameters(options)}"
107
+ "#{Facebooker.install_url_base}#{install_url_optional_parameters(options)}"
108
108
  end
109
109
 
110
110
  # The url to get user to approve extended permissions
@@ -122,7 +122,9 @@ module Facebooker
122
122
  # * sms
123
123
  def permission_url(permission,options={})
124
124
  options = default_login_url_options.merge(options)
125
- "http://#{Facebooker.www_server_base_url}/authorize.php?api_key=#{@api_key}&v=1.0&ext_perm=#{permission}#{install_url_optional_parameters(options)}"
125
+ options = add_next_parameters(options)
126
+ options << "&ext_perm=#{permission}"
127
+ "#{Facebooker.permission_url_base}#{options.join}"
126
128
  end
127
129
 
128
130
  def install_url_optional_parameters(options)
@@ -145,6 +147,8 @@ module Facebooker
145
147
  optional_parameters << "&skipcookie=true" if options[:skip_cookie]
146
148
  optional_parameters << "&hide_checkbox=true" if options[:hide_checkbox]
147
149
  optional_parameters << "&canvas=true" if options[:canvas]
150
+ optional_parameters << "&fbconnect=true" if options[:fbconnect]
151
+ optional_parameters << "&req_perms=#{options[:req_perms]}" if options[:req_perms]
148
152
  optional_parameters.join
149
153
  end
150
154
 
@@ -269,6 +273,23 @@ module Facebooker
269
273
  end
270
274
  end
271
275
 
276
+ # Creates an event with the event_info hash and an optional Net::HTTP::MultipartPostFile for the event picture
277
+ # Returns the eid of the newly created event
278
+ # http://wiki.developers.facebook.com/index.php/Events.create
279
+ def create_event(event_info, multipart_post_file = nil)
280
+ post_file('facebook.events.create', :event_info => event_info.to_json, nil => multipart_post_file)
281
+ end
282
+
283
+ # Cancel an event
284
+ # http://wiki.developers.facebook.com/index.php/Events.cancel
285
+ # E.g:
286
+ # @session.cancel_event('100321123', :cancel_message => "It's raining...")
287
+ # # => Returns true if all went well
288
+ def cancel_event(eid, options = {})
289
+ result = post('facebook.events.cancel', options.merge(:eid => eid))
290
+ result == '1' ? true : false
291
+ end
292
+
272
293
  def event_members(eid)
273
294
  @members ||= post('facebook.events.getMembers', :eid => eid) do |response|
274
295
  response.map do |attendee_hash|
@@ -347,7 +368,9 @@ module Facebooker
347
368
  if [subj_id, pids, aid].all? {|arg| arg.nil?}
348
369
  raise ArgumentError, "Can't get a photo without a picture, album or subject ID"
349
370
  end
350
- @photos = post('facebook.photos.get', :subj_id => subj_id, :pids => pids, :aid => aid ) do |response|
371
+ # We have to normalize params orherwise FB complain about signature
372
+ params = {:pids => pids, :subj_id => subj_id, :aid => aid}.delete_if { |k,v| v.nil? }
373
+ @photos = post('facebook.photos.get', params ) do |response|
351
374
  response.map do |hash|
352
375
  Photo.from_hash(hash)
353
376
  end
@@ -414,6 +437,18 @@ module Facebooker
414
437
  post("facebook.feed.registerTemplateBundle", parameters, false)
415
438
  end
416
439
 
440
+ ##
441
+ # Deactivate a template bundle with Facebook.
442
+ # Returns true if a bundle with the specified id is active and owned by this app.
443
+ # Useful to avoid exceeding the 100 templates/app limit.
444
+ def deactivate_template_bundle_by_id(template_bundle_id)
445
+ post("facebook.feed.deactivateTemplateBundleByID", {:template_bundle_id => template_bundle_id.to_s}, false)
446
+ end
447
+
448
+ def active_template_bundles
449
+ post("facebook.feed.getRegisteredTemplateBundles",{},false)
450
+ end
451
+
417
452
  ##
418
453
  # publish a previously rendered template bundle
419
454
  # see http://wiki.developers.facebook.com/index.php/Feed.publishUserAction
@@ -2,7 +2,7 @@ module Facebooker #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- TINY = 44
5
+ TINY = 48
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -171,4 +171,21 @@ class Facebooker::AdaptersTest < Test::Unit::TestCase
171
171
  assert_equal 'my secret key', @secret_in_outer_block
172
172
  end
173
173
 
174
+ def test_adapter_loaded_when_config_applied
175
+ flexmock( Facebooker ).
176
+ should_receive( :fetch_config_for ).
177
+ and_return(
178
+ { 'api_key' => 'a_key',
179
+ 'canvas_page_name' => 'default_name' },
180
+ { 'api_key' => 'another_key',
181
+ 'canvas_page_name' => 'alternative_name' }
182
+ )
183
+ Facebooker.with_application('a_key') do
184
+ assert_equal 'default_name', Facebooker.current_adapter.facebooker_config['canvas_page_name']
185
+ Facebooker.with_application('another_key') do
186
+ assert_equal 'alternative_name', Facebooker.current_adapter.facebooker_config['canvas_page_name']
187
+ end
188
+ end
189
+ end
190
+
174
191
  end
@@ -137,7 +137,7 @@ class Facebooker::UserTest < Test::Unit::TestCase
137
137
  end
138
138
  def test_publish_to_converts_attachment_to_json
139
139
  @user = Facebooker::User.new(548871286, @session)
140
- @user.session.expects(:post).with("facebook.stream.publish",has_entry(:attachment=>instance_of(String)))
140
+ @user.session.expects(:post).with("facebook.stream.publish",has_entry(:attachment=>instance_of(String)),false)
141
141
  @user.publish_to(@other_user, :message => 'i love you man',:attachment=>{:a=>"b"})
142
142
  end
143
143
 
@@ -254,6 +254,12 @@ class Facebooker::UserTest < Test::Unit::TestCase
254
254
  assert_equal "http://www.facebook.com/profile.php?id=8055", @user.profile_url
255
255
  end
256
256
 
257
+ def test_can_rsvp_to_event
258
+ expect_http_posts_with_responses(example_events_rsvp_xml)
259
+ result = @user.rsvp_event(1000, 'attending')
260
+ assert result
261
+ end
262
+
257
263
  private
258
264
  def example_profile_photos_get_xml
259
265
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
@@ -11,7 +11,7 @@ class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
11
11
  def test_one_or_true_on_string_1
12
12
  assert @rewriter.one_or_true( "1" )
13
13
  end
14
-
14
+
15
15
  def test_one_or_true_on_string_0
16
16
  assert !@rewriter.one_or_true( "0" )
17
17
  end
@@ -23,7 +23,7 @@ class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
23
23
  def test_one_or_true_on_float_1
24
24
  assert @rewriter.one_or_true( 1.0 )
25
25
  end
26
-
26
+
27
27
  def test_one_or_true_on_true
28
28
  assert @rewriter.one_or_true( true )
29
29
  end
@@ -36,4 +36,41 @@ class Facebooker::Rails::FacebookUrlRewritingTest < Test::Unit::TestCase
36
36
  assert !@rewriter.one_or_true( nil )
37
37
  end
38
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
+
39
76
  end
@@ -1,10 +1,13 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../rails_test_helper')
2
2
  require File.expand_path(File.dirname(__FILE__) + '/../../../lib/facebooker/rails/integration_session')
3
+
3
4
  class Facebooker::Rails::IntegrationSessionTest < Test::Unit::TestCase
5
+
4
6
  def test_include_api_key_in_default_request_params
5
7
  ENV['FACEBOOK_API_KEY'] = 'a key'
6
8
  integration_session = Facebooker::Rails::IntegrationSession.new
7
9
  integration_session.reset!
8
10
  assert_equal 'a key', integration_session.default_request_params[ :fb_sig_api_key ]
9
11
  end
12
+
10
13
  end
@@ -141,10 +141,10 @@ end
141
141
 
142
142
  class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
143
143
  FacebookTemplate = Facebooker::Rails::Publisher::FacebookTemplate
144
- include Facebooker::Rails::TestHelpers
145
144
 
146
145
  def setup
147
146
  super
147
+ ENV['FACEBOOK_API_KEY'] = '1234567'
148
148
  @template = mock("facebook template")
149
149
  FacebookTemplate.stubs(:register).returns(@template)
150
150
  FacebookTemplate.clear_cache!
@@ -167,13 +167,13 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
167
167
  end
168
168
 
169
169
  def test_find_in_db_should_run_find
170
- FacebookTemplate.expects(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
170
+ FacebookTemplate.expects(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
171
171
  @template.stubs(:template_changed?).returns(false)
172
172
  assert_equal FacebookTemplate.find_in_db(TestPublisher,"simple_user_action"), @template
173
173
  end
174
174
 
175
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)
176
+ FacebookTemplate.expects(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(nil)
177
177
  FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
178
178
  FacebookTemplate.find_cached(TestPublisher,"simple_user_action")
179
179
 
@@ -186,22 +186,15 @@ class Facebooker::Rails::Publisher::FacebookTemplateTest < Test::Unit::TestCase
186
186
  FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
187
187
  end
188
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
189
  def test_find_in_db_should_re_register_if_changed
198
- FacebookTemplate.stubs(:find_by_template_name).with("TestPublisher::simple_user_action").returns(@template)
190
+ FacebookTemplate.stubs(:find_by_template_name).with("1234567: TestPublisher::simple_user_action").returns(@template)
199
191
  FacebookTemplate.stubs(:hashed_content).returns("MY CONTENT")
200
192
  @template.stubs(:template_changed?).returns(true)
201
193
  @template.stubs(:destroy)
202
194
  FacebookTemplate.expects(:register).with(TestPublisher,"simple_user_action").returns(@template)
203
195
  FacebookTemplate.find_in_db(TestPublisher,"simple_user_action")
204
196
  end
197
+
205
198
  end
206
199
 
207
200
  class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
@@ -331,6 +324,20 @@ class Facebooker::Rails::Publisher::PublisherTest < Test::Unit::TestCase
331
324
  Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
332
325
  TestPublisher.register_user_action
333
326
  end
327
+
328
+ def test_register_should_deactivate_template_bundle_if_exists
329
+ @template = mock
330
+ @template.stubs(:bundle_id).returns(999)
331
+ @template.stubs(:bundle_id=)
332
+ @template.stubs(:save!)
333
+ @session = mock
334
+ @session.stubs(:register_template_bundle).returns(1000)
335
+ Facebooker::Session.stubs(:create).returns(@session)
336
+ Facebooker::Rails::Publisher::FacebookTemplate.stubs(:find_or_initialize_by_template_name).returns(@template)
337
+ @template.expects(:deactivate)
338
+ FacebookTemplate.register(TestPublisher, "simple_user_action")
339
+ end
340
+
334
341
  def test_register_user_action_with_action_links
335
342
  ActionController::Base.append_view_path("./test/../../app/views")
336
343
  Facebooker::Rails::Publisher::FacebookTemplate.expects(:register)
@@ -125,10 +125,6 @@ class PlainOldRailsController < ActionController::Base
125
125
  end
126
126
  end
127
127
 
128
- class Test::Unit::TestCase
129
- include Facebooker::Rails::TestHelpers
130
- end
131
-
132
128
 
133
129
  # you can't use asset_recognize, because it can't pass parameters in to the requests
134
130
  class UrlRecognitionTests < Test::Unit::TestCase
@@ -160,9 +156,10 @@ class RailsIntegrationTestForFBConnect < Test::Unit::TestCase
160
156
  include FBConnectTestHelpers
161
157
 
162
158
  def setup
163
- ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
164
- ENV['FACEBOOK_API_KEY'] = '1234567'
165
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
159
+ Facebooker.apply_configuration({
160
+ 'api_key' => '1234567',
161
+ 'canvas_page_name' => 'facebook_app_name',
162
+ 'secret_key' => '7654321' })
166
163
  @controller = FBConnectController.new
167
164
  @request = ActionController::TestRequest.new
168
165
  @response = ActionController::TestResponse.new
@@ -181,9 +178,10 @@ end
181
178
 
182
179
  class RailsIntegrationTestForNonFacebookControllers < Test::Unit::TestCase
183
180
  def setup
184
- ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
185
- ENV['FACEBOOK_API_KEY'] = '1234567'
186
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
181
+ Facebooker.apply_configuration({
182
+ 'api_key' => '1234567',
183
+ 'canvas_page_name' => 'facebook_app_name',
184
+ 'secret_key' => '7654321' })
187
185
  @controller = PlainOldRailsController.new
188
186
  @request = ActionController::TestRequest.new
189
187
  @response = ActionController::TestResponse.new
@@ -216,8 +214,9 @@ end
216
214
 
217
215
  class RailsIntegrationTestForExtendedPermissions < Test::Unit::TestCase
218
216
  def setup
219
- ENV['FACEBOOK_API_KEY'] = '1234567'
220
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
217
+ Facebooker.apply_configuration({
218
+ 'api_key' => '1234567',
219
+ 'secret_key' => '7654321' })
221
220
  @controller = ControllerWhichRequiresExtendedPermissions.new
222
221
  @request = ActionController::TestRequest.new
223
222
  @response = ActionController::TestResponse.new
@@ -255,8 +254,9 @@ end
255
254
 
256
255
  class RailsIntegrationTestForApplicationInstallation < Test::Unit::TestCase
257
256
  def setup
258
- ENV['FACEBOOK_API_KEY'] = '1234567'
259
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
257
+ Facebooker.apply_configuration({
258
+ 'api_key' => '1234567',
259
+ 'secret_key' => '7654321' })
260
260
  @controller = ControllerWhichRequiresApplicationInstallation.new
261
261
  @request = ActionController::TestRequest.new
262
262
  @response = ActionController::TestResponse.new
@@ -285,10 +285,12 @@ end
285
285
  class RailsIntegrationTest < Test::Unit::TestCase
286
286
  include FBConnectTestHelpers
287
287
  def setup
288
- ENV['FACEBOOK_CANVAS_PATH'] ='root'
289
- ENV['FACEBOOK_API_KEY'] = '1234567'
290
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
291
- ActionController::Base.asset_host="http://root.example.com"
288
+ Facebooker.apply_configuration({
289
+ 'api_key' => '1234567',
290
+ 'canvas_page_name' => 'root',
291
+ 'secret_key' => '7654321',
292
+ 'set_asset_host_to_callback_url' => true,
293
+ 'callback_url' => "http://root.example.com" })
292
294
  @controller = ControllerWhichRequiresFacebookAuthentication.new
293
295
  @request = ActionController::TestRequest.new
294
296
  @response = ActionController::TestResponse.new
@@ -296,10 +298,10 @@ class RailsIntegrationTest < Test::Unit::TestCase
296
298
 
297
299
  end
298
300
 
299
- def test_named_route_includes_new_canvas_path_when_in_new_canvas
300
- get :named_route_test, facebook_params("fb_sig_in_new_facebook"=>"1")
301
- assert_equal "http://apps.facebook.com/root/comments",@response.body
302
- end
301
+ def test_named_route_includes_new_canvas_path_when_in_new_canvas
302
+ get :named_route_test, facebook_params("fb_sig_in_new_facebook"=>"1")
303
+ assert_equal "http://apps.facebook.com/root/comments",@response.body
304
+ end
303
305
 
304
306
  def test_if_controller_requires_facebook_authentication_unauthenticated_requests_will_redirect
305
307
  get :index
@@ -326,6 +328,16 @@ class RailsIntegrationTest < Test::Unit::TestCase
326
328
  get :index, facebook_params('fb_sig_added' => "1")
327
329
  assert_equal(true, @controller.facebook_params['added'])
328
330
  end
331
+
332
+ def test_facebook_params_convert_added_to_boolean_false_when_already_false
333
+ get :index, facebook_params('fb_sig_added' => false)
334
+ assert_equal(false, @controller.facebook_params['added'])
335
+ end
336
+
337
+ def test_facebook_params_convert_added_to_boolean_true_when_already_true
338
+ get :index, facebook_params('fb_sig_added' => true)
339
+ assert_equal(true, @controller.facebook_params['added'])
340
+ end
329
341
 
330
342
  def test_facebook_params_convert_expirey_into_nil
331
343
  get :index, facebook_params(:fb_sig_expires => '0')
@@ -423,7 +435,7 @@ class RailsIntegrationTest < Test::Unit::TestCase
423
435
  setup_fb_connect_cookies
424
436
  get :index
425
437
  assert_equal(77777, @controller.facebook_session.user.id)
426
- end
438
+ end
427
439
 
428
440
  def test_session_does_NOT_secure_with_expired_cookies
429
441
  setup_fb_connect_cookies(expired_cookie_hash_for_auth)
@@ -532,14 +544,32 @@ end
532
544
 
533
545
  class RailsSignatureTest < Test::Unit::TestCase
534
546
  def setup
535
- ENV['FACEBOOKER_RELATIVE_URL_ROOT'] ='root'
536
- ENV['FACEBOOK_API_KEY'] = '1234567'
537
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
547
+ Facebooker.apply_configuration({
548
+ 'api_key' => '1234567',
549
+ 'canvas_page_name' => 'root',
550
+ 'secret_key' => '7654321' })
538
551
  @controller = ControllerWhichRequiresFacebookAuthentication.new
539
552
  @request = ActionController::TestRequest.new
540
553
  @response = ActionController::TestResponse.new
541
554
 
542
555
  end
556
+
557
+ if Rails.version < '2.3'
558
+
559
+ def test_should_raise_on_bad_sig
560
+ begin
561
+ get :fb_params_test, facebook_params.merge('fb_sig' => 'incorrect')
562
+ fail "No IncorrectSignature raised"
563
+ rescue Facebooker::Session::IncorrectSignature=>e
564
+ end
565
+ end
566
+
567
+ def test_valid_signature
568
+ @controller.expects(:earliest_valid_session).returns(Time.at(1186588275.5988)-1)
569
+ get :fb_params_test, facebook_params
570
+ end
571
+
572
+ end
543
573
 
544
574
  def test_should_raise_too_old_for_replayed_session
545
575
  begin
@@ -549,20 +579,6 @@ class RailsSignatureTest < Test::Unit::TestCase
549
579
  end
550
580
  end
551
581
 
552
- def test_should_raise_on_bad_sig
553
- begin
554
- get :fb_params_test, facebook_params.merge('fb_sig' => 'incorrect')
555
- fail "No IncorrectSignature raised"
556
- rescue Facebooker::Session::IncorrectSignature=>e
557
- end
558
- end
559
-
560
- def test_valid_signature
561
- @controller.expects(:earliest_valid_session).returns(Time.at(1186588275.5988)-1)
562
- get :fb_params_test, facebook_params
563
-
564
- end
565
-
566
582
  end
567
583
  class RailsHelperTest < Test::Unit::TestCase
568
584
  class HelperClass
@@ -597,10 +613,10 @@ class RailsHelperTest < Test::Unit::TestCase
597
613
  attr_accessor :_erbout
598
614
 
599
615
  def setup
600
- ENV['FACEBOOK_CANVAS_PATH'] ='facebook'
601
- ENV['FACEBOOK_API_KEY'] = '1234567'
602
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
603
-
616
+ Facebooker.apply_configuration({
617
+ 'api_key' => '1234567',
618
+ 'canvas_page_name' => 'facebook',
619
+ 'secret_key' => '7654321' })
604
620
  @_erbout = ""
605
621
  @h = HelperClass.new
606
622
  #use an asset path where the canvas path equals the hostname to make sure we handle that case right
@@ -692,7 +708,15 @@ class RailsHelperTest < Test::Unit::TestCase
692
708
  assert_equal "<fb:add-section-button section=\"info\" />",@h.fb_add_info_section
693
709
  end
694
710
 
695
- def test_fb_name_with_invalid_key_sizee
711
+ def test_fb_application_name
712
+ assert_equal "<fb:application-name />", @h.fb_application_name
713
+ end
714
+
715
+ def test_fb_application_name_with_linked_false
716
+ assert_equal '<fb:application-name linked="false" />', @h.fb_application_name( :linked => false )
717
+ end
718
+
719
+ def test_fb_name_with_invalid_key_size
696
720
  assert_raises(ArgumentError) {@h.fb_name(1234, :sizee => false)}
697
721
  end
698
722
 
@@ -1057,13 +1081,17 @@ class RailsHelperTest < Test::Unit::TestCase
1057
1081
  def test_fb_logout_link
1058
1082
  assert_equal @h.fb_logout_link("Logout","My URL"),"<a href=\"#\" onclick=\"FB.Connect.logoutAndRedirect(&quot;My URL&quot;);; return false;\">Logout</a>"
1059
1083
  end
1084
+
1060
1085
  def test_fb_user_action_with_literal_callback
1061
1086
  action = Facebooker::Rails::Publisher::UserAction.new
1062
- assert_equal @h.fb_user_action(action,"message","prompt","function() {alert('hi')}"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, function() {alert('hi')}, \"prompt\", {\"value\": \"message\"});"
1087
+ assert_equal "FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, function() {alert('hi')}, \"prompt\", #{{"value" => "message"}.to_json});",
1088
+ @h.fb_user_action(action,"message","prompt","function() {alert('hi')}")
1063
1089
  end
1090
+
1064
1091
  def test_fb_user_action_with_nil_callback
1065
1092
  action = Facebooker::Rails::Publisher::UserAction.new
1066
- assert_equal @h.fb_user_action(action,"message","prompt"),"FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", {\"value\": \"message\"});"
1093
+ assert_equal "FB.Connect.showFeedDialog(null, null, null, null, null, FB.RequireConnect.promptConnect, null, \"prompt\", #{{"value" => "message"}.to_json});",
1094
+ @h.fb_user_action(action,"message","prompt")
1067
1095
  end
1068
1096
 
1069
1097
 
@@ -1074,6 +1102,13 @@ class RailsHelperTest < Test::Unit::TestCase
1074
1102
  end
1075
1103
  end
1076
1104
 
1105
+ def test_fb_connect_javascript_tag_with_language_option
1106
+ silence_warnings do
1107
+ assert_equal "<script src=\"http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US\" type=\"text/javascript\"></script>",
1108
+ @h.fb_connect_javascript_tag(:lang => "en_US")
1109
+ end
1110
+ end
1111
+
1077
1112
  def test_fb_connect_javascript_tag_ssl
1078
1113
  @h.instance_eval do
1079
1114
  def request
@@ -1089,6 +1124,21 @@ class RailsHelperTest < Test::Unit::TestCase
1089
1124
  end
1090
1125
  end
1091
1126
 
1127
+ def test_fb_connect_javascript_tag_ssl_with_language_option
1128
+ @h.instance_eval do
1129
+ def request
1130
+ ssl_request = ActionController::TestRequest.new
1131
+ ssl_request.stubs(:ssl?).returns(true)
1132
+ ssl_request
1133
+ end
1134
+ end
1135
+
1136
+ silence_warnings do
1137
+ assert_equal "<script src=\"https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US\" type=\"text/javascript\"></script>",
1138
+ @h.fb_connect_javascript_tag(:lang => "en_US")
1139
+ end
1140
+ end
1141
+
1092
1142
  def test_fb_container
1093
1143
  @h.expects(:capture).returns("Inner Stuff")
1094
1144
  @h.fb_container(:condition=>"somejs") do
@@ -1411,9 +1461,10 @@ class RailsRequestFormatTest < Test::Unit::TestCase
1411
1461
  end
1412
1462
 
1413
1463
  def setup
1414
- ENV['FACEBOOK_CANVAS_PATH'] ='facebook_app_name'
1415
- ENV['FACEBOOK_API_KEY'] = '1234567'
1416
- ENV['FACEBOOK_SECRET_KEY'] = '7654321'
1464
+ Facebooker.apply_configuration({
1465
+ 'api_key' => '1234567',
1466
+ 'canvas_page_name' => 'facebook_app_name',
1467
+ 'secret_key' => '7654321' })
1417
1468
  @controller = FacebookController.new
1418
1469
  @request = ActionController::TestRequest.new
1419
1470
  @response = ActionController::TestResponse.new