al-facebooker 1.0.9 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/TODO.txt CHANGED
@@ -1,10 +1,4 @@
1
- [ ] Refactor facebook form builder so erbout won't be deeply nested, causing erubis to break
2
- [ ] Support missing parameters on methods---most notably authentication-related parameters such as next and canvas
3
- [ ] Finish FQL Querying
4
- [ ] Refactor FQL Querying
5
- [ ] Transform incoming data into appropriate classes (Integers, Dates, etc.)
1
+ [ ] Document session handling. Come up with different cases and paths for the flow and create tests for each
2
+ [ ] Verify that sessions are used only where required. Raise exceptions on User methods that require a session when none is available
3
+ [ ] Refactor setup / Adapter loading code
6
4
 
7
- [x] Specify fields wanted when getting user info (defaults to all now) [shane]
8
- [x] Create facebooker.yml config file and merge with tunnel.yml [shane]
9
- [X] Remove facebook prefix from resource routes, making them worth with facebook and regular Rails controllers [mike]
10
- [X] Use fb_sig_request_method to make facebook routes more Rails-like [mike]
@@ -168,4 +168,4 @@ require 'facebooker/models/info_section'
168
168
  require 'facebooker/adapters/adapter_base'
169
169
  require 'facebooker/adapters/facebook_adapter'
170
170
  require 'facebooker/adapters/bebo_adapter'
171
- require 'facebooker/models/friend_list'
171
+ require 'facebooker/models/friend_list'
@@ -77,6 +77,18 @@ module Facebooker
77
77
  end)
78
78
  end
79
79
  end
80
+
81
+ def id_is(attribute)
82
+ class_eval <<-EOS
83
+ def #{attribute}=(value)
84
+ @#{attribute} = value.to_i
85
+ end
86
+
87
+ attr_reader #{attribute.inspect}
88
+ alias :id #{attribute.inspect}
89
+ alias :id= #{"#{attribute}=".to_sym.inspect}
90
+ EOS
91
+ end
80
92
  end
81
93
 
82
94
  ##
@@ -22,5 +22,7 @@ module Facebooker
22
22
 
23
23
  include Model
24
24
  attr_accessor :eid, :pic, :pic_small, :pic_big, :name, :creator, :update_time, :description, :tagline, :venue, :host, :event_type, :nid, :location, :end_time, :start_time, :event_subtype
25
+
26
+ id_is :eid
25
27
  end
26
28
  end
@@ -6,6 +6,8 @@ module Facebooker
6
6
  include Model
7
7
  attr_accessor :flid, :name
8
8
 
9
+ id_is :flid
10
+
9
11
  # We need this to be an integer, so do the conversion
10
12
  def flid=(f)
11
13
  @flid= ( f.nil? ? nil : f.to_i)
@@ -10,6 +10,7 @@ module Facebooker
10
10
  include Model
11
11
  attr_accessor :pic, :pic_small, :pic_big, :name, :creator, :recent_news, :gid, :update_time, :group_subtype, :group_type, :website, :office, :description, :venue, :nid
12
12
 
13
+ id_is :gid
13
14
 
14
15
  ##
15
16
  # Get the full list of members as populated User objects. First time fetches group members via Facebook API call.
@@ -6,5 +6,7 @@ module Facebooker
6
6
  :link, :caption, :created,
7
7
  :src, :src_big, :src_small,
8
8
  :story_fbid
9
+
10
+ id_is :pid
9
11
  end
10
12
  end
@@ -12,7 +12,6 @@ module Facebooker
12
12
  end
13
13
  FIELDS = [:status, :political, :pic_small, :name, :quotes, :is_app_user, :tv, :profile_update_time, :meeting_sex, :hs_info, :timezone, :relationship_status, :hometown_location, :about_me, :wall_count, :significant_other_id, :pic_big, :music, :uid, :work_history, :sex, :religion, :notes_count, :activities, :pic_square, :movies, :has_added_app, :education_history, :birthday, :first_name, :meeting_for, :last_name, :interests, :current_location, :pic, :books, :affiliations, :locale, :profile_url, :proxied_email,:email_hashes]
14
14
  STANDARD_FIELDS = [:uid, :first_name, :last_name, :name, :timezone, :birthday, :sex, :affiliations, :locale, :profile_url]
15
- attr_accessor :id, :session
16
15
  populating_attr_accessor *FIELDS
17
16
  attr_reader :affiliations
18
17
  populating_hash_settable_accessor :current_location, Location
@@ -28,10 +27,10 @@ module Facebooker
28
27
  # attribute_hash
29
28
  def initialize(*args)
30
29
  if (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args.size==1
31
- @id=Integer(args.shift)
30
+ self.uid = args.shift
32
31
  @session = Session.current
33
32
  elsif (args.first.kind_of?(String) || args.first.kind_of?(Integer)) && args[1].kind_of?(Session)
34
- @id = Integer(args.shift)
33
+ self.uid = args.shift
35
34
  @session = args.shift
36
35
  end
37
36
  if args.last.kind_of?(Hash)
@@ -39,6 +38,9 @@ module Facebooker
39
38
  end
40
39
  end
41
40
 
41
+ id_is :uid
42
+ alias :facebook_id :id
43
+
42
44
  # Returns a user's events, params correspond to API call parameters (except UID):
43
45
  # http://wiki.developers.facebook.com/index.php/Events.get
44
46
  # E.g:
@@ -86,7 +88,7 @@ module Facebooker
86
88
 
87
89
  #use __blank instead of nil so that this is cached
88
90
  cache_key = flid||"__blank"
89
- options = {:uid=>@id}
91
+ options = {:uid=>self.id}
90
92
  options[:flid] = flid unless flid.nil?
91
93
  @friends_hash[cache_key] ||= @session.post('facebook.friends.get', options,false).map do |uid|
92
94
  User.new(uid, @session)
@@ -203,7 +205,7 @@ module Facebooker
203
205
  end
204
206
 
205
207
  def profile_fbml
206
- session.post('facebook.profile.getFBML', :uid => @id)
208
+ session.post('facebook.profile.getFBML', :uid => id)
207
209
  end
208
210
 
209
211
  ##
@@ -229,7 +231,7 @@ module Facebooker
229
231
  end
230
232
 
231
233
  def set_profile_fbml(profile_fbml, mobile_fbml, profile_action_fbml, profile_main = nil)
232
- parameters = {:uid => @id}
234
+ parameters = {:uid => id}
233
235
  parameters[:profile] = profile_fbml if profile_fbml
234
236
  parameters[:profile_action] = profile_action_fbml if profile_action_fbml
235
237
  parameters[:mobile_profile] = mobile_fbml if mobile_fbml
@@ -243,12 +245,12 @@ module Facebooker
243
245
  # Note: using set_profile_info as I feel using user.set_info could be confused with the user.getInfo facebook method.
244
246
  # Also, I feel it fits in line with user.set_profile_fbml.
245
247
  def set_profile_info(title, info_fields, format = :text)
246
- session.post('facebook.profile.setInfo', :title => title, :uid => @id,
248
+ session.post('facebook.profile.setInfo', :title => title, :uid => id,
247
249
  :type => format.to_s == "text" ? 1 : 5, :info_fields => info_fields.to_json)
248
250
  end
249
251
 
250
252
  def get_profile_info
251
- session.post('facebook.profile.getInfo', :uid => @id)
253
+ session.post('facebook.profile.getInfo', :uid => id)
252
254
  end
253
255
 
254
256
  ##
@@ -284,19 +286,19 @@ module Facebooker
284
286
  ##
285
287
  # Convenience method to send email to the current user
286
288
  def send_email(subject, text=nil, fbml=nil)
287
- session.send_email([@id], subject, text, fbml)
289
+ session.send_email([id], subject, text, fbml)
288
290
  end
289
291
 
290
292
  ##
291
293
  # Convenience method to set cookie for the current user
292
294
  def set_cookie(name, value, expires=nil, path=nil)
293
- session.data.set_cookie(@id, name, value, expires, path)
295
+ session.data.set_cookie(id, name, value, expires, path)
294
296
  end
295
297
 
296
298
  ##
297
299
  # Convenience method to get cookies for the current user
298
300
  def get_cookies(name=nil)
299
- session.data.get_cookies(@id, name)
301
+ session.data.get_cookies(id, name)
300
302
  end
301
303
 
302
304
  ##
@@ -359,10 +361,6 @@ module Facebooker
359
361
  end
360
362
  end
361
363
 
362
- def facebook_id
363
- @id
364
- end
365
-
366
364
  def self.user_fields(fields = [])
367
365
  valid_fields(fields)
368
366
  end
@@ -385,7 +383,7 @@ module Facebooker
385
383
  end
386
384
 
387
385
  def profile_pic_album_id
388
- merge_aid(-3, @id)
386
+ merge_aid(-3, id)
389
387
  end
390
388
 
391
389
  def merge_aid(aid, uid)
@@ -58,23 +58,23 @@ module Facebooker
58
58
 
59
59
  def self.hashinate(response_element)
60
60
  response_element.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |hash, child|
61
- # If the node hasn't any child, and is not a list, we want empty strings, not empty hashes.
62
- hash[child.name] = if (child.children.size == 1 && child.children.first.kind_of?(REXML::Text)) || (child.children.size == 0 && child.attributes['list'] != 'true')
61
+ # If the node hasn't any child, and is not a list, we want empty strings, not empty hashes,
62
+ # except if attributes['nil'] == true
63
+ hash[child.name] =
64
+ if (child.attributes['nil'] == 'true')
65
+ nil
66
+ elsif (child.children.size == 1 && child.children.first.kind_of?(REXML::Text)) || (child.children.size == 0 && child.attributes['list'] != 'true')
63
67
  anonymous_field_from(child, hash) || child.text_value
68
+ elsif child.attributes['list'] == 'true'
69
+ child.children.reject{|c| c.kind_of? REXML::Text}.map { |subchild| hash_or_value_for(subchild)}
64
70
  else
65
- if child.attributes['list'] == 'true'
66
- child.children.reject{|c| c.kind_of? REXML::Text}.map do |subchild|
67
- hash_or_value_for(subchild)
68
- end
69
- else
70
- child.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |subhash, subchild|
71
- subhash[subchild.name] = hash_or_value_for(subchild)
72
- subhash
73
- end
71
+ child.children.reject{|c| c.kind_of? REXML::Text}.inject({}) do |subhash, subchild|
72
+ subhash[subchild.name] = hash_or_value_for(subchild)
73
+ subhash
74
74
  end
75
- end
75
+ end #if (child.attributes)
76
76
  hash
77
- end
77
+ end #do |hash, child|
78
78
  end
79
79
 
80
80
  def self.anonymous_field_from(child, hash)
@@ -94,13 +94,14 @@ module Facebooker
94
94
 
95
95
  #returning gracefully if the cookies aren't set or have expired
96
96
  return unless parsed['session_key'] && parsed['user'] && parsed['expires'] && parsed['ss']
97
- return unless Time.at(parsed['expires'].to_f) > Time.now
97
+ return unless Time.at(parsed['expires'].to_f) > Time.now || (parsed['expires'] == "0")
98
98
 
99
99
  #if we have the unexpired cookies, we'll throw an exception if the sig doesn't verify
100
100
  verify_signature(parsed,cookies[Facebooker.api_key])
101
101
 
102
102
  @facebook_session = new_facebook_session
103
103
  @facebook_session.secure_with!(parsed['session_key'],parsed['user'],parsed['expires'],parsed['ss'])
104
+ session[:facebook_session] = @facebook_session
104
105
  end
105
106
 
106
107
  def secure_with_token!
@@ -277,4 +278,4 @@ module Facebooker
277
278
  end
278
279
  end
279
280
  end
280
- end
281
+ end
@@ -31,7 +31,7 @@ class CGI
31
31
  def initialize(request, option={})
32
32
  @request = request
33
33
  @initialization_options = option
34
- option['session_id'] = set_session_id
34
+ option['session_id'] ||= set_session_id
35
35
  initialize_aliased_by_facebooker(request, option)
36
36
  end
37
37
 
@@ -90,9 +90,9 @@ module ActionView
90
90
  # Altered to throw an error on :popup and sanitize the javascript
91
91
  # for Facebook.
92
92
  def convert_options_to_javascript_with_facebooker!(html_options, url ='')
93
- if !request_comes_from_facebook?
93
+ if !respond_to?(:request_comes_from_facebook?) || !request_comes_from_facebook?
94
94
  convert_options_to_javascript_without_facebooker!(html_options,url)
95
- else
95
+ else
96
96
  confirm, popup = html_options.delete("confirm"), html_options.delete("popup")
97
97
 
98
98
  method, href = html_options.delete("method"), html_options['href']
@@ -124,23 +124,24 @@ module ActionView
124
124
  # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>"Go to Facebooker?")
125
125
  # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>{:title=>"the page says:, :content=>"Go to Facebooker?"})
126
126
  # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>{:title=>"the page says:, :content=>"Go to Facebooker?", :color=>"pink"})
127
- def confirm_javascript_function_with_facebooker(confirm, fun = nil)
128
- if !request_comes_from_facebook?
129
- confirm_javascript_function_without_facebooker(confirm)
130
- else
131
- if(confirm.is_a?(Hash))
132
- confirm_options = confirm.stringify_keys
133
- title = confirm_options.delete("title") || "Please Confirm"
134
- content = confirm_options.delete("content") || "Are you sure?"
135
- style = confirm_options.empty? ? "" : convert_options_to_css(confirm_options)
136
- else
137
- title,content,style = 'Please Confirm', confirm, ""
127
+ def confirm_javascript_function_with_facebooker(confirm, fun = nil)
128
+ if !request_comes_from_facebook?
129
+ confirm_javascript_function_without_facebooker(confirm)
130
+ else
131
+ if(confirm.is_a?(Hash))
132
+ confirm_options = confirm.stringify_keys
133
+ title = confirm_options.delete("title") || "Please Confirm"
134
+ content = confirm_options.delete("content") || "Are you sure?"
135
+ button_confirm = confirm_options.delete("button_confirm") || "Okay"
136
+ button_cancel = confirm_options.delete("button_cancel") || "Cancel"
137
+ style = confirm_options.empty? ? "" : convert_options_to_css(confirm_options)
138
+ else
139
+ title,content,style,button_confirm,button_cancel = 'Please Confirm', confirm, "", "Okay", "Cancel"
138
140
  end
139
-
140
- "var dlg = new Dialog().showChoice('#{escape_javascript(title.to_s)}','#{escape_javascript(content.to_s)}').setStyle(#{style});"+
141
+ "var dlg = new Dialog().showChoice('#{escape_javascript(title.to_s)}','#{escape_javascript(content.to_s)}','#{escape_javascript(button_confirm.to_s)}','#{escape_javascript(button_cancel.to_s)}').setStyle(#{style});"+
141
142
  "var a=this;dlg.onconfirm = function() { #{fun ? fun : 'document.setLocation(a.getHref());'} };"
142
143
  end
143
- end
144
+ end
144
145
 
145
146
  alias_method_chain :confirm_javascript_function, :facebooker
146
147
 
@@ -4,7 +4,11 @@ module Facebooker
4
4
  module FbConnect
5
5
 
6
6
  def fb_connect_javascript_tag
7
- javascript_include_tag "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
7
+ if request.ssl?
8
+ javascript_include_tag "https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
9
+ else
10
+ javascript_include_tag "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
11
+ end
8
12
  end
9
13
 
10
14
  def init_fb_connect(*required_features)
@@ -31,4 +35,4 @@ module Facebooker
31
35
  end
32
36
  end
33
37
  end
34
- end
38
+ end
@@ -176,8 +176,8 @@ module Facebooker
176
176
  publisher = setup_publisher(klass,method)
177
177
  # sort the Hash elements (in the short_story and full_story) before generating MD5
178
178
  Digest::MD5.hexdigest [publisher.one_line_story_templates,
179
- (publisher.short_story_templates and publisher.short_story_templates.collect{|ss| ss.to_a.sort_by{|e| e[0]}}),
180
- (publisher.full_story_template and publisher.full_story_template.to_a.sort_by{|e| e[0]})
179
+ (publisher.short_story_templates and publisher.short_story_templates.collect{|ss| ss.to_a.sort_by{|e| e[0].to_s}}),
180
+ (publisher.full_story_template and publisher.full_story_template.to_a.sort_by{|e| e[0].to_s})
181
181
  ].to_json
182
182
  end
183
183
 
@@ -396,6 +396,9 @@ module Facebooker
396
396
  returning ActionView::Base.new([template_root,controller_root], assigns, self) do |template|
397
397
  template.controller=self
398
398
  template.extend(self.class.master_helper_module)
399
+ def template.request_comes_from_facebook?
400
+ true
401
+ end
399
402
  end
400
403
  end
401
404
 
@@ -34,11 +34,6 @@ module Facebooker
34
34
  send verb, path, params
35
35
  end
36
36
 
37
- def facebook_post(path, params={}, fb_params=facebook_parameters)
38
- params = fb_params.merge(:canvas => true).merge(params)
39
- post path, params
40
- end
41
-
42
37
  def facebook_parameters(overrides=nil)
43
38
  overrides ||= {}
44
39
  params = default_facebook_parameters.merge(overrides)
@@ -1,8 +1,8 @@
1
1
  begin
2
2
  require 'curb'
3
3
  Facebooker.use_curl = true
4
- rescue Exception=>e
5
- puts e
4
+ rescue LoadError
5
+ $stderr.puts "Curb not found. Using Net::HTTP."
6
6
  require 'net/http'
7
7
  end
8
8
  require 'facebooker/parser'
@@ -78,11 +78,11 @@ module Facebooker
78
78
  end
79
79
 
80
80
  def self.current
81
- @current_session
81
+ Thread.current['facebook_session']
82
82
  end
83
83
 
84
84
  def self.current=(session)
85
- @current_session=session
85
+ Thread.current['facebook_session'] = session
86
86
  end
87
87
 
88
88
  def login_url(options={})
@@ -166,20 +166,23 @@ module Facebooker
166
166
  def fql_query(query, format = 'XML')
167
167
  post('facebook.fql.query', :query => query, :format => format) do |response|
168
168
  type = response.shift
169
- return [] if type.nil?
170
- response.shift.map do |hash|
171
- case type
172
- when 'user'
173
- user = User.new
174
- user.session = self
175
- user.populate_from_hash!(hash)
176
- user
177
- when 'photo'
178
- Photo.from_hash(hash)
179
- when 'event_member'
180
- Event::Attendance.from_hash(hash)
181
- else
182
- hash
169
+ if type.nil?
170
+ []
171
+ else
172
+ response.shift.map do |hash|
173
+ case type
174
+ when 'user'
175
+ user = User.new
176
+ user.session = self
177
+ user.populate_from_hash!(hash)
178
+ user
179
+ when 'photo'
180
+ Photo.from_hash(hash)
181
+ when 'event_member'
182
+ Event::Attendance.from_hash(hash)
183
+ else
184
+ hash
185
+ end
183
186
  end
184
187
  end
185
188
  end
@@ -319,24 +322,15 @@ module Facebooker
319
322
  # Register a template bundle with Facebook.
320
323
  # returns the template id to use to send using this template
321
324
  def register_template_bundle(one_line_story_templates,short_story_templates=nil,full_story_template=nil, action_links=nil)
322
- if !one_line_story_templates.is_a?(Array)
323
- one_line_story_templates = [one_line_story_templates]
324
- end
325
- parameters = {:one_line_story_templates=>one_line_story_templates.to_json}
325
+ parameters = {:one_line_story_templates => Array(one_line_story_templates).to_json}
326
326
 
327
- if !action_links.blank?
328
- parameters[:action_links] = action_links.to_json
329
- end
327
+ parameters[:action_links] = action_links.to_json unless action_links.blank?
330
328
 
331
- if !short_story_templates.blank?
332
- short_story_templates = [short_story_templates] unless short_story_templates.is_a?(Array)
333
- parameters[:short_story_templates]= short_story_templates.to_json
334
- end
329
+ parameters[:short_story_templates] = Array(short_story_templates).to_json unless short_story_templates.blank?
335
330
 
336
- if !full_story_template.blank?
337
- parameters[:full_story_template]= full_story_template.to_json
338
- end
339
- post("facebook.feed.registerTemplateBundle", parameters,false)
331
+ parameters[:full_story_template] = full_story_template.to_json unless full_story_template.blank?
332
+
333
+ post("facebook.feed.registerTemplateBundle", parameters, false)
340
334
  end
341
335
 
342
336
  ##
@@ -546,7 +540,7 @@ module Facebooker
546
540
  end
547
541
 
548
542
  def uid?
549
- ! @uid.nil?
543
+ !! @uid
550
544
  end
551
545
 
552
546
  def signature_for(params)
@@ -97,7 +97,14 @@ class TestFacebooker < Test::Unit::TestCase
97
97
  assert_equal('I rule', friend.status.message)
98
98
  assert_equal(nil, friend.hometown_location)
99
99
  end
100
-
100
+
101
+ def test_can_handle_nil_data
102
+ friends = populate_session_friends_with_nil_data
103
+ friend = friends.detect{|f| f.id == 222333}
104
+ assert_equal(nil,friend.current_location)
105
+ assert_equal(nil,friend.pic)
106
+ end
107
+
101
108
  def test_session_can_expire_on_server_and_client_handles_appropriately
102
109
  expect_http_posts_with_responses(example_session_expired_error_response)
103
110
  assert_raises(Facebooker::Session::SessionExpired) {
@@ -217,6 +224,7 @@ class TestFacebooker < Test::Unit::TestCase
217
224
  photos = @session.get_photos([97503428461115590, 97503428461115573])
218
225
  assert_equal 2, photos.size
219
226
  assert_equal "Rooftop barbecues make me act funny", photos.first.caption
227
+ assert_equal 97503428461115590, photos[0].id
220
228
  end
221
229
 
222
230
  def test_can_get_photos_by_subject_and_album
@@ -355,7 +363,12 @@ class TestFacebooker < Test::Unit::TestCase
355
363
  expect_http_posts_with_responses(example_friends_xml, example_limited_user_info_xml)
356
364
  @session.user.friends!(:affiliations, :status, :meeting_for)
357
365
  end
358
-
366
+
367
+ def populate_session_friends_with_nil_data
368
+ expect_http_posts_with_responses(example_friends_xml, example_nil_user_info_xml)
369
+ @session.user.friends!(:name, :current_location, :pic)
370
+ end
371
+
359
372
  def sample_args_to_post
360
373
  {:method=>"facebook.auth.createToken", :sig=>"18b3dc4f5258a63c0ad641eebd3e3930"}
361
374
  end
@@ -636,6 +649,21 @@ class TestFacebooker < Test::Unit::TestCase
636
649
  end
637
650
 
638
651
 
652
+ def example_nil_user_info_xml
653
+ <<-XML
654
+ <?xml version="1.0" encoding="UTF-8"?>
655
+ <users_getInfo_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.facebook.com/1.0/ http://api.facebook.com/1.0/facebook.xsd" list="true">
656
+ <user>
657
+ <uid>222333</uid>
658
+ <name>Kevin Lochner</name>
659
+ <current_location xsi:nil="true"/>
660
+ <pic xsi:nil="true"/>
661
+ </user>
662
+ </users_getInfo_response>
663
+ XML
664
+ end
665
+
666
+
639
667
  def example_friends_xml
640
668
  <<-XML
641
669
  <?xml version="1.0" encoding="UTF-8"?>
@@ -542,6 +542,9 @@ class RailsHelperTest < Test::Unit::TestCase
542
542
  def url_for(arg)
543
543
  arg
544
544
  end
545
+ def request
546
+ ActionController::TestRequest.new
547
+ end
545
548
  def fields_for(*args)
546
549
  ""
547
550
  end
@@ -1097,6 +1100,14 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
1097
1100
  def protect_against_forgery?
1098
1101
  false
1099
1102
  end
1103
+
1104
+ def request_comes_from_facebook?
1105
+ @request_comes_from_facebook
1106
+ end
1107
+
1108
+ def request_comes_from_facebook=(val)
1109
+ @request_comes_from_facebook = val
1110
+ end
1100
1111
 
1101
1112
  end
1102
1113
  class UrlHelperExtensionsController < NoisyController
@@ -1117,10 +1128,10 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
1117
1128
  @response = ActionController::TestResponse.new
1118
1129
 
1119
1130
  @u = UrlHelperExtensionsClass.new(@controller)
1120
- @u.stubs(:request_comes_from_facebook?).returns(true)
1131
+ @u.request_comes_from_facebook = true
1121
1132
 
1122
1133
  @non_canvas_u = UrlHelperExtensionsClass.new(@controller)
1123
- @non_canvas_u.stubs(:request_comes_from_facebook?).returns(false)
1134
+ @non_canvas_u.request_comes_from_facebook = false
1124
1135
 
1125
1136
  @label = "Testing"
1126
1137
  @url = "test.host"
@@ -1129,6 +1140,8 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
1129
1140
  @title = "Confirm Request"
1130
1141
  @style = {:color => 'black', :background => 'white'}
1131
1142
  @verbose_style = "{background: 'white', color: 'black'}"
1143
+ @default_okay = "Okay"
1144
+ @default_cancel = "Cancel"
1132
1145
  @default_style = "" #"'width','200px'"
1133
1146
  end
1134
1147
 
@@ -1141,19 +1154,19 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
1141
1154
  end
1142
1155
 
1143
1156
  def test_link_to_with_confirm
1144
- assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\').setStyle(#{@default_style});"+
1157
+ assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
1145
1158
  "var a=this;dlg.onconfirm = function() { " +
1146
1159
  "document.setLocation(a.getHref()); };return false;\">#{@label}</a>",
1147
1160
  @u.link_to(@label, @url, :confirm => @prompt) )
1148
1161
  end
1149
1162
  def test_link_to_with_confirm_with_title
1150
- assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@title}\',\'#{@prompt}\').setStyle(#{@default_style});"+
1163
+ assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
1151
1164
  "var a=this;dlg.onconfirm = function() { " +
1152
1165
  "document.setLocation(a.getHref()); };return false;\">#{@label}</a>",
1153
1166
  @u.link_to(@label, @url, :confirm => {:title=>@title,:content=>@prompt}) )
1154
1167
  end
1155
1168
  def test_link_to_with_confirm_with_title_and_style
1156
- assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@title}\',\'#{@prompt}\').setStyle(#{@verbose_style});"+
1169
+ assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@verbose_style});"+
1157
1170
  "var a=this;dlg.onconfirm = function() { " +
1158
1171
  "document.setLocation(a.getHref()); };return false;\">#{@label}</a>",
1159
1172
  @u.link_to(@label, @url, :confirm => {:title=>@title,:content=>@prompt}.merge!(@style)) )
@@ -1168,7 +1181,7 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
1168
1181
  end
1169
1182
 
1170
1183
  def test_link_to_with_confirm_and_method
1171
- assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\').setStyle(#{@default_style});"+
1184
+ assert_dom_equal( "<a href=\"#{@url}\" onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
1172
1185
  "var a=this;dlg.onconfirm = function() { " +
1173
1186
  "var f = document.createElement('form'); f.setStyle('display','none'); "+
1174
1187
  "a.getParentNode().appendChild(f); f.setMethod('POST'); f.setAction(a.getHref());" +
@@ -1191,7 +1204,7 @@ class RailsUrlHelperExtensionsTest < Test::Unit::TestCase
1191
1204
 
1192
1205
  def test_button_to_with_confirm
1193
1206
  assert_equal "<form method=\"post\" action=\"#{@url}\" class=\"button-to\"><div>" +
1194
- "<input onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\').setStyle(#{@default_style});"+
1207
+ "<input onclick=\"var dlg = new Dialog().showChoice(\'#{@default_title}\',\'#{@prompt}\',\'#{@default_okay}\',\'#{@default_cancel}\').setStyle(#{@default_style});"+
1195
1208
  "var a=this;dlg.onconfirm = function() { "+
1196
1209
  "a.getForm().submit(); };return false;\" type=\"submit\" value=\"#{@label}\" /></div></form>",
1197
1210
  @u.button_to(@label,@url, :confirm=>@prompt)
@@ -27,6 +27,22 @@ class UserTest < Test::Unit::TestCase
27
27
  def test_can_ask_user_if_he_or_she_is_friends_with_another_user_by_user_id
28
28
  assert(@user.friends_with?(@other_user.id))
29
29
  end
30
+
31
+ def test_does_not_query_facebook_for_uid
32
+ @session.expects(:post).never
33
+ assert_equal 1234, Facebooker::User.new(1234, @session).uid
34
+ end
35
+
36
+ def test_uid_is_always_an_integer
37
+ assert_equal 1234, Facebooker::User.new(:uid => "1234").uid
38
+ assert_equal 1234, Facebooker::User.new(:id => "1234").uid
39
+
40
+ assert_equal 1234, Facebooker::User.new(:uid => "1234").id
41
+ assert_equal 1234, Facebooker::User.new(:id => "1234").id
42
+
43
+ assert_equal 1234, Facebooker::User.new(:uid => "1234").facebook_id
44
+ assert_equal 1234, Facebooker::User.new(:id => "1234").facebook_id
45
+ end
30
46
 
31
47
  def test_cast_to_friend_list_id_with_nil
32
48
  assert_nil @user.cast_to_friend_list_id(nil)
@@ -55,6 +71,10 @@ class UserTest < Test::Unit::TestCase
55
71
  user=Facebooker::User.new(1)
56
72
  assert_equal("current",user.session)
57
73
  end
74
+
75
+ def test_raises_when_no_session_bound
76
+ assert_raises(Facebooker::Model::UnboundSessionException) { Facebooker::User.new(1, nil).populate }
77
+ end
58
78
 
59
79
  def test_can_set_mobile_fbml
60
80
  @user.expects(:set_profile_fbml).with(nil,"test",nil)
@@ -127,7 +147,7 @@ class UserTest < Test::Unit::TestCase
127
147
  @user = Facebooker::User.new(9507801, @session)
128
148
  expect_http_posts_with_responses(example_events_get_xml)
129
149
  events = @user.events
130
- assert_equal "29511517904", events.first.eid
150
+ assert_equal 29511517904, events.first.eid
131
151
  end
132
152
 
133
153
  def test_events_caching_honors_params
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: al-facebooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler