Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8228817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T16:35:23+00:00 2026-06-07T16:35:23+00:00

I am currently creating an application that uses OmniAuth to create and authenticate users.

  • 0

I am currently creating an application that uses OmniAuth to create and authenticate users. I am encountering problems during testing due to Factory Girl being unable to generate users without OmniAuth.

I have several different ways to get factory girl to create users with omniauth but none have been successful.

I have added the following 2 lines to my spec_helper file

OmniAuth.config.test_mode = true \\ allows me to fake signins
OmniAuth.config.add_mock(:twitter, { :uid => '12345', :info => { :nickname => 'Joe Blow' }})

current factories.rb

FactoryGirl.define do
  factory :user do
    provider "twitter"
    sequence(:uid) { |n| "#{n}" }
    sequence(:name) { |n| "Person_#{n}" }
  end
end

The following test currently fails because no user is being generated

let(:user) { FactoryGirl.create(:user) }
before { sign_in user }

describe "registering" do

  it "should increment" do
    expect do
      click_button 'register'
    end.to change(user.rounds, :count).by(1)
end

How should I change my factories/tests in order to get Factory Girl to create test users with OmniAuth?

Edit: I used the RailsCast guide to setup Omniauth,

#create function inside user.rb
def self.create_with_omniauth(auth)
  create! do |user|
    user.provider = auth["provider"]
    user.uid = auth["uid"]
    user.name = auth["info"]["name"]
  end
end

hopefully also useful

#create inside the session_controller
def create
  auth = request.env["omniauth.auth"]
  user = User.find_by_provider_and_uid(auth["provider"], auth["uid"]) ||    User.create_with_omniauth(auth)
  session[:user_id] = user.id
  redirect_to root_url, :notice => "Signed in!"
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T16:35:25+00:00Added an answer on June 7, 2026 at 4:35 pm

    Did you remember to do the following somewhere in the test setup?

    request.env[“omniauth.auth”] = OmniAuth.config.mock_auth[:twitter]

    If you did, is it possible the user’s UID doesn’t match the mock uid?

    You can try changing the factory definition from sequence(:uid) { |n| "#{n}" } to uid '12345'.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently creating an application (iPhone/iPad/Android) that uses a map to display houses
I'm currently creating an MVC application that will likely to expand to include a
I am currently in the process of creating an application that records current location
Here's something that has been bugging me... I am currently creating an application for
I'm creating an installer for my Windows client application. Currently I create an MSI
I am creating a mapping application that uses a WSGI service and needs a
I am creating an application that uses the MS Ribbon Control. The ribbon has
I am currently in the middle of creating an app that uses a sql
I have a web application that I am currently working on that uses a
I am creating a Facebook iFrame tab application that features weekly interviews and uses

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.