DEV: Let `create!` handle the check for persistence.

DEV: Let `create!` handle the check for persistence.

This is unlikely to fail but we want to know when it does.

From 86926f4aee3539718fb42a6f5638404b9cf003ee Mon Sep 17 00:00:00 2001
From: Guo Xiang Tan <tgx_world@hotmail.com>
Date: Wed, 12 Dec 2018 08:36:13 +0800
Subject: [PATCH] DEV: Let `create!` handle the check for persistence.

This is unlikely to fail but we want to know when it does.

diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index dd8790b..77dba98 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -220,8 +220,7 @@ class InvitesController < ApplicationController
   end
 
   def send_activation_email(user)
-    email_token = user.email_tokens.create(email: user.email)
-    raise ActiveRecord::RecordInvalid.new(email_token) if !email_token.persisted?
+    email_token = user.email_tokens.create!(email: user.email)
 
     Jobs.enqueue(:critical_user_email,
                  type: :signup,

GitHub

2 Likes