From 3573ab24aee0a0d033614931b21bd1aba2b24416 Mon Sep 17 00:00:00 2001 From: Steven van Driel Date: Thu, 30 May 2024 15:18:13 +0200 Subject: [PATCH] Use should_skip_webflow_sync? in sync_job --- app/jobs/webflow_sync/initial_sync_job.rb | 2 +- spec/jobs/webflow_sync/initial_sync_job_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/jobs/webflow_sync/initial_sync_job.rb b/app/jobs/webflow_sync/initial_sync_job.rb index 54b2e54..064b6dd 100644 --- a/app/jobs/webflow_sync/initial_sync_job.rb +++ b/app/jobs/webflow_sync/initial_sync_job.rb @@ -5,7 +5,7 @@ class InitialSyncJob < ApplicationJob def perform(collection_slug) model_class = collection_slug.underscore.classify.constantize model_class.where(webflow_item_id: nil).find_each do |record| - next if record.webflow_site_id.blank? + next if record.should_skip_webflow_sync? client(record.webflow_site_id).create_item(collection_id: record.webflow_collection_id, record:) end diff --git a/spec/jobs/webflow_sync/initial_sync_job_spec.rb b/spec/jobs/webflow_sync/initial_sync_job_spec.rb index 4e40cc2..7b735ce 100644 --- a/spec/jobs/webflow_sync/initial_sync_job_spec.rb +++ b/spec/jobs/webflow_sync/initial_sync_job_spec.rb @@ -8,9 +8,16 @@ end before(:each) do + @skip_webflow_sync = WebflowSync.configuration.skip_webflow_sync + WebflowSync.configuration.skip_webflow_sync = false + allow(Webflow::Client).to receive(:new).and_return(webflow_mock_client) end + after(:each) do + WebflowSync.configuration.skip_webflow_sync = @skip_webflow_sync # rubocop:disable RSpec/InstanceVariable + end + it 'assigns webflow_item_id to record' do article = create(:article) @@ -25,7 +32,10 @@ end it 'raises an error when it cannot find a webflow collection' do + WebflowSync.configuration.skip_webflow_sync = true create(:article) + WebflowSync.configuration.skip_webflow_sync = false + error_message = "Cannot find collection articles for Webflow site #{ENV.fetch('WEBFLOW_SITE_ID')}" expect do