Functional test for HTTP Basic Authentication in Rails 2

If you want to provide a username and password for a HTTP Basic Authentication in one of your functional tests, simply use the following:

def test_should_get_index
@request.env["HTTP_AUTHORIZATION"] = “Basic ” + Base64::encode64(”username:password”)
get :index
assert_response :success
assert_not_nil assigns(:articles)
end

Keywords: rails test, functionals, authorization, basic http authentication, how to test

Ruby: a ||= b

a ||= b
means
a = b if a.nil? || a == false


linkboost