Skip to content

Conversation

@zysend
Copy link
Contributor

@zysend zysend commented Nov 8, 2022

evaluate_given ignores tests for arrays, and it judges with the wrong parameters.

@zysend
Copy link
Contributor Author

zysend commented Nov 8, 2022

application/x-www-form-urlencoded can not handle the ordering of the object elements of the array in params
[{ b: 'b' }, { a: 'a', b: 'b' }] => [{ a: 'a', b: 'b' }, { b: 'b' }]

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! Any reason not to mark this as ready?

@zysend
Copy link
Contributor Author

zysend commented Nov 10, 2022

I think this row in meets_dependency? may affect the judgment when I use meets_dependency? to judge given

return false if @parent.present? && !@parent.meets_dependency?(@parent.params(request_params), request_params)

spec maybe like:

optional :array, type: Array do
  optional :a
  optional :c
  given :a do
    given :c do
      optional :b
    end
  end
end

@zysend
Copy link
Contributor Author

zysend commented Nov 10, 2022

Then I added and run

it 'evaluate_given_true' do
  post '/evaluate_given_true', { array: [{ a: 'a', b: 'b' }, { c: 'c', b: 'b'}, { a: 'a', c: 'c', b: 'b' }] }.to_json, 'CONTENT_TYPE' => 'application/json'
  expect(JSON.parse(last_response.body)).to eq('array' => [{ 'a' => 'a', 'c' => nil }, { 'a' => nil, 'c' => 'c' }, { 'a' => 'a', 'b' => 'b', 'c' => 'c' }])
end

got this:

expected: {"array"=>[{"a"=>"a", "c"=>nil}, {"a"=>nil, "c"=>"c"}, {"a"=>"a", "b"=>"b", "c"=>"c"}]}
got: {"array"=>[{"a"=>"a", "c"=>nil}, {"a"=>nil, "b"=>"b", "c"=>"c"}, {"a"=>"a", "b"=>"b", "c"=>"c"}]}

So I have to change the meets_dependency? or create a new method.

@zysend
Copy link
Contributor Author

zysend commented Nov 10, 2022

I will complete the modification as soon

…equest_params) when request_params is not given
@zysend zysend marked this pull request as ready for review November 11, 2022 07:49
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, should I merge this or do you want to do more work on this?

@zysend
Copy link
Contributor Author

zysend commented Nov 23, 2022

Thanks for the review.There is nothing to change and can be merged.

@dblock dblock merged commit f8aaaec into ruby-grape:master Nov 24, 2022
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

Successfully merging this pull request may close these issues.

2 participants