I am currently creating an application that uses OmniAuth to create and authenticate users. I am experiencing problems during testing due to Factory Girl cannot generate users without OmniAuth.
I have several different ways to get a Factory girl to create users with omniauth, but none of them have been successful.
I 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 is currently failing as no user is created
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 do I change my factories / tests to get Factory Girl to create test users using OmniAuth?
Edit: I used the RailsCast manual to configure Omniauth ,
def self.create_with_omniauth(auth)
create! do |user|
user.provider = auth["provider"]
user.uid = auth["uid"]
user.name = auth["info"]["name"]
end
end
,
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