-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5b5481
commit a4784cf
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |