diff --git a/app/controllers/html_variant_trials_controller.rb b/app/controllers/html_variant_trials_controller.rb index 00d212136..2a5bec0fe 100644 --- a/app/controllers/html_variant_trials_controller.rb +++ b/app/controllers/html_variant_trials_controller.rb @@ -1,6 +1,6 @@ class HtmlVariantTrialsController < ApplicationController def create - HtmlVariantTrial.delay.create(html_variant_id: params[:html_variant_id], article_id: params[:article_id]) + HtmlVariantTrialCreateJob.perform_later(html_variant_id: params[:html_variant_id], article_id: params[:article_id]) head :ok end end diff --git a/app/jobs/html_variant_trial_create_job.rb b/app/jobs/html_variant_trial_create_job.rb new file mode 100644 index 000000000..0552b1381 --- /dev/null +++ b/app/jobs/html_variant_trial_create_job.rb @@ -0,0 +1,7 @@ +class HtmlVariantTrialCreateJob < ApplicationJob + queue_as :html_variant_trial_create + + def perform(html_variant_id:, article_id:) + HtmlVariantTrial.create!(html_variant_id: html_variant_id, article_id: article_id) + end +end diff --git a/spec/jobs/html_variant_trial_create_job_spec.rb b/spec/jobs/html_variant_trial_create_job_spec.rb new file mode 100644 index 000000000..468a12d8b --- /dev/null +++ b/spec/jobs/html_variant_trial_create_job_spec.rb @@ -0,0 +1,6 @@ +require "rails_helper" +require "jobs/shared_examples/enqueues_job" + +RSpec.describe HtmlVariantTrialCreateJob, type: :job do + include_examples "#enqueues_job", "html_variant_trial_create", [{ html_variant_id: 789, article_id: 456 }] +end diff --git a/spec/requests/html_variant_trials_spec.rb b/spec/requests/html_variant_trials_spec.rb index 8f1c60da6..9edc1d9da 100644 --- a/spec/requests/html_variant_trials_spec.rb +++ b/spec/requests/html_variant_trials_spec.rb @@ -7,7 +7,7 @@ RSpec.describe "HtmlVariantTrials", type: :request do describe "POST /html_variant_trials" do it "rejects non-permissioned user" do - run_background_jobs_immediately do + perform_enqueued_jobs do post "/html_variant_trials", params: { article_id: article.id, html_variant_id: html_variant.id