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

Unsupported nested given blocks #1800

Closed
andreacfm opened this issue Oct 17, 2018 · 4 comments · Fixed by #1811
Closed

Unsupported nested given blocks #1800

andreacfm opened this issue Oct 17, 2018 · 4 comments · Fixed by #1811
Labels

Comments

@andreacfm
Copy link
Contributor

andreacfm commented Oct 17, 2018

Example:

optional :filters, type: Array, default: [] do
  requires :name, type: String, values: [.....]
  requires :operator, values: [......]
  given name: ->(val) {val == 'name'} do
    requires :operator, values: ['a', 'b']
    given operator: -> (val) {val == 'b'} do
      requires :values, type: Array[String]
    end
    given operator: -> (val) { val == 'b' } do
      requires :value, type: Numeric
    end
  end
end

This fails because the params :operator seems not defined when passed to the nested given block. Is this use case supported?

@dblock
Copy link
Member

dblock commented Oct 17, 2018

It should be supported, care to PR a spec?

@dblock dblock added the bug? label Oct 17, 2018
@andreacfm
Copy link
Contributor Author

@dblock #1804

@andreacfm
Copy link
Contributor Author

andreacfm commented Oct 23, 2018

@dblock The issue seems being that validations are not isolated when defined into a given block. Example:

optional :filters, type: Array, default: [] do
  requires :name, type: String, values: [.....]
  requires :operator, values: [......]
  given name: ->(val) {val == 'name'} do
    requires :operator, values: ['a', 'b']
    optional :p1 
    optional :p2 
    at_least_one_of :p1, :p2
  end
  given name: ->(val) {val == 'another_name'} do
    requires :operator, values: ['a']
    optional :p3 
  end
end

Executing a call where name == another_name still requires one between :p1 and :p2 to be provided even if the block where given executes as true does not even define them.

@dblock
Copy link
Member

dblock commented Nov 1, 2018

@andreacfm Try HEAD, #1811 fixes this.

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

Successfully merging a pull request may close this issue.

2 participants