Skip to content

Commit

Permalink
Merge pull request scambra#419 from zawaideh/master
Browse files Browse the repository at this point in the history
confirmation emails get sent inifinitely when an invited user signs up
  • Loading branch information
scambra committed Jan 2, 2014
2 parents bbeeff8 + d1529cc commit 154fc51
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Expand Up @@ -7,6 +7,7 @@ def build_resource(hash = nil)
self.resource = resource_class.where(:email => hash[:email], :encrypted_password => '').first
if self.resource
self.resource.attributes = hash
self.resource.send_confirmation_instructions if self.resource.confirmation_required_for_invited?
self.resource.accept_invitation
end
end
Expand Down
11 changes: 5 additions & 6 deletions lib/devise_invitable/model.rb
Expand Up @@ -37,8 +37,6 @@ module Invitable

include ActiveSupport::Callbacks
define_callbacks :invitation_accepted
before_update :generate_confirmation_token, :if => :confirmation_required_for_invited?
after_update :send_on_create_confirmation_instructions, :if => :confirmation_required_for_invited?

attr_writer :skip_password

Expand Down Expand Up @@ -164,16 +162,17 @@ def encrypted_invitation_token
self.invitation_token
end

def confirmation_required_for_invited?
respond_to?(:confirmation_required?, true) && confirmation_required?
end

protected
# Overriding the method in Devise's :validatable module so password is not required on inviting
def password_required?
!@skip_password && super
end

def confirmation_required_for_invited?
respond_to?(:confirmation_required?, true) && confirmation_required? && invitation_accepted?
end


# Checks if the invitation for the user is within the limit time.
# We do this by calculating if the difference between today and the
# invitation sent date does not exceed the invite for time configured.
Expand Down
9 changes: 9 additions & 0 deletions test/functional/registrations_controller_test.rb
Expand Up @@ -33,6 +33,15 @@ def setup
end

@invitee = User.where(:email => invitee_email).first

# do not send emails on model changes
assert_difference('ActionMailer::Base.deliveries.size', 0) do
@invitee.bio = "I am a robot"
@invitee.save!
@invitee.bio = "I am a human"
@invitee.save!
end

assert_present @invitee.encrypted_password
assert_not_nil @invitee.invitation_accepted_at
assert_nil @invitee.invitation_token
Expand Down

0 comments on commit 154fc51

Please sign in to comment.