diff --git a/app/models/concerns/bulkrax/has_matchers.rb b/app/models/concerns/bulkrax/has_matchers.rb index 9eb8933a0..c4bb1feb2 100644 --- a/app/models/concerns/bulkrax/has_matchers.rb +++ b/app/models/concerns/bulkrax/has_matchers.rb @@ -130,10 +130,10 @@ def field_supported?(field) return false if excluded?(field) return true if supported_bulkrax_fields.include?(field) - property_defined = factory_class.singleton_methods.include?(:properties) && factory_class.properties[field].present? - - if factory_class == Bulkrax::ValkyrieObjectFactory - factory_class.method_defined?(field) && (Bulkrax::ValkyrieObjectFactory.schema_properties(factory_class).include?(field) || property_defined) + if Bulkrax.object_factory == Bulkrax::ValkyrieObjectFactory + # used in cases where we have a Fedora object class but use the Valkyrie object factory + property_defined = factory_class.singleton_methods.include?(:properties) && factory_class.properties[field].present? + factory_class.method_defined?(field) && (property_defined || Bulkrax::ValkyrieObjectFactory.schema_properties(factory_class).include?(field)) else factory_class.method_defined?(field) && factory_class.properties[field].present? end @@ -168,7 +168,7 @@ def multiple?(field) return true if @multiple_bulkrax_fields.include?(field) return false if field == 'model' - if factory_class == Bulkrax::ValkyrieObjectFactory + if Bulkrax.object_factory == Bulkrax::ValkyrieObjectFactory field_supported?(field) && valkyrie_multiple?(field) else field_supported?(field) && ar_multiple?(field) @@ -185,8 +185,12 @@ def ar_multiple?(field) def valkyrie_multiple?(field) # TODO: there has got to be a better way. Only array types have 'of' - sym_field = field.to_sym - factory_class.schema.key(sym_field).respond_to?(:of) if factory_class.fields.include?(sym_field) + if factory_class.respond_to?(:schema) + sym_field = field.to_sym + factory_class.schema.key(sym_field).respond_to?(:of) if factory_class.fields.include?(sym_field) + else + ar_multiple?(field) + end end # Hyrax field to use for the given import field diff --git a/spec/bulkrax/entry_spec_helper_spec.rb b/spec/bulkrax/entry_spec_helper_spec.rb index f265e8ff2..d13cdd836 100644 --- a/spec/bulkrax/entry_spec_helper_spec.rb +++ b/spec/bulkrax/entry_spec_helper_spec.rb @@ -25,6 +25,10 @@ context 'when ActiveFedora object' do let(:data) { { model: "Work", source_identifier: identifier, title: "If You Want to Go Far" } } + before do + allow(Bulkrax).to receive(:object_factory).and_return(Bulkrax::ObjectFactory) + end + it { is_expected.to be_a(Bulkrax::CsvEntry) } it "parses metadata" do @@ -41,25 +45,33 @@ end end - # TODO: Add specs for when Bulkrax::ValkyrieObjectFactory is used - # context 'when Valkyrie object' do - # let(:data) { { model: "Work", source_identifier: identifier, title: "If You Want to Go Far" } } - - # it { is_expected.to be_a(Bulkrax::CsvEntry) } - - # it "parses metadata" do - # entry.build_metadata - - # expect(entry.factory_class).to eq(Work) - # { - # "title" => ["If You Want to Go Far"], - # "admin_set_id" => "admin_set/default", - # "source" => [identifier] - # }.each do |key, value| - # expect(entry.parsed_metadata.fetch(key)).to eq(value) - # end - # end - # end + context 'when using ValkyrieObjectFactory' do + ['Work', 'WorkResource'].each do |model_name| + + context "for #{model_name}" do + let(:data) { { model: model_name, source_identifier: identifier, title: "If You Want to Go Far" } } + + before do + allow(Bulkrax).to receive(:object_factory).and_return(Bulkrax::ValkyrieObjectFactory) + end + + it { is_expected.to be_a(Bulkrax::CsvEntry) } + + it "parses metadata" do + entry.build_metadata + + expect(entry.factory_class).to eq(model_name.constantize) + { + "title" => ["If You Want to Go Far"], + "admin_set_id" => "admin_set/default", + "source" => [identifier] + }.each do |key, value| + expect(entry.parsed_metadata.fetch(key)).to eq(value) + end + end + end + end + end end context 'for parser_class_name: "Bulkrax::OaiDcParser"' do diff --git a/spec/test_app/app/models/work_resource.rb b/spec/test_app/app/models/work_resource.rb new file mode 100644 index 000000000..a1ab399e9 --- /dev/null +++ b/spec/test_app/app/models/work_resource.rb @@ -0,0 +1,6 @@ +# frozen_string_literal: true + +class WorkResource < Hyrax::Work + include Hyrax::Schema(:basic_metadata) + include Hyrax::Schema(:work_resource) +end diff --git a/spec/test_app/config/metadata/work_resource.yaml b/spec/test_app/config/metadata/work_resource.yaml new file mode 100644 index 000000000..0a113b40d --- /dev/null +++ b/spec/test_app/config/metadata/work_resource.yaml @@ -0,0 +1,11 @@ +attributes: + source_identifier: + type: string + multiple: false + index_keys: + - "source_identifier_sim" + - "source_identifier_tesim" + form: + required: false + primary: false + multiple: false diff --git a/spec/test_app/db/schema.rb b/spec/test_app/db/schema.rb index 70580d6ec..af0e23b5f 100644 --- a/spec/test_app/db/schema.rb +++ b/spec/test_app/db/schema.rb @@ -2,11 +2,11 @@ # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. # # It's strongly recommended that you check this file into your version control system. @@ -99,6 +99,8 @@ t.integer "total_file_set_entries", default: 0 t.integer "processed_works", default: 0 t.integer "failed_works", default: 0 + t.integer "processed_children", default: 0 + t.integer "failed_children", default: 0 t.index ["importer_id"], name: "index_bulkrax_importer_runs_on_importer_id" end