OmniAuthを使用してユーザーを作成および認証するアプリケーションを現在作成しています。工場ガールがOmniAuthなしでユーザーを生成できないため、テスト中に問題が発生しています。Factory GirlでOmniAuthを使用してユーザーを作成しますか?
私は工場の女の子にオムニバスのユーザーを作成させるためにいくつかの方法がありますが、どれも成功していません。
私は私のspec_helperファイル
OmniAuth.config.test_mode = true \\ allows me to fake signins
OmniAuth.config.add_mock(:twitter, { :uid => '12345', :info => { :nickname => 'Joe Blow' }})
現在factories.rbに次の2行を追加したどのユーザーが生成されていないため、次のテストは、現在失敗し
FactoryGirl.define do
factory :user do
provider "twitter"
sequence(:uid) { |n| "#{n}" }
sequence(:name) { |n| "Person_#{n}" }
end
end
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
ファクトリーガールにテストユーザーを作成させるために、工場/テストをどのように変更すればよいですか? OmniAuth?
編集:私はRailsCast guide to setup Omniauthを使用し、
#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
皆さんのお手伝いをするために提供できる情報はありますか? – SomberClock