Authentication and password and password attributes are not available?

I am trying to verify that mine successfully creates a new user after logging in (using authlogic). Ive added some new fields to the user, so I just want to make sure that the user is saved correctly.

The problem is that by creating a valid factory user, whenever I try to grab its attributes for publication in the create method, the password and password confirmation are omitted. I presuem is a security method that authlogic runs in the background. This leads to test failures and test failure.

I am wondering how can I get around this problem? I could just type the attributes manually, but that doesn't seem very dry.

context "on POST to :create" do context "on posting a valid user" do setup do @user = Factory.build(:user) post :create, :user => @user.attributes end should "be valid" do assert @user.valid? end should_redirect_to("users sentences index page") { sentences_path() } should "add user to the db" do assert User.find_by_username(@user.username) end end ##User factory Factory.define :user do |f| f.username {Factory.next(:username) } f.email { Factory.next(:email)} f.password_confirmation "password" f.password "password" f.native_language {|nl| nl.association(:language)} f.second_language {|nl| nl.association(:language)} end 
+1
source share
1 answer

You definitely cannot read the password and configuration_password from the User object. You need to combine in :password and :password_confirmation with the hash @user.attributes . If you store this hash somewhere along with the rest of your factory definitions, it is not super dry, but better than hard coding it to your test.

+2
source