grape icon indicating copy to clipboard operation
grape copied to clipboard

Optional parameter with a message attribute exception

Open ericproulx opened this issue 11 months ago • 4 comments

It probably never happened but defining a optional parameter with a message attribute will raise an exception.

The following test will fail.

context 'optional param with message' do
  let(:app) do
    Class.new(described_class) do
      params do
        optional 'test', message: 'is required'
      end
      get 'test'
    end
  end

  before do

  end

  it 'should return a message' do
    expect { get 'test' }.not_to raise_error
  end
end

It's an easy fix where we need to remove the message key even if presence is not required.

ericproulx avatar Dec 21 '24 21:12 ericproulx

@wwqwq2313 almost, but since :message act only on required field, we just need to delete it on optional field. Also, when adding :presence, we should delete the :message the validations.

ericproulx avatar Dec 21 '24 23:12 ericproulx

I think @wwqwq2313 is an AI (!)

dblock avatar Dec 22 '24 21:12 dblock

@dblock yeah I know. I just wanted to know if it would respond back after my comment.

ericproulx avatar Dec 22 '24 22:12 ericproulx