Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

'extra' method undefined #558

Closed
benjamintanweihao opened this Issue · 7 comments

5 participants

@benjamintanweihao

Hi all! This is driving me nuts. I've set up Devise 1.5 + Omniauth 1.0. Funny thing is, development mode works fine. But when testing with cucumber, I get this error:


When I follow "Sign in with Facebook" # features/step_definitions/web_steps.rb:57
undefined method
extra' for #Hash:0x007fc59c482bc8 (NoMethodError)
./app/models/user.rb:15:in find_for_facebook_oauth'
./app/controllers/users/omniauth_callbacks_controller.rb:4:in
facebook'
(eval):2:in click_link'
./features/step_definitions/web_steps.rb:58:in
/^(?:|I )follow "([^"]*)"$/'
features/facebook.feature:11:in When I follow "Sign in with Facebook"'

I have OmniAuth.config.test_mode = true in test.rb. Any suggestions? Thanks!

@benjamintanweihao

FWIW, here's the way I'm getting it to pass the Cucumber tests for now, which is pretty lame. I keep getting trouble at the data.extra.raw_info part:

    def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)

        case Rails.env
        when "test"
            data = access_token['extra']['user_hash']
            if user = User.find_by_email(data["email"])
                user
            else 
                User.create!(:email => data["email"], :password => Devise.friendly_token[0,20])
            end
        else
            data = access_token.extra.raw_info
            if user = User.where(:email => data.email).first
                user
            else 
                User.create!(:email => data.email, :password => Devise.friendly_token[0,20]) 
            end
        end
    end

Here's my Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.1'

gem 'haml'
gem 'jquery-rails'
gem "devise", :git => "https://github.com/plataformatec/devise.git"
gem 'omniauth', :git => 'git://github.com/piotrj/omniauth.git'
gem 'omniauth-facebook'
gem 'pg'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'coffee-rails', '~> 3.1.1'
  gem 'sass-rails',   '~> 3.1.5'
  gem 'uglifier', '>= 1.0.3'
end

group :development do
  gem 'sqlite3'
    gem 'haml-rails', '>= 0.3.4'
end

group :development, :test do
    gem 'rspec-rails'
    gem 'ZenTest'
  gem 'autotest-fsevent'    
  gem 'autotest-growl'
  gem 'autotest-rails'
end

group :test do
    gem 'cucumber-rails', '1.0.6'
  gem 'capybara'
  gem 'database_cleaner'
  gem 'email_spec'
  gem 'factory_girl'
  gem 'minitest'
  gem 'spork', '> 0.9.0.rc'
  gem 'turn', '~> 0.8.3', :require => false
end

@piotrj

This error should be fixed while Pull Request #556 will get merged.

@benjamintanweihao

Thanks! I think I tried your fix, is it the one stated in the Gemfile I have above? Seems like not many people are having this strange issue. Anyhow, thanks for the patch!

@piotrj

Probably people don't use the Mash functionality -> using data.extra instead of data["extra"]. That's why they don't stumble upon this issue.

If you want to use my fix for now then except for using my fork you need to specify that you want to use branch mash_in_test_mode - use smth like that:

gem 'omniauth', :git => 'git://github.com/piotrj/omniauth.git', :branch => "mash_in_test_mode"
@benjamintanweihao

Hi piotrj, I have tried your fix but I'm still running into the same issues. :(.

@dombesz

I have submited my patch to solve this issue, you can find it here: #564
Also encountered this problem and my patch solves this issue.
https://github.com/dombesz/omniauth

@mbleigh mbleigh closed this
@karangb

I still have the same issue - ive been pulling out my hair with this. Did anyone manage to get it working?

I tried:

gem 'omniauth', :git => 'git://github.com/piotrj/omniauth.git', :branch => "mash_in_test_mode"

gem 'omniauth', :git => 'https://github.com/dombesz/omniauth.git'

neither worked ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.