Testing the User Model with Rspec, Devise, and Factory Girl?

In Factory Girl, this create attributes: @user_attr = Factory. Attributes_for(:user) And this create a new instance: @user = Factory(:user) So change the above and try: User. Create!(@user_attr) In depth, what you're trying to do fails because: you were creating a new unsaved instance password is a virtual attribute the attributes of the instance do not contain the virtual attributes (I guess).

Unfortunately that didn't seem to work. I do want to build attributes though I think, so that I can easily manipulate @user for future tests using @user.attributes. Merge(:name => "Whatever").

That's why I was trying User. Create!(@user. Attributes).

I tried doing User. Create!(@user) but it failed, this time saying that the Email was blank, and the Password was blank. – ardavis May 17 at 14:30 Read my updated answer and keep me updated – apneadiving May 17 at 14:34 That worked.

That's very interesting. I guess what confuses me now is that I'm not sure why my other one seems to work. I have a "Role" model, and I do the same thing, using @role = Factory.

Build(:role), and Role. Create!(@role. Attributes) And it seems to pass.Interesting.

Thank you sir. – ardavis May 17 at 14:38 Your test here failed because of the virtual attributes – apneadiving May 17 at 14:41 1 No at all, they are just a mean to an end: basically, you have no password_confirmation column in your model. See here for more info: railscasts.Com/episodes/16-virtual-attributes – apneadiving May 17 at 14:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions