Skip to content

Commit

Permalink
Add Valkyrie::Types::Params::ID
Browse files Browse the repository at this point in the history
This handles blank-string casting from HTML forms.

Closes #605.
  • Loading branch information
tpendragon committed Jan 13, 2019
1 parent 025ff80 commit 022631b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/valkyrie/types.rb
Expand Up @@ -29,6 +29,16 @@ module Types
end
end

module Params
ID = Valkyrie::Types::ID.constructor do |input|
if input.blank?
nil
else
Valkyrie::Types::ID[input]
end
end
end

# Valkyrie::URI
URI = Dry::Types::Definition
.new(RDF::URI)
Expand Down
13 changes: 13 additions & 0 deletions spec/valkyrie/types_spec.rb
Expand Up @@ -49,6 +49,19 @@ class Resource < Valkyrie::Resource
end
end

describe "Valkyrie::Types::Params::ID" do
context "when a blank string is passed in" do
it "returns nil" do
expect(Valkyrie::Types::Params::ID[""]).to eq nil
end
end
context "when passed a string" do
it "returns a Valkyrie::Types::ID" do
expect(Valkyrie::Types::Params::ID["test"]).to be_a Valkyrie::ID
end
end
end

describe 'The URI Type' do
it 'returns an RDF::URI' do
# We don't want to modify the defaults in the schema.
Expand Down

0 comments on commit 022631b

Please sign in to comment.