Skip to content

Commit

Permalink
🧹 Fix Specs & add Valkyrie Specs
Browse files Browse the repository at this point in the history
  • Loading branch information
LaRita Robinson committed Jan 25, 2024
1 parent aa1f2f0 commit f160e20
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 31 deletions.
18 changes: 11 additions & 7 deletions app/models/concerns/bulkrax/has_matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
50 changes: 31 additions & 19 deletions spec/bulkrax/entry_spec_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/test_app/app/models/work_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class WorkResource < Hyrax::Work
include Hyrax::Schema(:basic_metadata)
include Hyrax::Schema(:work_resource)
end
11 changes: 11 additions & 0 deletions spec/test_app/config/metadata/work_resource.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions spec/test_app/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit f160e20

Please sign in to comment.