diff --git a/app/controllers/application_controller/handles_devices.rb b/app/controllers/application_controller/handles_devices.rb index 8428b4b9a..8fc15b278 100644 --- a/app/controllers/application_controller/handles_devices.rb +++ b/app/controllers/application_controller/handles_devices.rb @@ -59,14 +59,12 @@ module ApplicationController::HandlesDevices # add device if needed http_user_agent = ENV['HTTP_USER_AGENT'] || request.env['HTTP_USER_AGENT'] - Delayed::Job.enqueue( - Observer::UserDeviceLogJob.new( - http_user_agent, - remote_ip, - user.id, - session[:user_device_fingerprint], - type, - ) + UserDeviceLogJob.perform_later( + http_user_agent, + remote_ip, + user.id, + session[:user_device_fingerprint], + type, ) end end diff --git a/app/jobs/user_device_log_job.rb b/app/jobs/user_device_log_job.rb new file mode 100644 index 000000000..ea2e1d735 --- /dev/null +++ b/app/jobs/user_device_log_job.rb @@ -0,0 +1,11 @@ +class UserDeviceLogJob < ApplicationJob + def perform(http_user_agent, remote_ip, user_id, fingerprint, type) + UserDevice.add( + http_user_agent, + remote_ip, + user_id, + fingerprint, + type, + ) + end +end diff --git a/app/models/observer/user_device_log_job.rb b/app/models/observer/user_device_log_job.rb deleted file mode 100644 index 72c4b2a34..000000000 --- a/app/models/observer/user_device_log_job.rb +++ /dev/null @@ -1,19 +0,0 @@ -class Observer::UserDeviceLogJob - def initialize(http_user_agent, remote_ip, user_id, fingerprint, type) - @http_user_agent = http_user_agent - @remote_ip = remote_ip - @user_id = user_id - @fingerprint = fingerprint - @type = type - end - - def perform - UserDevice.add( - @http_user_agent, - @remote_ip, - @user_id, - @fingerprint, - @type, - ) - end -end diff --git a/spec/jobs/user_device_log_job_spec.rb b/spec/jobs/user_device_log_job_spec.rb new file mode 100644 index 000000000..5c2305981 --- /dev/null +++ b/spec/jobs/user_device_log_job_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe UserDeviceLogJob, type: :job do + + let!(:user) { create(:user) } + + it 'executes user device log job' do + expect do + described_class.perform_now( + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36', + '172.0.0.1', + user.id, + 'fingerprintABC123', + 'session', + ) + end.to change { + UserDevice.where( + user_id: user.id, + ).count + }.by(1) + end +end