rspec_api_documentation
rspec_api_documentation copied to clipboard
abillity of per-request header definitions.
Is it possible to override headers and parameters in do_request
? Do they get mixed up with other custom params?
do_request auth_headers
- this works (accepts them as headers), but on frontend they are listed as body.
You can specify a headers
in the DSL:
resource "SmartTip" do
header "Authorization", :authorization
header "Content-Type", "application/json"
header "Accept", "application/vnd.api+json"
let(:authorization) { 'Bearer 43721984702319' }
# ... do your tests
end
yep, that's how I'm using it now. but I'd like to change headers as I go because some routes in resource require different headers.
@lakesare you can put this part let(:authorization) { 'Bearer 43721984702319' }
within a context and switch it out for any variation you need.
Hello guys.
I'm trying to set per request header as described above,
resource "Users" do
header "X-Auth-Token", :auth_token
get "/api/users/:id.json" do
parameter :id, "User id"
let(:user) { create :user }
let(:id) { user.id }
let(:auth_token) { user.authentication_token }
example_request "Get user details" do
expect(status).to eq 200
end
end
end
but looks like this approach is not working.
When i'm run spec i got this in output:
Failure/Error: expect(status).to eq 200
expected: 200
got: 401
(compared using ==)
in my controller i use header that way:
def current_user
@current_user ||= User.find_by(authentication_token: headers['X-Auth-Token'])
end