Permalink
Browse files

Reuse facebook_session if we can, so as that Mocks are preserved

  • Loading branch information...
jstirk committed Jul 16, 2010
1 parent 43069f1 commit ee13ea57345692e630f10e3cc748ee984b38bc58
Showing with 18 additions and 11 deletions.
  1. +18 −11 lib/facebooker_authentication/model.rb
@@ -3,6 +3,10 @@ module Model
def self.included(includer)
includer.send(:extend,ClassMethods)
includer.send(:include,InstanceMethods)
# Provide a way to set the facebook_session in cases where for_facebook_id() doesn't suit.
# For example, if the model shouldn't be created...
attr_writer :facebook_session
end
module InstanceMethods
@@ -16,22 +20,25 @@ def facebook_session
end
def store_session(session_key)
if self.session_key != session_key
update_attribute(:session_key,session_key)
end
end
if self.session_key != session_key
update_attribute(:session_key,session_key)
end
end
end
module ClassMethods
def for_facebook_id(facebook_id,facebook_session=nil)
returning find_or_create_by_facebook_id(facebook_id) do |user|
unless facebook_session.nil?
user.store_session(facebook_session.session_key)
end
end
end
returning find_or_create_by_facebook_id(facebook_id) do |user|
unless facebook_session.nil?
user.store_session(facebook_session.session_key)
# Set the session now - this ensures that Cucumber correctly passes the Facebooker::Mock::Session object,
# rather than letting facebook_session create a standar Facebooker::Session
user.facebook_session=facebook_session
end
end
end
end
end
end
end

0 comments on commit ee13ea5

Please sign in to comment.