diff --git a/.rubocop.yml b/.rubocop.yml index 24dfbb561..7523e0e48 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,7 +11,7 @@ AllCops: - 'script/**/*' - 'vendor/**/*' - 'spec/internal/**/*' - - 'curation_concerns-models/app/models/concerns/curation_concerns/generic_file/export.rb' + - 'curation_concerns-models/app/models/concerns/curation_concerns/file_set/export.rb' Lint/AssignmentInCondition: Exclude: @@ -25,20 +25,20 @@ Metrics/AbcSize: Metrics/CyclomaticComplexity: Exclude: - - 'curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb' - - 'app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb' + - 'curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb' + - 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb' - 'app/helpers/curation_concerns/curation_concerns_helper_behavior.rb' - 'app/helpers/curation_concerns/attribute_helper.rb' - - 'curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb' + - 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb' - 'curation_concerns-models/app/actors/curation_concerns/work_actor_behavior.rb' Metrics/PerceivedComplexity: Exclude: - - 'curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb' - - 'app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb' + - 'curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb' + - 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb' - 'app/helpers/curation_concerns/curation_concerns_helper_behavior.rb' - 'app/helpers/curation_concerns/attribute_helper.rb' - - 'curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb' + - 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb' Metrics/MethodLength: Enabled: false @@ -47,14 +47,14 @@ Metrics/ClassLength: Exclude: - 'lib/generators/curation_concerns/templates/catalog_controller.rb' - 'curation_concerns-models/app/models/datastreams/fits_datastream.rb' - - 'curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb' + - 'curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb' Metrics/ModuleLength: Exclude: - 'app/controllers/concerns/curation_concerns/curation_concern_controller.rb' - 'app/controllers/concerns/curation_concerns/users_controller_behavior.rb' - 'app/controllers/concerns/curation_concerns/catalog_controller.rb' - - 'app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb' + - 'app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb' - 'app/helpers/curation_concerns/curation_concerns_helper_behavior.rb' - 'curation_concerns-models/app/models/concerns/curation_concerns/solr_document_behavior.rb' @@ -138,7 +138,7 @@ Style/ClassVars: Exclude: - 'curation_concerns-models/lib/curation_concerns/models.rb' - 'curation_concerns-models/lib/curation_concerns/models/engine.rb' - - 'curation_concerns-models/app/models/concerns/curation_concerns/generic_file/versions.rb' + - 'curation_concerns-models/app/models/concerns/curation_concerns/file_set/versions.rb' Style/SignalException: Enabled: false diff --git a/app/controllers/concerns/curation_concerns/curation_concern_controller.rb b/app/controllers/concerns/curation_concerns/curation_concern_controller.rb index 27fb065c7..906a08f17 100644 --- a/app/controllers/concerns/curation_concerns/curation_concern_controller.rb +++ b/app/controllers/concerns/curation_concerns/curation_concern_controller.rb @@ -55,7 +55,7 @@ def show wants.json do # load and authorize @curation_concern manually because it's skipped for html # This has to use #find instead of #load_instance_from_solr because - # we want to return values like generic_file_ids in the json + # we want to return values like file_set_ids in the json @curation_concern = curation_concern_type.find(params[:id]) unless curation_concern authorize! :show, @curation_concern render :show, status: :ok diff --git a/app/controllers/concerns/curation_concerns/embargoes_controller_behavior.rb b/app/controllers/concerns/curation_concerns/embargoes_controller_behavior.rb index 8563afbe6..1a89c8c8a 100644 --- a/app/controllers/concerns/curation_concerns/embargoes_controller_behavior.rb +++ b/app/controllers/concerns/curation_concerns/embargoes_controller_behavior.rb @@ -16,7 +16,7 @@ def index def destroy EmbargoActor.new(curation_concern).destroy flash[:notice] = curation_concern.embargo_history.last - if curation_concern.works_generic_work? && curation_concern.generic_files.present? + if curation_concern.work? && curation_concern.file_sets.present? redirect_to confirm_curation_concerns_permission_path(curation_concern) else redirect_to edit_embargo_path(curation_concern) diff --git a/app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb b/app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb similarity index 68% rename from app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb rename to app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb index 81dea7c5d..1c63279bf 100644 --- a/app/controllers/concerns/curation_concerns/generic_files_controller_behavior.rb +++ b/app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb @@ -1,11 +1,11 @@ module CurationConcerns - module GenericFilesControllerBehavior + module FileSetsControllerBehavior extend ActiveSupport::Concern included do include CurationConcerns::ThemedLayoutController with_themed_layout '1_column' - load_and_authorize_resource class: ::GenericFile, except: :show + load_and_authorize_resource class: ::FileSet, except: :show helper_method :curation_concern include CurationConcerns::ParentContainer include Blacklight::Base @@ -14,7 +14,7 @@ module GenericFilesControllerBehavior end def curation_concern - @generic_file + @file_set end # routed to /files/new @@ -33,9 +33,9 @@ def create def create_from_upload(params) # check error condition No files - return render_json_response(response_type: :bad_request, options: { message: 'Error! No file to save' }) unless params.key?(:generic_file) && params.fetch(:generic_file).key?(:files) + return render_json_response(response_type: :bad_request, options: { message: 'Error! No file to save' }) unless params.key?(:file_set) && params.fetch(:file_set).key?(:files) - file = params[:generic_file][:files].detect { |f| f.respond_to?(:original_filename) } + file = params[:file_set][:files].detect { |f| f.respond_to?(:original_filename) } if !file render_json_response(response_type: :bad_request, options: { message: 'Error! No file for upload', description: 'unknown file' }) elsif empty_file?(file) @@ -44,7 +44,7 @@ def create_from_upload(params) process_file(file) end rescue RSolr::Error::Http => error - logger.error "GenericFilesController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n" + logger.error "FileSetController::create rescued #{error.class}\n\t#{error}\n #{error.backtrace.join("\n")}\n\n" render_json_response(response_type: :internal_error, options: { message: 'Error occurred while creating generic file.' }) ensure # remove the tempfile (only if it is a temp file) @@ -55,15 +55,15 @@ def create_from_upload(params) def show respond_to do |wants| wants.html do - _, document_list = search_results(params, [:add_access_controls_to_solr_params, :find_one, :only_generic_files]) + _, document_list = search_results(params, [:add_access_controls_to_solr_params, :find_one, :only_file_sets]) curation_concern = document_list.first raise CanCan::AccessDenied unless curation_concern @presenter = show_presenter.new(curation_concern, current_ability) end wants.json do # load and authorize @curation_concern manually because it's skipped for html - @generic_file = curation_concern_type.load_instance_from_solr(params[:id]) unless curation_concern - authorize! :show, @generic_file + @file_set = curation_concern_type.load_instance_from_solr(params[:id]) unless curation_concern + authorize! :show, @file_set render :show, status: :ok end additional_response_formats(wants) @@ -73,21 +73,21 @@ def show # Gives the class of the show presenter. Override this if you want # to use a different presenter. def show_presenter - CurationConcerns::GenericFilePresenter + CurationConcerns::FileSetPresenter end def destroy actor.destroy - redirect_to [main_app, :curation_concerns, @generic_file.generic_works.first], notice: 'The file has been deleted.' + redirect_to [main_app, :curation_concerns, @file_set.in_works.first], notice: 'The file has been deleted.' end # routed to /files/:id (PUT) def update success = if wants_to_revert? actor.revert_content(params[:revision]) - elsif params.key?(:generic_file) - if params[:generic_file].key?(:files) - actor.update_content(params[:generic_file][:files].first) + elsif params.key?(:file_set) + if params[:file_set].key?(:files) + actor.update_content(params[:file_set][:files].first) else update_metadata end @@ -95,20 +95,20 @@ def update if success respond_to do |wants| wants.html do - redirect_to [main_app, :curation_concerns, @generic_file], notice: - "The file #{view_context.link_to(@generic_file, [main_app, :curation_concerns, @generic_file])} has been updated." + redirect_to [main_app, :curation_concerns, @file_set], notice: + "The file #{view_context.link_to(@file_set, [main_app, :curation_concerns, @file_set])} has been updated." end - wants.json { render :show, status: :ok, location: polymorphic_path([main_app, :curation_concerns, @generic_file]) } + wants.json { render :show, status: :ok, location: polymorphic_path([main_app, :curation_concerns, @file_set]) } end else respond_to do |wants| wants.html { render 'edit', status: :unprocessable_entity } - wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: @generic_file.errors }) } + wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: @file_set.errors }) } end end rescue RSolr::Error::Http => error flash[:error] = error.message - logger.error "GenericFilesController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n" + logger.error "FileSetsController::update rescued #{error.class}\n\t#{error.message}\n #{error.backtrace.join("\n")}\n\n" render action: 'edit' end @@ -119,7 +119,7 @@ def versions # this is provided so that implementing application can override this behavior and map params to different attributes def update_metadata # attrs_without_visibility_info = actor.interpret_visibility(attributes) - file_attributes = CurationConcerns::Forms::GenericFileEditForm.model_attributes(attributes) + file_attributes = CurationConcerns::Forms::FileSetEditForm.model_attributes(attributes) actor.update_metadata(file_attributes, attributes) end @@ -131,26 +131,26 @@ def additional_response_formats(_) # nop end - def generic_file_params - params.require(:generic_file).permit( + def file_set_params + params.require(:file_set).permit( :visibility_during_embargo, :embargo_release_date, :visibility_after_embargo, :visibility_during_lease, :lease_expiration_date, :visibility_after_lease, :visibility, title: []) end def version_list - CurationConcerns::VersionListPresenter.new(@generic_file.original_file.versions.all) + CurationConcerns::VersionListPresenter.new(@file_set.original_file.versions.all) end def wants_to_revert? - params.key?(:revision) && params[:revision] != @generic_file.latest_content_version.label + params.key?(:revision) && params[:revision] != @file_set.latest_content_version.label end def actor - @actor ||= ::CurationConcerns::GenericFileActor.new(@generic_file, current_user) + @actor ||= ::CurationConcerns::FileSetActor.new(@file_set, current_user) end def attributes - # params.fetch(:generic_file, {}).dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things - params.fetch(:generic_file, {}).except(:files).permit!.dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things + # params.fetch(:file_set, {}).dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things + params.fetch(:file_set, {}).except(:files).permit!.dup # use a copy of the hash so that original params stays untouched when interpret_visibility modifies things end def _prefixes @@ -164,14 +164,14 @@ def empty_file?(file) def process_file(file) update_metadata_from_upload_screen - actor.create_metadata(params[:upload_set_id], parent_id, params[:generic_file]) + actor.create_metadata(params[:upload_set_id], parent_id, params[:file_set]) if actor.create_content(file) respond_to do |format| format.html do if request.xhr? render 'jq_upload', formats: 'json', content_type: 'text/html' else - redirect_to [main_app, :curation_concerns, @generic_file.generic_works.first] + redirect_to [main_app, :curation_concerns, @file_set.in_works.first] end end format.json do @@ -179,7 +179,7 @@ def process_file(file) end end else - msg = @generic_file.errors.full_messages.join(', ') + msg = @file_set.errors.full_messages.join(', ') flash[:error] = msg json_error "Error creating generic file: #{msg}" end @@ -188,11 +188,11 @@ def process_file(file) # this is provided so that implementing application can override this behavior and map params to different attributes def update_metadata_from_upload_screen # Relative path is set by the jquery uploader when uploading a directory - @generic_file.relative_path = params[:relative_path] if params[:relative_path] + @file_set.relative_path = params[:relative_path] if params[:relative_path] end def curation_concern_type - ::GenericFile + ::FileSet end end end diff --git a/app/controllers/concerns/curation_concerns/leases_controller_behavior.rb b/app/controllers/concerns/curation_concerns/leases_controller_behavior.rb index 5c35b60ba..49e7007d2 100644 --- a/app/controllers/concerns/curation_concerns/leases_controller_behavior.rb +++ b/app/controllers/concerns/curation_concerns/leases_controller_behavior.rb @@ -15,7 +15,7 @@ def index def destroy LeaseActor.new(curation_concern).destroy flash[:notice] = curation_concern.lease_history.last - if curation_concern.works_generic_work? && curation_concern.generic_files.present? + if curation_concern.work? && curation_concern.file_sets.present? redirect_to confirm_curation_concerns_permission_path(curation_concern) else redirect_to edit_lease_path(curation_concern) diff --git a/app/controllers/concerns/curation_concerns/single_use_links_viewer_controller_behavior.rb b/app/controllers/concerns/curation_concerns/single_use_links_viewer_controller_behavior.rb index dad289015..f9b6b3ce5 100644 --- a/app/controllers/concerns/curation_concerns/single_use_links_viewer_controller_behavior.rb +++ b/app/controllers/concerns/curation_concerns/single_use_links_viewer_controller_behavior.rb @@ -13,7 +13,7 @@ module SingleUseLinksViewerControllerBehavior rescue_from CanCan::AccessDenied, with: :render_single_use_error rescue_from ActiveRecord::RecordNotFound, with: :render_single_use_error class_attribute :presenter_class - self.presenter_class = CurationConcerns::GenericFilePresenter + self.presenter_class = CurationConcerns::FileSetPresenter copy_blacklight_config_from(::CatalogController) end diff --git a/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb b/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb index a46a3c08d..54e07698e 100644 --- a/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb +++ b/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb @@ -8,7 +8,7 @@ module UploadSetsControllerBehavior with_themed_layout '1_column' class_attribute :edit_form_class - self.edit_form_class = CurationConcerns::Forms::GenericFileEditForm + self.edit_form_class = CurationConcerns::Forms::FileSetEditForm end def edit @@ -21,7 +21,7 @@ def update @upload_set = UploadSet.find_or_create(params[:id]) @upload_set.status = ["processing"] @upload_set.save - file_attributes = edit_form_class.model_attributes(params[:generic_file]) + file_attributes = edit_form_class.model_attributes(params[:file_set]) UploadSetUpdateJob.perform_later(current_user.user_key, params[:id], params[:title], file_attributes, params[:visibility]) flash[:notice] = 'Your files are being processed by ' + t('curation_concerns.product_name') + ' in the background. The metadata and access controls you specified are being applied. Files will be marked Private until this process is complete (shouldn\'t take too long, hang in there!). You may need to refresh your dashboard to see these updates.' @@ -31,8 +31,8 @@ def update protected def edit_form - generic_file = ::GenericFile.new(creator: [current_user.user_key], title: @upload_set.generic_files.map(&:label)) - edit_form_class.new(generic_file) + file_set = ::FileSet.new(creator: [current_user.user_key], title: @upload_set.file_sets.map(&:label)) + edit_form_class.new(file_set) end end end diff --git a/app/controllers/curation_concerns/file_sets_controller.rb b/app/controllers/curation_concerns/file_sets_controller.rb new file mode 100644 index 000000000..fe2b70344 --- /dev/null +++ b/app/controllers/curation_concerns/file_sets_controller.rb @@ -0,0 +1,5 @@ +module CurationConcerns + class FileSetsController < ApplicationController + include CurationConcerns::FileSetsControllerBehavior + end +end diff --git a/app/controllers/curation_concerns/generic_files_controller.rb b/app/controllers/curation_concerns/generic_files_controller.rb deleted file mode 100644 index c70d04e1f..000000000 --- a/app/controllers/curation_concerns/generic_files_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -module CurationConcerns - class GenericFilesController < ApplicationController - include CurationConcerns::GenericFilesControllerBehavior - end -end diff --git a/app/forms/curation_concerns/forms/generic_file_edit_form.rb b/app/forms/curation_concerns/forms/file_set_edit_form.rb similarity index 85% rename from app/forms/curation_concerns/forms/generic_file_edit_form.rb rename to app/forms/curation_concerns/forms/file_set_edit_form.rb index 19918cda2..f7056c7e5 100644 --- a/app/forms/curation_concerns/forms/generic_file_edit_form.rb +++ b/app/forms/curation_concerns/forms/file_set_edit_form.rb @@ -1,11 +1,11 @@ module CurationConcerns module Forms - class GenericFileEditForm + class FileSetEditForm include HydraEditor::Form include HydraEditor::Form::Permissions self.required_fields = [:title, :creator, :tag, :rights] - self.model_class = ::GenericFile + self.model_class = ::FileSet self.terms = [:resource_type, :title, :creator, :contributor, :description, :tag, :rights, :publisher, :date_created, :subject, :language, :identifier, :based_near, :related_url] diff --git a/app/helpers/curation_concerns/file_set_helper.rb b/app/helpers/curation_concerns/file_set_helper.rb new file mode 100644 index 000000000..f7bd50de1 --- /dev/null +++ b/app/helpers/curation_concerns/file_set_helper.rb @@ -0,0 +1,31 @@ +module CurationConcerns::FileSetHelper + def parent_path(parent) + if parent.is_a?(Collection) + main_app.collection_path(parent) + else + polymorphic_path([main_app, :curation_concerns, parent]) + end + end + + def media_display(file_set, locals = {}) + render media_display_partial(file_set), + locals.merge(file_set: file_set) + end + + def media_display_partial(file_set) + 'curation_concerns/file_sets/media_display/' + + if file_set.image? + 'image' + elsif file_set.video? + 'video' + elsif file_set.audio? + 'audio' + elsif file_set.pdf? + 'pdf' + elsif file_set.office_document? + 'office_document' + else + 'default' + end + end +end diff --git a/app/helpers/curation_concerns/generic_file_helper.rb b/app/helpers/curation_concerns/generic_file_helper.rb deleted file mode 100644 index e8e0bc72e..000000000 --- a/app/helpers/curation_concerns/generic_file_helper.rb +++ /dev/null @@ -1,31 +0,0 @@ -module CurationConcerns::GenericFileHelper - def parent_path(parent) - if parent.is_a?(Collection) - main_app.collection_path(parent) - else - polymorphic_path([main_app, :curation_concerns, parent]) - end - end - - def media_display(generic_file, locals = {}) - render media_display_partial(generic_file), - locals.merge(generic_file: generic_file) - end - - def media_display_partial(generic_file) - 'curation_concerns/generic_files/media_display/' + - if generic_file.image? - 'image' - elsif generic_file.video? - 'video' - elsif generic_file.audio? - 'audio' - elsif generic_file.pdf? - 'pdf' - elsif generic_file.office_document? - 'office_document' - else - 'default' - end - end -end diff --git a/app/helpers/curation_concerns/main_app_helpers.rb b/app/helpers/curation_concerns/main_app_helpers.rb index fbb01f0d8..333de4936 100644 --- a/app/helpers/curation_concerns/main_app_helpers.rb +++ b/app/helpers/curation_concerns/main_app_helpers.rb @@ -1,6 +1,6 @@ module CurationConcerns::MainAppHelpers include CurationConcerns::TitleHelper - include CurationConcerns::GenericFileHelper + include CurationConcerns::FileSetHelper include CurationConcerns::SearchPathsHelper include CurationConcerns::RenderConstraintsHelper include CurationConcerns::AbilityHelper diff --git a/app/helpers/curation_concerns/url_helper.rb b/app/helpers/curation_concerns/url_helper.rb index 547c86d3e..d2bfd9853 100644 --- a/app/helpers/curation_concerns/url_helper.rb +++ b/app/helpers/curation_concerns/url_helper.rb @@ -14,7 +14,7 @@ def track_collection_path(*args) main_app.track_solr_document_path(*args) end - def track_generic_file_path(*args) + def track_file_set_path(*args) main_app.track_solr_document_path(*args) end diff --git a/app/jobs/visibility_copy_job.rb b/app/jobs/visibility_copy_job.rb index 9c844ca1b..a71d80f8c 100644 --- a/app/jobs/visibility_copy_job.rb +++ b/app/jobs/visibility_copy_job.rb @@ -4,7 +4,7 @@ class VisibilityCopyJob < ActiveFedoraIdBasedJob def perform(id) @id = id work = object - work.generic_files.each do |file| + work.file_sets.each do |file| file.visibility = work.visibility # visibility must come first, because it can clear an embargo/lease if work.lease file.build_lease unless file.lease diff --git a/app/presenters/curation_concerns/generic_file_presenter.rb b/app/presenters/curation_concerns/file_set_presenter.rb similarity index 97% rename from app/presenters/curation_concerns/generic_file_presenter.rb rename to app/presenters/curation_concerns/file_set_presenter.rb index 09e3c23be..c841f6135 100644 --- a/app/presenters/curation_concerns/generic_file_presenter.rb +++ b/app/presenters/curation_concerns/file_set_presenter.rb @@ -1,5 +1,5 @@ module CurationConcerns - class GenericFilePresenter + class FileSetPresenter include ModelProxy include PresentsAttributes attr_accessor :solr_document, :current_ability diff --git a/app/presenters/curation_concerns/form_presenter.rb b/app/presenters/curation_concerns/form_presenter.rb index 5e34f2336..766d2e306 100644 --- a/app/presenters/curation_concerns/form_presenter.rb +++ b/app/presenters/curation_concerns/form_presenter.rb @@ -10,15 +10,15 @@ def initialize(curation_concern, current_ability) @current_ability = current_ability end - # @return [Hash] All generic files in the collection, file.to_s is the key, file.id is the value + # @return [Hash] All file sets in the collection, file.to_s is the key, file.id is the value def files_hash Hash[file_presenters.map { |file| [file.to_s, file.id] }] end - # @return [Array] presenters for the generic files in order of the ids + # @return [Array] presenters for the file sets in order of the ids def file_presenters - @generic_files ||= begin - PresenterFactory.build_presenters(curation_concern.member_ids, GenericFilePresenter, current_ability) + @file_sets ||= begin + PresenterFactory.build_presenters(curation_concern.member_ids, FileSetPresenter, current_ability) end end end diff --git a/app/presenters/curation_concerns/generic_work_show_presenter.rb b/app/presenters/curation_concerns/generic_work_show_presenter.rb index d5ff21f04..490bf58ad 100644 --- a/app/presenters/curation_concerns/generic_work_show_presenter.rb +++ b/app/presenters/curation_concerns/generic_work_show_presenter.rb @@ -24,9 +24,9 @@ def page_title :embargo_release_date, :lease_expiration_date, :rights, to: :solr_document def file_presenters - @generic_files ||= begin - ids = solr_document.fetch('generic_file_ids_ssim', []) - PresenterFactory.build_presenters(ids, GenericFilePresenter, current_ability) + @file_sets ||= begin + ids = solr_document.fetch('file_set_ids_ssim', []) + PresenterFactory.build_presenters(ids, FileSetPresenter, current_ability) end end end diff --git a/app/search_builders/curation_concerns/search_builder.rb b/app/search_builders/curation_concerns/search_builder.rb index 78f2e8595..d628a5ade 100644 --- a/app/search_builders/curation_concerns/search_builder.rb +++ b/app/search_builders/curation_concerns/search_builder.rb @@ -2,8 +2,8 @@ class CurationConcerns::SearchBuilder < Hydra::SearchBuilder include BlacklightAdvancedSearch::AdvancedSearchBuilder include Hydra::Collections::SearchBehaviors - def only_generic_files(solr_parameters) - solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: GenericFile.to_class_uri) + def only_file_sets(solr_parameters) + solr_parameters[:fq] << ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: FileSet.to_class_uri) end def find_one(solr_parameters) diff --git a/app/services/curation_concerns/curation_concern.rb b/app/services/curation_concerns/curation_concern.rb index 9f098a1d4..dba002252 100644 --- a/app/services/curation_concerns/curation_concern.rb +++ b/app/services/curation_concerns/curation_concern.rb @@ -5,9 +5,5 @@ def self.actor(curation_concern, *args) klass = "CurationConcerns::#{actor_identifier}Actor".constantize klass.new(curation_concern, *args) end - - def self.attach_file_to_generic_file(generic_file, user, file_to_attach) - CurationConcerns::GenericFileActor.new(generic_file, user).create_content(file_to_attach) - end end end diff --git a/app/views/collections/_edit_descriptions.html.erb b/app/views/collections/_edit_descriptions.html.erb index 63063dab8..3d6caa20c 100644 --- a/app/views/collections/_edit_descriptions.html.erb +++ b/app/views/collections/_edit_descriptions.html.erb @@ -1,4 +1,4 @@ -<%# This mimics the generic_files/descriptions partial & re-uses some of its sub-partials %> +<%# This mimics the file_sets/descriptions partial & re-uses some of its sub-partials %>
<%= form_for collection, url: collections.collection_path, html: {multipart: true, class: 'form-horizontal'} do |f| %> <%= hidden_field_tag('redirect_tab', 'descriptions') %> @@ -6,13 +6,12 @@
<% (collection.terms_for_editing).each do |term| %> - <%= render partial: "generic_files/field_form", locals: { generic_file: collection, f: f, render_req: true, key: term } %> + <%= render partial: "file_sets/field_form", locals: { file_set: collection, f: f, render_req: true, key: term } %> <% end %> -
- <%= f.button ' Save Descriptions'.html_safe, type: 'submit', class: 'btn-primary', + <%= f.button ' Save Descriptions'.html_safe, type: 'submit', class: 'btn-primary', onclick: "confirmation_needed = false;", id: "upload_submit", name: "update_descriptions" %>
diff --git a/app/views/curation_concerns/base/_representative_media.html.erb b/app/views/curation_concerns/base/_representative_media.html.erb index 51ce30ba4..b6a5c0464 100644 --- a/app/views/curation_concerns/base/_representative_media.html.erb +++ b/app/views/curation_concerns/base/_representative_media.html.erb @@ -1,5 +1,5 @@ -<% if work.representative.present? && (gf = ::GenericFile.load_instance_from_solr(work.representative)) %> - <%= media_display gf %> +<% if work.representative.present? && (fs = ::FileSet.load_instance_from_solr(work.representative)) %> + <%= media_display fs %> <% else %> <%= image_tag 'nope.png', class: "canonical-image" %> <% end %> diff --git a/app/views/curation_concerns/base/show.html.erb b/app/views/curation_concerns/base/show.html.erb index c2bedec5f..c24fd3d5c 100644 --- a/app/views/curation_concerns/base/show.html.erb +++ b/app/views/curation_concerns/base/show.html.erb @@ -10,7 +10,7 @@ <%= render 'attributes', curation_concern: @presenter %> <%= render 'related_files', presenter: @presenter %> <% if editor %> - <%= render partial: 'curation_concerns/generic_files/multiple_upload', presenter: @presenter %> + <%= render partial: 'curation_concerns/file_sets/multiple_upload', presenter: @presenter %> <% end %> <% if collector || editor %> @@ -18,7 +18,7 @@ <% if editor %> <%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, :curation_concerns, @presenter]), class: 'btn btn-primary' %> <%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, :curation_concerns, @presenter], class: 'btn btn-primary', data: { confirm: "Delete this #{@presenter.human_readable_type}?" }, method: :delete %> - <%= link_to "Attach a File", main_app.new_curation_concerns_generic_file_path(@presenter), class: 'btn btn-primary' %> + <%= link_to "Attach a File", main_app.new_curation_concerns_file_set_path(@presenter), class: 'btn btn-primary' %> <% end %>
<% end %> diff --git a/app/views/curation_concerns/file_sets/_actions.html.erb b/app/views/curation_concerns/file_sets/_actions.html.erb new file mode 100644 index 000000000..2ef61bd5d --- /dev/null +++ b/app/views/curation_concerns/file_sets/_actions.html.erb @@ -0,0 +1,16 @@ +<% if can?(:edit, file_set.id) %> + <%= link_to( 'Edit', edit_polymorphic_path([main_app, :curation_concerns, file_set]), + { class: 'btn btn-default', title: "Edit #{file_set}" }) %> + <%= link_to( 'Rollback', main_app.versions_curation_concerns_file_set_path(file_set), + { class: 'btn btn-default', title: "Rollback to previous version" }) %> +<% end %> +<% if can?(:destroy, file_set.id) %> + <%= link_to( 'Delete', polymorphic_path([main_app, :curation_concerns, file_set]), + class: 'btn btn-default', method: :delete, title: "Delete #{file_set}", + data: {confirm: "Deleting #{file_set} from #{t('curation_concerns.product_name')} is permanent. Click OK to delete this from #{t('curation_concerns.product_name')}, or Cancel to cancel this operation"} + )%> +<% end %> +<% if can?(:read, file_set.id) %> + <%= link_to 'Download', main_app.download_path(file_set), + class: 'btn btn-default', title: "Download #{file_set.to_s.inspect}", target: "_blank" %> +<% end %> diff --git a/app/views/curation_concerns/file_sets/_file_set.html.erb b/app/views/curation_concerns/file_sets/_file_set.html.erb new file mode 100644 index 000000000..550f2594c --- /dev/null +++ b/app/views/curation_concerns/file_sets/_file_set.html.erb @@ -0,0 +1,12 @@ + + + <%= render_thumbnail_tag file_set %> + + <%= link_to(file_set.link_name, main_app.curation_concerns_file_set_path(file_set)) %> + <%= file_set.date_uploaded %> + <%= file_set.permission_badge %> + + <%= render 'curation_concerns/file_sets/actions', file_set: file_set %> + + + diff --git a/app/views/curation_concerns/generic_files/_form.html.erb b/app/views/curation_concerns/file_sets/_form.html.erb similarity index 83% rename from app/views/curation_concerns/generic_files/_form.html.erb rename to app/views/curation_concerns/file_sets/_form.html.erb index 99086864e..90f90a936 100644 --- a/app/views/curation_concerns/generic_files/_form.html.erb +++ b/app/views/curation_concerns/file_sets/_form.html.erb @@ -6,9 +6,9 @@
Your File’s Title - <%= label_tag 'generic_file[title][]', 'Title', class: "string optional" %> + <%= label_tag 'file_set[title][]', 'Title', class: "string optional" %> - <%= text_field_tag 'generic_file[title][]', curation_concern.title.first, class: 'form-control' %> + <%= text_field_tag 'file_set[title][]', curation_concern.title.first, class: 'form-control' %>
diff --git a/app/views/curation_concerns/file_sets/_multiple_upload.html.erb b/app/views/curation_concerns/file_sets/_multiple_upload.html.erb new file mode 100644 index 000000000..b6655092f --- /dev/null +++ b/app/views/curation_concerns/file_sets/_multiple_upload.html.erb @@ -0,0 +1,3 @@ +<%= render partial: 'curation_concerns/file_sets/upload/alerts', presenter: @presenter %> +<%= render partial: 'curation_concerns/file_sets/upload/form', presenter: @presenter %> +<%= render partial: 'curation_concerns/file_sets/upload/script_templates', presenter: @presenter %> diff --git a/app/views/curation_concerns/generic_files/edit.html.erb b/app/views/curation_concerns/file_sets/edit.html.erb similarity index 100% rename from app/views/curation_concerns/generic_files/edit.html.erb rename to app/views/curation_concerns/file_sets/edit.html.erb diff --git a/app/views/curation_concerns/file_sets/jq_upload.json.jbuilder b/app/views/curation_concerns/file_sets/jq_upload.json.jbuilder new file mode 100644 index 000000000..3ac8089d3 --- /dev/null +++ b/app/views/curation_concerns/file_sets/jq_upload.json.jbuilder @@ -0,0 +1,8 @@ +json.files [@file_set] do |file_set| + json.name file_set.title.first + json.size file_set.file_size.first + json.url "/files/#{file_set.id}" + json.thumbnail_url file_set.id + json.delete_url "deleteme" + json.delete_type "DELETE" +end diff --git a/app/views/curation_concerns/file_sets/media_display/_audio.html.erb b/app/views/curation_concerns/file_sets/media_display/_audio.html.erb new file mode 100644 index 000000000..bd76730ee --- /dev/null +++ b/app/views/curation_concerns/file_sets/media_display/_audio.html.erb @@ -0,0 +1,6 @@ + + diff --git a/app/views/curation_concerns/file_sets/media_display/_default.html.erb b/app/views/curation_concerns/file_sets/media_display/_default.html.erb new file mode 100644 index 000000000..923c9c9de --- /dev/null +++ b/app/views/curation_concerns/file_sets/media_display/_default.html.erb @@ -0,0 +1,4 @@ + <%= link_to main_app.download_path(file_set), target: "_new", title: "Download the document" do %> + <%= image_tag "default.png", alt: "No preview available", class: "img-responsive" %> + <% end %> + diff --git a/app/views/curation_concerns/file_sets/media_display/_image.html.erb b/app/views/curation_concerns/file_sets/media_display/_image.html.erb new file mode 100644 index 000000000..58f3d2334 --- /dev/null +++ b/app/views/curation_concerns/file_sets/media_display/_image.html.erb @@ -0,0 +1,8 @@ + <%= link_to main_app.download_path(file_set), target: "_new", title: "Download the full-sized image" do %> + <%= image_tag(main_app.download_path(file_set, file: 'thumbnail'), + class: "img-responsive", + alt: "Download the full-sized image of #{file_set.to_s}" + ) %> + Download the full-sized image + <% end %> + diff --git a/app/views/curation_concerns/file_sets/media_display/_office_document.html.erb b/app/views/curation_concerns/file_sets/media_display/_office_document.html.erb new file mode 100644 index 000000000..49b4ef209 --- /dev/null +++ b/app/views/curation_concerns/file_sets/media_display/_office_document.html.erb @@ -0,0 +1,7 @@ + <%= link_to main_app.download_path(file_set), target: "_new", title: "Download the document" do %> + <%= image_tag(main_app.download_path(file_set, file: 'thumbnail'), + class: "img-responsive", + alt: "Download the document \"#{file_set.to_s}\"" + ) %> + Download the document + <% end %> diff --git a/app/views/curation_concerns/file_sets/media_display/_pdf.html.erb b/app/views/curation_concerns/file_sets/media_display/_pdf.html.erb new file mode 100644 index 000000000..d2a2f9f54 --- /dev/null +++ b/app/views/curation_concerns/file_sets/media_display/_pdf.html.erb @@ -0,0 +1,7 @@ + <%= link_to main_app.download_path(file_set), target: "_new", title: "Download the full-sized PDF" do%> + <%= image_tag main_app.download_path(file_set, file: 'thumbnail'), + class: "img-responsive", + alt: "Download the full-sized PDF of #{file_set.to_s}" %> + Download the full-sized PDF + <% end %> + diff --git a/app/views/curation_concerns/file_sets/media_display/_video.html.erb b/app/views/curation_concerns/file_sets/media_display/_video.html.erb new file mode 100644 index 000000000..73278fe0e --- /dev/null +++ b/app/views/curation_concerns/file_sets/media_display/_video.html.erb @@ -0,0 +1,6 @@ + + diff --git a/app/views/curation_concerns/generic_files/show.html.erb b/app/views/curation_concerns/file_sets/show.html.erb similarity index 100% rename from app/views/curation_concerns/generic_files/show.html.erb rename to app/views/curation_concerns/file_sets/show.html.erb diff --git a/app/views/curation_concerns/file_sets/show.json.jbuilder b/app/views/curation_concerns/file_sets/show.json.jbuilder new file mode 100644 index 000000000..529b0d7c6 --- /dev/null +++ b/app/views/curation_concerns/file_sets/show.json.jbuilder @@ -0,0 +1 @@ +json.extract! @file_set, *[:id] + @file_set.class.fields.select {|f| ![:has_model].include? f} diff --git a/app/views/curation_concerns/generic_files/upload/_alerts.html.erb b/app/views/curation_concerns/file_sets/upload/_alerts.html.erb similarity index 100% rename from app/views/curation_concerns/generic_files/upload/_alerts.html.erb rename to app/views/curation_concerns/file_sets/upload/_alerts.html.erb diff --git a/app/views/curation_concerns/file_sets/upload/_form.html.erb b/app/views/curation_concerns/file_sets/upload/_form.html.erb new file mode 100644 index 000000000..38301a51b --- /dev/null +++ b/app/views/curation_concerns/file_sets/upload/_form.html.erb @@ -0,0 +1,6 @@ +<%= form_for(FileSet.new, url: main_app.curation_concerns_file_sets_path(parent_id: @presenter.id), html: { multipart: true, id: 'fileupload' }) do |f| %> +
+ <%= render partial: 'curation_concerns/file_sets/upload/form_fields', presenter: @presenter, locals: { upload_set_id: ActiveFedora::Noid::Service.new.mint } %> +
+<% end %> + diff --git a/app/views/curation_concerns/generic_files/upload/_form_fields.html.erb b/app/views/curation_concerns/file_sets/upload/_form_fields.html.erb similarity index 92% rename from app/views/curation_concerns/generic_files/upload/_form_fields.html.erb rename to app/views/curation_concerns/file_sets/upload/_form_fields.html.erb index 9863ac0e5..f62bd0866 100644 --- a/app/views/curation_concerns/generic_files/upload/_form_fields.html.erb +++ b/app/views/curation_concerns/file_sets/upload/_form_fields.html.erb @@ -10,14 +10,14 @@ Select files... - + <% ua = request.env['HTTP_USER_AGENT'] %> <% if !!(ua =~ /Chrome/) %> Select folder... - + <% end %> diff --git a/app/views/upload_sets/edit.html.erb b/app/views/upload_sets/edit.html.erb index 17ee74f7f..52ae7c87c 100644 --- a/app/views/upload_sets/edit.html.erb +++ b/app/views/upload_sets/edit.html.erb @@ -14,7 +14,7 @@ <%= render 'metadata', f: f %> - <%#= render 'generic_files/permission_form', f: f, upload_set: @upload_set %> + <%#= render 'file_sets/permission_form', f: f, upload_set: @upload_set %>
<%= button_tag type: 'submit', class: 'btn btn-primary btn-lg', diff --git a/curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb b/curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb similarity index 57% rename from curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb rename to curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb index 0c06ac29c..4b307a565 100644 --- a/curation_concerns-models/app/actors/curation_concerns/generic_file_actor.rb +++ b/curation_concerns-models/app/actors/curation_concerns/file_set_actor.rb @@ -1,48 +1,48 @@ module CurationConcerns # Actions are decoupled from controller logic so that they may be called from a controller or a background job. - class GenericFileActor + class FileSetActor include CurationConcerns::ManagesEmbargoesActor - attr_reader :generic_file, :user, :attributes, :curation_concern + attr_reader :file_set, :user, :attributes, :curation_concern - def initialize(generic_file, user) + def initialize(file_set, user) # we're setting attributes and curation_concern to bridge the difference - # between CurationConcerns::GenericFileActor and ManagesEmbargoesActor - @curation_concern = generic_file - @generic_file = generic_file + # between CurationConcerns::FileSetActor and ManagesEmbargoesActor + @curation_concern = file_set + @file_set = file_set @user = user end - # Adds the appropriate metadata, visibility and relationships to generic_file + # Adds the appropriate metadata, visibility and relationships to file_set # # *Note*: In past versions of Sufia this method did not perform a save because it is mainly used in conjunction with # create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects, - # we have to save both the parent work and the generic_file in order to record the "metadata" relationship + # we have to save both the parent work and the file_set in order to record the "metadata" relationship # between them. # @param [String] upload_set_id id of the batch of files that the file was uploaded with - # @param [String] work_id id of the parent work that will contain the generic_file. - # @param [Hash] generic_file_params specifying the visibility, lease and/or embargo of the generic file. If you don't provide at least one of visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent. + # @param [String] work_id id of the parent work that will contain the file_set. + # @param [Hash] file_set specifying the visibility, lease and/or embargo of the file set. If you don't provide at least one of visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent. - def create_metadata(upload_set_id, work_id, generic_file_params = {}) - generic_file.apply_depositor_metadata(user) + def create_metadata(upload_set_id, work_id, file_set_params = {}) + file_set.apply_depositor_metadata(user) now = CurationConcerns::TimeService.time_in_utc - generic_file.date_uploaded = now - generic_file.date_modified = now - generic_file.creator = [user.user_key] + file_set.date_uploaded = now + file_set.date_modified = now + file_set.creator = [user.user_key] - if upload_set_id && generic_file.respond_to?(:upload_set_id=) + if upload_set_id && file_set.respond_to?(:upload_set_id=) UploadSet.create(id: upload_set_id) unless UploadSet.exists?(upload_set_id) - generic_file.upload_set_id = upload_set_id + file_set.upload_set_id = upload_set_id else ActiveFedora::Base.logger.warn 'unable to find UploadSet to attach to' end - if assign_visibility?(generic_file_params) - interpret_visibility generic_file_params + if assign_visibility?(file_set_params) + interpret_visibility file_set_params end # TODO: Why do we need to check if work_id is blank? Shoudn't that raise an error? - attach_file_to_work(work_id, generic_file, generic_file_params) unless work_id.blank? - yield(generic_file) if block_given? + attach_file_to_work(work_id, file_set, file_set_params) unless work_id.blank? + yield(file_set) if block_given? end # Puts the uploaded content into a staging directory. Then kicks off a @@ -52,63 +52,63 @@ def create_metadata(upload_set_id, work_id, generic_file_params = {}) # have made it to the repo # @param [ActionDigest::HTTP::UploadedFile, Tempfile] file the file uploaded by the user. def create_content(file) - generic_file.label ||= file.original_filename - generic_file.title = [generic_file.label] if generic_file.title.blank? - return false unless generic_file.save + file_set.label ||= file.original_filename + file_set.title = [file_set.label] if file_set.title.blank? + return false unless file_set.save - working_file = copy_file_to_working_directory(file, generic_file.id) - IngestFileJob.perform_later(generic_file.id, working_file, file.content_type, user.user_key) - make_derivative(generic_file.id, working_file) + working_file = copy_file_to_working_directory(file, file_set.id) + IngestFileJob.perform_later(file_set.id, working_file, file.content_type, user.user_key) + make_derivative(file_set.id, working_file) true end def revert_content(revision_id) - generic_file.original_file.restore_version(revision_id) + file_set.original_file.restore_version(revision_id) - return false unless generic_file.save + return false unless file_set.save - CurationConcerns::VersioningService.create(generic_file.original_file, user) + CurationConcerns::VersioningService.create(file_set.original_file, user) # Retrieve a copy of the orginal file from the repository - working_file = copy_repository_resource_to_working_directory(generic_file) - make_derivative(generic_file.id, working_file) + working_file = copy_repository_resource_to_working_directory(file_set) + make_derivative(file_set.id, working_file) return true unless CurationConcerns.config.respond_to?(:after_revert_content) - CurationConcerns.config.after_revert_content.call(generic_file, user, revision_id) + CurationConcerns.config.after_revert_content.call(file_set, user, revision_id) true end def update_content(file) - working_file = copy_file_to_working_directory(file, generic_file.id) - IngestFileJob.perform_later(generic_file.id, working_file, file.content_type, user.user_key) - make_derivative(generic_file.id, working_file) + working_file = copy_file_to_working_directory(file, file_set.id) + IngestFileJob.perform_later(file_set.id, working_file, file.content_type, user.user_key) + make_derivative(file_set.id, working_file) return true unless CurationConcerns.config.respond_to?(:after_update_content) - CurationConcerns.config.after_update_content.call(generic_file, user) + CurationConcerns.config.after_update_content.call(file_set, user) true end def update_metadata(model_attributes, all_attributes) update_visibility(all_attributes) model_attributes.delete(:visibility) # Applying this attribute is handled by update_visibility - generic_file.attributes = model_attributes - generic_file.date_modified = CurationConcerns::TimeService.time_in_utc + file_set.attributes = model_attributes + file_set.date_modified = CurationConcerns::TimeService.time_in_utc save do if CurationConcerns.config.respond_to?(:after_update_metadata) - CurationConcerns.config.after_update_metadata.call(generic_file, user) + CurationConcerns.config.after_update_metadata.call(file_set, user) end end end def destroy - generic_file.destroy + file_set.destroy # TODO: need to mend the linked list of proxies (possibly wrap with a lock) - CurationConcerns.config.after_destroy.call(generic_file.id, user) if CurationConcerns.config.respond_to?(:after_destroy) + CurationConcerns.config.after_destroy.call(file_set.id, user) if CurationConcerns.config.respond_to?(:after_destroy) end private - def make_derivative(generic_file_id, working_file) - CharacterizeJob.perform_later(generic_file_id, working_file) + def make_derivative(file_set_id, working_file) + CharacterizeJob.perform_later(file_set_id, working_file) end # @param [ActionDispatch::Http::UploadedFile] file @@ -118,11 +118,11 @@ def copy_file_to_working_directory(file, id) copy_stream_to_working_directory(id, file.original_filename, file) end - # @param [GenericFile] generic_file the resource + # @param [FileSet] file_set the resource # @return [String] path of the working file - def copy_repository_resource_to_working_directory(generic_file) - file = generic_file.original_file - copy_stream_to_working_directory(generic_file.id, file.original_name, StringIO.new(file.content)) + def copy_repository_resource_to_working_directory(file_set) + file = file_set.original_file + copy_stream_to_working_directory(file_set.id, file.original_name, StringIO.new(file.content)) end # @param [String] id the identifer @@ -146,9 +146,9 @@ def full_filename(id, original_name) def save save_tries = 0 begin - return false unless generic_file.save + return false unless file_set.save rescue RSolr::Error::Http => error - ActiveFedora::Base.logger.warn "CurationConcerns::GenericFileActor#save Caught RSOLR error #{error.inspect}" + ActiveFedora::Base.logger.warn "CurationConcerns::FileSetActor#save Caught RSOLR error #{error.inspect}" save_tries += 1 # fail for good if the tries is greater than 3 raise error if save_tries >= 3 @@ -159,18 +159,18 @@ def save true end - # Adds a GenericFile to the work using ore:Aggregations. + # Adds a FileSet to the work using ore:Aggregations. # Locks to ensure that only one process is operating on # the list at a time. - def attach_file_to_work(work_id, generic_file, generic_file_params) + def attach_file_to_work(work_id, file_set, file_set_params) acquire_lock_for(work_id) do work = ActiveFedora::Base.find(work_id) - unless assign_visibility?(generic_file_params) - copy_visibility(work, generic_file) + unless assign_visibility?(file_set_params) + copy_visibility(work, file_set) end - work.generic_files << generic_file - # Save the work so the association between the work and the generic_file is persisted (head_id) + work.file_sets << file_set + # Save the work so the association between the work and the file_set is persisted (head_id) work.save end end @@ -186,8 +186,8 @@ def lock_manager CurationConcerns.config.lock_retry_delay) end - def assign_visibility?(generic_file_params = {}) - !((generic_file_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty? + def assign_visibility?(file_set_params = {}) + !((file_set_params || {}).keys & %w(visibility embargo_release_date lease_expiration_date)).empty? end # This method can be overridden in case there is a custom approach for visibility (e.g. embargo) diff --git a/curation_concerns-models/app/actors/curation_concerns/work_actor_behavior.rb b/curation_concerns-models/app/actors/curation_concerns/work_actor_behavior.rb index 33d5e5cfe..63a367f9b 100644 --- a/curation_concerns-models/app/actors/curation_concerns/work_actor_behavior.rb +++ b/curation_concerns-models/app/actors/curation_concerns/work_actor_behavior.rb @@ -57,9 +57,9 @@ def add_to_collections(new_collection_ids) end def assign_representative - @generic_files ||= [] + @file_sets ||= [] unless curation_concern.representative - curation_concern.representative = @generic_files.first.id unless @generic_files.empty? + curation_concern.representative = @file_sets.first.id unless @file_sets.empty? end curation_concern.save end @@ -67,18 +67,18 @@ def assign_representative private def attach_file(file) - generic_file = ::GenericFile.new - generic_file_actor = CurationConcerns::GenericFileActor.new(generic_file, user) + file_set = ::FileSet.new + file_set_actor = CurationConcerns::FileSetActor.new(file_set, user) # TODO: we're passing an ID rather than an object. This means the actor does an unnecessary lookup - generic_file_actor.create_metadata(curation_concern.id, curation_concern.id, visibility_attributes) - generic_file_actor.create_content(file) - @generic_files ||= [] - @generic_files << generic_file # This is so that other methods like assign_representative can access the generic_files wihtout reloading them from fedora - curation_concern.generic_files << generic_file + file_set_actor.create_metadata(curation_concern.id, curation_concern.id, visibility_attributes) + file_set_actor.create_content(file) + @file_sets ||= [] + @file_sets << file_set # This is so that other methods like assign_representative can access the file_sets without reloading them from fedora + curation_concern.file_sets << file_set end # The attributes used for visibility - used to send as initial params to - # created GenericFiles. + # created FileSets. def visibility_attributes raw_attributes.slice(:visibility, :visibility_during_lease, :visibility_after_lease, :lease_expiration_date, :embargo_release_date, :visibility_during_embargo, :visibility_after_embargo) end diff --git a/curation_concerns-models/app/jobs/active_fedora_id_based_job.rb b/curation_concerns-models/app/jobs/active_fedora_id_based_job.rb index c3c830995..ec88013d7 100644 --- a/curation_concerns-models/app/jobs/active_fedora_id_based_job.rb +++ b/curation_concerns-models/app/jobs/active_fedora_id_based_job.rb @@ -7,7 +7,7 @@ def object @object ||= ActiveFedora::Base.find(id) end - alias_method :generic_file, :object + alias_method :file_set, :object def perform(_) fail 'Define #run in a subclass' diff --git a/curation_concerns-models/app/jobs/audit_job.rb b/curation_concerns-models/app/jobs/audit_job.rb index 7c8a20f12..1a36d59a9 100644 --- a/curation_concerns-models/app/jobs/audit_job.rb +++ b/curation_concerns-models/app/jobs/audit_job.rb @@ -19,9 +19,9 @@ def perform(id, file_id, uri) fixity_ok = log.pass == 1 unless fixity_ok if CurationConcerns.config.respond_to?(:after_audit_failure) - login = generic_file.depositor + login = file_set.depositor user = User.find_by_user_key(login) - CurationConcerns.config.after_audit_failure.call(generic_file, user, log.created_at) + CurationConcerns.config.after_audit_failure.call(file_set, user, log.created_at) end end fixity_ok @@ -43,7 +43,7 @@ def run_audit logger.warn "***AUDIT*** Audit failed for #{uri} #{error_msg}" passing = 0 end - ChecksumAuditLog.create!(pass: passing, generic_file_id: id, version: uri, file_id: file_id) + ChecksumAuditLog.create!(pass: passing, file_set_id: id, version: uri, file_id: file_id) end def logger diff --git a/curation_concerns-models/app/jobs/characterize_job.rb b/curation_concerns-models/app/jobs/characterize_job.rb index 8bd5fe8f8..e39e67372 100644 --- a/curation_concerns-models/app/jobs/characterize_job.rb +++ b/curation_concerns-models/app/jobs/characterize_job.rb @@ -5,9 +5,9 @@ class CharacterizeJob < ActiveFedoraIdBasedJob # @param [String] filename a local path for the file to characterize. By using this, we don't have to pull a copy out of fedora. def perform(id, filename) @id = id - CurationConcerns::CharacterizationService.run(generic_file, filename) - generic_file.save - FulltextExtractionJob.perform_later(generic_file.id, filename) - CreateDerivativesJob.perform_later(generic_file.id, filename) + CurationConcerns::CharacterizationService.run(file_set, filename) + file_set.save + FulltextExtractionJob.perform_later(file_set.id, filename) + CreateDerivativesJob.perform_later(file_set.id, filename) end end diff --git a/curation_concerns-models/app/jobs/create_derivatives_job.rb b/curation_concerns-models/app/jobs/create_derivatives_job.rb index 009ddd60d..ad9e0aff2 100644 --- a/curation_concerns-models/app/jobs/create_derivatives_job.rb +++ b/curation_concerns-models/app/jobs/create_derivatives_job.rb @@ -3,8 +3,8 @@ class CreateDerivativesJob < ActiveFedoraIdBasedJob def perform(id, file_name) @id = id - return if generic_file.video? && !CurationConcerns.config.enable_ffmpeg + return if file_set.video? && !CurationConcerns.config.enable_ffmpeg - generic_file.create_derivatives(file_name) + file_set.create_derivatives(file_name) end end diff --git a/curation_concerns-models/app/jobs/fulltext_extraction_job.rb b/curation_concerns-models/app/jobs/fulltext_extraction_job.rb index ad431db46..e9cf7d29b 100644 --- a/curation_concerns-models/app/jobs/fulltext_extraction_job.rb +++ b/curation_concerns-models/app/jobs/fulltext_extraction_job.rb @@ -5,13 +5,13 @@ class FulltextExtractionJob < ActiveFedoraIdBasedJob # @param [String] filename a local path for the file to extract fulltext. By using this, we don't have to pull a copy out of fedora. def perform(id, filename) @id = id - store_fulltext(Hydra::Works::FullTextExtractionService.run(generic_file, filename)) - generic_file.save + store_fulltext(Hydra::Works::FullTextExtractionService.run(file_set, filename)) + file_set.save end def store_fulltext(extracted_text) return unless extracted_text.present? - extracted_text_file = generic_file.build_extracted_text + extracted_text_file = file_set.build_extracted_text extracted_text_file.content = extracted_text end end diff --git a/curation_concerns-models/app/jobs/import_url_job.rb b/curation_concerns-models/app/jobs/import_url_job.rb index 7b92ec4f8..04a6c9438 100644 --- a/curation_concerns-models/app/jobs/import_url_job.rb +++ b/curation_concerns-models/app/jobs/import_url_job.rb @@ -7,22 +7,22 @@ class ImportUrlJob < ActiveFedoraIdBasedJob def perform(id) @id = id - user = User.find_by_user_key(generic_file.depositor) + user = User.find_by_user_key(file_set.depositor) Tempfile.open(id.tr('/', '_')) do |f| - copy_remote_file(generic_file.import_url, f) + copy_remote_file(file_set.import_url, f) # attach downloaded file to generic file stubbed out - if CurationConcerns::GenericFileActor.new(generic_file, user).create_content(f) + if CurationConcerns::FileSetActor.new(file_set, user).create_content(f) # send message to user on download success if CurationConcerns.config.respond_to?(:after_import_url_success) - CurationConcerns.config.after_import_url_success.call(generic_file, user) + CurationConcerns.config.after_import_url_success.call(file_set, user) end else # send message to user on download failure if CurationConcerns.config.respond_to?(:after_import_url_failure) - CurationConcerns.config.after_import_url_failure.call(generic_file, user) + CurationConcerns.config.after_import_url_failure.call(file_set, user) end end end @@ -31,7 +31,7 @@ def perform(id) def copy_remote_file(_import_url, f) f.binmode # download file from url - uri = URI(generic_file.import_url) + uri = URI(file_set.import_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' # enable SSL/TLS http.verify_mode = OpenSSL::SSL::VERIFY_NONE diff --git a/curation_concerns-models/app/jobs/ingest_file_job.rb b/curation_concerns-models/app/jobs/ingest_file_job.rb index a9e5fe5cc..fd6a4bf95 100644 --- a/curation_concerns-models/app/jobs/ingest_file_job.rb +++ b/curation_concerns-models/app/jobs/ingest_file_job.rb @@ -1,18 +1,18 @@ class IngestFileJob < ActiveJob::Base queue_as :ingest - def perform(generic_file_id, filename, mime_type, user_key) - generic_file = GenericFile.find(generic_file_id) + def perform(file_set_id, filename, mime_type, user_key) + file_set = FileSet.find(file_set_id) file = Hydra::Derivatives::IoDecorator.new(File.open(filename, "rb")) file.mime_type = mime_type file.original_name = File.basename(filename) # Tell UploadFileToGenericFile service to skip versioning because versions will be minted by VersionCommitter (called by save_characterize_and_record_committer) when necessary - Hydra::Works::UploadFileToGenericFile.call(generic_file, file, versioning: false) - generic_file.save! - CurationConcerns::VersioningService.create(generic_file.original_file, user_key) + Hydra::Works::UploadFileToFileSet.call(file_set, file, versioning: false) + file_set.save! + CurationConcerns::VersioningService.create(file_set.original_file, user_key) return unless CurationConcerns.config.respond_to?(:after_create_content) - CurationConcerns.config.after_create_content.call(generic_file, user_key) + CurationConcerns.config.after_create_content.call(file_set, user_key) end end diff --git a/curation_concerns-models/app/jobs/ingest_local_file_job.rb b/curation_concerns-models/app/jobs/ingest_local_file_job.rb index e70c0bda5..b3c992ee2 100644 --- a/curation_concerns-models/app/jobs/ingest_local_file_job.rb +++ b/curation_concerns-models/app/jobs/ingest_local_file_job.rb @@ -1,34 +1,34 @@ class IngestLocalFileJob < ActiveJob::Base - attr_accessor :directory, :filename, :user_key, :generic_file_id + attr_accessor :directory, :filename, :user_key, :file_set_id queue_as :ingest_local - def perform(generic_file_id, directory, filename, user_key) - @generic_file_id = generic_file_id + def perform(file_set_id, directory, filename, user_key) + @file_set_id = file_set_id @directory = directory @filename = filename @user_key = user_key user = User.find_by_user_key(user_key) fail "Unable to find user for #{user_key}" unless user - generic_file = GenericFile.find(generic_file_id) - generic_file.label ||= filename + file_set = FileSet.find(file_set_id) + file_set.label ||= filename path = File.join(directory, filename) - actor = CurationConcerns::GenericFileActor.new(generic_file, user) + actor = CurationConcerns::FileSetActor.new(file_set, user) if actor.create_content(File.open(path)) FileUtils.rm(path) # send message to user on import success if CurationConcerns.config.respond_to?(:after_import_local_file_success) - CurationConcerns.config.after_import_local_file_success.call(generic_file, user, filename) + CurationConcerns.config.after_import_local_file_success.call(file_set, user, filename) end else # send message to user on import failure if CurationConcerns.config.respond_to?(:after_import_local_file_failure) - CurationConcerns.config.after_import_local_file_failure.call(generic_file, user, filename) + CurationConcerns.config.after_import_local_file_failure.call(file_set, user, filename) end end end diff --git a/curation_concerns-models/app/jobs/upload_set_update_job.rb b/curation_concerns-models/app/jobs/upload_set_update_job.rb index 7a7974ee9..07a0dbf34 100644 --- a/curation_concerns-models/app/jobs/upload_set_update_job.rb +++ b/curation_concerns-models/app/jobs/upload_set_update_job.rb @@ -19,7 +19,7 @@ def perform(login, upload_set_id, title, file_attributes, visibility) upload_set = UploadSet.find_or_create(self.upload_set_id) user = User.find_by_user_key(self.login) - upload_set.generic_files.each do |gf| + upload_set.file_sets.each do |gf| update_file(gf, user) end @@ -52,12 +52,12 @@ def update_file(gf, user) end # update the file using the actor after setting the title gf.title = title[gf.id] if title[gf.id] - CurationConcerns::GenericFileActor.new(gf, user).update_metadata(file_attributes, visibility: visibility) + CurationConcerns::FileSetActor.new(gf, user).update_metadata(file_attributes, visibility: visibility) # update the work to the same metadata as the file. # NOTE: For the moment we are assuming copied metadata. This is likely to change. - # NOTE2: TODO: stop assuming that files only belong to one generic_work - work = gf.generic_works.first + # NOTE2: TODO: stop assuming that files only belong to one work + work = gf.in_works.first unless work.nil? work.title = title[gf.id] if title[gf.id] CurationConcerns::GenericWorkActor.new(work, user, work_attributes).update diff --git a/curation_concerns-models/app/models/checksum_audit_log.rb b/curation_concerns-models/app/models/checksum_audit_log.rb index 7125ad32d..070a0a4a7 100644 --- a/curation_concerns-models/app/models/checksum_audit_log.rb +++ b/curation_concerns-models/app/models/checksum_audit_log.rb @@ -1,6 +1,6 @@ class ChecksumAuditLog < ActiveRecord::Base def self.get_audit_log(id, path, version_uri) - ChecksumAuditLog.find_or_create_by(generic_file_id: id, file_id: path, version: version_uri) + ChecksumAuditLog.find_or_create_by(file_set_id: id, file_id: path, version: version_uri) end # Check to see if there are previous passing logs that we can delete @@ -15,6 +15,6 @@ def self.prune_history(id, path) end def self.logs_for(id, path) - ChecksumAuditLog.where(generic_file_id: id, file_id: path).order('created_at desc, id desc') + ChecksumAuditLog.where(file_set_id: id, file_id: path).order('created_at desc, id desc') end end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/ability.rb b/curation_concerns-models/app/models/concerns/curation_concerns/ability.rb index 5eaff5423..61aa56e68 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/ability.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/ability.rb @@ -30,7 +30,7 @@ def admin? # to submit content def everyone_can_create_curation_concerns return if current_user.new_record? - can :create, [::GenericFile, ::Collection] + can :create, [::FileSet, ::Collection] can :create, [CurationConcerns.config.curation_concerns] end end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/belongs_to_upload_sets.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/belongs_to_upload_sets.rb similarity index 94% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/belongs_to_upload_sets.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/belongs_to_upload_sets.rb index d1e04639b..2ff5c1afb 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/belongs_to_upload_sets.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/belongs_to_upload_sets.rb @@ -1,5 +1,5 @@ module CurationConcerns - module GenericFile + module FileSet module BelongsToUploadSets extend ActiveSupport::Concern included do diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/belongs_to_works.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/belongs_to_works.rb similarity index 93% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/belongs_to_works.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/belongs_to_works.rb index 4a7de9111..59c539d2d 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/belongs_to_works.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/belongs_to_works.rb @@ -1,5 +1,5 @@ module CurationConcerns - module GenericFile + module FileSet module BelongsToWorks extend ActiveSupport::Concern @@ -31,7 +31,7 @@ def parent def related_files generic_works = self.generic_works return [] if generic_works.empty? - generic_works.flat_map { |work| work.generic_files.select { |generic_file| generic_file.id != id } } + generic_works.flat_map { |work| work.file_sets.select { |file_set| file_set.id != id } } end # If any parent works are pointing at this object as their representative, remove that pointer. diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/characterization.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/characterization.rb similarity index 99% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/characterization.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/characterization.rb index 9827abbde..9bda6e3d8 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/characterization.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/characterization.rb @@ -1,5 +1,5 @@ module CurationConcerns - module GenericFile + module FileSet module Characterization extend ActiveSupport::Concern included do diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/derivatives.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/derivatives.rb similarity index 99% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/derivatives.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/derivatives.rb index aba2c897f..733319971 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/derivatives.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/derivatives.rb @@ -1,5 +1,5 @@ module CurationConcerns - module GenericFile + module FileSet module Derivatives extend ActiveSupport::Concern diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/full_text_indexing.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/full_text_indexing.rb similarity index 88% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/full_text_indexing.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/full_text_indexing.rb index 780431bdd..55c9df2f4 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/full_text_indexing.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/full_text_indexing.rb @@ -1,5 +1,5 @@ module CurationConcerns - module GenericFile + module FileSet module FullTextIndexing extend ActiveSupport::Concern diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/indexing.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/indexing.rb similarity index 73% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/indexing.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/indexing.rb index 529f67b10..d4c6e6602 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/indexing.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/indexing.rb @@ -1,12 +1,12 @@ module CurationConcerns - module GenericFile + module FileSet module Indexing extend ActiveSupport::Concern module ClassMethods # override the default indexing service def indexer - CurationConcerns::GenericFileIndexingService + CurationConcerns::FileSetIndexingService end end end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/versions.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/versions.rb similarity index 95% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file/versions.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set/versions.rb index 6efbeccda..6e15bbc63 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/versions.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set/versions.rb @@ -1,5 +1,5 @@ module CurationConcerns - module GenericFile + module FileSet module Versions @@count = 0 def record_version_committer(user) diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file_behavior.rb b/curation_concerns-models/app/models/concerns/curation_concerns/file_set_behavior.rb similarity index 50% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_file_behavior.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/file_set_behavior.rb index cb5a80f6b..dbe03eb0f 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file_behavior.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/file_set_behavior.rb @@ -1,20 +1,19 @@ module CurationConcerns - module GenericFileBehavior + module FileSetBehavior extend ActiveSupport::Concern - include Hydra::Works::GenericFileBehavior - include Hydra::Works::GenericFile::VirusCheck + include Hydra::Works::FileSetBehavior + include Hydra::Works::VirusCheck include Hydra::WithDepositor include CurationConcerns::Serializers include CurationConcerns::Noid - include CurationConcerns::GenericFile::Derivatives + include CurationConcerns::FileSet::Derivatives include CurationConcerns::Permissions - include CurationConcerns::GenericFile::Characterization + include CurationConcerns::FileSet::Characterization include CurationConcerns::BasicMetadata - include CurationConcerns::GenericFile::Content - include CurationConcerns::GenericFile::FullTextIndexing - include CurationConcerns::GenericFile::Indexing - include CurationConcerns::GenericFile::BelongsToWorks - include CurationConcerns::GenericFile::BelongsToUploadSets + include CurationConcerns::FileSet::FullTextIndexing + include CurationConcerns::FileSet::Indexing + include CurationConcerns::FileSet::BelongsToWorks + include CurationConcerns::FileSet::BelongsToUploadSets include CurationConcerns::HumanReadableType include Hydra::AccessControls::Embargoable diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/content.rb b/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/content.rb deleted file mode 100644 index 6a4343e0f..000000000 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_file/content.rb +++ /dev/null @@ -1,7 +0,0 @@ -module CurationConcerns - module GenericFile - module Content - extend ActiveSupport::Concern - end - end -end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/solr_document_behavior.rb b/curation_concerns-models/app/models/concerns/curation_concerns/solr_document_behavior.rb index 4405efe9a..2acc41a2b 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/solr_document_behavior.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/solr_document_behavior.rb @@ -1,7 +1,7 @@ module CurationConcerns module SolrDocumentBehavior extend ActiveSupport::Concern - include Hydra::Works::GenericFile::MimeTypes + include Hydra::Works::MimeTypes def title_or_label title || label diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb b/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb index 7fedba884..6fa55ac93 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/upload_set_behavior.rb @@ -5,7 +5,7 @@ module UploadSetBehavior include CurationConcerns::Noid included do - has_many :generic_files, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: "GenericFile" + has_many :file_sets, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf property :creator, predicate: ::RDF::DC.creator property :title, predicate: ::RDF::DC.title diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/with_file_sets.rb b/curation_concerns-models/app/models/concerns/curation_concerns/with_file_sets.rb new file mode 100644 index 000000000..83153004d --- /dev/null +++ b/curation_concerns-models/app/models/concerns/curation_concerns/with_file_sets.rb @@ -0,0 +1,28 @@ +# Copied from Curate +module CurationConcerns + module WithFileSets + extend ActiveSupport::Concern + + included do + # The file_sets association and its accessor methods comes from Hydra::Works::AggregatesFileSets + before_destroy :before_destroy_cleanup_file_sets + end + + # Stopgap unil ActiveFedora ContainerAssociation includes an *_ids accessor. + # At the moment, this is no more efficient than calling file_sets, but hopefully that will change in the future. + def file_set_ids + file_sets.map(&:id) + end + + def before_destroy_cleanup_file_sets + file_sets.each(&:destroy) + end + + def copy_visibility_to_files + file_sets.each do |fs| + fs.visibility = visibility + fs.save! + end + end + end +end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/with_generic_files.rb b/curation_concerns-models/app/models/concerns/curation_concerns/with_generic_files.rb deleted file mode 100644 index 8a3d8e986..000000000 --- a/curation_concerns-models/app/models/concerns/curation_concerns/with_generic_files.rb +++ /dev/null @@ -1,28 +0,0 @@ -# Copied from Curate -module CurationConcerns - module WithGenericFiles - extend ActiveSupport::Concern - - included do - # The generic_files association and its accessor methods comes from Hydra::Works::AggregatesGenericFiles - before_destroy :before_destroy_cleanup_generic_files - end - - # Stopgap unil ActiveFedora ContainerAssociation includes an *_ids accessor. - # At the moment, this is no more efficient than calling generic_files, but hopefully that will change in the future. - def generic_file_ids - generic_files.map(&:id) - end - - def before_destroy_cleanup_generic_files - generic_files.each(&:destroy) - end - - def copy_visibility_to_files - generic_files.each do |gf| - gf.visibility = visibility - gf.save! - end - end - end -end diff --git a/curation_concerns-models/app/models/concerns/curation_concerns/generic_work_behavior.rb b/curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb similarity index 84% rename from curation_concerns-models/app/models/concerns/curation_concerns/generic_work_behavior.rb rename to curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb index d3992cc7b..020c5532c 100644 --- a/curation_concerns-models/app/models/concerns/curation_concerns/generic_work_behavior.rb +++ b/curation_concerns-models/app/models/concerns/curation_concerns/work_behavior.rb @@ -1,7 +1,7 @@ -module CurationConcerns::GenericWorkBehavior +module CurationConcerns::WorkBehavior extend ActiveSupport::Concern - include Hydra::Works::GenericWorkBehavior + include Hydra::Works::WorkBehavior include ::CurationConcerns::HumanReadableType include CurationConcerns::Noid include CurationConcerns::Permissions @@ -9,7 +9,7 @@ module CurationConcerns::GenericWorkBehavior include Hydra::WithDepositor include Solrizer::Common include ::CurationConcerns::HasRepresentative - include ::CurationConcerns::WithGenericFiles + include ::CurationConcerns::WithFileSets include Hydra::AccessControls::Embargoable included do @@ -19,7 +19,7 @@ module CurationConcerns::GenericWorkBehavior module ClassMethods def indexer - CurationConcerns::GenericWorkIndexingService + CurationConcerns::WorkIndexingService end end diff --git a/curation_concerns-models/app/services/curation_concerns/characterization_service.rb b/curation_concerns-models/app/services/curation_concerns/characterization_service.rb index c7db20cae..d17496bc2 100644 --- a/curation_concerns-models/app/services/curation_concerns/characterization_service.rb +++ b/curation_concerns-models/app/services/curation_concerns/characterization_service.rb @@ -2,36 +2,36 @@ module CurationConcerns # Run FITS to gather technical metadata about the content and the full text. # Store this extracted metadata in the characterization datastream. class CharacterizationService - attr_reader :generic_file, :file_path + attr_reader :file_set, :file_path - # @param [GenericFile] generic_file + # @param [FileSet] file_set # @param [String] file_path path to the file on disk - def self.run(generic_file, file_path) - new(generic_file, file_path).characterize + def self.run(file_set, file_path) + new(file_set, file_path).characterize end - # @param [GenericFile] generic_file + # @param [FileSet] file_set # @param [String] file_path path to the file on disk - def initialize(generic_file, file_path) - @generic_file = generic_file + def initialize(file_set, file_path) + @file_set = file_set @file_path = file_path end ## Extract the metadata from the content datastream and record it in the characterization datastream def characterize store_metadata(extract_metadata) - generic_file.filename = File.basename(file_path) + file_set.filename = File.basename(file_path) end protected def store_metadata(metadata) - generic_file.characterization.ng_xml = metadata if metadata.present? + file_set.characterization.ng_xml = metadata if metadata.present? append_metadata end def original_file - generic_file.original_file + file_set.original_file end def extract_metadata @@ -41,20 +41,20 @@ def extract_metadata end end - # Populate GenericFile's properties with fields from FITS (e.g. Author from pdfs) + # Populate FileSet's properties with fields from FITS (e.g. Author from pdfs) def append_metadata - terms = generic_file.characterization_terms + terms = file_set.characterization_terms CurationConcerns.config.fits_to_desc_mapping.each_pair do |k, v| next unless terms.key?(k) # coerce to array to remove a conditional terms[k] = [terms[k]] unless terms[k].is_a? Array terms[k].each do |term_value| - proxy_term = generic_file.send(v) + proxy_term = file_set.send(v) if proxy_term.is_a?(Array) proxy_term << term_value unless proxy_term.include?(term_value) else # these are single-valued terms which cannot be appended to - generic_file.send("#{v}=", term_value) + file_set.send("#{v}=", term_value) end end end diff --git a/curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb b/curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb similarity index 87% rename from curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb rename to curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb index 700b808f8..013c0b51c 100644 --- a/curation_concerns-models/app/services/curation_concerns/generic_file_audit_service.rb +++ b/curation_concerns-models/app/services/curation_concerns/file_set_audit_service.rb @@ -1,8 +1,8 @@ module CurationConcerns - class GenericFileAuditService - attr_reader :generic_file + class FileSetAuditService + attr_reader :file_set def initialize(file) - @generic_file = file + @file_set = file end NO_RUNS = 999 @@ -23,7 +23,7 @@ def human_readable_audit_status(stat) # Returns the set of most recent audit status for each version of the content file # @param [Hash] log container for messages, mapping file ids to status def audit(log = {}) - generic_file.files.each { |f| log[f.id] = audit_file(f) } + file_set.files.each { |f| log[f.id] = audit_file(f) } log end @@ -58,10 +58,10 @@ def audit_stat(file) # @param [String] file_id used to find the file within its parent object (usually "original_file") # @param [String] version_uri the version to be audited (or the file uri for non-versioned files) def audit_file_version(file_id, version_uri) - latest_audit = ChecksumAuditLog.logs_for(generic_file.id, file_id).first + latest_audit = ChecksumAuditLog.logs_for(file_set.id, file_id).first return latest_audit unless needs_audit?(latest_audit) - AuditJob.perform_later(generic_file.id, file_id, version_uri.to_s) - latest_audit || ChecksumAuditLog.new(pass: NO_RUNS, generic_file_id: generic_file.id, file_id: file_id, version: version_uri) + AuditJob.perform_later(file_set.id, file_id, version_uri.to_s) + latest_audit || ChecksumAuditLog.new(pass: NO_RUNS, file_set_id: file_set.id, file_id: file_id, version: version_uri) end # Check if time since the last audit is greater than the maximum days allowed between audits diff --git a/curation_concerns-models/app/services/curation_concerns/generic_file_indexing_service.rb b/curation_concerns-models/app/services/curation_concerns/file_set_indexing_service.rb similarity index 94% rename from curation_concerns-models/app/services/curation_concerns/generic_file_indexing_service.rb rename to curation_concerns-models/app/services/curation_concerns/file_set_indexing_service.rb index 814802112..f7a4e8098 100644 --- a/curation_concerns-models/app/services/curation_concerns/generic_file_indexing_service.rb +++ b/curation_concerns-models/app/services/curation_concerns/file_set_indexing_service.rb @@ -1,5 +1,5 @@ module CurationConcerns - class GenericFileIndexingService < ActiveFedora::IndexingService + class FileSetIndexingService < ActiveFedora::IndexingService include IndexesThumbnails def generate_solr_document diff --git a/curation_concerns-models/app/services/curation_concerns/repository_audit_service.rb b/curation_concerns-models/app/services/curation_concerns/repository_audit_service.rb index 75ef6b540..7f7c19df6 100644 --- a/curation_concerns-models/app/services/curation_concerns/repository_audit_service.rb +++ b/curation_concerns-models/app/services/curation_concerns/repository_audit_service.rb @@ -1,7 +1,7 @@ module CurationConcerns class RepositoryAuditService def self.audit_everything - ::GenericFile.find_each(&:audit) + ::FileSet.find_each(&:audit) end end end diff --git a/curation_concerns-models/app/services/curation_concerns/thumbnail_path_service.rb b/curation_concerns-models/app/services/curation_concerns/thumbnail_path_service.rb index 85f1a391b..beddd0d16 100644 --- a/curation_concerns-models/app/services/curation_concerns/thumbnail_path_service.rb +++ b/curation_concerns-models/app/services/curation_concerns/thumbnail_path_service.rb @@ -1,7 +1,7 @@ module CurationConcerns class ThumbnailPathService class << self - # @param [GenericWork, GenericFile] the object to get the thumbnail for + # @param [Work, FileSet] the object to get the thumbnail for # @return [String] a path to the thumbnail def call(object) return default_image unless object.representative @@ -19,7 +19,7 @@ def call(object) def fetch_representative(object) return object if object.representative == object.id - ::GenericFile.load_instance_from_solr(object.representative) + ::FileSet.load_instance_from_solr(object.representative) rescue ActiveFedora::ObjectNotFoundError Rails.logger.error("Couldn't find representative #{object.representative} for #{object.id}") nil diff --git a/curation_concerns-models/app/services/curation_concerns/generic_work_indexing_service.rb b/curation_concerns-models/app/services/curation_concerns/work_indexing_service.rb similarity index 63% rename from curation_concerns-models/app/services/curation_concerns/generic_work_indexing_service.rb rename to curation_concerns-models/app/services/curation_concerns/work_indexing_service.rb index 9df13e2f1..286946c50 100644 --- a/curation_concerns-models/app/services/curation_concerns/generic_work_indexing_service.rb +++ b/curation_concerns-models/app/services/curation_concerns/work_indexing_service.rb @@ -1,13 +1,13 @@ module CurationConcerns - class GenericWorkIndexingService < ActiveFedora::IndexingService + class WorkIndexingService < ActiveFedora::IndexingService include IndexesThumbnails def generate_solr_document super.tap do |solr_doc| # We know that all the members of GenericWorks are GenericFiles so we can use - # member_ids which requires fewer Fedora API calls than generic_file_ids. - # generic_file_ids requires loading all the members from Fedora but member_ids + # member_ids which requires fewer Fedora API calls than file_set_ids. + # file_set_ids requires loading all the members from Fedora but member_ids # looks just at solr - solr_doc[Solrizer.solr_name('generic_file_ids', :symbol)] = object.member_ids + solr_doc[Solrizer.solr_name('file_set_ids', :symbol)] = object.member_ids Solrizer.set_field(solr_doc, 'generic_type', 'Work', :facetable) solr_doc['thumbnail_path_ss'] = thumbnail_path end diff --git a/curation_concerns-models/lib/curation_concerns/messages.rb b/curation_concerns-models/lib/curation_concerns/messages.rb index 819031b8b..01b1bc848 100644 --- a/curation_concerns-models/lib/curation_concerns/messages.rb +++ b/curation_concerns-models/lib/curation_concerns/messages.rb @@ -46,7 +46,7 @@ def file_list(files) end def link_to_file(file) - link_to(file.to_s, Rails.application.class.routes.url_helpers.curation_concerns_generic_file_path(file)) + link_to(file.to_s, Rails.application.class.routes.url_helpers.curation_concerns_file_set_path(file)) end private diff --git a/curation_concerns-models/lib/generators/curation_concerns/models/install_generator.rb b/curation_concerns-models/lib/generators/curation_concerns/models/install_generator.rb index b8bd91734..fb6b23186 100644 --- a/curation_concerns-models/lib/generators/curation_concerns/models/install_generator.rb +++ b/curation_concerns-models/lib/generators/curation_concerns/models/install_generator.rb @@ -7,7 +7,7 @@ class CurationConcerns::Models::InstallGenerator < CurationConcerns::Models::Abs This generator makes the following changes to your application: 1. Creates several database migrations if they do not exist in /db/migrate 2. Creates the curation_concerns.rb configuration file and several others - 3. Creates the generic_file.rb, generic_work.rb and collection.rb models + 3. Creates the file_set.rb, generic_work.rb and collection.rb models 4. Runs full-text generator "'' def banner @@ -52,8 +52,8 @@ def create_collection copy_file 'app/models/collection.rb', 'app/models/collection.rb' end - def create_generic_file - copy_file 'app/models/generic_file.rb', 'app/models/generic_file.rb' + def create_file_set + copy_file 'app/models/file_set.rb', 'app/models/file_set.rb' end # Adds clamav initializtion diff --git a/curation_concerns-models/lib/generators/curation_concerns/models/templates/app/models/file_set.rb b/curation_concerns-models/lib/generators/curation_concerns/models/templates/app/models/file_set.rb new file mode 100644 index 000000000..8bd9b52cf --- /dev/null +++ b/curation_concerns-models/lib/generators/curation_concerns/models/templates/app/models/file_set.rb @@ -0,0 +1,4 @@ +# Generated by curation_concerns:models:install +class FileSet < ActiveFedora::Base + include ::CurationConcerns::FileSetBehavior +end diff --git a/curation_concerns-models/lib/generators/curation_concerns/models/templates/app/models/generic_file.rb b/curation_concerns-models/lib/generators/curation_concerns/models/templates/app/models/generic_file.rb deleted file mode 100644 index 9df0c36d2..000000000 --- a/curation_concerns-models/lib/generators/curation_concerns/models/templates/app/models/generic_file.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Generated by curation_concerns:models:install -class GenericFile < ActiveFedora::Base - include ::CurationConcerns::GenericFileBehavior -end diff --git a/curation_concerns-models/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb b/curation_concerns-models/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb index 0f6b2c7cd..00c9ea7a9 100644 --- a/curation_concerns-models/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb +++ b/curation_concerns-models/lib/generators/curation_concerns/models/templates/migrations/create_checksum_audit_logs.rb @@ -1,7 +1,7 @@ class CreateChecksumAuditLogs < ActiveRecord::Migration def self.up create_table :checksum_audit_logs do |t| - t.string :generic_file_id + t.string :file_set_id t.string :file_id t.string :version t.integer :pass @@ -9,11 +9,11 @@ def self.up t.string :actual_result t.timestamps end - add_index :checksum_audit_logs, [:generic_file_id, :file_id], name: 'by_generic_file_id_and_file_id', order: { created_at: 'DESC' } + add_index :checksum_audit_logs, [:file_set_id, :file_id], name: 'by_file_set_id_and_file_id', order: { created_at: 'DESC' } end def self.down - remove_index(:checksum_audit_logs, name: 'by_generic_file_id_and_file_id') + remove_index(:checksum_audit_logs, name: 'by_file_set_id_and_file_id') drop_table :checksum_audit_logs end end diff --git a/curation_concerns-models/lib/tasks/migrate.rake b/curation_concerns-models/lib/tasks/migrate.rake index 86751b2e3..5222b5b75 100644 --- a/curation_concerns-models/lib/tasks/migrate.rake +++ b/curation_concerns-models/lib/tasks/migrate.rake @@ -4,7 +4,7 @@ desc "Migrate audit logs" task audit_logs: :environment do ChecksumAuditLog.all.each do |cs| - cs.generic_file_id = cs.generic_file_id.delete "#{CurationConcerns.config.redis_namespace}:" + cs.file_set_id = cs.file_set_id.delete "#{CurationConcerns.config.redis_namespace}:" cs.save end end diff --git a/lib/curation_concerns/rails/routes.rb b/lib/curation_concerns/rails/routes.rb index 260265be1..147e19a82 100644 --- a/lib/curation_concerns/rails/routes.rb +++ b/lib/curation_concerns/rails/routes.rb @@ -4,7 +4,7 @@ def curation_concerns_basic_routes resources :downloads, only: :show # Batch edit routes get 'upload_sets/:id/edit' => 'upload_sets#edit', as: :edit_upload_set - post 'upload_sets/:id' => 'upload_sets#update', as: :upload_set_generic_files + post 'upload_sets/:id' => 'upload_sets#update', as: :upload_set_file_sets namespace :curation_concerns, path: :concern do CurationConcerns.config.registered_curation_concern_types.map(&:tableize).each do |curation_concern_name| @@ -16,8 +16,8 @@ def curation_concerns_basic_routes post :copy end end - resources :generic_files, only: [:new, :create], path: 'container/:parent_id/generic_files' - resources :generic_files, only: [:show, :edit, :update, :destroy] do + resources :file_sets, only: [:new, :create], path: 'container/:parent_id/file_sets' + resources :file_sets, only: [:show, :edit, :update, :destroy] do member do get :versions put :rollback diff --git a/lib/generators/curation_concerns/work/templates/model.rb.erb b/lib/generators/curation_concerns/work/templates/model.rb.erb index b982e5a8a..6182ed7b8 100644 --- a/lib/generators/curation_concerns/work/templates/model.rb.erb +++ b/lib/generators/curation_concerns/work/templates/model.rb.erb @@ -1,7 +1,7 @@ # Generated via # `rails generate curation_concerns:work <%= class_name %>` class <%= class_name %> < ActiveFedora::Base - include ::CurationConcerns::GenericWorkBehavior + include ::CurationConcerns::WorkBehavior include ::CurationConcerns::BasicMetadata validates :title, presence: { message: 'Your work must have a title.' } end diff --git a/spec/abilities/collection_abilities_spec.rb b/spec/abilities/collection_abilities_spec.rb index fa02ba659..e866a6f4d 100644 --- a/spec/abilities/collection_abilities_spec.rb +++ b/spec/abilities/collection_abilities_spec.rb @@ -6,10 +6,10 @@ subject { ability } let(:ability) { Ability.new(current_user) } let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE } - let(:creating_user) { FactoryGirl.create(:user) } - let(:user) { FactoryGirl.create(:user) } + let(:creating_user) { create(:user) } + let(:user) { create(:user) } let(:current_user) { user } - let(:collection) { FactoryGirl.create(:collection, visibility: visibility, user: creating_user) } + let(:collection) { create(:collection, visibility: visibility, user: creating_user) } before do collection.visibility = visibility collection.save @@ -38,7 +38,7 @@ describe 'a nil user' do let(:current_user) { nil } it do - should_not be_able_to(:create, GenericFile.new) + should_not be_able_to(:create, ::Collection.new) should_not be_able_to(:read, collection) should_not be_able_to(:update, collection) should_not be_able_to(:destroy, collection) diff --git a/spec/abilities/file_set_abilities_spec.rb b/spec/abilities/file_set_abilities_spec.rb new file mode 100644 index 000000000..284e3c96f --- /dev/null +++ b/spec/abilities/file_set_abilities_spec.rb @@ -0,0 +1,67 @@ +require 'spec_helper' +require 'cancan/matchers' + +describe 'User' do + describe 'Abilities' do + subject { ability } + let(:ability) { Ability.new(current_user) } + let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE } + let(:creating_user) { create(:user) } + let(:user) { create(:user) } + let(:current_user) { user } + let(:generic_work) { create(:generic_work, visibility: visibility, user: creating_user) } + let(:file_set) { create(:file_set, visibility: visibility, user: creating_user) } + + describe 'without embargo' do + describe 'creator of object' do + let(:creating_user) { user } + let(:current_user) { user } + it do + is_expected.to be_able_to(:create, FileSet.new) + is_expected.to be_able_to(:versions, file_set) + is_expected.to be_able_to(:read, file_set) + is_expected.to be_able_to(:update, file_set) + is_expected.to_not be_able_to(:delete, file_set) + end + end + + describe 'as a repository manager' do + let(:manager_user) { FactoryGirl.create(:admin) } + let(:creating_user) { user } + let(:current_user) { manager_user } + it do + is_expected.to be_able_to(:create, FileSet.new) + is_expected.to be_able_to(:versions, file_set) + is_expected.to be_able_to(:read, file_set) + is_expected.to be_able_to(:update, file_set) + is_expected.to be_able_to(:destroy, file_set) + end + end + + describe 'another authenticated user' do + let(:creating_user) { FactoryGirl.create(:user) } + let(:current_user) { user } + + it do + is_expected.to be_able_to(:create, FileSet.new) + is_expected.to_not be_able_to(:versions, file_set) + is_expected.to_not be_able_to(:read, file_set) + is_expected.to_not be_able_to(:update, file_set) + is_expected.to_not be_able_to(:delete, file_set) + end + end + + describe 'a nil user' do + let(:creating_user) { FactoryGirl.create(:user) } + let(:current_user) { nil } + it do + is_expected.to_not be_able_to(:create, FileSet.new) + is_expected.to_not be_able_to(:versions, file_set) + is_expected.to_not be_able_to(:read, file_set) + is_expected.to_not be_able_to(:update, file_set) + is_expected.to_not be_able_to(:delete, file_set) + end + end + end + end +end diff --git a/spec/abilities/generic_file_abilities_spec.rb b/spec/abilities/generic_file_abilities_spec.rb deleted file mode 100644 index 9e645af42..000000000 --- a/spec/abilities/generic_file_abilities_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'spec_helper' -require 'cancan/matchers' - -describe 'User' do - describe 'Abilities' do - subject { ability } - let(:ability) { Ability.new(current_user) } - let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE } - let(:creating_user) { FactoryGirl.create(:user) } - let(:user) { FactoryGirl.create(:user) } - let(:current_user) { user } - let(:generic_work) { FactoryGirl.create(:generic_work, visibility: visibility, user: creating_user) } - let(:generic_file) { FactoryGirl.create(:generic_file, visibility: visibility, user: creating_user) } - - describe 'without embargo' do - describe 'creator of object' do - let(:creating_user) { user } - let(:current_user) { user } - it do - is_expected.to be_able_to(:create, GenericFile.new) - is_expected.to be_able_to(:versions, generic_file) - is_expected.to be_able_to(:read, generic_file) - is_expected.to be_able_to(:update, generic_file) - is_expected.to_not be_able_to(:delete, generic_file) - end - end - - describe 'as a repository manager' do - let(:manager_user) { FactoryGirl.create(:admin) } - let(:creating_user) { user } - let(:current_user) { manager_user } - it do - is_expected.to be_able_to(:create, GenericFile.new) - is_expected.to be_able_to(:versions, generic_file) - is_expected.to be_able_to(:read, generic_file) - is_expected.to be_able_to(:update, generic_file) - is_expected.to be_able_to(:destroy, generic_file) - end - end - - describe 'another authenticated user' do - let(:creating_user) { FactoryGirl.create(:user) } - let(:current_user) { user } - - it do - is_expected.to be_able_to(:create, GenericFile.new) - is_expected.to_not be_able_to(:versions, generic_file) - is_expected.to_not be_able_to(:read, generic_file) - is_expected.to_not be_able_to(:update, generic_file) - is_expected.to_not be_able_to(:delete, generic_file) - end - end - - describe 'a nil user' do - let(:creating_user) { FactoryGirl.create(:user) } - let(:current_user) { nil } - it do - is_expected.to_not be_able_to(:create, GenericFile.new) - is_expected.to_not be_able_to(:versions, generic_file) - is_expected.to_not be_able_to(:read, generic_file) - is_expected.to_not be_able_to(:update, generic_file) - is_expected.to_not be_able_to(:delete, generic_file) - end - end - end - end -end diff --git a/spec/actors/curation_concerns/generic_file_actor_spec.rb b/spec/actors/curation_concerns/file_set_actor_spec.rb similarity index 74% rename from spec/actors/curation_concerns/generic_file_actor_spec.rb rename to spec/actors/curation_concerns/file_set_actor_spec.rb index 26e98de3c..98cdd2ae3 100644 --- a/spec/actors/curation_concerns/generic_file_actor_spec.rb +++ b/spec/actors/curation_concerns/file_set_actor_spec.rb @@ -1,17 +1,17 @@ require 'spec_helper' -describe CurationConcerns::GenericFileActor do +describe CurationConcerns::FileSetActor do include ActionDispatch::TestProcess - let(:user) { FactoryGirl.create(:user) } - let(:generic_file) { FactoryGirl.create(:generic_file) } - let(:actor) { described_class.new(generic_file, user) } + let(:user) { create(:user) } + let(:file_set) { create(:file_set) } + let(:actor) { described_class.new(file_set, user) } let(:uploaded_file) { fixture_file_upload('/world.png', 'image/png') } describe 'creating metadata and content' do let(:upload_set_id) { nil } let(:work_id) { nil } - subject { generic_file.reload } + subject { file_set.reload } let(:date_today) { DateTime.now } before do @@ -20,7 +20,7 @@ before do expect(CharacterizeJob).to receive(:perform_later) - expect(IngestFileJob).to receive(:perform_later).with(generic_file.id, /world\.png$/, 'image/png', user.user_key) + expect(IngestFileJob).to receive(:perform_later).with(file_set.id, /world\.png$/, 'image/png', user.user_key) allow(actor).to receive(:acquire_lock_for).and_yield actor.create_metadata(upload_set_id, work_id) actor.create_content(uploaded_file) @@ -47,7 +47,7 @@ it 'adds the generic file to the parent work' do expect(subject.generic_works).to eq [work] - expect(work.reload.generic_files).to include(subject) + expect(work.reload.file_sets).to include(subject) # Confirming that date_uploaded and date_modified were set expect(subject.date_uploaded).to eq date_today.utc @@ -69,7 +69,7 @@ it 'copies visibility from the parent' do allow(actor).to receive(:acquire_lock_for).and_yield actor.create_metadata(nil, work_id) - saved_file = generic_file.reload + saved_file = file_set.reload expect(saved_file.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC end end @@ -77,23 +77,23 @@ describe '#create_content' do it 'calls ingest file job' do expect(CharacterizeJob).to receive(:perform_later) - expect(IngestFileJob).to receive(:perform_later).with(generic_file.id, /world\.png$/, 'image/png', user.user_key) + expect(IngestFileJob).to receive(:perform_later).with(file_set.id, /world\.png$/, 'image/png', user.user_key) actor.create_content(uploaded_file) end - context 'when generic_file.title is empty and generic_file.label is not' do + context 'when file_set.title is empty and file_set.label is not' do let(:file) { 'world.png' } let(:long_name) { 'an absurdly long title that goes on way to long and messes up the display of the page which should not need to be this big in order to show this impossibly long, long, long, oh so long string' } let(:short_name) { 'Nice Short Name' } - let(:actor) { described_class.new(generic_file, user) } + let(:actor) { described_class.new(file_set, user) } before do allow(CharacterizeJob).to receive(:perform_later) - allow(generic_file).to receive(:label).and_return(short_name) + allow(file_set).to receive(:label).and_return(short_name) actor.create_content(fixture_file_upload(file)) end - subject { generic_file.title } + subject { file_set.title } it { is_expected.to eql [short_name] } end @@ -101,13 +101,13 @@ context 'when a label is already specified' do let(:file) { 'world.png' } let(:label) { 'test_file.png' } - let(:generic_file_with_label) do - GenericFile.new do |f| + let(:file_set_with_label) do + FileSet.new do |f| f.apply_depositor_metadata(user.user_key) f.label = label end end - let(:actor) { described_class.new(generic_file_with_label, user) } + let(:actor) { described_class.new(file_set_with_label, user) } before do allow(IngestFileJob).to receive(:perform_later) @@ -116,7 +116,7 @@ end it "retains the object's original label" do - expect(generic_file_with_label.label).to eql(label) + expect(file_set_with_label.label).to eql(label) end end end @@ -124,20 +124,20 @@ describe "#destroy" do it "destroys the object" do actor.destroy - expect { generic_file.reload }.to raise_error ActiveFedora::ObjectNotFoundError + expect { file_set.reload }.to raise_error ActiveFedora::ObjectNotFoundError end context "representative of a work" do let!(:work) do - work = FactoryGirl.create(:generic_work) + work = create(:generic_work) # this is not part of a block on the create, since the work must be saved be fore the representative can be assigned - work.generic_files << generic_file - work.representative = generic_file.id + work.file_sets << file_set + work.representative = file_set.id work.save work end it "removes representative" do - expect(work.reload.representative).to eq(generic_file.id) + expect(work.reload.representative).to eq(file_set.id) actor.destroy expect(work.reload.representative).to be_nil end diff --git a/spec/actors/curation_concerns/work_actor_spec.rb b/spec/actors/curation_concerns/work_actor_spec.rb index 0d226bef8..1138d7287 100644 --- a/spec/actors/curation_concerns/work_actor_spec.rb +++ b/spec/actors/curation_concerns/work_actor_spec.rb @@ -59,7 +59,7 @@ it "applies it to attached files" do allow(CharacterizeJob).to receive(:perform_later).and_return(true) subject.create - file = curation_concern.generic_files.first + file = curation_concern.file_sets.first expect(file).to be_persisted expect(file.visibility_during_embargo).to eq 'authenticated' expect(file.visibility_after_embargo).to eq 'open' @@ -127,14 +127,14 @@ expect(curation_concern.date_modified).to eq xmas expect(curation_concern.depositor).to eq user.user_key expect(curation_concern.representative).to_not be_nil - expect(curation_concern.generic_files.size).to eq 1 + expect(curation_concern.file_sets.size).to eq 1 # Sanity test to make sure the file we uploaded is stored and has same permission as parent. - generic_file = curation_concern.generic_files.first + file_set = curation_concern.file_sets.first file.rewind - expect(generic_file.reload.original_file.content).to eq file.read + expect(file_set.reload.original_file.content).to eq file.read expect(curation_concern).to be_authenticated_only_access - expect(generic_file).to be_authenticated_only_access + expect(file_set).to be_authenticated_only_access end end end @@ -160,7 +160,7 @@ expect(curation_concern.date_modified).to eq xmas expect(curation_concern.depositor).to eq user.user_key - expect(curation_concern.generic_files.size).to eq 2 + expect(curation_concern.file_sets.size).to eq 2 # Sanity test to make sure the file we uploaded is stored and has same permission as parent. expect(curation_concern).to be_authenticated_only_access @@ -230,18 +230,18 @@ end end - context 'with multiple files file' do - let(:file1) { FactoryGirl.create(:generic_file) } - let(:file2) { FactoryGirl.create(:generic_file) } - let(:curation_concern) { FactoryGirl.create(:generic_work, user: user, generic_files: [file1, file2]) } + context 'with multiple file sets' do + let(:file_set1) { create(:file_set) } + let(:file_set2) { create(:file_set) } + let(:curation_concern) { FactoryGirl.create(:generic_work, user: user, file_sets: [file_set1, file_set2]) } let(:attributes) do - FactoryGirl.attributes_for(:generic_work, generic_files: [file2, file1]) + FactoryGirl.attributes_for(:generic_work, file_sets: [file_set2, file_set1]) end - it 'updates the order of files' do - expect(curation_concern.generic_files).to eq [file1, file2] + it 'updates the order of file sets' do + expect(curation_concern.file_sets).to eq [file_set1, file_set2] expect(subject.update).to be true curation_concern.reload - expect(curation_concern.generic_files).to eq [file2, file1] + expect(curation_concern.file_sets).to eq [file_set2, file_set1] end end end diff --git a/spec/controllers/catalog_controller_spec.rb b/spec/controllers/catalog_controller_spec.rb index 736c1b770..fe8bd4fba 100644 --- a/spec/controllers/catalog_controller_spec.rb +++ b/spec/controllers/catalog_controller_spec.rb @@ -10,7 +10,7 @@ let!(:work1) { FactoryGirl.create(:work_with_one_file, user: user) } let!(:work2) { FactoryGirl.create(:public_generic_work) } let!(:collection) { FactoryGirl.create(:collection, user: user) } - let!(:file) { work1.generic_files.first } + let!(:file) { work1.file_sets.first } before do sign_in user end diff --git a/spec/controllers/curation_concerns/generic_files_controller_json_spec.rb b/spec/controllers/curation_concerns/file_sets_controller_json_spec.rb similarity index 64% rename from spec/controllers/curation_concerns/generic_files_controller_json_spec.rb rename to spec/controllers/curation_concerns/file_sets_controller_json_spec.rb index d4cdd82a5..bed5aae6a 100644 --- a/spec/controllers/curation_concerns/generic_files_controller_json_spec.rb +++ b/spec/controllers/curation_concerns/file_sets_controller_json_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -describe CurationConcerns::GenericFilesController do +describe CurationConcerns::FileSetsController do let(:user) { create(:user) } - let(:parent) { FactoryGirl.create(:generic_work, edit_users: [user.user_key], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) } - let(:generic_file) do - generic_file = create(:generic_file, user: user) - parent.generic_files << generic_file - generic_file + let(:parent) { create(:generic_work, edit_users: [user.user_key], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) } + let(:file_set) do + create(:file_set, user: user).tap do |file_set| + parent.file_sets << file_set + end end let(:file) { fixture_file_upload('/world.png', 'image/png') } let(:empty_file) { fixture_file_upload('/empty_file.txt', 'text/plain') } @@ -14,7 +14,7 @@ before { sign_in user } context "JSON" do - let(:resource) { generic_file } + let(:resource) { file_set } let(:resource_request) { get :show, id: resource, format: :json } subject { response } describe "unauthorized" do @@ -41,53 +41,53 @@ expect(controller.send(:actor)).to receive(:create_metadata).with(nil, parent.id, hash_including(:files, title: ['a title'])) expect(controller.send(:actor)).to receive(:create_content).with(file).and_return(true) - allow_any_instance_of(GenericFile).to receive(:persisted?).and_return(true) - allow_any_instance_of(GenericFile).to receive(:to_param).and_return('999') + allow_any_instance_of(FileSet).to receive(:persisted?).and_return(true) + allow_any_instance_of(FileSet).to receive(:to_param).and_return('999') - post :create, generic_file: { title: ['a title'], files: [file] }, parent_id: parent.id, format: :json + post :create, file_set: { title: ['a title'], files: [file] }, parent_id: parent.id, format: :json - expect(assigns[:generic_file]).to be_instance_of ::GenericFile # this object is used by the jbuilder template - expect(controller).to render_template('curation_concerns/generic_files/jq_upload') + expect(assigns[:file_set]).to be_instance_of ::FileSet # this object is used by the jbuilder template + expect(controller).to render_template('curation_concerns/file_sets/jq_upload') expect(response.status).to eq 201 created_resource = controller.curation_concern - expect(response.location).to eq main_app.curation_concerns_generic_file_path(created_resource) + expect(response.location).to eq main_app.curation_concerns_file_set_path(created_resource) end end describe 'failed create: no file' do - before { post :create, generic_file: { title: ["foo"] }, parent_id: parent.id, format: :json } + before { post :create, file_set: { title: ["foo"] }, parent_id: parent.id, format: :json } it { is_expected.to respond_bad_request(message: 'Error! No file to save') } end describe 'failed create: bad file' do - before { post :create, generic_file: { files: ['not a file'] }, parent_id: parent.id, format: :json } + before { post :create, file_set: { files: ['not a file'] }, parent_id: parent.id, format: :json } it { is_expected.to respond_bad_request(message: 'Error! No file for upload', description: 'unknown file') } end describe 'failed create: empty file' do - before { post :create, generic_file: { files: [empty_file] }, parent_id: parent.id, format: :json } + before { post :create, file_set: { files: [empty_file] }, parent_id: parent.id, format: :json } it { is_expected.to respond_unprocessable_entity(errors: { files: "#{empty_file.original_filename} has no content! (Zero length file)" }, description: I18n.t('curation_concerns.api.unprocessable_entity.empty_file')) } end describe 'failed create: solr error' do before do allow(controller).to receive(:process_file).and_raise(RSolr::Error::Http.new(controller.request, response)) - post :create, generic_file: { files: [file] }, parent_id: parent.id, format: :json + post :create, file_set: { files: [file] }, parent_id: parent.id, format: :json end it { is_expected.to respond_internal_error(message: 'Error occurred while creating generic file.') } end describe 'found' do before { resource_request } it "returns json of the work" do - expect(assigns[:generic_file]).to be_instance_of ::GenericFile # this object is used by the jbuilder template - expect(controller).to render_template('curation_concerns/generic_files/show') + expect(assigns[:file_set]).to be_instance_of ::FileSet # this object is used by the jbuilder template + expect(controller).to render_template('curation_concerns/file_sets/show') expect(response.code).to eq "200" end end describe 'updated' do - before { put :update, id: resource, generic_file: { title: ['updated title'] }, format: :json } + before { put :update, id: resource, file_set: { title: ['updated title'] }, format: :json } it "returns json of updated work and sets location header" do - expect(assigns[:generic_file]).to be_instance_of ::GenericFile # this object is used by the jbuilder template - expect(controller).to render_template('curation_concerns/generic_files/show') + expect(assigns[:file_set]).to be_instance_of ::FileSet # this object is used by the jbuilder template + expect(controller).to render_template('curation_concerns/file_sets/show') expect(response.status).to eq 200 - created_resource = assigns[:generic_file] - expect(response.location).to eq main_app.curation_concerns_generic_file_path(created_resource) + created_resource = assigns[:file_set] + expect(response.location).to eq main_app.curation_concerns_file_set_path(created_resource) end end describe 'failed update' do @@ -96,7 +96,7 @@ controller.curation_concern.errors.add(:some_field, "This is not valid. Fix it.") false end - post :update, id: resource, generic_file: { title: nil, depositor: nil }, format: :json + post :update, id: resource, file_set: { title: nil, depositor: nil }, format: :json } it "returns 422 and the errors" do expect(response).to respond_unprocessable_entity(errors: { "some_field": ["This is not valid. Fix it."] }) diff --git a/spec/controllers/curation_concerns/generic_files_controller_spec.rb b/spec/controllers/curation_concerns/file_sets_controller_spec.rb similarity index 63% rename from spec/controllers/curation_concerns/generic_files_controller_spec.rb rename to spec/controllers/curation_concerns/file_sets_controller_spec.rb index 65b5ea571..c86c7867f 100644 --- a/spec/controllers/curation_concerns/generic_files_controller_spec.rb +++ b/spec/controllers/curation_concerns/file_sets_controller_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe CurationConcerns::GenericFilesController do +describe CurationConcerns::FileSetsController do let(:user) { FactoryGirl.create(:user) } let(:file) { fixture_file_upload('files/image.png', 'image/png') } let(:parent) { FactoryGirl.create(:generic_work, edit_users: [user.user_key], visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) } @@ -10,7 +10,7 @@ describe '#create' do before do - GenericFile.destroy_all + FileSet.destroy_all end context 'on the happy path' do @@ -24,18 +24,18 @@ expect(controller.send(:actor)).to receive(:create_metadata).with(nil, parent.id, files: [file], title: ['test title'], visibility: 'restricted') expect(controller.send(:actor)).to receive(:create_content).with(file).and_return(true) xhr :post, :create, parent_id: parent, - generic_file: { files: [file], - title: ['test title'], - visibility: 'restricted' } + file_set: { files: [file], + title: ['test title'], + visibility: 'restricted' } expect(response).to be_success expect(flash[:error]).to be_nil end end context "on something that isn't a file" do - # Note: This is a duplicate of coverage in generic_files_controller_json_spec.rb + # Note: This is a duplicate of coverage in file_sets_controller_json_spec.rb it 'renders error' do - xhr :post, :create, parent_id: parent, generic_file: { files: ['hello'] }, + xhr :post, :create, parent_id: parent, file_set: { files: ['hello'] }, permission: { group: { 'public' => 'read' } }, terms_of_service: '1' expect(response.status).to eq 400 msg = JSON.parse(response.body)['message'] @@ -46,8 +46,8 @@ context 'when the file has a virus' do it 'displays a flash error' do skip 'pending hydra-works#89' - expect(CurationConcerns::GenericFileActor).to receive(:virus_check).with(file.path).and_raise(CurationConcerns::VirusFoundError.new('A virus was found')) - xhr :post, :create, parent_id: parent, generic_file: { files: [file] }, + expect(CurationConcerns::FileSetActor).to receive(:virus_check).with(file.path).and_raise(CurationConcerns::VirusFoundError.new('A virus was found')) + xhr :post, :create, parent_id: parent, file_set: { files: [file] }, permission: { group: { 'public' => 'read' } }, terms_of_service: '1' expect(flash[:error]).to include('A virus was found') end @@ -60,7 +60,7 @@ end it 'errors out of create after on continuous rsolr error' do - xhr :post, :create, parent_id: parent, generic_file: { files: [file] }, + xhr :post, :create, parent_id: parent, file_set: { files: [file] }, permission: { group: { 'public' => 'read' } }, terms_of_service: '1' expect(response.body).to include('Error occurred while creating generic file.') end @@ -68,79 +68,79 @@ end describe 'destroy' do - let(:generic_file) do - generic_file = GenericFile.create! do |gf| + let(:file_set) do + file_set = FileSet.create! do |gf| gf.apply_depositor_metadata(user) end - parent.generic_files << generic_file - generic_file + parent.file_sets << file_set + file_set end it 'deletes the file' do - expect(GenericFile.find(generic_file.id)).to be_kind_of GenericFile - delete :destroy, id: generic_file - expect { GenericFile.find(generic_file.id) }.to raise_error Ldp::Gone + expect(FileSet.find(file_set.id)).to be_kind_of FileSet + delete :destroy, id: file_set + expect { FileSet.find(file_set.id) }.to raise_error Ldp::Gone expect(response).to redirect_to main_app.curation_concerns_generic_work_path(parent) end end describe 'update' do - let!(:generic_file) do - generic_file = GenericFile.new.tap do |gf| + let!(:file_set) do + file_set = FileSet.new.tap do |gf| gf.apply_depositor_metadata(user) gf.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE gf.save! end - parent.generic_files << generic_file - generic_file + parent.file_sets << file_set + file_set end after do - generic_file.destroy + file_set.destroy end context 'updating metadata' do it 'is successful and update attributes' do - post :update, id: generic_file, generic_file: + post :update, id: file_set, file_set: { title: ['new_title'], tag: [''], permissions_attributes: [{ type: 'person', name: 'archivist1', access: 'edit' }] } - expect(response).to redirect_to main_app.curation_concerns_generic_file_path(generic_file) - expect(assigns[:generic_file].title).to eq(['new_title']) + expect(response).to redirect_to main_app.curation_concerns_file_set_path(file_set) + expect(assigns[:file_set].title).to eq(['new_title']) end it 'goes back to edit on an error' do - allow_any_instance_of(GenericFile).to receive(:valid?).and_return(false) - post :update, id: generic_file, generic_file: + allow_any_instance_of(FileSet).to receive(:valid?).and_return(false) + post :update, id: file_set, file_set: { title: ['new_title'], tag: [''], permissions_attributes: [{ type: 'person', name: 'archivist1', access: 'edit' }] } expect(response.status).to eq 422 expect(response).to render_template('edit') - expect(assigns[:generic_file]).to eq generic_file + expect(assigns[:file_set]).to eq file_set end it 'adds a new groups and users' do - post :update, id: generic_file, generic_file: + post :update, id: file_set, file_set: { title: ['new_title'], tag: [''], permissions_attributes: [{ type: 'group', name: 'group1', access: 'read' }, { type: 'person', name: 'user1', access: 'edit' }] } - expect(assigns[:generic_file].read_groups).to eq ['group1'] - expect(assigns[:generic_file].edit_users).to include('user1') + expect(assigns[:file_set].read_groups).to eq ['group1'] + expect(assigns[:file_set].edit_users).to include('user1') end it 'updates existing groups and users' do - generic_file.read_groups = ['group3'] - generic_file.save! # TODO: slow , more than one save. - post :update, id: generic_file, generic_file: + file_set.read_groups = ['group3'] + file_set.save! # TODO: slow , more than one save. + post :update, id: file_set, file_set: { title: ['new_title'], tag: [''], permissions_attributes: [{ type: 'group', name: 'group3', access: 'edit' }] } - expect(assigns[:generic_file].edit_groups).to eq ['group3'] + expect(assigns[:file_set].edit_groups).to eq ['group3'] end context 'updating visibility' do it 'applies public' do new_visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC - post :update, id: generic_file, generic_file: { visibility: new_visibility, embargo_release_date: '' } - expect(generic_file.reload.visibility).to eq new_visibility + post :update, id: file_set, file_set: { visibility: new_visibility, embargo_release_date: '' } + expect(file_set.reload.visibility).to eq new_visibility end it 'applies embargo' do - post :update, id: generic_file, generic_file: { + post :update, id: file_set, file_set: { visibility: 'embargo', visibility_during_embargo: 'restricted', embargo_release_date: '2099-09-05', @@ -149,20 +149,21 @@ lease_expiration_date: '2099-09-05', visibility_after_lease: 'restricted' } - generic_file.reload - expect(generic_file).to be_under_embargo - expect(generic_file).to_not be_active_lease + file_set.reload + expect(file_set).to be_under_embargo + expect(file_set).to_not be_active_lease end end end context 'updating file content' do it 'is successful' do - expect(CharacterizeJob).to receive(:perform_later).with(generic_file.id, kind_of(String)) - post :update, id: generic_file, generic_file: { files: [file] } - expect(response).to redirect_to main_app.curation_concerns_generic_file_path(generic_file) + expect(IngestFileJob).to receive(:perform_later) + expect(CharacterizeJob).to receive(:perform_later).with(file_set.id, kind_of(String)) + post :update, id: file_set, file_set: { files: [file] } + expect(response).to redirect_to main_app.curation_concerns_file_set_path(file_set) skip 'pending hydra-works#89' - expect(generic_file.reload.label).to eq 'image.png' + expect(file_set.reload.label).to eq 'image.png' end end @@ -171,18 +172,18 @@ # don't run characterization jobs allow(CharacterizeJob).to receive(:perform_later) # Create version 1 - Hydra::Works::AddFileToGenericFile.call(generic_file, File.open(fixture_file_path('small_file.txt')), :original_file) + Hydra::Works::AddFileToFileSet.call(file_set, File.open(fixture_file_path('small_file.txt')), :original_file) # Create version 2 - Hydra::Works::AddFileToGenericFile.call(generic_file, File.open(fixture_file_path('curation_concerns_generic_stub.txt')), :original_file) + Hydra::Works::AddFileToFileSet.call(file_set, File.open(fixture_file_path('curation_concerns_generic_stub.txt')), :original_file) end - # TODO: This test should move into the GenericFileActor spec and just ensure the actor is called. + # TODO: This test should move into the FileSetActor spec and just ensure the actor is called. it 'is successful' do - expect(generic_file.latest_content_version.label).to eq('version2') - expect(generic_file.original_file.content).to eq("This is a test fixture for curation_concerns: <%= @id %>.\n") - post :update, id: generic_file, revision: 'version1' - expect(response).to redirect_to main_app.curation_concerns_generic_file_path(generic_file) - reloaded = generic_file.reload.original_file + expect(file_set.latest_content_version.label).to eq('version2') + expect(file_set.original_file.content).to eq("This is a test fixture for curation_concerns: <%= @id %>.\n") + post :update, id: file_set, revision: 'version1' + expect(response).to redirect_to main_app.curation_concerns_file_set_path(file_set) + reloaded = file_set.reload.original_file expect(reloaded.versions.last.label).to eq 'version3' expect(reloaded.content).to eq "small\n" expect(reloaded.mime_type).to eq 'text/plain' @@ -193,12 +194,12 @@ context 'someone elses (public) files' do let(:creator) { create(:user, email: 'archivist1@example.com') } - let(:public_generic_file) { create(:generic_file, user: creator, read_groups: ['public']) } + let(:public_file_set) { create(:file_set, user: creator, read_groups: ['public']) } before { sign_in user } describe '#edit' do it 'gives me the unauthorized page' do - get :edit, id: public_generic_file + get :edit, id: public_file_set expect(response.code).to eq '401' expect(response).to render_template(:unauthorized) end @@ -206,32 +207,32 @@ describe '#show' do it 'allows access to the file' do - get :show, id: public_generic_file + get :show, id: public_file_set expect(response).to be_success end end end context 'when not signed in' do - let(:private_generic_file) { create(:generic_file) } - let(:public_generic_file) { create(:generic_file, read_groups: ['public']) } + let(:private_file_set) { create(:file_set) } + let(:public_file_set) { create(:file_set, read_groups: ['public']) } describe '#edit' do it 'requires login' do - get :edit, id: public_generic_file + get :edit, id: public_file_set expect(response).to fail_redirect_and_flash(main_app.new_user_session_path, 'You are not authorized to access this page.') end end describe '#show' do it 'denies access to private files' do - get :show, id: private_generic_file + get :show, id: private_file_set expect(response).to fail_redirect_and_flash(main_app.new_user_session_path, 'You are not authorized to access this page.') end it 'allows access to public files' do expect(controller).to receive(:additional_response_formats).with(ActionController::MimeResponds::Collector) - get :show, id: public_generic_file + get :show, id: public_file_set expect(response).to be_success end end diff --git a/spec/controllers/curation_concerns/single_use_links_controller_spec.rb b/spec/controllers/curation_concerns/single_use_links_controller_spec.rb index a9a44a140..d96af583e 100644 --- a/spec/controllers/curation_concerns/single_use_links_controller_spec.rb +++ b/spec/controllers/curation_concerns/single_use_links_controller_spec.rb @@ -5,7 +5,7 @@ let(:user) { FactoryGirl.find_or_create(:jill) } let(:file) do - GenericFile.create do |file| + FileSet.create do |file| file.apply_depositor_metadata(user) end end diff --git a/spec/controllers/curation_concerns/single_use_links_viewer_controller_spec.rb b/spec/controllers/curation_concerns/single_use_links_viewer_controller_spec.rb index 73a0113e7..962fea3f5 100644 --- a/spec/controllers/curation_concerns/single_use_links_viewer_controller_spec.rb +++ b/spec/controllers/curation_concerns/single_use_links_viewer_controller_spec.rb @@ -3,17 +3,17 @@ describe CurationConcerns::SingleUseLinksViewerController do routes { CurationConcerns::Engine.routes } let(:file) do - file = GenericFile.create do |lfile| + file = FileSet.create do |lfile| lfile.label = 'world.png' lfile.apply_depositor_metadata('mjg') end - Hydra::Works::AddFileToGenericFile.call(file, File.open(fixture_path + '/world.png'), :original_file) + Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_path + '/world.png'), :original_file) file end describe "retrieval links" do let :show_link do - SingleUseLink.create itemId: file.id, path: Rails.application.routes.url_helpers.curation_concerns_generic_file_path(id: file) + SingleUseLink.create itemId: file.id, path: Rails.application.routes.url_helpers.curation_concerns_file_set_path(id: file) end let :download_link do diff --git a/spec/controllers/downloads_controller_spec.rb b/spec/controllers/downloads_controller_spec.rb index 1835d2455..92950bd69 100644 --- a/spec/controllers/downloads_controller_spec.rb +++ b/spec/controllers/downloads_controller_spec.rb @@ -3,7 +3,7 @@ describe DownloadsController do describe '#show' do let(:user) { FactoryGirl.create(:user) } - let(:generic_file) do + let(:file_set) do FactoryGirl.create(:file_with_work, user: user, content: File.open(fixture_file_path('files/image.png'))) end it 'raise not_found if the object does not exist' do @@ -17,7 +17,7 @@ sign_in another_user end it 'redirects to root' do - get :show, id: generic_file.to_param + get :show, id: file_set.to_param expect(response).to redirect_to root_path expect(flash['alert']).to eq 'You are not authorized to access this page.' end @@ -25,7 +25,7 @@ context "when user isn't logged in" do it 'redirects to sign in' do - get :show, id: generic_file.to_param + get :show, id: file_set.to_param expect(response).to redirect_to new_user_session_path expect(flash['alert']).to eq 'You are not authorized to access this page.' end @@ -37,8 +37,8 @@ end it 'sends the original file' do - get :show, id: generic_file - expect(response.body).to eq generic_file.original_file.content + get :show, id: file_set + expect(response.body).to eq file_set.original_file.content end context "with an alternative file" do @@ -52,7 +52,7 @@ end it 'sends requested file content' do - get :show, id: generic_file, file: 'thumbnail' + get :show, id: file_set, file: 'thumbnail' expect(response.body).to eq content expect(response.headers['Content-Length']).to eq "4218" expect(response.headers['Accept-Ranges']).to eq "bytes" @@ -61,14 +61,14 @@ context "that isn't persisted" do it "returns 404 if the requested file does not exist" do - get :show, id: generic_file, file: 'thumbnail' + get :show, id: file_set, file: 'thumbnail' expect(response.status).to eq 404 end end end it "returns 404 if the requested association does not exist" do - get :show, id: generic_file, file: 'non-existant' + get :show, id: file_set, file: 'non-existant' expect(response.status).to eq 404 end end diff --git a/spec/controllers/embargoes_controller_spec.rb b/spec/controllers/embargoes_controller_spec.rb index 36c32a98f..62d3fb1de 100644 --- a/spec/controllers/embargoes_controller_spec.rb +++ b/spec/controllers/embargoes_controller_spec.rb @@ -64,7 +64,7 @@ context 'that has files' do before do - a_work.generic_files << create(:generic_file) + a_work.file_sets << create(:file_set) a_work.save! end @@ -79,10 +79,10 @@ describe '#update' do context 'when I have permission to edit the object' do - let(:a_file) { FactoryGirl.create(:generic_file, visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED) } + let(:file_set) { create(:file_set, visibility: Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED) } let(:release_date) { Date.today + 2 } before do - a_work.generic_files << a_file + a_work.file_sets << file_set a_work.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED a_work.visibility_during_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED a_work.visibility_after_embargo = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC @@ -96,7 +96,7 @@ it 'deactivates embargo, update the visibility and redirect' do patch :update, batch_document_ids: [a_work.id], embargoes: { '0' => { copy_visibility: a_work.id } } expect(a_work.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC - expect(a_file.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC + expect(file_set.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC expect(response).to redirect_to embargoes_path end end diff --git a/spec/controllers/leases_controller_spec.rb b/spec/controllers/leases_controller_spec.rb index 6f05e7cf7..b314a3c12 100644 --- a/spec/controllers/leases_controller_spec.rb +++ b/spec/controllers/leases_controller_spec.rb @@ -63,7 +63,7 @@ context 'with files' do before do - a_work.generic_files << create(:generic_file) + a_work.file_sets << create(:file_set) a_work.save! end diff --git a/spec/controllers/upload_sets_controller_spec.rb b/spec/controllers/upload_sets_controller_spec.rb index 542448d82..52fdd96ea 100644 --- a/spec/controllers/upload_sets_controller_spec.rb +++ b/spec/controllers/upload_sets_controller_spec.rb @@ -14,7 +14,7 @@ it "enqueues a upload_set job and redirects to generic_works list with a flash message" do expect(UploadSetUpdateJob).to receive(:perform_later).with(user.user_key, upload_set.id, { '1' => 'foo' }, { tag: [] }, 'open').once - post :update, id: upload_set.id, title: { '1' => 'foo' }, visibility: 'open', generic_file: { tag: [""] } + post :update, id: upload_set.id, title: { '1' => 'foo' }, visibility: 'open', file_set: { tag: [""] } expect(response).to redirect_to routes.url_helpers.curation_concerns_generic_works_path expect(flash[:notice]).to include("Your files are being processed") end @@ -22,22 +22,22 @@ describe "when user has edit permissions on a file" do # TODO: all these tests could move to upload_set_update_job_spec.rb - let!(:file) { GenericFile.create(upload_set: upload_set) { |f| f.apply_depositor_metadata(user) } } + let!(:file) { FileSet.create(upload_set: upload_set) { |f| f.apply_depositor_metadata(user) } } it "they can set permissions groups" do - post :update, id: upload_set, "generic_file" => { "permissions_attributes" => [{ "type" => "group", "name" => "public", "access" => "read" }] } + post :update, id: upload_set, "file_set" => { "permissions_attributes" => [{ "type" => "group", "name" => "public", "access" => "read" }] } file.reload expect(file.read_groups).to include "public" expect(response).to redirect_to routes.url_helpers.curation_concerns_generic_works_path end it "they can set public read access" do - post :update, id: upload_set, visibility: "open", generic_file: { tag: [""] } + post :update, id: upload_set, visibility: "open", file_set: { tag: [""] } expect(file.reload.read_groups).to eq ['public'] end it "they can set metadata like title" do - post :update, id: upload_set, generic_file: { tag: ["footag", "bartag"] }, title: { file.id => ["New Title"] } + post :update, id: upload_set, file_set: { tag: ["footag", "bartag"] }, title: { file.id => ["New Title"] } file.reload expect(file.title).to eq ["New Title"] # TODO: is order important? @@ -45,7 +45,7 @@ end it "they cannot set any tags" do - post :update, id: upload_set, generic_file: { tag: [""] } + post :update, id: upload_set, file_set: { tag: [""] } expect(file.reload.tag).to be_empty end end @@ -53,14 +53,14 @@ describe "when user does not have edit permissions on a file" do # TODO: all these tests could move to upload_set_update_job_spec.rb let(:file) do - GenericFile.new(upload_set: upload_set, title: ['Original Title']).tap do |f| + FileSet.new(upload_set: upload_set, title: ['Original Title']) do |f| f.apply_depositor_metadata('someone_else') f.save! end end it "they cannot modify the object" do - post :update, id: upload_set, "generic_file" => { "read_groups_string" => "group1, group2", "read_users_string" => "", "tag" => [""] }, "title" => { file.id => "Title Wont Change" } + post :update, id: upload_set, "file_set" => { "read_groups_string" => "group1, group2", "read_users_string" => "", "tag" => [""] }, "title" => { file.id => "Title Wont Change" } file.reload expect(file.title).to eq ["Original Title"] expect(file.read_groups).to eq [] @@ -70,8 +70,8 @@ describe "#edit" do let(:us1) { UploadSet.create } - let!(:file) { GenericFile.create(upload_set: us1, label: 'f1') { |f| f.apply_depositor_metadata(user) } } - let!(:file2) { GenericFile.create(upload_set: us1, label: 'f2') { |f| f.apply_depositor_metadata(user) } } + let!(:file) { FileSet.create(upload_set: us1, label: 'f1') { |f| f.apply_depositor_metadata(user) } } + let!(:file2) { FileSet.create(upload_set: us1, label: 'f2') { |f| f.apply_depositor_metadata(user) } } it "sets up attributes for the form" do get :edit, id: us1 diff --git a/spec/factories/generic_files.rb b/spec/factories/file_sets.rb similarity index 68% rename from spec/factories/generic_files.rb rename to spec/factories/file_sets.rb index d813e6c21..cb6c0cd0f 100644 --- a/spec/factories/generic_files.rb +++ b/spec/factories/file_sets.rb @@ -1,7 +1,7 @@ FactoryGirl.define do - # The ::GenericFile model is defined in spec/internal/app/models by the + # The ::FileSet model is defined in spec/internal/app/models by the # curation_concerns:install generator. - factory :generic_file, class: GenericFile do + factory :file_set, class: FileSet do transient do user { FactoryGirl.create(:user) } content nil @@ -9,7 +9,7 @@ after(:create) do |file, evaluator| if evaluator.content - Hydra::Works::UploadFileToGenericFile.call(file, evaluator.content) + Hydra::Works::UploadFileToFileSet.call(file, evaluator.content) end end @@ -19,9 +19,9 @@ end after(:create) do |file, evaluator| if evaluator.content - Hydra::Works::UploadFileToGenericFile.call(file, evaluator.content) + Hydra::Works::UploadFileToFileSet.call(file, evaluator.content) end - FactoryGirl.create(:generic_work, user: evaluator.user).generic_files << file + FactoryGirl.create(:generic_work, user: evaluator.user).file_sets << file end end after(:build) do |file, evaluator| diff --git a/spec/factories/generic_works.rb b/spec/factories/generic_works.rb index c5ae2151a..af5cc4bc1 100644 --- a/spec/factories/generic_works.rb +++ b/spec/factories/generic_works.rb @@ -19,12 +19,12 @@ factory :work_with_one_file do before(:create) do |work, evaluator| - work.generic_files << FactoryGirl.create(:generic_file, user: evaluator.user, title: ['A Contained Generic File'], filename: 'filename.pdf') + work.file_sets << FactoryGirl.create(:file_set, user: evaluator.user, title: ['A Contained Generic File'], filename: 'filename.pdf') end end factory :work_with_files do - before(:create) { |work, evaluator| 2.times { work.generic_files << FactoryGirl.create(:generic_file, user: evaluator.user) } } + before(:create) { |work, evaluator| 2.times { work.file_sets << FactoryGirl.create(:file_set, user: evaluator.user) } } end factory :with_embargo_date do @@ -37,7 +37,7 @@ factory :embargoed_work_with_files do after(:build) { |work, evaluator| work.apply_embargo(evaluator.embargo_date, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC) } - after(:create) { |work, evaluator| 2.times { work.generic_files << FactoryGirl.create(:generic_file, user: evaluator.user) } } + after(:create) { |work, evaluator| 2.times { work.file_sets << FactoryGirl.create(:file_set, user: evaluator.user) } } end factory :leased_work do @@ -46,7 +46,7 @@ factory :leased_work_with_files do after(:build) { |work, evaluator| work.apply_lease(evaluator.embargo_date, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC, Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE) } - after(:create) { |work, evaluator| 2.times { work.generic_files << FactoryGirl.create(:generic_file, user: evaluator.user) } } + after(:create) { |work, evaluator| 2.times { work.file_sets << FactoryGirl.create(:file_set, user: evaluator.user) } } end end end diff --git a/spec/features/add_file_spec.rb b/spec/features/add_file_spec.rb index 60e79a9f6..73a7eba55 100644 --- a/spec/features/add_file_spec.rb +++ b/spec/features/add_file_spec.rb @@ -8,14 +8,14 @@ sign_in user # stub out characterization. Travis doesn't have fits installed, and it's not relevant to the test. allow(CharacterizeJob).to receive(:perform_later) - allow_any_instance_of(CurationConcerns::GenericFileActor).to receive(:acquire_lock_for).and_yield + allow_any_instance_of(CurationConcerns::FileSetActor).to receive(:acquire_lock_for).and_yield end it 'updates the file' do visit "/concern/generic_works/#{work.id}" click_link 'Attach a File' - within('form.new_generic_file') do + within('form.new_file_set') do fill_in('Title', with: 'image.png') attach_file('Upload a file', fixture_file_path('files/image.png')) click_on('Attach to Generic Work') diff --git a/spec/features/update_file_spec.rb b/spec/features/update_file_spec.rb index 94dba70ee..96339cd03 100644 --- a/spec/features/update_file_spec.rb +++ b/spec/features/update_file_spec.rb @@ -3,7 +3,7 @@ describe 'Editing attached files' do let(:user) { create(:user) } let!(:parent) { create(:work_with_one_file, user: user) } - let!(:generic_file) { parent.generic_files.first } + let!(:file_set) { parent.file_sets.first } before do sign_in user @@ -23,8 +23,8 @@ expect(page).to have_content 'The file A Contained Generic File has been updated.' # TODO: this stuff belongs in an Actor or Controller test: - generic_file.reload - expect(generic_file.original_file.original_name).to eq 'image.png' - expect(generic_file.original_file.mime_type).to eq 'image/png' + file_set.reload + expect(file_set.original_file.original_name).to eq 'image.png' + expect(file_set.original_file.mime_type).to eq 'image/png' end end diff --git a/spec/features/work_generator_spec.rb b/spec/features/work_generator_spec.rb index e3bdbddec..33deb6b32 100644 --- a/spec/features/work_generator_spec.rb +++ b/spec/features/work_generator_spec.rb @@ -24,7 +24,7 @@ it 'catapults should behave like generic works' do visit '/concern/catapults/new' - # within("form.new_generic_file") do + # within("form.new_file_set") do # attach_file("Upload a file", fixture_file_path('files/image.png')) # click_button "Attach to Generic Work" # end diff --git a/spec/forms/collection_edit_form_spec.rb b/spec/forms/collection_edit_form_spec.rb index 46cc07c69..62671b1a0 100644 --- a/spec/forms/collection_edit_form_spec.rb +++ b/spec/forms/collection_edit_form_spec.rb @@ -47,8 +47,8 @@ context 'with a work/file attached' do let(:work) { create(:work_with_one_file) } - let(:title) { work.generic_files.first.title.first } - let(:file_id) { work.generic_files.first.id } + let(:title) { work.file_sets.first.title.first } + let(:file_id) { work.file_sets.first.id } let(:collection_with_file) do Collection.create!(title: 'foo', members: [work]) do |c| c.apply_depositor_metadata('jcoyne') diff --git a/spec/forms/generic_file_edit_form_spec.rb b/spec/forms/file_set_edit_form_spec.rb similarity index 92% rename from spec/forms/generic_file_edit_form_spec.rb rename to spec/forms/file_set_edit_form_spec.rb index ef2583311..dae61e7e9 100644 --- a/spec/forms/generic_file_edit_form_spec.rb +++ b/spec/forms/file_set_edit_form_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe CurationConcerns::Forms::GenericFileEditForm do - subject { described_class.new(GenericFile.new) } +describe CurationConcerns::Forms::FileSetEditForm do + subject { described_class.new(FileSet.new) } describe '#terms' do it 'returns a list' do diff --git a/spec/helpers/curation_concerns/file_set_helper_spec.rb b/spec/helpers/curation_concerns/file_set_helper_spec.rb new file mode 100644 index 000000000..9d4ea7b3a --- /dev/null +++ b/spec/helpers/curation_concerns/file_set_helper_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper' + +describe CurationConcerns::FileSetHelper do + describe '#media_display' do + let(:file_set) { SolrDocument.new(mime_type_ssi: mime_type) } + let(:mime_type) { 'image/tiff' } + + before do + allow(helper).to receive(:media_display_partial).with(file_set) + .and_return('curation_concerns/file_sets/media_display/image') + end + + it "renders a partial" do + expect(helper).to receive(:render) + .with('curation_concerns/file_sets/media_display/image', file_set: file_set) + helper.media_display(file_set) + end + + it "takes options" do + expect(helper).to receive(:render) + .with('curation_concerns/file_sets/media_display/image', file_set: file_set, transcript_id: '123') + helper.media_display(file_set, transcript_id: '123') + end + end + + describe '#media_display_partial' do + subject { helper.media_display_partial(file_set) } + + let(:file_set) { SolrDocument.new(mime_type_ssi: mime_type) } + + context "with an image" do + let(:mime_type) { 'image/tiff' } + it { is_expected.to eq 'curation_concerns/file_sets/media_display/image' } + end + + context "with a video" do + let(:mime_type) { 'video/webm' } + it { is_expected.to eq 'curation_concerns/file_sets/media_display/video' } + end + + context "with an audio" do + let(:mime_type) { 'audio/wav' } + it { is_expected.to eq 'curation_concerns/file_sets/media_display/audio' } + end + + context "with a pdf" do + let(:mime_type) { 'application/pdf' } + it { is_expected.to eq 'curation_concerns/file_sets/media_display/pdf' } + end + + context "with a word document" do + let(:mime_type) { 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' } + it { is_expected.to eq 'curation_concerns/file_sets/media_display/office_document' } + end + + context "with anything else" do + let(:mime_type) { 'application/binary' } + it { is_expected.to eq 'curation_concerns/file_sets/media_display/default' } + end + end +end diff --git a/spec/helpers/curation_concerns/generic_file_helper_spec.rb b/spec/helpers/curation_concerns/generic_file_helper_spec.rb deleted file mode 100644 index 095c74a21..000000000 --- a/spec/helpers/curation_concerns/generic_file_helper_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'spec_helper' - -describe CurationConcerns::GenericFileHelper do - describe '#media_display' do - let(:generic_file) { SolrDocument.new(mime_type_ssi: mime_type) } - let(:mime_type) { 'image/tiff' } - - before do - allow(helper).to receive(:media_display_partial).with(generic_file) - .and_return('curation_concerns/generic_files/media_display/image') - end - - it "renders a partial" do - expect(helper).to receive(:render) - .with('curation_concerns/generic_files/media_display/image', generic_file: generic_file) - helper.media_display(generic_file) - end - - it "takes options" do - expect(helper).to receive(:render) - .with('curation_concerns/generic_files/media_display/image', generic_file: generic_file, transcript_id: '123') - helper.media_display(generic_file, transcript_id: '123') - end - end - - describe '#media_display_partial' do - subject { helper.media_display_partial(generic_file) } - - let(:generic_file) { SolrDocument.new(mime_type_ssi: mime_type) } - - context "with an image" do - let(:mime_type) { 'image/tiff' } - it { is_expected.to eq 'curation_concerns/generic_files/media_display/image' } - end - - context "with a video" do - let(:mime_type) { 'video/webm' } - it { is_expected.to eq 'curation_concerns/generic_files/media_display/video' } - end - - context "with an audio" do - let(:mime_type) { 'audio/wav' } - it { is_expected.to eq 'curation_concerns/generic_files/media_display/audio' } - end - - context "with a pdf" do - let(:mime_type) { 'application/pdf' } - it { is_expected.to eq 'curation_concerns/generic_files/media_display/pdf' } - end - - context "with a word document" do - let(:mime_type) { 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' } - it { is_expected.to eq 'curation_concerns/generic_files/media_display/office_document' } - end - - context "with anything else" do - let(:mime_type) { 'application/binary' } - it { is_expected.to eq 'curation_concerns/generic_files/media_display/default' } - end - end -end diff --git a/spec/helpers/url_helper_spec.rb b/spec/helpers/url_helper_spec.rb index ad4778c75..0cd49fdad 100644 --- a/spec/helpers/url_helper_spec.rb +++ b/spec/helpers/url_helper_spec.rb @@ -5,17 +5,19 @@ GenericWork.destroy_all end let(:profile) { ["{\"datastreams\":{}}"] } - let(:work) { FactoryGirl.create(:generic_work) } + let(:work) { create(:generic_work) } let(:document) { SolrDocument.new(work.to_solr) } subject { helper.url_for_document document } - it { should eq "/concern/generic_works/#{work.id}" } + it { is_expected.to eq "/concern/generic_works/#{work.id}" } + it 'uses the curation_concern namespace' do expect(helper.url_for_document document).to eq "/concern/generic_works/#{work.id}" end - context 'when document is a GenericFile' do - let(:file) { FactoryGirl.create(:generic_file) } + + context 'when document is a FileSet' do + let(:file) { create(:file_set) } subject { helper.url_for_document file } - it { should eq "/concern/generic_files/#{file.id}" } + it { is_expected.to eq "/concern/file_sets/#{file.id}" } end end diff --git a/spec/jobs/active_fedora_id_based_job_spec.rb b/spec/jobs/active_fedora_id_based_job_spec.rb index 884305005..8330b3a81 100644 --- a/spec/jobs/active_fedora_id_based_job_spec.rb +++ b/spec/jobs/active_fedora_id_based_job_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' describe ActiveFedoraIdBasedJob do - let(:generic_file) { GenericFile.new } - let(:generic_file_id) { 'abc123' } + let(:file_set) { FileSet.new } + let(:file_set_id) { 'abc123' } before do - allow(ActiveFedora::Base).to receive(:find).with(generic_file_id).and_return(generic_file) + allow(ActiveFedora::Base).to receive(:find).with(file_set_id).and_return(file_set) end it 'finds object' do job = described_class.new - job.id = generic_file_id - expect(job.generic_file).to eq generic_file + job.id = file_set_id + expect(job.file_set).to eq file_set end end diff --git a/spec/jobs/audit_job_spec.rb b/spec/jobs/audit_job_spec.rb index 5234f22b7..352ce642e 100644 --- a/spec/jobs/audit_job_spec.rb +++ b/spec/jobs/audit_job_spec.rb @@ -4,9 +4,9 @@ let(:user) { create(:user) } let(:file) do - GenericFile.create do |file| + FileSet.create do |file| file.apply_depositor_metadata(user) - Hydra::Works::AddFileToGenericFile.call(file, File.open(fixture_file_path('world.png')), :original_file, versioning: true) + Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_file_path('world.png')), :original_file, versioning: true) end end let(:file_id) { file.original_file.id } @@ -36,8 +36,8 @@ describe 'run_audit' do let(:uri) { CurationConcerns::VersioningService.latest_version_of(file.original_file).uri } - let!(:old) { ChecksumAuditLog.create(generic_file_id: file.id, file_id: file_id, version: uri, pass: 1, created_at: 2.minutes.ago) } - let!(:new) { ChecksumAuditLog.create(generic_file_id: file.id, file_id: file_id, version: uri, pass: 0) } + let!(:old) { ChecksumAuditLog.create(file_set_id: file.id, file_id: file_id, version: uri, pass: 1, created_at: 2.minutes.ago) } + let!(:new) { ChecksumAuditLog.create(file_set_id: file.id, file_id: file_id, version: uri, pass: 0) } let(:mock_service) { double('mock fixity check service') } before do diff --git a/spec/jobs/characterize_job_spec.rb b/spec/jobs/characterize_job_spec.rb index 9f4238716..e8b73643b 100644 --- a/spec/jobs/characterize_job_spec.rb +++ b/spec/jobs/characterize_job_spec.rb @@ -1,19 +1,19 @@ require 'spec_helper' describe CharacterizeJob do - let(:generic_file) { GenericFile.new(id: generic_file_id) } - let(:generic_file_id) { 'abc123' } + let(:file_set) { FileSet.new(id: file_set_id) } + let(:file_set_id) { 'abc123' } let(:filename) { double } before do - allow(ActiveFedora::Base).to receive(:find).with(generic_file_id).and_return(generic_file) + allow(ActiveFedora::Base).to receive(:find).with(file_set_id).and_return(file_set) end it 'runs CurationConcerns::CharacterizationService and creates a CreateDerivativesJob' do - expect(CurationConcerns::CharacterizationService).to receive(:run).with(generic_file, filename) - expect(generic_file).to receive(:save) - expect(FulltextExtractionJob).to receive(:perform_later).with(generic_file_id, filename) - expect(CreateDerivativesJob).to receive(:perform_later).with(generic_file_id, filename) - described_class.perform_now generic_file_id, filename + expect(CurationConcerns::CharacterizationService).to receive(:run).with(file_set, filename) + expect(file_set).to receive(:save) + expect(FulltextExtractionJob).to receive(:perform_later).with(file_set_id, filename) + expect(CreateDerivativesJob).to receive(:perform_later).with(file_set_id, filename) + described_class.perform_now file_set_id, filename end end diff --git a/spec/jobs/create_derivatives_job_spec.rb b/spec/jobs/create_derivatives_job_spec.rb index f81add9fb..dec285777 100644 --- a/spec/jobs/create_derivatives_job_spec.rb +++ b/spec/jobs/create_derivatives_job_spec.rb @@ -4,19 +4,19 @@ before do @ffmpeg_enabled = CurationConcerns.config.enable_ffmpeg CurationConcerns.config.enable_ffmpeg = true - allow(ActiveFedora::Base).to receive(:find).with('123').and_return(generic_file) - allow(generic_file).to receive(:mime_type).and_return('audio/x-wav') - allow(generic_file).to receive(:id).and_return('123') + allow(ActiveFedora::Base).to receive(:find).with('123').and_return(file_set) + allow(file_set).to receive(:mime_type).and_return('audio/x-wav') + allow(file_set).to receive(:id).and_return('123') end - let(:generic_file) { GenericFile.new } + let(:file_set) { FileSet.new } after do CurationConcerns.config.enable_ffmpeg = @ffmpeg_enabled end context "with a file name" do - it 'calls create_derivatives and save on a generic_file' do + it 'calls create_derivatives and save on a file set' do expect(Hydra::Derivatives::AudioDerivatives).to receive(:create) CreateDerivativesJob.perform_now('123', 'spec/fixtures/piano_note.wav') end diff --git a/spec/jobs/fulltext_extraction_job_spec.rb b/spec/jobs/fulltext_extraction_job_spec.rb index 337779bdc..e034d2e1e 100644 --- a/spec/jobs/fulltext_extraction_job_spec.rb +++ b/spec/jobs/fulltext_extraction_job_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' describe FulltextExtractionJob do - let(:generic_file) { create(:generic_file) } + let(:file_set) { create(:file_set) } let(:filename) { double } it 'extracts the fulltext' do - expect(Hydra::Works::FullTextExtractionService).to receive(:run).with(generic_file, filename).and_return('stuff') - described_class.perform_now generic_file.id, filename - expect(generic_file.reload.extracted_text.content).to eq 'stuff' + expect(Hydra::Works::FullTextExtractionService).to receive(:run).with(file_set, filename).and_return('stuff') + described_class.perform_now file_set.id, filename + expect(file_set.reload.extracted_text.content).to eq 'stuff' end end diff --git a/spec/jobs/import_url_job_spec.rb b/spec/jobs/import_url_job_spec.rb index b0d19c013..2842bde13 100644 --- a/spec/jobs/import_url_job_spec.rb +++ b/spec/jobs/import_url_job_spec.rb @@ -6,13 +6,13 @@ let(:file_path) { fixture_path + '/world.png' } let(:file_hash) { '/673467823498723948237462429793840923582' } - let(:generic_file) do - GenericFile.new(import_url: "http://example.org#{file_hash}", label: file_path) do |f| + let(:file_set) do + FileSet.new(import_url: "http://example.org#{file_hash}", label: file_path) do |f| f.apply_depositor_metadata(user.user_key) end end - let(:generic_file_id) { 'abc123' } + let(:file_set_id) { 'abc123' } let(:actor) { double } let(:mock_response) do @@ -25,14 +25,14 @@ context 'after running the job' do before do - allow(ActiveFedora::Base).to receive(:find).with(generic_file_id).and_return(generic_file) - allow(CurationConcerns::GenericFileActor).to receive(:new).with(generic_file, user).and_return(actor) + allow(ActiveFedora::Base).to receive(:find).with(file_set_id).and_return(file_set) + allow(CurationConcerns::FileSetActor).to receive(:new).with(file_set, user).and_return(actor) end it 'creates a content datastream' do expect_any_instance_of(Net::HTTP).to receive(:request_get).with(file_hash).and_yield(mock_response) expect(actor).to receive(:create_content).and_return(true) - described_class.perform_now(generic_file_id) + described_class.perform_now(file_set_id) end end end diff --git a/spec/jobs/ingest_file_job_spec.rb b/spec/jobs/ingest_file_job_spec.rb index 402daf636..43c6cbb42 100644 --- a/spec/jobs/ingest_file_job_spec.rb +++ b/spec/jobs/ingest_file_job_spec.rb @@ -1,36 +1,36 @@ require 'spec_helper' describe IngestFileJob do - let(:generic_file) { create(:generic_file) } + let(:file_set) { create(:file_set) } let(:filename) { fixture_file_path('/world.png') } it 'uses the provided mime_type' do - described_class.perform_now(generic_file.id, filename, 'image/png', 'bob') - expect(generic_file.reload.original_file.mime_type).to eq 'image/png' + described_class.perform_now(file_set.id, filename, 'image/png', 'bob') + expect(file_set.reload.original_file.mime_type).to eq 'image/png' end context 'with two existing versions from different users' do let(:file1) { fixture_file_path 'world.png' } let(:file2) { fixture_file_path 'small_file.txt' } - let(:actor1) { described_class.new(generic_file, user) } - let(:actor2) { described_class.new(generic_file, second_user) } + let(:actor1) { described_class.new(file_set, user) } + let(:actor2) { described_class.new(file_set, second_user) } let(:second_user) { create(:user) } - let(:versions) { generic_file.reload.original_file.versions } + let(:versions) { file_set.reload.original_file.versions } before do - described_class.perform_now(generic_file.id, file1, 'image/png', 'bob') - described_class.perform_now(generic_file.id, file2, 'text/plain', 'bess') + described_class.perform_now(file_set.id, file1, 'image/png', 'bob') + described_class.perform_now(file_set.id, file2, 'text/plain', 'bess') end it 'has two versions' do expect(versions.all.count).to eq 2 # the current version - expect(CurationConcerns::VersioningService.latest_version_of(generic_file.reload.original_file).label).to eq 'version2' - expect(generic_file.original_file.content).to eq File.open(file2).read - expect(generic_file.original_file.mime_type).to eq 'text/plain' - expect(generic_file.original_file.original_name).to eq 'small_file.txt' + expect(CurationConcerns::VersioningService.latest_version_of(file_set.reload.original_file).label).to eq 'version2' + expect(file_set.original_file.content).to eq File.open(file2).read + expect(file_set.original_file.mime_type).to eq 'text/plain' + expect(file_set.original_file.original_name).to eq 'small_file.txt' # the user for each version expect(VersionCommitter.where(version_id: versions.first.uri).pluck(:committer_login)).to eq ['bob'] diff --git a/spec/jobs/ingest_local_file_job_spec.rb b/spec/jobs/ingest_local_file_job_spec.rb index baa823daa..9b9d3f5a5 100644 --- a/spec/jobs/ingest_local_file_job_spec.rb +++ b/spec/jobs/ingest_local_file_job_spec.rb @@ -3,8 +3,8 @@ describe IngestLocalFileJob do let(:user) { create(:user) } - let(:generic_file) { GenericFile.new } - let(:generic_file_id) { 'abc123' } + let(:file_set) { FileSet.new } + let(:file_set_id) { 'abc123' } let(:actor) { double } let(:mock_upload_directory) { 'spec/mock_upload_directory' } @@ -12,12 +12,12 @@ before do Dir.mkdir mock_upload_directory unless File.exist? mock_upload_directory FileUtils.copy(File.expand_path('../../fixtures/world.png', __FILE__), mock_upload_directory) - allow(GenericFile).to receive(:find).with(generic_file_id).and_return(generic_file) - allow(CurationConcerns::GenericFileActor).to receive(:new).with(generic_file, user).and_return(actor) + allow(FileSet).to receive(:find).with(file_set_id).and_return(file_set) + allow(CurationConcerns::FileSetActor).to receive(:new).with(file_set, user).and_return(actor) end it 'has attached a file' do expect(actor).to receive(:create_content).and_return(true) - described_class.perform_now(generic_file_id, mock_upload_directory, 'world.png', user.user_key) + described_class.perform_now(file_set_id, mock_upload_directory, 'world.png', user.user_key) end end diff --git a/spec/jobs/upload_set_update_job_spec.rb b/spec/jobs/upload_set_update_job_spec.rb index 15058f17f..64f6ba719 100644 --- a/spec/jobs/upload_set_update_job_spec.rb +++ b/spec/jobs/upload_set_update_job_spec.rb @@ -4,8 +4,8 @@ let(:user) { FactoryGirl.find_or_create(:jill) } let(:upload_set) { UploadSet.create } - let!(:file) { FactoryGirl.create(:generic_file, user: user, upload_set: upload_set) } - let!(:file2) { FactoryGirl.create(:generic_file, user: user, upload_set: upload_set) } + let!(:file) { create(:file_set, user: user, upload_set: upload_set) } + let!(:file2) { create(:file_set, user: user, upload_set: upload_set) } describe "#perform" do let(:title) { { file.id => ['File One'], file2.id => ['File Two'] } } diff --git a/spec/jobs/visibility_copy_job_spec.rb b/spec/jobs/visibility_copy_job_spec.rb index fc05892e4..068a2540d 100644 --- a/spec/jobs/visibility_copy_job_spec.rb +++ b/spec/jobs/visibility_copy_job_spec.rb @@ -6,12 +6,12 @@ it 'copies visibility to its contained files' do # files are private at the outset - expect(work.generic_files.first.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE + expect(work.file_sets.first.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE work.visibility = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC work.save described_class.perform_now(work.id) - work.reload.generic_files.each do |file| + work.reload.file_sets.each do |file| expect(file.visibility).to eq 'open' end end @@ -23,14 +23,14 @@ before do expect(work.visibility).to eq 'restricted' expect(work).to be_under_embargo - expect(work.generic_files.first).to_not be_under_embargo + expect(work.file_sets.first).to_not be_under_embargo end before do described_class.perform_now(work.id) work.reload end - let(:file) { work.generic_files.first } + let(:file) { work.file_sets.first } it 'copies visibility to its contained files and apply a copy of the embargo to the files' do expect(file).to be_under_embargo @@ -44,14 +44,14 @@ before do expect(work.visibility).to eq 'open' expect(work).to be_active_lease - expect(work.generic_files.first).to_not be_active_lease + expect(work.file_sets.first).to_not be_active_lease end before do described_class.perform_now(work.id) work.reload end - let(:file) { work.generic_files.first } + let(:file) { work.file_sets.first } it 'copies visibility to its contained files and apply a copy of the lease to the files' do expect(file).to be_active_lease diff --git a/spec/lib/curation_concerns/messages_spec.rb b/spec/lib/curation_concerns/messages_spec.rb index 06ab95398..2976abe12 100644 --- a/spec/lib/curation_concerns/messages_spec.rb +++ b/spec/lib/curation_concerns/messages_spec.rb @@ -18,7 +18,7 @@ class TestClass let(:upload_set_id) { '1' } let(:single) { double(to_param: '1', to_s: 'File 1') } let(:multiple) { [double(to_param: '1', to_s: 'File 1'), double(to_param: '2', to_s: 'File 2'), double(to_param: '3', to_s: 'File 3')] } - let(:file_list) { "File 1, File 2, File 3" } + let(:file_list) { "File 1, File 2, File 3" } describe 'message subjects' do it 'provides a subject for a success message' do @@ -33,7 +33,7 @@ class TestClass it 'renders a success message for a single file' do node = Capybara::Node::Simple.new(message.single_success(upload_set_id, single)) expect(node).to have_selector("span[id=\"ss-1\"]", text: 'File 1 has been saved.') - expect(node).to have_selector("a[href=\"/concern/generic_files/1\"]") + expect(node).to have_selector("a[href=\"/concern/file_sets/1\"]") end end @@ -49,7 +49,7 @@ class TestClass it 'renders a failure message for a single file' do node = Capybara::Node::Simple.new(message.single_failure(upload_set_id, single)) expect(node).to have_selector("span[id=\"ss-1\"]", text: 'File 1 could not be updated. You do not have sufficient privileges to edit it.') - expect(node).to have_selector("a[href=\"/concern/generic_files/1\"]") + expect(node).to have_selector("a[href=\"/concern/file_sets/1\"]") end end diff --git a/spec/models/checksum_audit_log_spec.rb b/spec/models/checksum_audit_log_spec.rb index 2c2fc1fa3..5206d574a 100644 --- a/spec/models/checksum_audit_log_spec.rb +++ b/spec/models/checksum_audit_log_spec.rb @@ -7,10 +7,10 @@ end let(:f) do - file = GenericFile.create do |gf| + file = FileSet.create do |gf| gf.apply_depositor_metadata('mjg36') end - Hydra::Works::AddFileToGenericFile.call(file, File.open(fixture_path + '/world.png'), :original_file) + Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_path + '/world.png'), :original_file) file end @@ -19,8 +19,8 @@ f.original_file.versions.first.uri end let(:content_id) { f.original_file.id } - let(:old) { described_class.create(generic_file_id: f.id, file_id: content_id, version: version_uri, pass: 1, created_at: 2.minutes.ago) } - let(:new) { described_class.create(generic_file_id: f.id, file_id: content_id, version: version_uri, pass: 0, created_at: 1.minute.ago) } + let(:old) { described_class.create(file_set_id: f.id, file_id: content_id, version: version_uri, pass: 1, created_at: 2.minutes.ago) } + let(:new) { described_class.create(file_set_id: f.id, file_id: content_id, version: version_uri, pass: 0, created_at: 1.minute.ago) } context 'a file with multiple checksums audits' do specify 'should return a list of logs for this datastream sorted by date descending' do @@ -31,11 +31,11 @@ context 'after multiple checksum audits where the checksum does not change' do specify 'only one of them should be kept' do - success1 = described_class.create(generic_file_id: f.id, file_id: content_id, version: version_uri, pass: 1) + success1 = described_class.create(file_set_id: f.id, file_id: content_id, version: version_uri, pass: 1) described_class.prune_history(f.id, content_id) - success2 = described_class.create(generic_file_id: f.id, file_id: content_id, version: version_uri, pass: 1) + success2 = described_class.create(file_set_id: f.id, file_id: content_id, version: version_uri, pass: 1) described_class.prune_history(f.id, content_id) - success3 = described_class.create(generic_file_id: f.id, file_id: content_id, version: version_uri, pass: 1) + success3 = described_class.create(file_set_id: f.id, file_id: content_id, version: version_uri, pass: 1) described_class.prune_history(f.id, content_id) expect { described_class.find(success2.id) }.to raise_exception ActiveRecord::RecordNotFound @@ -48,21 +48,21 @@ context 'should have an audit log history' do before do - described_class.create(generic_file_id: f.id, file_id: content_id, version: 'v2', pass: 1) - described_class.create(generic_file_id: f.id, file_id: 'thumbnail', version: 'v1', pass: 1) + described_class.create(file_set_id: f.id, file_id: content_id, version: 'v2', pass: 1) + described_class.create(file_set_id: f.id, file_id: 'thumbnail', version: 'v1', pass: 1) end it "has an audit log history" do audit = described_class.get_audit_log(f.id, content_id, version_uri) - expect(audit.generic_file_id).to eq(f.id) + expect(audit.file_set_id).to eq(f.id) expect(audit.version).to eq(version_uri) audit = described_class.get_audit_log(f.id, content_id, 'v2') - expect(audit.generic_file_id).to eq(f.id) + expect(audit.file_set_id).to eq(f.id) expect(audit.version).to eq('v2') audit = described_class.get_audit_log(f.id, 'thumbnail', 'v1') - expect(audit.generic_file_id).to eq(f.id) + expect(audit.file_set_id).to eq(f.id) expect(audit.version).to eq('v1') end end diff --git a/spec/models/curation_concerns/collection_behavior_spec.rb b/spec/models/curation_concerns/collection_behavior_spec.rb index 6b671e3b6..453acd168 100644 --- a/spec/models/curation_concerns/collection_behavior_spec.rb +++ b/spec/models/curation_concerns/collection_behavior_spec.rb @@ -22,7 +22,7 @@ context 'with two 50 byte files' do let(:bitstream) { double('content', size: '50') } - let(:file) { mock_model ::GenericFile, content: bitstream } + let(:file) { mock_model ::FileSet, content: bitstream } before { allow(collection).to receive(:members).and_return([file, file]) } it { is_expected.to eq 100 } end @@ -78,12 +78,13 @@ expect(subject.pcdm_object?).to be false expect(subject.type).to_not include Hydra::PCDM::Vocab::PCDMTerms.Object end + it 'contains objects' do - expect(subject.generic_works).to eq [] - expect(subject.generic_work_ids).to eq [] - expect(subject.generic_works << work1).to eq [work1] - expect(subject.generic_works).to eq [work1] - expect(subject.generic_work_ids).to eq [work1.id] + expect(subject.works).to eq [] + expect(subject.work_ids).to eq [] + expect(subject.works << work1).to eq [work1] + expect(subject.works).to eq [work1] + expect(subject.work_ids).to eq [work1.id] end it 'contains collections' do diff --git a/spec/models/curation_concerns/generic_file/derivatives_spec.rb b/spec/models/curation_concerns/file_set/derivatives_spec.rb similarity index 70% rename from spec/models/curation_concerns/generic_file/derivatives_spec.rb rename to spec/models/curation_concerns/file_set/derivatives_spec.rb index 70fe82594..cc74b9697 100644 --- a/spec/models/curation_concerns/generic_file/derivatives_spec.rb +++ b/spec/models/curation_concerns/file_set/derivatives_spec.rb @@ -1,14 +1,14 @@ require 'spec_helper' -describe CurationConcerns::GenericFile do - let(:generic_file) { GenericFile.create { |gf| gf.apply_depositor_metadata('jcoyne@example.com') } } +describe CurationConcerns::FileSet do + let(:file_set) { FileSet.create { |gf| gf.apply_depositor_metadata('jcoyne@example.com') } } before do - allow(generic_file).to receive(:mime_type).and_return(mime_type) + allow(file_set).to receive(:mime_type).and_return(mime_type) end after do - dir = File.join(CurationConcerns.config.derivatives_path, generic_file.id) + dir = File.join(CurationConcerns.config.derivatives_path, file_set.id) FileUtils.rm_r(dir) if File.directory?(dir) end @@ -17,7 +17,7 @@ let(:file_name) { File.join(fixture_path, 'image.jp2') } it 'only makes one thumbnail' do expect_any_instance_of(Hydra::Derivatives::Image).to receive(:process).once - generic_file.create_derivatives(file_name) + file_set.create_derivatives(file_name) end end @@ -26,7 +26,7 @@ let(:file_name) { File.join(fixture_path, 'test.pdf') } it 'only makes one thumbnail' do expect_any_instance_of(Hydra::Derivatives::Image).to receive(:process).once - generic_file.create_derivatives(file_name) + file_set.create_derivatives(file_name) end end @@ -35,7 +35,7 @@ let(:file_name) { File.join(fixture_path, 'charter.docx') } it 'only makes one thumbnail' do expect_any_instance_of(Hydra::Derivatives::Document).to receive(:process).once - generic_file.create_derivatives(file_name) + file_set.create_derivatives(file_name) end end @@ -52,10 +52,10 @@ let(:file_name) { File.join(fixture_path, 'countdown.avi') } it 'transcodes to webm and mp4' do - new_webm = "#{Rails.root}/tmp/derivatives/#{generic_file.id}/webm.webm" - new_mp4 = "#{Rails.root}/tmp/derivatives/#{generic_file.id}/mp4.mp4" + new_webm = "#{Rails.root}/tmp/derivatives/#{file_set.id}/webm.webm" + new_mp4 = "#{Rails.root}/tmp/derivatives/#{file_set.id}/mp4.mp4" expect { - generic_file.create_derivatives(file_name) + file_set.create_derivatives(file_name) }.to change { File.exist?(new_webm) } .from(false).to(true) .and change { File.exist?(new_mp4) } @@ -68,10 +68,10 @@ let(:file_name) { File.join(fixture_path, 'piano_note.wav') } it 'transcodes to mp3 and ogg' do - new_mp3 = "#{Rails.root}/tmp/derivatives/#{generic_file.id}/mp3.mp3" - new_ogg = "#{Rails.root}/tmp/derivatives/#{generic_file.id}/ogg.ogg" + new_mp3 = "#{Rails.root}/tmp/derivatives/#{file_set.id}/mp3.mp3" + new_ogg = "#{Rails.root}/tmp/derivatives/#{file_set.id}/ogg.ogg" expect { - generic_file.create_derivatives(file_name) + file_set.create_derivatives(file_name) }.to change { File.exist?(new_mp3) } .from(false).to(true) .and change { File.exist?(new_ogg) } diff --git a/spec/models/curation_concerns/generic_work_behavior_spec.rb b/spec/models/curation_concerns/work_behavior_spec.rb similarity index 79% rename from spec/models/curation_concerns/generic_work_behavior_spec.rb rename to spec/models/curation_concerns/work_behavior_spec.rb index 0e78196c2..d72620a7f 100644 --- a/spec/models/curation_concerns/generic_work_behavior_spec.rb +++ b/spec/models/curation_concerns/work_behavior_spec.rb @@ -1,9 +1,9 @@ require 'spec_helper' -describe CurationConcerns::GenericWorkBehavior do +describe CurationConcerns::WorkBehavior do before do class EssentialWork < ActiveFedora::Base - include CurationConcerns::GenericWorkBehavior + include CurationConcerns::WorkBehavior include CurationConcerns::BasicMetadata end end @@ -14,7 +14,7 @@ class EssentialWork < ActiveFedora::Base subject { EssentialWork.new } it 'mixs together all the goodness' do - [::CurationConcerns::WithGenericFiles, ::CurationConcerns::HumanReadableType, CurationConcerns::Noid, CurationConcerns::Serializers, Hydra::WithDepositor, Hydra::AccessControls::Embargoable, Solrizer::Common].each do |mixin| + [::CurationConcerns::WithFileSets, ::CurationConcerns::HumanReadableType, CurationConcerns::Noid, CurationConcerns::Serializers, Hydra::WithDepositor, Hydra::AccessControls::Embargoable, Solrizer::Common].each do |mixin| expect(subject.class.ancestors).to include(mixin) end end diff --git a/spec/models/generic_file_spec.rb b/spec/models/file_set_spec.rb similarity index 91% rename from spec/models/generic_file_spec.rb rename to spec/models/file_set_spec.rb index 878ca2e64..0b8f5eb46 100644 --- a/spec/models/generic_file_spec.rb +++ b/spec/models/file_set_spec.rb @@ -1,18 +1,18 @@ require 'spec_helper' -# This tests the GenericFile model that is inserted into the host app by curation_concerns:models:install -# It includes the CurationConcerns::GenericFileBehavior module and nothing else -# So this test covers both the GenericFileBehavior module and the generated GenericFile model -describe GenericFile do +# This tests the FileSet model that is inserted into the host app by curation_concerns:models:install +# It includes the CurationConcerns::FileSetBehavior module and nothing else +# So this test covers both the FileSetBehavior module and the generated FileSet model +describe FileSet do let(:user) { FactoryGirl.find_or_create(:jill) } describe 'rdf type' do subject { described_class.new.type } - it { is_expected.to include(Hydra::PCDM::Vocab::PCDMTerms.Object, Hydra::Works::Vocab::WorksTerms.GenericFile) } + it { is_expected.to include(Hydra::PCDM::Vocab::PCDMTerms.Object, Hydra::Works::Vocab::WorksTerms.FileSet) } end - it 'is a Hydra::Works GenericFile' do - expect(subject).to be_generic_file + it 'is a Hydra::Works::FileSet' do + expect(subject).to be_file_set end it 'has depositor' do @@ -150,7 +150,7 @@ describe '#indexer' do subject { described_class.indexer } - it { is_expected.to eq CurationConcerns::GenericFileIndexingService } + it { is_expected.to eq CurationConcerns::FileSetIndexingService } end it 'supports multi-valued fields in solr' do @@ -172,7 +172,7 @@ before do allow(@f).to receive(mime_type: 'video/quicktime') # Would get set by the characterization job @f.save - Hydra::Works::AddFileToGenericFile.call(subject, File.open("#{fixture_path}/countdown.avi", 'rb'), :original_file) + Hydra::Works::AddFileToFileSet.call(subject, File.open("#{fixture_path}/countdown.avi", 'rb'), :original_file) end it 'makes a png thumbnail' do @f.create_thumbnail @@ -193,10 +193,10 @@ context 'when there are related files' do let(:parent_work) { FactoryGirl.create(:work_with_files) } - let(:f1) { parent_work.generic_files.first } - let(:f2) { parent_work.generic_files.last } + let(:f1) { parent_work.file_sets.first } + let(:f2) { parent_work.file_sets.last } subject { f1.reload.related_files } - it 'returns all generic_files contained in parent work(s) but excludes itself' do + it 'returns all files contained in parent work(s) but excludes itself' do expect(subject).to include(f2) expect(subject).to_not include(f1) end @@ -285,7 +285,7 @@ describe 'overriding' do let(:asset) { SampleKlass.new } before do - class SampleKlass < GenericFile + class SampleKlass < FileSet def paranoid_edit_permissions [] end @@ -341,15 +341,15 @@ def paranoid_edit_permissions end describe 'file content validation' do - subject { FactoryGirl.create(:generic_file) } + subject { create(:file_set) } let(:file_path) { fixture_path + '/small_file.txt' } context 'when file contains a virus' do before do allow(subject).to receive(:warn) # suppress virus warnings expect(ClamAV.instance).to receive(:scanfile).and_return('EL CRAPO VIRUS') - # TODO: Test that this works with Hydra::Works::UploadFileToGenericFile. see https://github.com/projecthydra-labs/hydra-works/pull/139 - # Hydra::Works::UploadFileToGenericFile.call(subject, file_path, original_name: 'small_file.txt') + # TODO: Test that this works with Hydra::Works::UploadFileToFileSet. see https://github.com/projecthydra-labs/hydra-works/pull/139 + # Hydra::Works::UploadFileToFileSet.call(subject, file_path, original_name: 'small_file.txt') of = subject.build_original_file of.content = File.open(file_path) end @@ -371,7 +371,7 @@ def paranoid_edit_permissions describe 'to_solr' do let(:indexer) { double(generate_solr_document: {}) } before do - allow(CurationConcerns::GenericFileIndexingService).to receive(:new) + allow(CurationConcerns::FileSetIndexingService).to receive(:new) .with(subject).and_return(indexer) end @@ -381,7 +381,7 @@ def paranoid_edit_permissions end it 'has human readable type' do - expect(subject.to_solr.fetch('human_readable_type_tesim')).to eq 'Generic File' + expect(subject.to_solr.fetch('human_readable_type_tesim')).to eq 'File Set' end end @@ -405,8 +405,8 @@ def paranoid_edit_permissions end describe 'work associations' do - let(:work) { FactoryGirl.create(:work_with_one_file) } - subject { work.generic_files.first.reload } + let(:work) { create(:work_with_one_file) } + subject { work.file_sets.first.reload } it 'belongs to works' do expect(subject.generic_works).to eq [work] end @@ -486,13 +486,13 @@ def paranoid_edit_permissions end describe 'with a parent work' do - let(:parent) { FactoryGirl.create(:work_with_one_file) } + let(:parent) { create(:work_with_one_file) } let(:parent_id) { parent.id } describe '#related_files' do - let(:parent) { FactoryGirl.create(:work_with_files) } - let(:sibling) { parent.generic_files.last } - subject { parent.generic_files.first.reload } + let(:parent) { create(:work_with_files) } + let(:sibling) { parent.file_sets.last } + subject { parent.file_sets.first.reload } it 'returns related files, but not itself' do expect(subject.related_files).to eq([sibling]) expect(sibling.reload.related_files).to eq([subject]) @@ -501,7 +501,7 @@ def paranoid_edit_permissions describe '#remove_representative_relationship' do let(:some_other_id) { 'something456' } - subject { parent.generic_files.first.reload } + subject { parent.file_sets.first.reload } context "the parent object doesn't exist" do before do parent.representative = subject.id diff --git a/spec/models/fits_datastream_spec.rb b/spec/models/fits_datastream_spec.rb index b942c288d..3eaa185eb 100644 --- a/spec/models/fits_datastream_spec.rb +++ b/spec/models/fits_datastream_spec.rb @@ -4,8 +4,8 @@ describe 'image' do before(:all) do @file_path = fixture_file_path('world.png') - @file = GenericFile.create { |gf| gf.apply_depositor_metadata('blah') } - Hydra::Works::AddFileToGenericFile.call(@file, File.open(@file_path), :original_file) + @file = FileSet.create { |gf| gf.apply_depositor_metadata('blah') } + Hydra::Works::AddFileToFileSet.call(@file, File.open(@file_path), :original_file) CurationConcerns::CharacterizationService.run(@file, @file_path) end it 'has a format label' do @@ -45,8 +45,8 @@ describe 'video' do before(:all) do @file_path = fixture_file_path('sample_mpeg4.mp4') - @file = GenericFile.create { |gf| gf.apply_depositor_metadata('blah') } - Hydra::Works::AddFileToGenericFile.call(@file, File.open(@file_path), :original_file) + @file = FileSet.create { |gf| gf.apply_depositor_metadata('blah') } + Hydra::Works::AddFileToFileSet.call(@file, File.open(@file_path), :original_file) CurationConcerns::CharacterizationService.run(@file, @file_path) end it 'has a format label' do @@ -88,8 +88,8 @@ describe 'pdf' do let(:file_path) { fixture_file_path('test4.pdf') } before do - @myfile = GenericFile.create { |gf| gf.apply_depositor_metadata('blah') } - Hydra::Works::AddFileToGenericFile.call(@myfile, File.open(file_path), :original_file) + @myfile = FileSet.create { |gf| gf.apply_depositor_metadata('blah') } + Hydra::Works::AddFileToFileSet.call(@myfile, File.open(file_path), :original_file) # characterize method saves CurationConcerns::CharacterizationService.run(@myfile, file_path) end @@ -116,8 +116,8 @@ describe 'm4a' do let(:file_path) { fixture_file_path('spoken-text.m4a') } before do - @myfile = GenericFile.create { |gf| gf.apply_depositor_metadata('blah') } - Hydra::Works::AddFileToGenericFile.call(@myfile, File.open(file_path), :original_file) + @myfile = FileSet.create { |gf| gf.apply_depositor_metadata('blah') } + Hydra::Works::AddFileToFileSet.call(@myfile, File.open(file_path), :original_file) # characterize method saves CurationConcerns::CharacterizationService.run(@myfile, file_path) end diff --git a/spec/models/generic_work_spec.rb b/spec/models/generic_work_spec.rb index ce1e9fb28..83dabff43 100644 --- a/spec/models/generic_work_spec.rb +++ b/spec/models/generic_work_spec.rb @@ -12,22 +12,24 @@ context 'with attached files' do subject { FactoryGirl.create(:work_with_files) } - it 'has two files' do - expect(subject.generic_files.size).to eq 2 - expect(subject.generic_files.first).to be_kind_of GenericFile + it 'has two file_sets' do + expect(subject.file_sets.size).to eq 2 + expect(subject.file_sets.first).to be_kind_of FileSet end end describe '#indexer' do subject { described_class.indexer } - it { is_expected.to eq CurationConcerns::GenericWorkIndexingService } + it { is_expected.to eq CurationConcerns::WorkIndexingService } end describe 'to_solr' do - subject { FactoryGirl.build(:work, date_uploaded: Date.today).to_solr } + subject { build(:work, date_uploaded: Date.today).to_solr } + it 'indexes some fields' do expect(subject.keys).to include 'date_uploaded_dtsi' end + it 'inherits (and extends) to_solr behaviors from superclass' do expect(subject.keys).to include(:id) expect(subject.keys).to include('has_model_ssim') diff --git a/spec/models/single_use_link_spec.rb b/spec/models/single_use_link_spec.rb index 65a8f66d9..74017dbf0 100644 --- a/spec/models/single_use_link_spec.rb +++ b/spec/models/single_use_link_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe SingleUseLink do - let(:file) { GenericFile.new(id: 'abc123') } + let(:file) { FileSet.new(id: 'abc123') } let(:now) { DateTime.now } let(:hash) { "sha2hash#{now.to_f}" } @@ -17,12 +17,12 @@ end describe "show" do - let(:path) { Rails.application.routes.url_helpers.curation_concerns_generic_file_path(file.id) } + let(:path) { Rails.application.routes.url_helpers.curation_concerns_file_set_path(file.id) } it "creates link" do expect(subject.downloadKey).to eq(hash) expect(subject.itemId).to eq(file.id) - expect(subject.path).to eq(Rails.application.routes.url_helpers.curation_concerns_generic_file_path(file.id)) + expect(subject.path).to eq(Rails.application.routes.url_helpers.curation_concerns_file_set_path(file.id)) end end describe "download" do diff --git a/spec/models/upload_set_spec.rb b/spec/models/upload_set_spec.rb index f7f302f1f..bd9567604 100644 --- a/spec/models/upload_set_spec.rb +++ b/spec/models/upload_set_spec.rb @@ -10,8 +10,8 @@ expect(subject.title).to eq ["test collection"] end - it "responds to .generic_files" do - expect(subject).to respond_to(:generic_files) + it "responds to .file_sets" do + expect(subject).to respond_to(:file_sets) end it "supports to_solr" do diff --git a/spec/presenters/curation_concerns/generic_file_presenter_spec.rb b/spec/presenters/curation_concerns/file_set_presenter_spec.rb similarity index 80% rename from spec/presenters/curation_concerns/generic_file_presenter_spec.rb rename to spec/presenters/curation_concerns/file_set_presenter_spec.rb index 8723f5f29..ce152e9c0 100644 --- a/spec/presenters/curation_concerns/generic_file_presenter_spec.rb +++ b/spec/presenters/curation_concerns/file_set_presenter_spec.rb @@ -1,10 +1,10 @@ require 'spec_helper' -describe CurationConcerns::GenericFilePresenter do +describe CurationConcerns::FileSetPresenter do let(:solr_document) { SolrDocument.new("title_tesim" => ["foo bar"], - "human_readable_type_tesim" => ["Generic File"], + "human_readable_type_tesim" => ["File Set"], "mime_type_ssi" => 'image/jpeg', - "has_model_ssim" => ["GenericFile"]) } + "has_model_ssim" => ["FileSet"]) } let(:ability) { nil } let(:presenter) { described_class.new(solr_document, ability) } @@ -15,7 +15,7 @@ describe "#human_readable_type" do subject { presenter.human_readable_type } - it { is_expected.to eq 'Generic File' } + it { is_expected.to eq 'File Set' } end describe "#model_name" do @@ -25,7 +25,7 @@ describe "#to_partial_path" do subject { presenter.to_partial_path } - it { is_expected.to eq 'generic_files/generic_file' } + it { is_expected.to eq 'file_sets/file_set' } end describe "office_document?" do @@ -40,7 +40,7 @@ describe "first" do subject { presenter.first('human_readable_type_tesim') } - it { is_expected.to eq 'Generic File' } + it { is_expected.to eq 'File Set' } end describe "date_uploaded" do diff --git a/spec/presenters/curation_concerns/form_presenter_spec.rb b/spec/presenters/curation_concerns/form_presenter_spec.rb index d6a1475ad..5c1694194 100644 --- a/spec/presenters/curation_concerns/form_presenter_spec.rb +++ b/spec/presenters/curation_concerns/form_presenter_spec.rb @@ -2,8 +2,8 @@ describe CurationConcerns::FormPresenter do let(:curation_concern) { create(:work_with_one_file) } - let(:title) { curation_concern.generic_files.first.title.first } - let(:file_id) { curation_concern.generic_files.first.id } + let(:title) { curation_concern.file_sets.first.title.first } + let(:file_id) { curation_concern.file_sets.first.id } let(:ability) { nil } let(:presenter) { described_class.new(curation_concern, ability) } diff --git a/spec/presenters/curation_concerns/presenter_factory_spec.rb b/spec/presenters/curation_concerns/presenter_factory_spec.rb index 70e0a3f21..a195aa3ad 100644 --- a/spec/presenters/curation_concerns/presenter_factory_spec.rb +++ b/spec/presenters/curation_concerns/presenter_factory_spec.rb @@ -2,7 +2,7 @@ describe CurationConcerns::PresenterFactory do describe "#build_presenters" do - let(:presenter_class) { CurationConcerns::GenericFilePresenter } + let(:presenter_class) { CurationConcerns::FileSetPresenter } before do allow(ActiveFedora::SolrService).to receive(:query).with("{!terms f=id}12,13", rows: 1000).and_return(results) diff --git a/spec/routing/route_spec.rb b/spec/routing/route_spec.rb index 2995a8f11..c48bd6bd5 100644 --- a/spec/routing/route_spec.rb +++ b/spec/routing/route_spec.rb @@ -49,31 +49,31 @@ describe 'GenericFile' do it 'routes to create' do - expect(post: 'concern/container/1/generic_files').to route_to(controller: 'curation_concerns/generic_files', action: 'create', parent_id: '1') + expect(post: 'concern/container/1/file_sets').to route_to(controller: 'curation_concerns/file_sets', action: 'create', parent_id: '1') end it 'routes to new' do - expect(get: 'concern/container/2/generic_files/new').to route_to(controller: 'curation_concerns/generic_files', action: 'new', parent_id: '2') + expect(get: 'concern/container/2/file_sets/new').to route_to(controller: 'curation_concerns/file_sets', action: 'new', parent_id: '2') end it 'routes to edit' do - expect(get: 'concern/generic_files/3/edit').to route_to(controller: 'curation_concerns/generic_files', action: 'edit', id: '3') + expect(get: 'concern/file_sets/3/edit').to route_to(controller: 'curation_concerns/file_sets', action: 'edit', id: '3') end it 'routes to show' do - expect(get: 'concern/generic_files/4').to route_to(controller: 'curation_concerns/generic_files', action: 'show', id: '4') + expect(get: 'concern/file_sets/4').to route_to(controller: 'curation_concerns/file_sets', action: 'show', id: '4') end it 'routes to update' do - expect(put: 'concern/generic_files/5').to route_to(controller: 'curation_concerns/generic_files', action: 'update', id: '5') + expect(put: 'concern/file_sets/5').to route_to(controller: 'curation_concerns/file_sets', action: 'update', id: '5') end it 'routes to destroy' do - expect(delete: 'concern/generic_files/6').to route_to(controller: 'curation_concerns/generic_files', action: 'destroy', id: '6') + expect(delete: 'concern/file_sets/6').to route_to(controller: 'curation_concerns/file_sets', action: 'destroy', id: '6') end it '*not*s route to index' do - expect(get: 'concern/generic_files').not_to route_to(controller: 'curation_concerns/generic_files', action: 'index') + expect(get: 'concern/file_sets').not_to route_to(controller: 'curation_concerns/file_sets', action: 'index') end end diff --git a/spec/search_builders/curation_concerns/search_builder_spec.rb b/spec/search_builders/curation_concerns/search_builder_spec.rb index 3464c0b1c..cfbd6dc8c 100644 --- a/spec/search_builders/curation_concerns/search_builder_spec.rb +++ b/spec/search_builders/curation_concerns/search_builder_spec.rb @@ -9,11 +9,11 @@ subject { described_class.new(processor_chain, context) } - describe '#only_generic_files' do - before { subject.only_generic_files(solr_params) } + describe '#only_file_sets' do + before { subject.only_file_sets(solr_params) } - it 'adds GenericFile to query' do - expect(solr_params[:fq].first).to include('{!raw f=has_model_ssim}GenericFile') + it 'adds FileSet to query' do + expect(solr_params[:fq].first).to include('{!raw f=has_model_ssim}FileSet') end end diff --git a/spec/services/characterization_service_spec.rb b/spec/services/characterization_service_spec.rb index 3bb8abf3a..09e822400 100644 --- a/spec/services/characterization_service_spec.rb +++ b/spec/services/characterization_service_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' describe CurationConcerns::CharacterizationService do - let(:generic_file) { create(:generic_file) } + let(:file_set) { create(:file_set) } describe '#run' do let(:service_instance) { double } let(:file_name) { double } it 'creates an instance of the service and calls .characterize on it' do - expect(described_class).to receive(:new).with(generic_file, file_name).and_return(service_instance) + expect(described_class).to receive(:new).with(file_set, file_name).and_return(service_instance) expect(service_instance).to receive(:characterize) - described_class.run(generic_file, file_name) + described_class.run(file_set, file_name) end end @@ -34,14 +34,14 @@ } let(:file_name) { fixture_file_path('charter.docx') } - subject { described_class.new(generic_file, file_name) } + subject { described_class.new(file_set, file_name) } it 'characterizes and stores the results' do expect(Hydra::FileCharacterization).to receive(:characterize).and_return(fits_xml) subject.characterize - expect(generic_file.mime_type).to eq 'application/vnd.oasis.opendocument.text' - expect(generic_file.filename).to eq 'charter.docx' + expect(file_set.mime_type).to eq 'application/vnd.oasis.opendocument.text' + expect(file_set.filename).to eq 'charter.docx' end end end diff --git a/spec/services/generic_file_audit_service_spec.rb b/spec/services/file_set_audit_service_spec.rb similarity index 85% rename from spec/services/generic_file_audit_service_spec.rb rename to spec/services/file_set_audit_service_spec.rb index 24532df8b..581e9f211 100644 --- a/spec/services/generic_file_audit_service_spec.rb +++ b/spec/services/file_set_audit_service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' -describe CurationConcerns::GenericFileAuditService do - let(:f) { FactoryGirl.create(:generic_file, content: File.open(fixture_file_path('world.png'))) } +describe CurationConcerns::FileSetAuditService do + let(:f) { create(:file_set, content: File.open(fixture_file_path('world.png'))) } let(:service) { described_class.new(f) } describe '#audit' do @@ -27,7 +27,7 @@ subject { service.send(:audit_file_version, f.original_file.id, f.original_file.uri) } specify 'returns a single ChecksumAuditLog for the given file' do expect(subject).to be_kind_of ChecksumAuditLog - expect(subject.generic_file_id).to eq(f.id) + expect(subject.file_set_id).to eq(f.id) expect(subject.version).to eq(f.original_file.uri) end end @@ -43,7 +43,7 @@ context 'when no audit is pasing' do before do CurationConcerns::VersioningService.create(f.original_file) - ChecksumAuditLog.create!(pass: 1, generic_file_id: f.id, version: f.original_file.versions.first.uri, file_id: 'original_file') + ChecksumAuditLog.create!(pass: 1, file_set_id: f.id, version: f.original_file.versions.first.uri, file_id: 'original_file') end it 'reports that audits have not been run' do diff --git a/spec/services/generic_file_indexing_service_spec.rb b/spec/services/file_set_indexing_service_spec.rb similarity index 92% rename from spec/services/generic_file_indexing_service_spec.rb rename to spec/services/file_set_indexing_service_spec.rb index 04b4b65c9..d3b3ad256 100644 --- a/spec/services/generic_file_indexing_service_spec.rb +++ b/spec/services/file_set_indexing_service_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe CurationConcerns::GenericFileIndexingService do - let(:generic_file) do - GenericFile.new( +describe CurationConcerns::FileSetIndexingService do + let(:file_set) do + FileSet.new( id: 'foo123', part_of: ['Arabiana'], contributor: ['Mohammad'], @@ -30,10 +30,10 @@ describe '#generate_solr_document' do before do - allow(generic_file).to receive(:label).and_return('CastoriaAd.tiff') + allow(file_set).to receive(:label).and_return('CastoriaAd.tiff') allow(CurationConcerns::ThumbnailPathService).to receive(:call).and_return('/downloads/foo123?file=thumbnail') end - subject { described_class.new(generic_file).generate_solr_document } + subject { described_class.new(file_set).generate_solr_document } it 'has fields' do expect(subject[Solrizer.solr_name('representative')]).to eq 'foo123' diff --git a/spec/services/generic_work_indexing_service_spec.rb b/spec/services/generic_work_indexing_service_spec.rb index dfd7d9558..566229092 100644 --- a/spec/services/generic_work_indexing_service_spec.rb +++ b/spec/services/generic_work_indexing_service_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe CurationConcerns::GenericWorkIndexingService do - # TODO: generic_file_ids returns an empty set unless you persist the work +describe CurationConcerns::WorkIndexingService do + # TODO: file_set_ids returns an empty set unless you persist the work let(:user) { create(:user) } let!(:generic_work) { create(:work_with_one_file, user: user) } let(:service) { described_class.new(generic_work) } - let(:file) { generic_work.generic_files.first } + let(:file) { generic_work.file_sets.first } before do allow(CurationConcerns::ThumbnailPathService).to receive(:call).and_return("/downloads/#{file.id}?file=thumbnail") @@ -15,7 +15,7 @@ subject { service.generate_solr_document } it 'indexes files' do - expect(subject['generic_file_ids_ssim']).to eq generic_work.member_ids + expect(subject['file_set_ids_ssim']).to eq generic_work.member_ids expect(subject['generic_type_sim']).to eq ['Work'] expect(subject.fetch('thumbnail_path_ss')).to eq "/downloads/#{file.id}?file=thumbnail" end diff --git a/spec/services/repository_audit_service_spec.rb b/spec/services/repository_audit_service_spec.rb index 63c537f62..2bfc57ef1 100644 --- a/spec/services/repository_audit_service_spec.rb +++ b/spec/services/repository_audit_service_spec.rb @@ -3,16 +3,16 @@ describe CurationConcerns::RepositoryAuditService do let(:user) { FactoryGirl.create(:user) } let!(:file) do - gf = GenericFile.create! do |f| + fs = FileSet.create! do |f| f.apply_depositor_metadata(user) end - Hydra::Works::AddFileToGenericFile.call(gf, File.open(fixture_path + '/world.png'), :original_file) - gf + Hydra::Works::AddFileToFileSet.call(fs, File.open(fixture_path + '/world.png'), :original_file) + fs end describe '#audit_everything' do it 'audits everything' do - expect_any_instance_of(GenericFile).to receive(:audit) + expect_any_instance_of(FileSet).to receive(:audit) described_class.audit_everything end end diff --git a/spec/services/thumbnail_path_service_spec.rb b/spec/services/thumbnail_path_service_spec.rb index 42dac2507..edb595b46 100644 --- a/spec/services/thumbnail_path_service_spec.rb +++ b/spec/services/thumbnail_path_service_spec.rb @@ -3,8 +3,8 @@ describe CurationConcerns::ThumbnailPathService do subject { described_class.call(object) } - context "with a GenericFile" do - let(:object) { GenericFile.new(id: '999', mime_type: mime_type) } + context "with a FileSet" do + let(:object) { FileSet.new(id: '999', mime_type: mime_type) } let(:mime_type) { 'image/jpeg' } context "that has a thumbnail" do before do @@ -26,17 +26,17 @@ context "with a Work" do context "that has a representative" do let(:object) { GenericWork.new(representative: '999') } - let(:representative) { GenericFile.new(id: '777') } + let(:representative) { FileSet.new(id: '777') } before do allow(File).to receive(:exist?).and_return(true) - allow(GenericFile).to receive(:load_instance_from_solr).with('999').and_return(representative) + allow(FileSet).to receive(:load_instance_from_solr).with('999').and_return(representative) end it { is_expected.to eq '/downloads/999?file=thumbnail' } end context "that doesn't have a representative" do - let(:object) { GenericWork.new } + let(:object) { FileSet.new } it { is_expected.to eq '/assets/default.png' } end end diff --git a/spec/services/versioning_service_spec.rb b/spec/services/versioning_service_spec.rb index fbb022a7f..aaf5bd37b 100644 --- a/spec/services/versioning_service_spec.rb +++ b/spec/services/versioning_service_spec.rb @@ -3,14 +3,14 @@ describe CurationConcerns::VersioningService do describe '#latest_version_of' do let(:file) do - GenericFile.create do |f| + FileSet.create do |f| f.apply_depositor_metadata('mjg36') end end before do # Add the original_file (this service creates a version after saving when you call it with versioning: true) - Hydra::Works::AddFileToGenericFile.call(file, File.open(fixture_file_path('world.png')), :original_file, versioning: true) + Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_file_path('world.png')), :original_file, versioning: true) end describe 'latest_version_of' do diff --git a/spec/tasks/rake_spec.rb b/spec/tasks/rake_spec.rb index b3913f06c..1db9c8bd8 100644 --- a/spec/tasks/rake_spec.rb +++ b/spec/tasks/rake_spec.rb @@ -10,12 +10,12 @@ Rake::Task.define_task(:environment) end - describe 'deleting the namespace from ChecksumAuditLog#generic_file_id' do + describe 'deleting the namespace from ChecksumAuditLog#file_set_id' do before do - ChecksumAuditLog.create(generic_file_id: namespaced_id) + ChecksumAuditLog.create(file_set_id: namespaced_id) Rake::Task['curation_concerns:migrate:audit_logs'].invoke end - subject { ChecksumAuditLog.first.generic_file_id } + subject { ChecksumAuditLog.first.file_set_id } it { is_expected.to eql corrected_id } end end diff --git a/spec/test_app_templates/Gemfile.extra b/spec/test_app_templates/Gemfile.extra index 98b8864e6..ad53627f8 100644 --- a/spec/test_app_templates/Gemfile.extra +++ b/spec/test_app_templates/Gemfile.extra @@ -1,4 +1,4 @@ # placeholder to use for pinning against specific gem commit references -gem 'hydra-works', github: 'projecthydra-labs/hydra-works', ref: 'ecb7af5' +gem 'hydra-works', github: 'projecthydra-labs/hydra-works', ref: 'd1f7cf2' # Prior to 3.0.0.rc1 gem 'hydra-derivatives', github: 'projecthydra/hydra-derivatives', ref: 'a81d412' diff --git a/spec/views/curation_concerns/generic_files/_generic_file.html.erb_spec.rb b/spec/views/curation_concerns/file_sets/_file_set.html.erb_spec.rb similarity index 77% rename from spec/views/curation_concerns/generic_files/_generic_file.html.erb_spec.rb rename to spec/views/curation_concerns/file_sets/_file_set.html.erb_spec.rb index e7019f1ab..bd3120884 100644 --- a/spec/views/curation_concerns/generic_files/_generic_file.html.erb_spec.rb +++ b/spec/views/curation_concerns/file_sets/_file_set.html.erb_spec.rb @@ -1,15 +1,15 @@ require 'spec_helper' -describe 'curation_concerns/generic_files/_generic_file.html.erb' do +describe 'curation_concerns/file_sets/_file_set.html.erb' do let(:solr_document) { SolrDocument.new(id: '999', - has_model_ssim: ['GenericFile'], + has_model_ssim: ['FileSet'], thumbnail_path_ss: '/downloads/999?file=thumbnail', representative_tesim: ["999"], title_tesim: ["My File"]) } - # Ability is checked in GenericFilePresenter#link_name + # Ability is checked in FileSetPresenter#link_name let(:ability) { double(can?: true) } - let(:presenter) { CurationConcerns::GenericFilePresenter.new(solr_document, ability) } + let(:presenter) { CurationConcerns::FileSetPresenter.new(solr_document, ability) } before do assign(:presenter, presenter) @@ -20,7 +20,7 @@ allow(view).to receive(:can?).with(:read, kind_of(String)).and_return(true) allow(view).to receive(:can?).with(:edit, kind_of(String)).and_return(true) allow(view).to receive(:can?).with(:destroy, String).and_return(true) - render 'curation_concerns/generic_files/generic_file.html.erb', generic_file: presenter + render 'curation_concerns/file_sets/file_set.html.erb', file_set: presenter end it 'renders the view' do @@ -29,7 +29,7 @@ # Action buttons expect(rendered).to have_selector "a[title=\"Edit My File\"][href='#{edit_polymorphic_path([:curation_concerns, presenter])}']", text: 'Edit' - expect(rendered).to have_selector "a[title=\"Rollback to previous version\"][href='#{versions_curation_concerns_generic_file_path(presenter)}']", text: 'Rollback' + expect(rendered).to have_selector "a[title=\"Rollback to previous version\"][href='#{versions_curation_concerns_file_set_path(presenter)}']", text: 'Rollback' expect(rendered).to have_selector "a[title=\"Delete My File\"][data-method='delete'][href='#{polymorphic_path([:curation_concerns, presenter])}']", text: 'Delete' expect(rendered).to have_link('Download') expect(rendered).to have_selector "a[title='Download \"My File\"'][href='#{download_path(presenter)}']", text: 'Download' diff --git a/spec/views/curation_concerns/file_sets/show.json.jbuilder_spec.rb b/spec/views/curation_concerns/file_sets/show.json.jbuilder_spec.rb new file mode 100644 index 000000000..77c63bbe4 --- /dev/null +++ b/spec/views/curation_concerns/file_sets/show.json.jbuilder_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'curation_concerns/file_sets/show.json.jbuilder' do + let(:file_set) { create(:file_set) } + + before do + assign(:file_set, file_set) + render + end + + it "renders json of the curation_concern" do + json = JSON.parse(rendered) + expect(json['id']).to eq file_set.id + expect(json['title']).to eq file_set.title + expected_fields = file_set.class.fields.select { |f| ![:has_model, :create_date].include? f } + expected_fields << :date_created + expected_fields.each do |field_symbol| + expect(json).to have_key(field_symbol.to_s) + end + end +end diff --git a/spec/views/curation_concerns/generic_files/show.json.jbuilder_spec.rb b/spec/views/curation_concerns/generic_files/show.json.jbuilder_spec.rb deleted file mode 100644 index 1c20abc65..000000000 --- a/spec/views/curation_concerns/generic_files/show.json.jbuilder_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'spec_helper' - -describe 'curation_concerns/generic_files/show.json.jbuilder' do - let(:generic_file) { FactoryGirl.create(:generic_file) } - - before do - assign(:generic_file, generic_file) - render - end - - it "renders json of the curation_concern" do - json = JSON.parse(rendered) - expect(json['id']).to eq generic_file.id - expect(json['title']).to eq generic_file.title - expected_fields = generic_file.class.fields.select { |f| ![:has_model, :create_date].include? f } - expected_fields << :date_created - expected_fields.each do |field_symbol| - expect(json).to have_key(field_symbol.to_s) - end - end -end diff --git a/spec/views/single_use_links/new_download.html.erb_spec.rb b/spec/views/single_use_links/new_download.html.erb_spec.rb index bea1289ae..02624c575 100644 --- a/spec/views/single_use_links/new_download.html.erb_spec.rb +++ b/spec/views/single_use_links/new_download.html.erb_spec.rb @@ -4,10 +4,10 @@ let(:user) { FactoryGirl.find_or_create(:jill) } let(:f) do - file = GenericFile.create do |gf| + file = FileSet.create do |gf| gf.apply_depositor_metadata(user) end - Hydra::Works::AddFileToGenericFile.call(file, File.open(fixture_path + '/world.png'), :original_file) + Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_path + '/world.png'), :original_file) file end diff --git a/spec/views/single_use_links_viewer/show.html.erb_spec.rb b/spec/views/single_use_links_viewer/show.html.erb_spec.rb index bd126b63a..1af7675a0 100644 --- a/spec/views/single_use_links_viewer/show.html.erb_spec.rb +++ b/spec/views/single_use_links_viewer/show.html.erb_spec.rb @@ -2,14 +2,14 @@ describe 'curation_concerns/single_use_links_viewer/show.html.erb' do let(:f) do - file = GenericFile.create do |gf| + file = FileSet.create do |gf| gf.apply_depositor_metadata('jill') end - Hydra::Works::AddFileToGenericFile.call(file, File.open(fixture_path + '/world.png'), :original_file) + Hydra::Works::AddFileToFileSet.call(file, File.open(fixture_path + '/world.png'), :original_file) file end - let(:solr_document) { SolrDocument.new(has_model_ssim: ['GenericFile']) } + let(:solr_document) { SolrDocument.new(has_model_ssim: ['FileSet']) } let(:ability) { double } let(:hash) { "some-dummy-sha2-hash" } @@ -17,7 +17,7 @@ before do assign :asset, f assign :download_link, CurationConcerns::Engine.routes.url_helpers.download_single_use_link_path(hash) - assign :presenter, CurationConcerns::GenericFilePresenter.new(solr_document, ability) + assign :presenter, CurationConcerns::FileSetPresenter.new(solr_document, ability) view.lookup_context.view_paths.push 'app/views/curation_concerns/base' render end