diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-09 14:56:02 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-09-09 14:56:02 +0200 |
commit | 0b5d627cd4a3f81934e7772e3558356c9dd2e3cf (patch) | |
tree | a232d232e543ef372d91d0dfffbc93985f37d982 /spec/requests | |
parent | 90c338a49541c95452181af9e0d0bcf9da6c51ad (diff) | |
parent | 0d610270d9634b783137bc6318eff4aa82572a7d (diff) | |
download | gitlab-ce-0b5d627cd4a3f81934e7772e3558356c9dd2e3cf.tar.gz |
Merge branch 'master' into ci-and-ce-sitting-in-a-tree-k-i-s-s-i-n-g
Diffstat (limited to 'spec/requests')
-rw-r--r-- | spec/requests/api/keys_spec.rb | 39 | ||||
-rw-r--r-- | spec/requests/api/services_spec.rb | 99 |
2 files changed, 80 insertions, 58 deletions
diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb new file mode 100644 index 00000000000..d2b87f88712 --- /dev/null +++ b/spec/requests/api/keys_spec.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe API::API, api: true do + include ApiHelpers + + let(:user) { create(:user) } + let(:admin) { create(:admin) } + let(:key) { create(:key, user: user) } + let(:email) { create(:email, user: user) } + + describe 'GET /keys/:uid' do + before { admin } + + context 'when unauthenticated' do + it 'should return authentication error' do + get api("/keys/#{key.id}") + expect(response.status).to eq(401) + end + end + + context 'when authenticated' do + it 'should return 404 for non-existing key' do + get api('/keys/999999', admin) + expect(response.status).to eq(404) + expect(json_response['message']).to eq('404 Not found') + end + + it 'should return single ssh key with user information' do + user.keys << key + user.save + get api("/keys/#{key.id}", admin) + expect(response.status).to eq(200) + expect(json_response['title']).to eq(key.title) + expect(json_response['user']['id']).to eq(user.id) + expect(json_response['user']['username']).to eq(user.username) + end + end + end +end 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 |