Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
minhngocd committed Nov 28, 2024
1 parent c31b750 commit 65dbd8e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/tasks/assets.rake
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ namespace :assets do
end
end

desc "Bulk fix assets"
namespace :bulk_fix do
desc "Bulk fix assets"
task :update_replacement_draft, %i[csv_path] => :environment do |_t, args|
csv_path = args.fetch(:csv_path)
CSV.foreach(csv_path, headers: false) do |row|
puts row[1]
original_asset_id = row[0]
original_asset = Asset.find(original_asset_id)

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

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Lint/UselessAssignment: Useless assignment to variable - `original_asset`. Did you mean `original_asset_id`? (https://rubystyle.guide#underscore-unused-vars)
# replacement_asset = original_asset.replacement
"Asset ID: abc123def456ghi789 - SKIPPED. No replacement asset found."

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

View workflow job for this annotation

GitHub Actions / Lint Ruby / Run RuboCop

Lint/Void: Literal `"Asset ID: abc123def456ghi789 - SKIPPED. No replacement asset found."` used in void context.
puts row[0]
end
end
end
Expand Down
8 changes: 6 additions & 2 deletions spec/lib/tasks/assets_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
)
end

# TODO: add batch parameter tests

# 80k assets in this category - we're updating their replacements (replacements are expected to be in draft and deleted)
describe "assets:bulk_fix:update_replacement_draft" do
let(:task) { Rake::Task["assets:bulk_fix:update_replacement_draft"] }
Expand Down Expand Up @@ -93,6 +91,7 @@
end

it "skips the asset and print exception if asset is not found" do
byebug
expected_output = <<~OUTPUT
"Asset ID: #{asset_id} - SKIPPED. No asset found."
OUTPUT
Expand All @@ -103,11 +102,16 @@
replacement = FactoryBot.create(:asset)
FactoryBot.create(:asset, id: asset_id, replacement_id: replacement.id)
replacement.delete

expected_output = <<~OUTPUT
"Asset ID: #{asset_id} - SKIPPED. No replacement asset found."
OUTPUT
expect { task.invoke(filepath) }.to output(expected_output).to_stdout
end

# TODO: add batch parameter tests
# it "should start from where last left off if kicked" do
# end
end

# 30k assets in this category - we're updating the assets themselves (these are the ones that have AD not deleted and not replaced in WH)
Expand Down

0 comments on commit 65dbd8e

Please sign in to comment.