Commit 0e73d7b6 authored by Stan Hu's avatar Stan Hu

Merge pull request #9762 from huacnlee/fix/api-helpers-bad-autoload-name-for-master

Fix API::APIHelpers -> API::Helpers again for master
parents a7174efa 3d613fe1
...@@ -25,7 +25,7 @@ module API ...@@ -25,7 +25,7 @@ module API
format :json format :json
content_type :txt, "text/plain" content_type :txt, "text/plain"
helpers APIHelpers helpers Helpers
mount Groups mount Groups
mount GroupMembers mount GroupMembers
......
module API module API
module APIHelpers module Helpers
PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN" PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN"
PRIVATE_TOKEN_PARAM = :private_token PRIVATE_TOKEN_PARAM = :private_token
SUDO_HEADER ="HTTP_SUDO" SUDO_HEADER ="HTTP_SUDO"
......
...@@ -26,7 +26,7 @@ module Ci ...@@ -26,7 +26,7 @@ module Ci
format :json format :json
helpers Helpers helpers Helpers
helpers ::API::APIHelpers helpers ::API::Helpers
mount Builds mount Builds
mount Commits mount Commits
......
require 'spec_helper' require 'spec_helper'
describe API, api: true do describe API, api: true do
include API::APIHelpers include API::Helpers
include ApiHelpers include ApiHelpers
let(:user) { create(:user) } let(:user) { create(:user) }
let(:admin) { create(:admin) } let(:admin) { create(:admin) }
...@@ -13,25 +13,25 @@ describe API, api: true do ...@@ -13,25 +13,25 @@ describe API, api: true do
def set_env(token_usr, identifier) def set_env(token_usr, identifier)
clear_env clear_env
clear_param clear_param
env[API::APIHelpers::PRIVATE_TOKEN_HEADER] = token_usr.private_token env[API::Helpers::PRIVATE_TOKEN_HEADER] = token_usr.private_token
env[API::APIHelpers::SUDO_HEADER] = identifier env[API::Helpers::SUDO_HEADER] = identifier
end end
def set_param(token_usr, identifier) def set_param(token_usr, identifier)
clear_env clear_env
clear_param clear_param
params[API::APIHelpers::PRIVATE_TOKEN_PARAM] = token_usr.private_token params[API::Helpers::PRIVATE_TOKEN_PARAM] = token_usr.private_token
params[API::APIHelpers::SUDO_PARAM] = identifier params[API::Helpers::SUDO_PARAM] = identifier
end end
def clear_env def clear_env
env.delete(API::APIHelpers::PRIVATE_TOKEN_HEADER) env.delete(API::Helpers::PRIVATE_TOKEN_HEADER)
env.delete(API::APIHelpers::SUDO_HEADER) env.delete(API::Helpers::SUDO_HEADER)
end end
def clear_param def clear_param
params.delete(API::APIHelpers::PRIVATE_TOKEN_PARAM) params.delete(API::Helpers::PRIVATE_TOKEN_PARAM)
params.delete(API::APIHelpers::SUDO_PARAM) params.delete(API::Helpers::SUDO_PARAM)
end end
def error!(message, status) def error!(message, status)
...@@ -40,22 +40,22 @@ describe API, api: true do ...@@ -40,22 +40,22 @@ describe API, api: true do
describe ".current_user" do describe ".current_user" do
it "should return nil for an invalid token" do it "should return nil for an invalid token" do
env[API::APIHelpers::PRIVATE_TOKEN_HEADER] = 'invalid token' env[API::Helpers::PRIVATE_TOKEN_HEADER] = 'invalid token'
allow_any_instance_of(self.class).to receive(:doorkeeper_guard){ false } allow_any_instance_of(self.class).to receive(:doorkeeper_guard){ false }
expect(current_user).to be_nil expect(current_user).to be_nil
end end
it "should return nil for a user without access" do it "should return nil for a user without access" do
env[API::APIHelpers::PRIVATE_TOKEN_HEADER] = user.private_token env[API::Helpers::PRIVATE_TOKEN_HEADER] = user.private_token
allow(Gitlab::UserAccess).to receive(:allowed?).and_return(false) allow(Gitlab::UserAccess).to receive(:allowed?).and_return(false)
expect(current_user).to be_nil expect(current_user).to be_nil
end end
it "should leave user as is when sudo not specified" do it "should leave user as is when sudo not specified" do
env[API::APIHelpers::PRIVATE_TOKEN_HEADER] = user.private_token env[API::Helpers::PRIVATE_TOKEN_HEADER] = user.private_token
expect(current_user).to eq(user) expect(current_user).to eq(user)
clear_env clear_env
params[API::APIHelpers::PRIVATE_TOKEN_PARAM] = user.private_token params[API::Helpers::PRIVATE_TOKEN_PARAM] = user.private_token
expect(current_user).to eq(user) expect(current_user).to eq(user)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment