Permalink
Browse files

Merge pull request #419 from zawaideh/master

confirmation emails get sent inifinitely when an invited user signs up
  • Loading branch information...
2 parents bbeeff8 + d1529cc commit 154fc51c41e4083dc288126dbb7adc87502b591f @scambra scambra committed Jan 2, 2014
@@ -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
@@ -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
@@ -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.
@@ -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

0 comments on commit 154fc51

Please sign in to comment.