Skip to content

Instantly share code, notes, and snippets.

@pgwillia
Last active September 29, 2023 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgwillia/c0eeac74f27b7d3adbece43f7cc4548c to your computer and use it in GitHub Desktop.
Save pgwillia/c0eeac74f27b7d3adbece43f7cc4548c to your computer and use it in GitHub Desktop.
Download target changes after editing metadata https://github.com/ualbertalib/jupiter/issues/3248#
require 'application_system_test_case'
class ItemEditTest < ApplicationSystemTestCase
test 'download path is stable after edit' do
admin = users(:user_admin)
item = items(:item_admin)
item.save
# Need to add file to item to be able to go through editing wizard.
File.open(file_fixture('pdf-sample.pdf'), 'r') do |file|
item.add_and_ingest_files([file])
end
login_user admin
file = item.files.first
path_before = Rails.application.routes.url_helpers.file_download_item_url(id: file.record.id, file_set_id: file.fileset_uuid)
visit item_path item
click_on I18n.t('edit')
select('Fancier Collection', from: 'draft_item_collection_id_')
click_on I18n.t('items.draft.save_and_continue')
click_on I18n.t('items.draft.save_and_continue')
click_on I18n.t('items.draft.save_and_continue')
click_on I18n.t('items.draft.save_and_deposit_edits')
assert_text I18n.t('items.draft.successful_deposit')
file = item.files.first
path_after = Rails.application.routes.url_helpers.file_download_item_url(id: file.record.id, file_set_id: file.fileset_uuid)
assert(path_before, path_after)
logout_user
end
end
require 'test_helper'
class ItemDraftLifecycleTest < ActionDispatch::IntegrationTest
test 'path is stable when files are the same' do
item = items(:item_fancy)
user = users(:user_admin)
File.open(file_fixture('text-sample.txt'), 'r') do |file|
item.add_and_ingest_files([file])
end
item.reload
file = item.files.first
path_before = Rails.application.routes.url_helpers.file_download_item_url(id: file.record.id, file_set_id: file.fileset_uuid)
draft = DraftItem.from_item(item, for_user: user)
item = Item.from_draft(draft)
item.save!
file = item.files.first
path_after = Rails.application.routes.url_helpers.file_download_item_url(id: file.record.id, file_set_id: file.fileset_uuid)
assert(path_before, path_after)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment