Skip to content

Commit

Permalink
fix bug in key transform inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
rabidaudio committed Mar 9, 2022
1 parent 41df542 commit c6fb36c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/simple_schema_serializers/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(name, serializer, options)
def key(serializer_instance)
return name unless @key_transform
return @key_transform.call(name) if @key_transform.respond_to?(:call)
if serializer_instance.public_methods(false).include?(@key_transform)
if serializer_instance.public_methods.include?(@key_transform)
return serializer_instance.public_send(@key_transform, name)
end

Expand Down
8 changes: 6 additions & 2 deletions spec/lib/serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -617,14 +617,18 @@ def inherited_serializers(&block)
it 'should allow inheriting key transforms' do
child = inherited_serializers do
parent do
transform_keys :upcase
transform_keys :upcase_keys

def upcase_keys(key)
options[:upcase] ? key.upcase : key
end
end

child do
attribute :name, :string
end
end
expect(child.serialize({ name: 'joe' })).to eq({ 'NAME' => 'joe' })
expect(child.serialize({ name: 'joe' }, upcase: true)).to eq({ 'NAME' => 'joe' })
end
end

Expand Down

0 comments on commit c6fb36c

Please sign in to comment.