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

[api] Remove #parse_response spec helper #7143

Merged
merged 2 commits into from
Mar 10, 2016

Conversation

imtayadeway
Copy link
Contributor

Each request method was calling #parse_response after the request was
submitted. This method was doing some things that were either unused, or
could be easily replaced by a method built into the request spec
framework.

In particular:

  • References to @code could be replaced with response.status, or use
    the built-in http status matcher
  • @success was not used externally
  • @status was not used
  • @message was not used
  • @result was used quite extensively, so was replaced with a method

The net result is that the state has been reduced, as has the work done
on each request.

/cc @jrafanie ✂️ 🔥 etc..
/cc @abellotti @gtanzillo
@miq-bot add-label test, refactoring, api

@status = API_STATUS[@code] || (@success ? Rack::Utils.status_code(:ok) : Rack::Utils.status_code(:bad_request))
@message = @result.kind_of?(Hash) ? @result.fetch_path("error", "message").to_s : @result
@success
def result
Copy link
Member

Choose a reason for hiding this comment

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

Naming is hard... Looking at the examples in this PR, I wouldn't know what result meant at just a glance. response_body, response_hash or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree...I kept at result to minimize the change from @result, but agree a more descriptive name would be better. Maybe parsed_body? @abellotti any thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, parsed_body is good but the naive part of me wants to see response in the name.

Copy link
Member

Choose a reason for hiding this comment

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

I like response_hash...similar to response_body, but clearly converted to a Hash, however it might not match the unauthorized case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Fryguy after chatting to @jrafanie about this I'm going to go with response_hash and make this method only responsible for parsing JSON from the response body....anything that doesn't confirm will have to do something else.

@jrafanie
Copy link
Member

jrafanie commented Mar 7, 2016

I like this change, just not sure of the new method name. 👍

@@ -85,7 +85,7 @@

it "can fetch a specific result as a primary collection" do
report = FactoryGirl.create(:miq_report_with_results)
result = report.miq_report_results.first
Copy link
Member

Choose a reason for hiding this comment

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

Wow, this would have been confusing with the prior iteration. 👍

I often use result as a variable(naming is hard) so using response_hash makes instances like this less confusing.

@Fryguy
Copy link
Member

Fryguy commented Mar 9, 2016

👍 👍 response_hash is SOOO much clearer than @result

@miq-bot
Copy link
Member

miq-bot commented Mar 10, 2016

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@gtanzillo
Copy link
Member

Looks great! 👍

Each request method was calling `#parse_response` after the request was
submitted. This method was doing some things that were either unused, or
could be easily replaced by a method built into the request spec
framework.

In particular:

* References to `@code` could be replaced with `response.status`, or use
  the built-in http status matcher
* `@success` was not used externally
* `@status` was not used
* `@message` was not used
* `@result` was used quite extensively, so was replaced with a method

The net result is that the state has been reduced, as has the work done
on each request.
Changing this method name to the more descriptive `response_hash`. The
original idea was to make this method only responsible for parsing JSON
from the response body, and to update any callers of it to do something
else where it was switching before. As it turned out, all callers could
happily parse the response body, which simplified the whole thing.
@miq-bot
Copy link
Member

miq-bot commented Mar 10, 2016

Checked commits imtayadeway/manageiq@65da02d~...38a6f5b with ruby 2.2.3, rubocop 0.37.2, and haml-lint 0.16.1
24 files checked, 0 offenses detected
Everything looks good. 👍

@imtayadeway
Copy link
Contributor Author

@jrafanie @Fryguy @gtanzillo Just rebased to make this mergeable again

@jrafanie
Copy link
Member

Looks great, thanks @imtayadeway 👍

jrafanie added a commit that referenced this pull request Mar 10, 2016
[api] Remove `#parse_response` spec helper
@jrafanie jrafanie merged commit c3e6307 into ManageIQ:master Mar 10, 2016
@jrafanie jrafanie added this to the Sprint 38 Ending Mar 28, 2016 milestone Mar 10, 2016
@chrisarcand
Copy link
Member

🎉 So much better

@imtayadeway imtayadeway deleted the api/delete-some-spec-code branch July 7, 2016 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants