Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Test example no longer working #174

Open
kiesia opened this issue Jun 30, 2017 · 3 comments
Open

Test example no longer working #174

kiesia opened this issue Jun 30, 2017 · 3 comments

Comments

@kiesia
Copy link

kiesia commented Jun 30, 2017

I just upgraded to Rails 5.1.2 (from 5.0.1) and discovered that it's no longer possible to pass in headers: {} into get/patch/post/etc request test helpers. So the example in the README:

get secured_resources_url, headers: authenticated_header

no longer works. I did a bit of digging and found a couple of solutions here. I ended up reimplementing my tests like this:

request.headers.merge!('HTTP_AUTHORIZATION' => retrieve_access_token(user))
get path, params: params

I'm happy to submit a PR if you think that's the best way to go. 🙂

@krsyoung
Copy link

krsyoung commented Jul 3, 2017

Hi @kiesia! I'm making use of headers with 5.1.2 (I need to look a little closer but my tests are still working) without issue.

Maybe this is a Rspec vs Minitest difference? I'm using the code referenced above but with Minitest:

get api_v1_claims_url(service_date: '2017-03-20'), as: :json, headers: authenticated_header_for(:one)

@kiesia
Copy link
Author

kiesia commented Jul 5, 2017

Perhaps! I'll build a fresh rails install in the weekend and look into it further.

@kiesia
Copy link
Author

kiesia commented Jul 25, 2017

Sorry for the slow update! It does appear to be a difference with rspec-rails, specifically with controller tests.

This doesn't work as controller tests include ActionController::TestCase::Behavior, which doesn't handle headers: in requests. Request specs work fine as they are including ActionDispatch::IntegrationTest::Behavior similar to your tests.

I'm happy to add an example rspec controller test in the README if you'd like?

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

No branches or pull requests

2 participants