diff --git a/lib/valkyrie/persistence/fedora/persister.rb b/lib/valkyrie/persistence/fedora/persister.rb index e7489cf24..a2e3cb9a3 100644 --- a/lib/valkyrie/persistence/fedora/persister.rb +++ b/lib/valkyrie/persistence/fedora/persister.rb @@ -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: diff --git a/lib/valkyrie/resource.rb b/lib/valkyrie/resource.rb index 572200c80..8d46be3ed 100644 --- a/lib/valkyrie/resource.rb +++ b/lib/valkyrie/resource.rb @@ -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 @@ -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 diff --git a/spec/valkyrie/persistence/solr/model_converter_spec.rb b/spec/valkyrie/persistence/solr/model_converter_spec.rb index ca5765f64..b22f712f1 100644 --- a/spec/valkyrie/persistence/solr/model_converter_spec.rb +++ b/spec/valkyrie/persistence/solr/model_converter_spec.rb @@ -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, diff --git a/spec/valkyrie/resource_spec.rb b/spec/valkyrie/resource_spec.rb index 1dbc6c69a..d0993b07d 100644 --- a/spec/valkyrie/resource_spec.rb +++ b/spec/valkyrie/resource_spec.rb @@ -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 @@ -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