Skip to content

Commit

Permalink
add simple_schema_loader spec
Browse files Browse the repository at this point in the history
  • Loading branch information
rococodogs committed Jan 23, 2025
1 parent a5b5481 commit a4784cf
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/services/spot/simple_schema_loader_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# frozen_string_literal: true
RSpec.describe Spot::SimpleSchemaLoader, valkyrization: true do
before(:each) do
# @note can't use described_class in this scope
class ResourceWithSchemaLoader < Hyrax::Resource
include Hyrax::Schema(:base_metadata, schema_loader: Spot::SimpleSchemaLoader.new)
end

class ResourceWithHyraxSchemaLoader < Hyrax::Resource
include Hyrax::Schema(:base_metadata)
end
end

after(:each) do
Object.send(:remove_const, :ResourceWithSchemaLoader)
Object.send(:remove_const, :ResourceWithHyraxSchemaLoader)
end

context 'when using the Hyrax schema loader' do
let(:resource) { ResourceWithHyraxSchemaLoader.new }

describe 'URI fields' do
it 'inits an RDF with a Dry::Types::Undefined value' do
expect(resource.send(:subject)).to eq [RDF::URI.new(Dry::Types::Undefined)]
expect(resource.send(:subject).map(&:to_s)).to eq ['Undefined']
end
end
end

context 'when using our schema loader' do
let(:schema_loader) { described_class.new }
let(:resource) { ResourceWithSchemaLoader.new }

describe 'URI fields' do
it 'inits no values' do
expect(resource.send(:subject).map(&:to_s)).to eq []
end
end

it 'wraps single-value fields in an Identity class' do
expect(schema_loader.attributes_for(schema: :core_metadata))
.to include(depositor: Spot::SimpleSchemaLoader::AttributeDefinition::Identity.of(Valkyrie::Types::String))
end
end
end

0 comments on commit a4784cf

Please sign in to comment.