I'm calling a method inside a model, from a spec file. However, the method has a background job. How can I set spec to waiting for a response from the background job? Is it possible?
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 endend
My Model File: user.rb
class User < ApplicationRecord def update_last_name! UpdateLastNameJob.perform_later(self.id,"Test Last Name") endend
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 endend