Skip to content

Commit

Permalink
Merge pull request #56 from richmolj/master
Browse files Browse the repository at this point in the history
Ensure ids with custom types are respected
  • Loading branch information
wadetandy committed Jan 8, 2019
2 parents 3d8fdc6 + b18f312 commit fa63625
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/graphiti/util/serializer_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def apply
return unless readable?

if @name == :id
@serializer.id(&@attr[:proc]) if @attr[:proc]
@serializer.id(&proc)
elsif @attr[:proc]
@serializer.send(_method, @name, serializer_options, &proc)
else
Expand Down
27 changes: 27 additions & 0 deletions spec/serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,33 @@ def self.name
expect(json['data'][0]['attributes']).to eq('first_name' => 'John')
end

context 'when id is custom type' do
before do
type = Dry::Types::Definition.new(String).constructor do |input|
'custom!'
end
Graphiti::Types[:custom] = {
params: type,
canonical_name: :string,
read: type,
write: type,
kind: 'scalar',
description: 'test'
}
resource.attribute :id, :custom
end

after do
Graphiti::Types.map.delete(:custom)
end

it 'goes through type coercion' do
PORO::Employee.create
render
expect(json['data'][0]['id']).to eq('custom!')
end
end

describe 'helper functions' do
let(:app_serializer) do
Class.new(Graphiti::Serializer) do
Expand Down

0 comments on commit fa63625

Please # to comment.