gitlab-org--gitlab-foss/spec/requests/api/services_spec.rb

52 lines
1.5 KiB
Ruby
Raw Normal View History

2013-10-29 10:39:46 -04:00
require "spec_helper"
2014-04-11 15:45:56 -04:00
describe API::API, api: true do
2013-10-29 10:39:46 -04:00
include ApiHelpers
let(:user) { create(:user) }
let(:project) {create(:project, creator_id: user.id, namespace: user.namespace) }
2013-10-29 10:39:46 -04:00
2015-08-26 19:58:49 -04:00
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
2014-10-14 13:07:34 -04:00
end
end
2013-10-29 10:39:46 -04:00
end