diff options
author | Kirilll Zaitsev <kirik910@gmail.com> | 2015-08-27 02:58:49 +0300 |
---|---|---|
committer | Kirilll Zaitsev <kirik910@gmail.com> | 2015-09-02 05:52:16 +0300 |
commit | 263abda3fd7ddfb826cd17ae88fb47d0e1d67fae (patch) | |
tree | 14a7085fc1998bbb0d30b7d1e5dca71f6b599193 /spec/requests/api/services_spec.rb | |
parent | 308c6428aef2a46b0370a24d85a97b0e133283a8 (diff) |
Drone CI service
Diffstat (limited to 'spec/requests/api/services_spec.rb')
-rw-r--r-- | spec/requests/api/services_spec.rb | 99 |
1 files changed, 41 insertions, 58 deletions
diff --git a/spec/requests/api/services_spec.rb b/spec/requests/api/services_spec.rb index 6d29a28580a..c297904614a 100644 --- a/spec/requests/api/services_spec.rb +++ b/spec/requests/api/services_spec.rb @@ -5,64 +5,47 @@ describe API::API, api: true do let(:user) { create(:user) } let(:project) {create(:project, creator_id: user.id, namespace: user.namespace) } - describe "POST /projects/:id/services/gitlab-ci" do - it "should update gitlab-ci settings" do - put api("/projects/#{project.id}/services/gitlab-ci", user), token: 'secrettoken', project_url: "http://ci.example.com/projects/1" - - expect(response.status).to eq(200) - end - - it "should return if required fields missing" do - put api("/projects/#{project.id}/services/gitlab-ci", user), project_url: "http://ci.example.com/projects/1", active: true - - 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 - it "should update gitlab-ci settings" do - delete api("/projects/#{project.id}/services/gitlab-ci", user) - - expect(response.status).to eq(200) - expect(project.gitlab_ci_service).to be_nil - end - end - - describe 'PUT /projects/:id/services/hipchat' do - it 'should update hipchat settings' do - put api("/projects/#{project.id}/services/hipchat", user), - token: 'secret-token', room: 'test' - - expect(response.status).to eq(200) - expect(project.hipchat_service).not_to be_nil - end - - it 'should return if required fields missing' do - put api("/projects/#{project.id}/services/gitlab-ci", user), - token: 'secret-token', active: true - - expect(response.status).to eq(400) - end - end - - describe 'DELETE /projects/:id/services/hipchat' do - it 'should delete hipchat settings' do - delete api("/projects/#{project.id}/services/hipchat", user) - - expect(response.status).to eq(200) - expect(project.hipchat_service).to be_nil + Service.available_services_names.each do |service| + describe "PUT /projects/:id/services/#{service.dasherize}" do + include_context service + + it "should update #{service} settings" do + put api("/projects/#{project.id}/services/#{dashed_service}", user), service_attrs + + expect(response.status).to eq(200) + end + + it "should return if required fields missing" do + attrs = service_attrs + + required_attributes = service_attrs_list.select do |attr| + service_klass.validators_on(attr).any? do |v| + v.class == ActiveRecord::Validations::PresenceValidator + end + end + + if required_attributes.empty? + expected_code = 200 + else + attrs.delete(required_attributes.shuffle.first) + expected_code = 400 + end + + put api("/projects/#{project.id}/services/#{dashed_service}", user), attrs + + expect(response.status).to eq(expected_code) + end + end + + describe "DELETE /projects/:id/services/#{service.dasherize}" do + include_context service + + it "should delete #{service}" do + delete api("/projects/#{project.id}/services/#{dashed_service}", user) + + expect(response.status).to eq(200) + expect(project.send(service_method).activated?).to be_falsey + end end end end |