Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional parameter with a message attribute exception #2517

Open
ericproulx opened this issue Dec 21, 2024 · 4 comments
Open

Optional parameter with a message attribute exception #2517

ericproulx opened this issue Dec 21, 2024 · 4 comments

Comments

@ericproulx
Copy link
Contributor

ericproulx commented Dec 21, 2024

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
Copy link
Contributor Author

@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.

@dblock
Copy link
Member

dblock commented Dec 22, 2024

I think @wwqwq2313 is an AI (!)

@ericproulx
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@dblock @ericproulx and others