Skip to content

Commit

Permalink
add test for multiple aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Sep 5, 2023
1 parent c1f52ad commit 98f2f50
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions spec/typed_params/transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@
expect(params[:bar].value).to be 'baz'
end

it 'should rename multiple aliased params' do
schema = TypedParams::Schema.new type: :hash do
param :foo, type: :integer, as: :qux
param :bar, type: :integer, as: :qux
param :baz, type: :integer, as: :qux
end

params = TypedParams::Parameterizer.new(schema:).call(value: { foo: 1, bar: 2, baz: 3 })
transformer = TypedParams::Transformer.new(schema:)

transformer.call(params)

expect(params[:foo]).to be nil
expect(params[:bar]).to be nil
expect(params[:baz]).to be nil
expect(params[:qux].value).to be 3
end

context 'with config to not ignore optional nils' do
before do
@ignore_nil_optionals = TypedParams.config.ignore_nil_optionals
Expand Down

0 comments on commit 98f2f50

Please sign in to comment.