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

Logical error for response processing #95

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ASnow
Copy link

@ASnow ASnow commented Jan 10, 2018

My case:
Result return "" for #errors when DELETE method responded with no body(204 status).

Problem
HashWithIndifferentAccess.new pass first argument to Hash.new that recognize it as default value for all keys. This happen when body don't repond to #to_hash

My case:
Result return "" for #errors when DELETE method responded with no body(204 status).

Problem
HashWithIndifferentAccess.new pass first argument to Hash.new that recognize it as default value for all keys. This happen when body don't repond to #to_hash
@coveralls
Copy link

Coverage Status

Coverage remained the same at 99.449% when pulling dea0002 on ASnow:master into 52c9178 on balvig:master.

@balvig
Copy link
Owner

balvig commented Jan 11, 2018

@ASnow usually I will handle this at the faraday layer, as the problems that occur can differ from each user.

You can massage the returned body in anyway you want here, so that eventually is follows this format before being passed on to Spyke:

{ data: { id: 1, name: 'Bob' }, metadata: {}, errors: {} }

https://github.com/balvig/spyke#configuration

@ASnow
Copy link
Author

ASnow commented Jan 11, 2018

@balvig, please look at Faraday default handling process
https://github.com/lostisland/faraday/search?utf8=%E2%9C%93&q=parse_body%3F&type=

It don't run parse in middleware for such case

@balvig
Copy link
Owner

balvig commented Jan 12, 2018

@ASnow you could add some middleware before that, that gets rid of blank strings, or even flesh out your own JSONParser middleware to come up with your own definition of when parse_body? should be true?

@ASnow
Copy link
Author

ASnow commented Jan 12, 2018

@balvig, yep I can. Is it ok that Result handles well(silent) when get not Hash?

@balvig
Copy link
Owner

balvig commented Feb 1, 2018

Is it ok that Result handles well(silent) when get not Hash?

@ASnow sorry, I couldn't quite catch what you mean by this question?

@ASnow
Copy link
Author

ASnow commented Feb 9, 2018

I can describe two possible solutions for current situation.

# This is rigth silent behavior
def not_respose_with_any_object
  mock = Minitest::Mock.new
  mock.expect :respond_to?, false, [:to_hash]

  res = Spyke:: Result.new mock
  refute_same res.data, mock # this error can cause false positve method call on mock
  refute_same res.metadata, mock
  refute_same res. errors, mock
end

# This is rigth fail behavior
def raise_error_when_not_duck
  mock = Minitest::Mock.new
  mock.expect :respond_to?, false, [:to_hash]

  assert_raises ExpectValidStruct do
    Spyke:: Result.new mock
  end
end

@balvig
Copy link
Owner

balvig commented Feb 13, 2018

@ASnow could you try showing a higher level test, for example based on a Recipe.destroy (maybe you can use some of the existing tests as a reference), that shows what the problem you're encountering is?

Base automatically changed from master to main February 24, 2021 03:59
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.

3 participants