Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpendragon committed Nov 30, 2018
1 parent 9c40d8a commit e56df2b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/valkyrie/persistence/fedora/persister.rb
Expand Up @@ -165,7 +165,7 @@ def validate_lock_token(resource)
# @return [Valkyrie::Persistence::OptimisticLockToken]
def native_lock_token(resource)
return unless resource.optimistic_locking_enabled?
resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK].find { |lock_token| lock_token.adapter_id == "native-#{adapter.id}" }
resource[Valkyrie::Persistence::Attributes::OPTIMISTIC_LOCK].find { |lock_token| lock_token.adapter_id.to_s == "native-#{adapter.id}" }
end

# Set Fedora request headers:
Expand Down
11 changes: 7 additions & 4 deletions lib/valkyrie/resource.rb
Expand Up @@ -31,14 +31,13 @@ def self.constructor_type(type)
# available key, and makes sure the defaults are set up if no value is
# given.
def self.allow_nonexistent_keys
transform_types { |t| t.meta(omittable: true) }
nil_2_undef = ->(v) { v.nil? ? Dry::Types::Undefined : v }
transform_types do |type|
type = type.meta(omittable: true)
current_meta = type.meta.merge(omittable: true)
if type.default?
type.constructor(nil_2_undef)
type.constructor(nil_2_undef).meta(current_meta)
else
type
type.meta(current_meta)
end
end
end
Expand Down Expand Up @@ -187,5 +186,9 @@ def attributes
nil_keys = (self.class.schema.keys - output.keys).map { |x| [x, nil] }.to_h
output.merge(nil_keys).freeze
end

def dup
new({})
end
end
end
1 change: 1 addition & 0 deletions spec/valkyrie/persistence/solr/model_converter_spec.rb
Expand Up @@ -24,6 +24,7 @@ class Resource < Valkyrie::Resource
internal_resource: 'Resource',
title: ["Test", RDF::Literal.new("French", language: :fr)],
author: ["Author"],
creator: "Creator",
attributes:
{
created_at: created_at,
Expand Down
7 changes: 4 additions & 3 deletions spec/valkyrie/resource_spec.rb
Expand Up @@ -147,7 +147,7 @@ class MyResource < Resource
subject(:resource) { MyResource.new }
describe "#fields" do
it "returns all configured parent fields as an array of symbols" do
expect(MyResource.fields).to eq [:id, :internal_resource, :created_at, :updated_at, :title]
expect(MyResource.fields).to contain_exactly :id, :internal_resource, :created_at, :updated_at, :title
end
end
describe "#internal_resource" do
Expand All @@ -157,8 +157,9 @@ class MyResource < Resource
end
describe "defining an internal attribute" do
it "warns you and changes the type" do
expect { MyResource.attribute(:id) }.to output(/is a reserved attribute/).to_stderr
expect(MyResource.schema[:id]).to eq Valkyrie::Types::Set.optional
old_type = MyResource.schema[:id]
expect { MyResource.attribute(:id, Valkyrie::Types::Set) }.to output(/is a reserved attribute/).to_stderr
expect(MyResource.schema[:id]).not_to eq old_type
end
end
end
Expand Down

0 comments on commit e56df2b

Please sign in to comment.