Skip to content

Commit

Permalink
wip on factories
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraghiorghisor-tw committed Dec 9, 2024
1 parent 4a2c69e commit 5934561
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/factories/attachment_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
content_type { AttachmentUploader::PDF_CONTENT_TYPE }

after(:build) do |attachment_data|
attachment_data.assets << build(:asset, asset_manager_id: "asset_manager_id_original", variant: Asset.variants[:original], filename: attachment_data.filename)
attachment_data.assets << build(:asset, asset_manager_id: "asset_manager_id", variant: Asset.variants[:original], filename: attachment_data.filename)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/asset_access_options_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def setup_publishing_api_for(edition)

def add_file_attachment_with_asset(filename, to:)
to.attachments << FactoryBot.build(
:csv_attachment,
:file_attachment,
title: filename,
attachable: to,
)
Expand Down
8 changes: 4 additions & 4 deletions test/integration/attachment_deletion_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class AttachmentDeletionIntegrationTest < ActionDispatch::IntegrationTest
context "given a draft document with multiple file attachments" do
let(:managing_editor) { create(:managing_editor) }
let(:first_attachment) { build(:csv_attachment, attachable: edition, title: "first attachment") }
let(:first_asset_id) { "asset_manager_id" }
let(:first_asset_id) { first_attachment.attachment_data.assets.first.asset_manager_id }
let(:second_attachment) { build(:file_attachment, attachable: edition) }
let(:second_asset_id_original) { "asset_manager_id_original" }
let(:second_asset_id) { second_attachment.attachment_data.assets.first.asset_manager_id }
let(:edition) { create(:news_article) }

before do
Expand All @@ -24,7 +24,7 @@ class AttachmentDeletionIntegrationTest < ActionDispatch::IntegrationTest
stub_publishing_api_expanded_links_with_taxons(edition.content_id, [])

stub_asset(first_asset_id)
stub_asset(second_asset_id_original)
stub_asset(second_asset_id)

edition.attachments << [first_attachment, second_attachment]
edition.save!
Expand Down Expand Up @@ -64,7 +64,7 @@ class AttachmentDeletionIntegrationTest < ActionDispatch::IntegrationTest

it "deletes all corresponding assets in Asset Manager" do
Services.asset_manager.expects(:delete_asset).once.with(first_asset_id)
Services.asset_manager.expects(:delete_asset).once.with(second_asset_id_original)
Services.asset_manager.expects(:delete_asset).once.with(second_asset_id)
assert_equal AssetManagerAttachmentMetadataWorker.jobs.count, 2

AssetManagerAttachmentMetadataWorker.drain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AttachmentDraftStatusIntegrationTest < ActionDispatch::IntegrationTest

before do
setup_publishing_api_for(edition)
attachable.attachments << build(:csv_attachment, attachable:)
attachable.attachments << build(:file_attachment, attachable:)
attachable.save!
end

Expand Down
2 changes: 1 addition & 1 deletion test/integration/attachment_link_header_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AttachmentLinkHeaderIntegrationTest < ActionDispatch::IntegrationTest
let(:topic_taxon) { build(:taxon_hash) }

before do
attachable.attachments << build(:csv_attachment, attachable:)
attachable.attachments << build(:file_attachment, attachable:)
attachable.save!
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AttachmentRedirectDueToUnpublishingIntegrationTest < ActionDispatch::Integ
stub_publishing_api_expanded_links_with_taxons(edition.content_id, [])
stub_asset(asset_manager_id)

attachable.attachments << build(:csv_attachment, attachable:)
attachable.attachments << build(:file_attachment, attachable:)
attachable.save!
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit/app/models/attachment_data_visibility_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AttachmentDataVisibilityTest < ActiveSupport::TestCase

context "when attachment is replaced" do
before do
replacement_attachment_data = build(:attachment_data_for_csv, to_replace_id: attachment_data.id, attachable:)
replacement_attachment_data = build(:attachment_data, to_replace_id: attachment_data.id, attachable:)
attachment.update!(attachment_data: replacement_attachment_data)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class AssetManagerUpdateAssetWorkerTest < ActiveSupport::TestCase
end
let(:attachment_data) { FactoryBot.create(:attachment_data, attachable: create(:draft_publication)) }

test "updates an attachment and its variant" do
AssetManager::AssetUpdater.expects(:call).with("asset_manager_id_original", auth_bypass_id_attributes)
test "updates a file attachment's original asset" do
AssetManager::AssetUpdater.expects(:call).with("asset_manager_id", auth_bypass_id_attributes)

AssetManagerUpdateAssetWorker.perform_async_in_queue("asset_manager_updater", "AttachmentData", attachment_data.id, auth_bypass_id_attributes)
AssetManagerUpdateAssetWorker.drain
Expand Down
8 changes: 4 additions & 4 deletions test/unit/lib/tasks/asset_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AssetManagerTest < ActiveSupport::TestCase
%w[unpublished superseded].each do |state|
context "for an asset attached only to a #{state} edition" do
let(:edition) { create(:"#{state}_publication") }
let(:attachment) { create(:csv_attachment, attachable: edition) }
let(:attachment) { create(:file_attachment, attachable: edition) }

context "when asset is not deleted from asset manager" do
before do
Expand Down Expand Up @@ -57,7 +57,7 @@ class AssetManagerTest < ActiveSupport::TestCase

context "for an asset attached only to a draft edition" do
let(:edition) { create(:draft_publication) }
let(:attachment) { create(:csv_attachment, attachable: edition) }
let(:attachment) { create(:file_attachment, attachable: edition) }

context "when asset is not deleted from asset manager" do
before do
Expand Down Expand Up @@ -114,7 +114,7 @@ class AssetManagerTest < ActiveSupport::TestCase
end

context "for an asset attached to both published and superseded editions" do
let(:attachment) { create(:csv_attachment) }
let(:attachment) { create(:file_attachment) }
let(:edition_1) { create(:superseded_publication, :with_alternative_format_provider, attachments: [attachment]) }
let(:edition_2) { create(:published_publication, :with_alternative_format_provider, attachments: [attachment]) }

Expand Down Expand Up @@ -144,7 +144,7 @@ class AssetManagerTest < ActiveSupport::TestCase
end

context "for an asset attached only to something that is not an edition" do
let(:attachment) { create(:csv_attachment, attachable: create(:double)) }
let(:attachment) { create(:file_attachment, attachable: create(:double)) }

test "it should include no output in the report" do
assert_output("") { task.invoke }
Expand Down
4 changes: 2 additions & 2 deletions test/unit/lib/whitehall/asset_manager_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class Whitehall::AssetManagerStorage::FileTest < ActiveSupport::TestCase
end

test "returns file url using asset_manager_id when the model has the original asset" do
model = build(:attachment_data_for_csv, attachable: build(:draft_edition, id: 1))
model = build(:attachment_data, attachable: build(:draft_edition, id: 1))
model.save!
model.reload

assert_equal "http://assets-host/media/asset_manager_id/sample.csv", model.file.url
assert_equal "http://assets-host/media/asset_manager_id/greenpaper.pdf", model.file.url
end

test "returns file url using asset_manager_id when the model has an asset variant" do
Expand Down

0 comments on commit 5934561

Please sign in to comment.