RailsCasts Pro episodes are now free!

Learn more or hide this

Eugene Dorian's Profile

GitHub User: lifegiver

Comments by Eugene Dorian

Avatar

Works great for me, but the cucumber test fails. I get “Password can't be blank” messages. I guess it is related with using “:without_protection => true” while creating new User.

step_definitions/user_steps.rb
def set_facebook_omniauth
 credentials = {:provider => :facebook, :uuid => '65', :info => {:email => 'machete@yourgarganta.mx', :name => 'Denny Trejo'}}
 OmniAuth.config.test_mode = true
 OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({'uid' => credentials[:uuid], 'info' => {'email' => credentials[:info][:email], 'name' => credentials[:info][:name]}})
end

When /^I login with Facebook$/ do
 set_facebook_omniauth
 visit root_path
 click_link 'Login with Facebook'
end

Then /^I see a successful sign in message$/ do
 page.should have_content "Signed in successfully."
end

As I’m using mongoid I’ve changed a bit “from_omniauth” method.

models/user.rb
 def self.from_omniauth(auth)
    where(auth.slice(:provider, :uid)).find_or_create_by do |user|
     user.provider = auth.provider
     user.uid = auth.uid
     user.name = auth.info.name
     user.email = auth.info.email
    end
 end