Skip to content

Commit

Permalink
Check for nested URI support.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Aug 29, 2017
1 parent 44f4935 commit d3d4cf7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions valkyrie/lib/valkyrie/persistence/solr/resource_factory.rb
Expand Up @@ -205,6 +205,17 @@ def result
end
end

class NestedResourceURI < ::Valkyrie::ValueMapper
NestedResourceConverter.register(self)
def self.handles?(value)
value.is_a?(Hash) && value[:@id]
end

def result
RDF::URI(value[:@id])
end
end

class NestedResourceLiteral < ::Valkyrie::ValueMapper
NestedResourceConverter.register(self)
def self.handles?(value)
Expand Down
4 changes: 2 additions & 2 deletions valkyrie/lib/valkyrie/specs/shared_specs/persister.rb
Expand Up @@ -54,14 +54,14 @@ class CustomResource < Valkyrie::Resource

it "can support deep nesting of resources" do
pending "No support for deep nesting." if flags.include?(:no_deep_nesting)
book = resource_class.new(title: "Sub-nested", author: [Valkyrie::ID.new("test"), RDF::Literal.new("Test", language: :fr)])
book = resource_class.new(title: "Sub-nested", author: [Valkyrie::ID.new("test"), RDF::Literal.new("Test", language: :fr), RDF::URI("http://test.com")])
book2 = resource_class.new(title: "Nested", nested_resource: book)
book3 = persister.save(resource: resource_class.new(nested_resource: book2))

reloaded = query_service.find_by(id: book3.id)
expect(reloaded.nested_resource.first.title).to eq ["Nested"]
expect(reloaded.nested_resource.first.nested_resource.first.title).to eq ["Sub-nested"]
expect(reloaded.nested_resource.first.nested_resource.first.author).to contain_exactly Valkyrie::ID.new("test"), RDF::Literal.new("Test", language: :fr)
expect(reloaded.nested_resource.first.nested_resource.first.author).to contain_exactly Valkyrie::ID.new("test"), RDF::Literal.new("Test", language: :fr), RDF::URI("http://test.com")
end

it "stores created_at/updated_at" do
Expand Down

0 comments on commit d3d4cf7

Please sign in to comment.