diff --git a/lib/tasks/assets.rake b/lib/tasks/assets.rake index c543066a..41ea7d2b 100644 --- a/lib/tasks/assets.rake +++ b/lib/tasks/assets.rake @@ -67,6 +67,16 @@ namespace :assets do next end + unless original_asset.redirect_url.nil? + puts "Asset ID: #{original_asset_id} - NOOP. Asset is redirected." + next + end + + if original_asset.draft? + puts "Asset ID: #{original_asset_id} - NOOP. Asset is in draft." + next + end + if replacement_asset.nil? puts "Asset ID: #{original_asset_id} - SKIPPED. No replacement asset found." next diff --git a/spec/lib/tasks/assets_spec.rb b/spec/lib/tasks/assets_spec.rb index 6e992297..7a0b7435 100644 --- a/spec/lib/tasks/assets_spec.rb +++ b/spec/lib/tasks/assets_spec.rb @@ -57,6 +57,24 @@ expect { task.invoke(filepath) }.to output(expected_output).to_stdout end + it "skips the asset if asset is itself in draft" do + FactoryBot.create(:asset, id: asset_id, draft: true) + + expected_output = <<~OUTPUT + Asset ID: #{asset_id} - NOOP. Asset is in draft. + OUTPUT + expect { task.invoke(filepath) }.to output(expected_output).to_stdout + end + + it "skips the asset if asset is itself redirected" do + FactoryBot.create(:asset, id: asset_id, draft: true, redirect_url: "https://example.com") + + expected_output = <<~OUTPUT + Asset ID: #{asset_id} - NOOP. Asset is redirected. + OUTPUT + expect { task.invoke(filepath) }.to output(expected_output).to_stdout + end + it "skips the asset and prints exception if replacement asset is not found" do replacement = FactoryBot.create(:asset) FactoryBot.create(:asset, id: asset_id, replacement_id: replacement.id)