{"id":767,"date":"2022-08-30T15:06:50","date_gmt":"2022-08-30T15:06:50","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/omniauth-facebook-devise-rspec-undefined-method-extra-for-nilnilclass-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:06:50","modified_gmt":"2022-08-30T15:06:50","slug":"omniauth-facebook-devise-rspec-undefined-method-extra-for-nilnilclass-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/omniauth-facebook-devise-rspec-undefined-method-extra-for-nilnilclass-collection-of-common-programming-errors\/","title":{"rendered":"Omniauth-facebook Devise Rspec, undefined method `extra&#39; for nil:NilClass-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to test omniauth-facebook integration in my app, but i keep getting this failures:<\/p>\n<pre><code>Failure\/Error: get :facebook\n NoMethodError:\n   undefined method `extra' for nil:NilClass\n # .\/app\/models\/user.rb:17:in `find_for_facebook_oauth'\n # .\/app\/controllers\/users\/omniauth_callbacks_controller.rb:4:in `facebook'\n # .\/spec\/controllers\/users\/omniauth_callbacks_controller_spec.rb:18:in `block (4 levels) in '\n<\/code><\/pre>\n<p>Here is the code lines raising the failure:<\/p>\n<p><strong>user.rb<\/strong> :<\/p>\n<pre><code>def self.find_for_facebook_oauth(auth, signed_in_resource=nil)\n  data = auth.extra.raw_info # this is line 17\n  if user = User.where(:email =&gt; data.email).first\n    user\n  else\n    user = User.new\n    user\n  end\nend\n<\/code><\/pre>\n<p><strong>omniauth_callbacks_controller.rb<\/strong> :<\/p>\n<pre><code>def facebook\n  @user = User.find_for_facebook_oauth(request.env[\"omniauth.auth\"], current_user) # this is line 4\n\n  if @user.persisted?\n    flash[:notice] = I18n.t \"devise.omniauth_callbacks.success\", :kind =&gt; \"Facebook\"\n    sign_in_and_redirect @user, :event =&gt; :authentication\n  else\n    flash[:notice] = \"Authentication was successful, please continue your registration process.\"\n    session[\"devise.facebook_data\"] = request.env[\"omniauth.auth\"]\n    redirect_to new_user_registration_url\n  end\nend\n<\/code><\/pre>\n<p><strong>omniauth_callbacks_controller_spec.rb<\/strong> :<\/p>\n<pre><code>before(:each) do\n  stub_env_for_omniauth\n\n  get :facebook # this is line 18\n  @user = User.where(:email =&gt; \"ghost@nobody.com\").first\nend\n\ndef stub_env_for_omniauth\n  request.env[\"devise.mapping\"] = Devise.mappings[:user]\n  pre = { \"omniauth.auth\" =&gt; { \"provider\" =&gt; \"facebook\", \"uid\" =&gt; \"1234\", \"credentials\" =&gt; {\"token\" =&gt; \"abcdefg\"}, \"extra\"=&gt;{\"raw_info\" =&gt; {\"id\" =&gt; \"1234567\", \"email\" =&gt; \"ghost@nobody.com\", \"name\" =&gt; \"Mark\", \"gender\" =&gt; \"male\" }}}}\n  env = OmniAuth::AuthHash.new(pre)\n  @controller.stub!(:env).and_return(env)\nend\n<\/code><\/pre>\n<p>And this is <strong>spec_helper.rb<\/strong> :<\/p>\n<pre><code>require 'omniauth'\nOmniAuth.config.test_mode = true\n<\/code><\/pre>\n<p>Any ideas?<\/p>\n<ol>\n<li>\n<p>hey just add following line in <strong>facebook<\/strong> method<\/p>\n<pre><code>def facebook\nraise request.env[\"omniauth.auth\"].to_yaml\n....\nend\n<\/code><\/pre>\n<p>and then check what response you are getting from facebook-omniauth.This might help you to detect the problem.<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:41:17. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to test omniauth-facebook integration in my app, but i keep getting this failures: Failure\/Error: get :facebook NoMethodError: undefined method `extra&#8217; for nil:NilClass # .\/app\/models\/user.rb:17:in `find_for_facebook_oauth&#8217; # .\/app\/controllers\/users\/omniauth_callbacks_controller.rb:4:in `facebook&#8217; # .\/spec\/controllers\/users\/omniauth_callbacks_controller_spec.rb:18:in `block (4 levels) in &#8216; Here is the code lines raising the failure: user.rb : def self.find_for_facebook_oauth(auth, signed_in_resource=nil) data = auth.extra.raw_info # this [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-767","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/767","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=767"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/767\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}