Change the way that id_code was created (#5348) [deploy]

The column id_code was created with a job in an after create callback,
that was replaced by an inline creation of the attribute
This commit is contained in:
Pablo Ifrán 2020-01-08 18:21:39 -03:00 committed by Molly Struve
parent e09e46ec99
commit f5d3593d4f
2 changed files with 9 additions and 1 deletions

View file

@ -247,7 +247,7 @@ class Comment < ApplicationRecord
end
def create_id_code
Comments::CreateIdCodeJob.perform_later(id)
update_column(:id_code, id.to_s(26))
end
def touch_user

View file

@ -248,6 +248,14 @@ RSpec.describe Comment, type: :model do
end
context "when callbacks are triggered after create" do
it "creates an id code" do
comment = build(:comment, user: user, commentable: article)
comment.save
expect(comment.reload.id_code).to eq(comment.id.to_s(26))
end
it "enqueue a worker to create the first reaction" do
comment = build(:comment, user: user, commentable: article)