diff --git a/lib/wings/transformer_value_mapper.rb b/lib/wings/transformer_value_mapper.rb index d67a72ebcc..0c2b29d55a 100644 --- a/lib/wings/transformer_value_mapper.rb +++ b/lib/wings/transformer_value_mapper.rb @@ -49,8 +49,12 @@ def self.handles?(value) end ## - # @return [RDF::Term] + # Valkyrie objects contain a URI string for location objects so we need + # to return just the string for mapping from Fedora + # + # @return [RDF::Term || String] def result + return value.id if value.is_a?(Hyrax::ControlledVocabularies::Location) value.to_term end end diff --git a/spec/wings/attribute_transformer_spec.rb b/spec/wings/attribute_transformer_spec.rb index 310014cb1f..4130e14524 100644 --- a/spec/wings/attribute_transformer_spec.rb +++ b/spec/wings/attribute_transformer_spec.rb @@ -5,21 +5,28 @@ require 'wings/attribute_transformer' RSpec.describe Wings::AttributeTransformer, :active_fedora do - let(:id) { 'moomin123' } + let(:id) { 'moomin123' } + let(:based_near) { Hyrax::ControlledVocabularies::Location.new("https://sws.geonames.org/4920808/") } let(:work) { GenericWork.new(id: id, **attributes) } let(:attributes) do { title: ['fake title', 'fake title 2'], contributor: ['user1'], - description: ['a description'] + description: ['a description'], + based_near: [based_near] } end - it "transform the attributes" do - expect(described_class.run(work)) + it "transforms the attributes" do + converted_work = described_class.run(work) + expect(converted_work) .to include title: work.title, contributor: work.contributor.first, description: work.description.first + # ensure that based_near is converted from RDF::URI to URI string during valkyrization + converted_based_near = Array.wrap(converted_work[:based_near]).first + expect(converted_based_near).to be_a(String) + expect(converted_based_near).to eq(work.based_near.first.id) end end