rspec_api_documentation icon indicating copy to clipboard operation
rspec_api_documentation copied to clipboard

abillity of per-request header definitions.

Open lakesare opened this issue 8 years ago • 4 comments

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.

lakesare avatar Feb 03 '16 16:02 lakesare

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

ianks avatar Feb 18 '16 19:02 ianks

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 avatar Feb 18 '16 20:02 lakesare

@lakesare you can put this part let(:authorization) { 'Bearer 43721984702319' } within a context and switch it out for any variation you need.

jakehow avatar Feb 18 '16 21:02 jakehow

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

DevilsNightsix avatar Mar 12 '16 18:03 DevilsNightsix