Skip to content

Commit

Permalink
Merge pull request #1587 from alphagov/update-draft-deleted-assets
Browse files Browse the repository at this point in the history
Allow updates to draft deleted assets
  • Loading branch information
lauraghiorghisor-tw authored Jan 8, 2025
2 parents a4089e8 + aab3b33 commit ae6696c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class AssetsController < BaseAssetsController
before_action :restrict_request_format

def update
@asset = find_asset
@asset = Asset.undeleted.or(Asset.where(draft: true)).find(params[:id])

if @asset.update(asset_params)
render json: AssetPresenter.new(@asset, view_context).as_json(status: :success)
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/assets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,22 @@

expect(body["draft"]).to be_truthy
end

it "changes draft state for draft deleted asset" do
asset.update!(deleted_at: 1.hour.ago, draft: true)

put :update, params: { id: asset.id, asset: attributes.merge(draft: false) }

expect(asset.reload).not_to be_draft
end

it "preserves draft state for live deleted asset" do
asset.update!(deleted_at: 1.hour.ago, draft: false)

put :update, params: { id: asset.id, asset: attributes.merge(draft: true) }

expect(asset.reload).not_to be_draft
end
end
end
end
Expand Down

0 comments on commit ae6696c

Please sign in to comment.