2013-11-15 13:29:53 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-04-11 19:45:56 +00:00
|
|
|
describe API::API, api: true do
|
2013-11-15 13:29:53 +00:00
|
|
|
include ApiHelpers
|
|
|
|
let(:admin) { create(:admin) }
|
2015-05-25 20:51:37 +00:00
|
|
|
let(:user) { create(:user) }
|
2013-11-15 13:29:53 +00:00
|
|
|
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")
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(response.status).to eq(401)
|
2013-11-15 13:29:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-25 20:51:37 +00:00
|
|
|
context "when authenticated as admin" do
|
2013-11-15 13:29:53 +00:00
|
|
|
it "admin: should return an array of all namespaces" do
|
|
|
|
get api("/namespaces", admin)
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
2013-11-15 13:29:53 +00:00
|
|
|
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(json_response.length).to eq(Namespace.count)
|
2013-11-15 13:29:53 +00:00
|
|
|
end
|
2015-05-25 20:51:37 +00:00
|
|
|
|
|
|
|
it "admin: should return an array of matched namespaces" do
|
|
|
|
get api("/namespaces?search=#{group1.name}", admin)
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
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)
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
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)
|
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response).to be_an Array
|
|
|
|
|
|
|
|
expect(json_response.length).to eq(1)
|
|
|
|
end
|
2013-11-15 13:29:53 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|