2012-01-16 309 views
0

我已經添加include Sorcery::TestHelpers::Rails sorcery.rb 我的控制器規範內部看起來像測試記錄軌道3.1

describe "success" do 
    before(:each) do 
    @user = Factory(:user) 
    @attr = { :username => @user.username, :password => @user.password } 
    end 
    it "should sign the user in" do 
    post :create, :session => @attr 
    # controller.current_user.should == @user 
    controller.should be_logged_in 
    end 
end 

我的控制器看起來像

class SessionsController < ApplicationController 
    def create 
    user = login(params[:username], params[:password], params[:remember_me]) 
    if user 
     redirect_back_or_to root_url, :notice => "Logged in!" 
    else 
     flash.now.alert = "Email or password was invalid" 
     render :new 
    end 
    end 
end 

我有用戶模型遷移到我的測試環境,當我運行測試時,它總是說沒有登錄。

+0

看起來好像巫術方法在rspec內部沒有被調用。任何想法讚賞? – bicepjai 2012-01-17 00:55:49

回答

1

您正在將params[:session]傳入方法從你的測試,但在你參考的行動params[:username]params[:password]