From fb0e7dc0b2c9c1bb2a8926b34892f617f936a870 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 25 Mar 2015 23:29:37 +0530 Subject: [PATCH] FIX: do not delete already redeemed invite --- app/models/invite_redeemer.rb | 2 +- spec/models/invite_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/invite_redeemer.rb b/app/models/invite_redeemer.rb index 76361996bc5..dae43a92bc9 100644 --- a/app/models/invite_redeemer.rb +++ b/app/models/invite_redeemer.rb @@ -117,6 +117,6 @@ InviteRedeemer = Struct.new(:invite, :username, :name) do end def delete_duplicate_invites - Invite.where('invites.email = ? and invites.id != ?', invite.email, invite.id).delete_all + Invite.where('invites.email = ? AND redeemed_at IS NULL AND invites.id != ?', invite.email, invite.id).delete_all end end diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb index ef57e635c87..8c538b70943 100644 --- a/spec/models/invite_spec.rb +++ b/spec/models/invite_spec.rb @@ -198,6 +198,13 @@ describe Invite do expect(duplicate_invite).to be_nil end + it 'does not delete already redeemed invite' do + redeemed_invite = Fabricate(:invite, email: invite.email, invited_by: another_user, redeemed_at: 1.day.ago) + invite.redeem + used_invite = Invite.find_by(id: redeemed_invite.id) + expect(used_invite).not_to be_nil + end + end context 'enqueues a job to email "set password" instructions' do