[28171] Output claimed attachments on wiki representer

https://community.openproject.com/wp/28171
pull/6507/head
Oliver Günther 6 years ago
parent b9f77916c0
commit 223284c401
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 8
      lib/api/v3/attachments/attachable_representer_mixin.rb
  2. 29
      spec/features/wiki/attachment_upload_spec.rb

@ -60,7 +60,13 @@ module API
uncacheable: true
def attachments
attachments = represented.attachments.includes(:container)
attachments = represented.attachments.includes(:container).to_a
# Concat any claimed attachments on this resource
# (e.g., when new an coming back from backend with an error)
claimed = represented.attachments_claimed
attachments.concat(claimed) unless claimed.nil?
::API::V3::Attachments::AttachmentCollectionRepresenter.new(attachments,
attachments_by_resource,
current_user: current_user)

@ -87,4 +87,33 @@ describe 'Upload attachment to wiki page', js: true do
expect(page).to have_content('Image uploaded the second time')
expect(page).to have_selector('attachment-list-item', text: 'image.png', count: 2)
end
it 'can upload an image on the new wiki page and recover from an error without losing the attachment (Regression #28171)' do
visit project_wiki_path(project, 'test')
expect(page).to have_selector('#content_page_title')
expect(page).to have_selector('.work-package--attachments--drop-box')
# Upload image to dropzone
expect(page).to have_no_selector('.work-package--attachments--filename')
attachments.attach_file_on_input(image_fixture)
expect(page).to have_selector('.work-package--attachments--filename', text: 'image.png')
# Don't add anything to the editor so we result in an error
click_on 'Save'
expect(page).to have_selector('#errorExplanation', text: 'Content is invalid')
expect(page).to have_selector('.work-package--attachments--filename', text: 'image.png')
editor.in_editor do |container, editable|
editable.send_keys 'hello there.'
end
click_on 'Save'
expect(page).to have_selector('.controller-wiki.action-show')
expect(page).to have_selector('h2', text: 'Test')
expect(page).to have_selector('.work-package--attachments--filename', text: 'image.png')
end
end

Loading…
Cancel
Save