Reputation: 852
I want to do unit testing for this method here is the code :
def self.find_for_facebook_oauth(access_token, sign_in_resource=nil)
data = access_token.extra.raw_info
if !Authentication.where(:uid => access_token['uid']).empty?
authentication = Authentication.find_by_uid(access_token['uid'])
if !authentication.user.nil?
user = authentication.user
return user
else
# in case for some reason the authentication has no user
raise "Something went wrong"
end
else
user = User.new
user.authentications.build(:provider => access_token['provider'], :uid => access_token['uid'], :token => access_token['credentials']['token'])
user.save(:validate=>false)
return user
end
return false
end
How to do it? Thank you :)
Upvotes: 1
Views: 1256
Reputation: 852
The answer is on this site
http://ashleshawrites.wordpress.com/2012/07/02/testing-omniauth-creating-mock-data/
cheers :) Tq
Upvotes: 4
Reputation: 146
You can use the example hash on the Omniauth-Facebook github page to isolate the test: https://github.com/mkdynamic/omniauth-facebook
Scroll down to the "Auth Hash" to find the example. Then it is simply a matter of testing like normal
Upvotes: 1