Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'extra' method undefined #558

Closed
benjamintanweihao opened this issue Dec 18, 2011 · 7 comments
Closed

'extra' method undefined #558

benjamintanweihao opened this issue Dec 18, 2011 · 7 comments

Comments

@benjamintanweihao
Copy link

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 methodextra' for #Hash:0x007fc59c482bc8 (NoMethodError)
./app/models/user.rb:15:in find_for_facebook_oauth' ./app/controllers/users/omniauth_callbacks_controller.rb:4:infacebook'
(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
Copy link
Author

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
Copy link

piotrj commented Dec 19, 2011

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

@benjamintanweihao
Copy link
Author

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
Copy link

piotrj commented Dec 19, 2011

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
Copy link
Author

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

@dombesz
Copy link

dombesz commented Jan 5, 2012

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 as completed Jan 17, 2012
@karangb
Copy link

karangb commented Apr 6, 2012

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants