set the user email if inviting by email

This commit is contained in:
Maxwell Salzberg 2011-08-17 14:56:31 -07:00
parent 4ed684491d
commit e0fb8a08cb
3 changed files with 24 additions and 2 deletions

View file

@ -71,7 +71,8 @@ class Invitation < ActiveRecord::Base
# @return [Invitation] self # @return [Invitation] self
def send! def send!
self.attach_recipient! self.attach_recipient!
puts self.recipient.inspect
# Sets an instance variable in User (set by devise invitable) # Sets an instance variable in User (set by devise invitable)
# This determines whether an email should be sent to the recipient. # This determines whether an email should be sent to the recipient.
recipient.skip_invitation = self.skip_email? recipient.skip_invitation = self.skip_email?

View file

@ -92,7 +92,7 @@ class User < ActiveRecord::Base
user = User.new user = User.new
user.generate_keys user.generate_keys
user.send(:generate_invitation_token) user.send(:generate_invitation_token)
#user.invitations_to_me << invitation user.email = invitation.identifier if invitation.service == 'email'
# we need to make a custom validator here to make this safer # we need to make a custom validator here to make this safer
user.save(:validate => false) user.save(:validate => false)
user user

View file

@ -367,6 +367,27 @@ describe User do
end end
end end
describe '.find_or_create_by_invitation' do
end
describe '.create_from_invitation!' do
before do
@identifier = 'max@foobar.com'
@inv = Factory.build(:invitation, :admin => true, :service => 'email', :identifier => @identifier)
@user = User.create_from_invitation!(@inv)
end
it 'creates a persisted user' do
@user.should be_persisted
end
it 'sets the email if the service is email' do
@user.email.should == @inv.identifier
end
end
describe 'update_user_preferences' do describe 'update_user_preferences' do
before do before do
@pref_count = UserPreference::VALID_EMAIL_TYPES.count @pref_count = UserPreference::VALID_EMAIL_TYPES.count