NoamB/sorcery — Issue #95: Testing CREATE Session and User Activation
Author: fzingg
Created: 2011-10-17 08:14:06+00:00
State: open

When you use the **User_activation** module, after a user signed up, his **activation_state** is = "pending", thanks to the function **prevent_not_active_login** in _lib/sorcery/model/submodules/user_activation.rb_.

The problem is when testing the CREATE Session Controller.
Because the activation_state of the test User is "pending", so it will not log the user in.

So, maybe it's not the best way, but you can add a new function **activate_user(user)** in _lib/sorcery/test_helpers/rails.rb_

**rails.rb**

def activate_user(user = nil)
@user ||= user
@user.send(:"activation_token=", nil)
@user.send(:"activation_state=", "active")
@user.save!(:validate => false)
end

**session_controller_spec.rb**

describe "POST\'create'" do
describe "Sign in with valid email and password" do

before(:each) do
@user = Factory(:user)
@attr = { :email => @user.email, :password => "foobar", :remember_me => 1 }
activate_user(@user)
end

it "should sign the user in" do
post :create, :email => @attr[:email], :password => @attr[:password], :remember_me => 1
controller.current_user.should == @user
controller.should be_logged_in
end
end
end