Here is my function :
Scenario: Professor is not signed up and tries to sign in with Facebook
Given I do not exist as a professor
When I sign in as a professor with Facebook
Then I should see a successful sign in message
When I return to the site
Then I should be signed in as a professor
Here is the step definition for When I sign in as a professor with Facebook
When /^I sign in as a professor with Facebook$/ do
set_omniauth
visit "/professors/auth/facebook"
end
And here is the definition of the set_omniauth helper :
def set_omniauth(opts = {})
default = {:provider => :facebook,
:uuid => "1234",
:facebook => {
:email => "foobar@example.com",
}
}
credentials = default.merge(opts)
provider = credentials[:provider]
user_hash = credentials[provider]
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[provider] = {
'uid' => credentials[:uuid],
"extra" => {
"user_hash" => {
"email" => user_hash[:email],
}
}
}
end
So ... When I visit /professors/auth/facebook, this action is called
def facebook
@professor = Professor.find_for_facebook_oauth(request.env["omniauth.auth"], current_professor)
if @professor.persisted?
flash[:notice] = "Welcome! You have signed up successfully."
sign_in_and_redirect @professor, :event => :authentication
else
session["devise.facebook_data"] = request.env["omniauth.auth"]
redirect_to new_professor_registration_url
end
end
Finally, the definition of the find_for_facebook_oauth method :
def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
data = access_token["extra"]["raw_info"]
if professor = self.find_by_email(data.email)
professor
else
self.create(:email => data.email, :password => Devise.friendly_token[0,20])
end
end
When you run this function, you receive the following error message:
undefined method `email' for {"email"=>"foobar@example.com"}:Hash (NoMethodError)
So, I checked that Facebook actually returns:
#<Hashie::Mash email="myemail@gmail.com" ...
But this is a different object than the regular hash set in:
OmniAuth.config.mock_auth[provider] = {
'uid' => credentials[:uuid],
"extra" => {
"user_hash" => {
"email" => user_hash[:email],
}
}
So my question is: How can I verify this correctly? I followed OmniAuth Integration Tetsing and they installed Hash, not Hash.