当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails - Rspec + OAuth: Having trouble signing in from within a test (omniauth mock)

问题描述:

I'm testing a controller in my app which should render one view for users who've given over their info and requested access ("signed in guests") and another view for the rest of the world (anonymous users). I'm using OmniAuth and Rolify.

Test goes like this:

context 'signed in guests' do

before do

guest = create(:user,:guest)

OmniAuth.config.mock_auth[:google] = {

uid: guest.uid

}

session[:user_id] = guest.id

end

it "shows the Please Wait for Confirmation view" do

puts "Rspec says Current User: #{@current_user.inspect}"

get :index

response.should render_template :pending_authorization

end

end

User factory looks like this:

FactoryGirl.define do

factory :user do

name "MyString"

email "MyString"

provider "MyString"

uid "MyString"

trait :admin do

after(:create) {|user| user.add_role(:admin)}

end

trait :guest do

after(:create) {|user| user.add_role(:guest)}

end

trait :authorized_user do

after(:create) {|user| user.add_role(:user)}

end

end

end

However, when I run this, my puts actually gives me this:

 Rspec says Current User: nil

So... why is the current user nil even though I create it with the omniauth mock?

Edit: current_user comes from my application helper, if that helps any.

Thanks in advance!

分享给朋友:
您可能感兴趣的文章:
随机阅读: