Skip to content

Commit

Permalink
Enable DefaultNewsOrganisationImageData to have assets and use non-le…
Browse files Browse the repository at this point in the history
…gacy-url

Co-authored-by: Iris Lau <[email protected]>
  • Loading branch information
syed-ali-tw and yuetylauiris committed Oct 19, 2023
1 parent 0bdc607 commit f6994d7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/default_news_organisation_image_data.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
class DefaultNewsOrganisationImageData < ApplicationRecord
has_many :assets,
as: :assetable,
inverse_of: :assetable

mount_uploader :file, FeaturedImageUploader, mount_on: :carrierwave_image
validates :file, presence: true
end
2 changes: 1 addition & 1 deletion lib/whitehall/asset_manager_storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_asset
def self.use_non_legacy_behaviour?(model)
return unless model

return true if model.instance_of?(AttachmentData) || model.instance_of?(ImageData) || model.instance_of?(Organisation)
return true if model.instance_of?(AttachmentData) || model.instance_of?(ImageData) || model.instance_of?(Organisation) || model.instance_of?(DefaultNewsOrganisationImageData)

model.respond_to?("use_non_legacy_endpoints") && model.use_non_legacy_endpoints
end
Expand Down
8 changes: 8 additions & 0 deletions test/unit/lib/whitehall/asset_manager_storage_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ def assets_protected?
@uploader.store!(@file)
end
end

test "should call AssetManagerCreateAssetWorker if uploader model is DefaultNewsOrganisationImageData" do
model = build(:default_news_organisation_image_data)
@uploader.stubs(:model).returns(model)

AssetManagerCreateAssetWorker.expects(:perform_async).with(anything, anything, anything, anything, anything, anything)
@uploader.store!(@file)
end
end

class Whitehall::AssetManagerStorage::FileTest < ActiveSupport::TestCase
Expand Down

0 comments on commit f6994d7

Please sign in to comment.