-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
assets:get_id_by_legacy_url_path
rake task
It seems unnecessarily laborious to have to run rails console commands (https://docs.publishing.service.gov.uk/manual/manage-assets.html#get-an-assets-id) in order to know what to pass to a rake task (https://docs.publishing.service.gov.uk/manual/manage-assets.html#redirect-an-asset). It should just be a rake task.
- Loading branch information
1 parent
864c6f7
commit 16de48d
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require "rails_helper" | ||
require "rake" | ||
|
||
RSpec.describe "assets.rake" do | ||
before do | ||
AssetManager::Application.load_tasks if Rake::Task.tasks.empty? | ||
end | ||
|
||
describe "get_id_by_legacy_url_path" do | ||
before do | ||
task.reenable # without this, calling `invoke` does nothing after first test | ||
end | ||
|
||
let(:task) { Rake::Task["assets:get_id_by_legacy_url_path"] } | ||
|
||
it "returns ID of asset by its legacy URL path" do | ||
id = "abc123def456ghi789" | ||
legacy_url_path = "/government/uploads/system/uploads/attachment_data/file/1234/document.pdf" | ||
FactoryBot.create(:whitehall_asset, id:, legacy_url_path:) | ||
|
||
expected_output = <<~OUTPUT | ||
Asset ID for #{legacy_url_path} is #{id}. | ||
OUTPUT | ||
|
||
expect { task.invoke(legacy_url_path) }.to output(expected_output).to_stdout | ||
end | ||
|
||
it "raises exception if no asset found" do | ||
expect { task.invoke("foo") }.to raise_error(Mongoid::Errors::DocumentNotFound) | ||
end | ||
end | ||
end |