bicepjai
bicepjai

Reputation: 1665

testing logging in function of sorcery using rspec in rails 3.1

i have added include Sorcery::TestHelpers::Rails inside sorcery.rb my controller spec looks like

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

my controller looks like

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

i have User model migrated to my test environment, when i run the test it always ends up saying not logged in.

Upvotes: 0

Views: 1074

Answers (1)

sevenseacat
sevenseacat

Reputation: 25029

You're passing params[:session] into the method from your test, but in the action you're referencing params[:username] and params[:password].

Upvotes: 1

Related Questions