ここにレールヌーブ。Omniauth-Facebookでの認証に関してテストする方法/内容を理解するのに問題があります。関連するrailscastとほぼ同じ設定になっています。テスト環境は、前の質問とGemwikiで説明されているものと同じように設定されています。
いくつかの質問。ユーザーファクトリを作成する場合、認証をモックする結果のオブジェクトをどのように取得しますか?
また、次のコードを実行するとどうなりますか?
before do
request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:facebook]
visit '/auth/facebook'
end
オブジェクトはデータベースに保存されていますか?
以下にいくつかのサンプル仕様とファクトリー仕様を追加しました。この場合も、spec_helper
セットアップファイルのテストモード構成はtrueに設定されています。
add_mock
セットアップ:
OmniAuth.config.add_mock(:facebook,
{ :provider => 'facebook',
:uid => '1234567',
:info => { :name => 'Jonathan', :image => 'http://graph.facebook.com/1234567/picture?type=square'},
:credentials => {
:expires_at => 1351270850,
:token=> 'AAADzk0b791YBAHCNhBI3n6ScmWvuXTY4yIUqXr9WiZCg1R808RYzaHxsHnrbn62IwrIgZCfSBZAVIP6ptF41nm8YtRtZCeBbxbbz1mF8RQZDZD'
} })
User_pages_spec:
describe "user pages" do
let(:user) { Factory.create(:user) }
describe "sign_in" do
before { visit '/' }
it "should add a user to the User model" do
expect { click_link "sign_in" }.to change(User, :count).by(1)
end
it "should route to the appropriate page if email is nil" do
click_link "sign_in"
page.should have_selector('h5', text: 'Edit Email')
end
it "should redirect to the show page upon" do
user.email = 'example@stanford.edu'
user.save!
click_link 'sign_in'
page.should have_selector('div', text: user.name)
end
end
end
工場
FactoryGirl.define do
factory :user do
provider "facebook"
uid '1234567'
name 'Jonathan'
end
end