debian-mirror-gitlab/spec/requests/api/namespaces_spec.rb

55 lines
1.6 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe API::API, api: true do
include ApiHelpers
let(:admin) { create(:admin) }
2015-09-11 14:41:01 +05:30
let(:user) { create(:user) }
2014-09-02 18:07:02 +05:30
let!(:group1) { create(:group) }
let!(:group2) { create(:group) }
describe "GET /namespaces" do
context "when unauthenticated" do
it "should return authentication error" do
get api("/namespaces")
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2014-09-02 18:07:02 +05:30
end
end
2015-09-11 14:41:01 +05:30
context "when authenticated as admin" do
2014-09-02 18:07:02 +05:30
it "admin: should return an array of all namespaces" do
get api("/namespaces", admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
expect(json_response.length).to eq(Namespace.count)
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
it "admin: should return an array of matched namespaces" do
get api("/namespaces?search=#{group1.name}", admin)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-09-11 14:41:01 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
end
end
context "when authenticated as a regular user" do
it "user: should return an array of namespaces" do
get api("/namespaces", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-09-11 14:41:01 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
end
it "admin: should return an array of matched namespaces" do
get api("/namespaces?search=#{user.username}", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-09-11 14:41:01 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
end
2014-09-02 18:07:02 +05:30
end
end
end