scambra/devise_invitable — comment on commit a7105842f77cfaf7a9f579a43f7d1a324ada8292
File: lib/devise_invitable/model.rb line 52
By scambra:

User.invite! try to find if user exists, or it's invited to resend the invitation, and finally send the invitation, so it's easier to send invitations you don't need write anything more than User.invite!(params[:email]) for example. Block was added as a request to allow some custom code.

If you build the user and call invite! on the instance you aren't using API as recommended in the documentation, so you must call valid? if you want to ensure user is valid. Also you are skipping resend invitation because you don't use User.invite!, for example.

Recommended way is User.invite! and it's not right to call valid? in invite! instance because it would run validations twice when you use default InvitationsController.

Also, I think you are testing code which is tested inside devise_invitable. Have you overrided invitations controller? Then you should test created record has right attributes