A platform for community discussion. Free, open, simple.
FIX: Don’t run validations when invalidating invites
Loïc Guitaut37b71c5903f3
diff --git a/app/models/invite.rb b/app/models/invite.rbindex 66697d34dfb..191da0818ca 100644--- a/app/models/invite.rb+++ b/app/models/invite.rb@@ -274,10 +274,12 @@ class Invite < ActiveRecord::Baseenddef self.invalidate_for_email(email)- invite = Invite.find_by(email: Email.downcase(email))- invite.update!(invalidated_at: Time.zone.now) if invite+ Invite.find_by(email: Email.downcase(email))&.invalidate!+ end- invite+ def invalidate!+ update_attribute(:invalidated_at, Time.current)+ selfenddef resend_invitediff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rbindex d467b30e8f4..e93f09561a1 100644--- a/spec/models/invite_spec.rb+++ b/spec/models/invite_spec.rb@@ -478,7 +478,7 @@ RSpec.describe Invite doendend- describe "#invalidate_for_email" do+ describe ".invalidate_for_email" doit "returns nil if there is no invite for the given email" doinvite = Invite.invalidate_for_email("[email protected]")expect(invite).to eq(nil)@@ -600,4 +600,29 @@ RSpec.describe Invite doendendend++ describe "#invalidate!" do+ subject(:invalidate) { invite.invalidate! }++ fab!(:invite) { Fabricate(:invite) }++ before { freeze_time }++ it "invalidates the invite" do+ expect { invalidate }.to change { invite.invalidated_at }.to Time.current+ end++ it "returns the invite" do+ expect(invalidate).to eq invite+ end++ context "when the invite is in an invalid state" do+ before { invite.update_attribute(:custom_message, "a" * 2000) }++ it "still invalidates the invite" do+ expect(invite).to be_invalid+ expect { invalidate }.to change { invite.invalidated_at }.to Time.current+ end+ end+ endend