rspec_api_documentation
rspec_api_documentation copied to clipboard
Ability to customize env for requests
User should be able to set env variables per request with do_request method call.
Do you mean customize the rack env hash? If so I'm not a fan. RAD is an integration level tool, so playing around with the env isn't something I want add.
@oestrich how would one set HTTP_AUTHORIZATION env if i wanted to test routes that require basic auth? Here's an example of what i'm trying to do:
resource 'Users' do
#header 'HTTP_AUTHORIZATION', ActionController::HttpAuthentication::Basic.encode_credentials('[email protected]', "password")
before do
@user = FactoryGirl.create :user, email: '[email protected]', password: 'password'
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(@user.email, "password")
end
get "/admin/api/v1/users" do
example "listing users" do
do_request
status.should == 200
response_body.should == {users: [{users: @user}]}.to_json
end
end
end
This returns a 401. However, using the standard Rspec DSL, the tests actually pass.
@kareemshahin we have done this in the past, I think you'll want to customize your client via config.client_method
You want to use the header
DSL.
header "Authorization", :basic_auth
let(:basic_auth) do
ActionController::HttpAuthentication::Basic.encode_credentials(user.email, "password")
end
thank you @oestrich, silly mistake on my behalf. i was using the wrong header