Skip to content

Commit

Permalink
Log when we've patched an invalid state or parent document URL
Browse files Browse the repository at this point in the history
  • Loading branch information
minhngocd authored and lauraghiorghisor-tw committed Dec 4, 2024
1 parent b262113 commit 42a8d48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ namespace :assets do
end

def delete_and_update_draft asset

Check failure on line 106 in lib/tasks/assets.rake

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/MethodDefParentheses: Use def with parentheses when there are parameters. (https://rubystyle.guide#method-parens)
asset.state = "uploaded" if asset.state.to_s == "deleted"
(asset.state = "uploaded"; puts "Patched state: #{asset.id}") if asset.state.to_s == "deleted"

Check failure on line 107 in lib/tasks/assets.rake

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/Semicolon: Do not use semicolons to terminate expressions. (https://rubystyle.guide#no-semicolon)
asset.destroy! unless asset.deleted?

asset.parent_document_url = nil if asset.parent_document_url&.include?("draft-origin")
(asset.parent_document_url = nil; puts "Patched Parent URL: #{asset.id}") if asset.parent_document_url&.include?("draft-origin")

Check failure on line 110 in lib/tasks/assets.rake

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Style/Semicolon: Do not use semicolons to terminate expressions. (https://rubystyle.guide#no-semicolon)
asset.draft = false
asset.save!
end
Expand Down
4 changes: 4 additions & 0 deletions spec/lib/tasks/assets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
FactoryBot.create(:asset, id: asset_id, replacement_id: replacement.id)

expected_output = <<~OUTPUT
Patched Parent URL: #{replacement.id}
Asset ID: #{asset_id} - OK. Draft replacement #{replacement.id} deleted and updated to false.
OUTPUT
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
Expand Down Expand Up @@ -99,6 +100,7 @@
replacement.save(validate: false)

Check failure on line 100 in spec/lib/tasks/assets_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Rails/SaveBang: Use `save!` instead of `save` if the return value is not checked. (https://rails.rubystyle.guide#save-bang)

expected_output = <<~OUTPUT
Patched state: #{replacement.id}
Asset ID: #{asset_id} - OK. Draft replacement #{replacement.id} deleted and updated to false.
OUTPUT
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
Expand All @@ -124,6 +126,7 @@
FactoryBot.create(:asset, replacement_id: asset.id)

expected_output = <<~OUTPUT
Patched Parent URL: #{asset_id}
Asset ID: #{asset_id} - is a replacement. Asset deleted and updated to false.
OUTPUT
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
Expand Down Expand Up @@ -152,6 +155,7 @@
asset.save(validate: false)

Check failure on line 155 in spec/lib/tasks/assets_spec.rb

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Rails/SaveBang: Use `save!` instead of `save` if the return value is not checked. (https://rails.rubystyle.guide#save-bang)

expected_output = <<~OUTPUT
Patched state: #{asset_id}
Asset ID: #{asset_id} - is a replacement. Asset deleted and updated to false.
OUTPUT
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
Expand Down

0 comments on commit 42a8d48

Please sign in to comment.