Skip to content

Commit

Permalink
Reuse facebook_session if we can, so as that Mocks are preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
jstirk committed Jul 16, 2010
1 parent 43069f1 commit ee13ea5
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lib/facebooker_authentication/model.rb
Expand Up @@ -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
Expand All @@ -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.