2015-08-12 03:40:54 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::ServicesController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2015-08-12 03:40:54 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:service) { create(:service, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(user)
|
|
|
|
project.team << [user, :master]
|
|
|
|
controller.instance_variable_set(:@project, project)
|
|
|
|
controller.instance_variable_set(:@service, service)
|
|
|
|
end
|
|
|
|
|
2015-10-20 03:28:28 -04:00
|
|
|
shared_examples_for 'services controller' do |referrer|
|
|
|
|
before do
|
|
|
|
request.env["HTTP_REFERER"] = referrer
|
2015-08-12 03:40:54 -04:00
|
|
|
end
|
|
|
|
|
2015-10-20 03:28:28 -04:00
|
|
|
describe "#test" do
|
|
|
|
context 'success' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it "redirects and show success message" do
|
2015-10-20 03:28:28 -04:00
|
|
|
expect(service).to receive(:test).and_return({ success: true, result: 'done' })
|
|
|
|
get :test, namespace_id: project.namespace.id, project_id: project.id, id: service.id, format: :html
|
|
|
|
expect(response.status).to redirect_to('/')
|
|
|
|
expect(flash[:notice]).to eq('We sent a request to the provided URL')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'failure' do
|
2016-07-25 14:16:19 -04:00
|
|
|
it "redirects and show failure message" do
|
2015-10-20 03:28:28 -04:00
|
|
|
expect(service).to receive(:test).and_return({ success: false, result: 'Bad test' })
|
|
|
|
get :test, namespace_id: project.namespace.id, project_id: project.id, id: service.id, format: :html
|
|
|
|
expect(response.status).to redirect_to('/')
|
|
|
|
expect(flash[:alert]).to eq('We tried to send a request to the provided URL but an error occurred: Bad test')
|
|
|
|
end
|
2015-08-12 03:40:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-20 03:28:28 -04:00
|
|
|
|
|
|
|
describe 'referrer defined' do
|
|
|
|
it_should_behave_like 'services controller' do
|
|
|
|
let!(:referrer) { "/" }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'referrer undefined' do
|
|
|
|
it_should_behave_like 'services controller' do
|
|
|
|
let!(:referrer) { nil }
|
|
|
|
end
|
|
|
|
end
|
2016-09-04 09:33:14 -04:00
|
|
|
|
|
|
|
describe 'PUT #update' do
|
|
|
|
context 'on successful update' do
|
|
|
|
it 'sets the flash' do
|
|
|
|
expect(service).to receive(:to_param).and_return('hipchat')
|
2017-01-12 17:33:04 -05:00
|
|
|
expect(service).to receive(:event_names).and_return(HipchatService.event_names)
|
2016-09-04 09:33:14 -04:00
|
|
|
|
|
|
|
put :update,
|
|
|
|
namespace_id: project.namespace.id,
|
|
|
|
project_id: project.id,
|
|
|
|
id: service.id,
|
|
|
|
service: { active: false }
|
|
|
|
|
|
|
|
expect(flash[:notice]).to eq 'Successfully updated.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-12 03:40:54 -04:00
|
|
|
end
|