I'm learning about RSpec, and I'm calling a method inside a model, from spec file, but the method have a background job, my questions are; How can I set spec to waiting for a response from the backgroound job? Is it possible?
Thanks for your help!!!!
My Rspec File: user_spec.rb
require 'rails_helper'
RSpec.describe User, type: :model do
let(:user) { user.create(name: "Test User Name",last_name: "") }
describe "existing user instance" do
it "fetch last name" do
user.update_last_name!
expect(user.last_name).to eq("Test Last Name")
end
end
end
My Model File: user.rb
class User < ApplicationRecord
def update_last_name!
UpdateLastNameJob.perform_later(self.id,"Test Last Name")
end
end
My Background Job Working in reddis: update_last_name_job.rb
class UpdateLastNameJob < ApplicationJob
@queue = :default
def perform(user_id,last_name)
@user = User.find(user_id)
@user.last_name = last_name
@user.save
end
end