Skip to content

Commit

Permalink
Skip assets (with draft replacements) if the assets are draft or redi…
Browse files Browse the repository at this point in the history
…rected
  • Loading branch information
lauraghiorghisor-tw committed Nov 29, 2024
1 parent 2014381 commit ab9cc40
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/lib/tasks/assets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ab9cc40

Please sign in to comment.