Add specs for gitlab ci service validity.

This commit is contained in:
Marin Jankovski 2015-07-17 17:03:15 +02:00
parent 302c52551a
commit c7daa5f17f
2 changed files with 39 additions and 0 deletions

View File

@ -26,6 +26,33 @@ describe GitlabCiService do
it { is_expected.to have_one(:service_hook) }
end
describe 'validations' do
context 'active' do
before { allow(subject).to receive(:activated?).and_return(true) }
it { is_expected.to validate_presence_of(:token) }
it { is_expected.to validate_presence_of(:project_url) }
it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) }
it { is_expected.to allow_value('http://ci.example.com/project/1').for(:project_url) }
it { is_expected.not_to allow_value('token with spaces').for(:token) }
it { is_expected.not_to allow_value('token/with%spaces').for(:token) }
it { is_expected.not_to allow_value('this is not url').for(:project_url) }
it { is_expected.not_to allow_value('http//noturl').for(:project_url) }
it { is_expected.not_to allow_value('ftp://ci.example.com/projects/3').for(:project_url) }
end
context 'inactive' do
before { allow(subject).to receive(:activated?).and_return(false) }
it { is_expected.not_to validate_presence_of(:token) }
it { is_expected.not_to validate_presence_of(:project_url) }
it { is_expected.to allow_value('ewf9843kdnfdfs89234n').for(:token) }
it { is_expected.to allow_value('http://ci.example.com/project/1').for(:project_url) }
it { is_expected.to allow_value('token with spaces').for(:token) }
it { is_expected.to allow_value('ftp://ci.example.com/projects/3').for(:project_url) }
end
end
describe 'commits methods' do
before do
@service = GitlabCiService.new

View File

@ -17,6 +17,18 @@ describe API::API, api: true do
expect(response.status).to eq(400)
end
it "should return if the format of token is invalid" do
put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'token-with dashes and spaces%', project_url: "http://ci.example.com/projects/1", active: true
expect(response.status).to eq(404)
end
it "should return if the format of token is invalid" do
put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'token-with dashes and spaces%', project_url: "ftp://ci.example/projects/1", active: true
expect(response.status).to eq(404)
end
end
describe "DELETE /projects/:id/services/gitlab-ci" do