debian-mirror-gitlab/spec/controllers/projects/mattermosts_controller_spec.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2017-08-17 22:00:37 +05:30
require 'spec_helper'
describe Projects::MattermostsController do
2017-09-10 17:25:29 +05:30
let!(:project) { create(:project) }
2017-08-17 22:00:37 +05:30
let!(:user) { create(:user) }
before do
2018-03-17 18:26:18 +05:30
project.add_master(user)
2017-08-17 22:00:37 +05:30
sign_in(user)
end
describe 'GET #new' do
before do
2017-09-10 17:25:29 +05:30
allow_any_instance_of(MattermostSlashCommandsService)
.to receive(:list_teams).and_return([])
2017-08-17 22:00:37 +05:30
end
it 'accepts the request' do
get(:new,
namespace_id: project.namespace.to_param,
project_id: project)
2018-03-17 18:26:18 +05:30
expect(response).to have_gitlab_http_status(200)
2017-08-17 22:00:37 +05:30
end
end
describe 'POST #create' do
let(:mattermost_params) { { trigger: 'http://localhost:3000/trigger', team_id: 'abc' } }
subject do
post(:create,
namespace_id: project.namespace.to_param,
project_id: project,
mattermost: mattermost_params)
end
context 'no request can be made to mattermost' do
it 'shows the error' do
allow_any_instance_of(MattermostSlashCommandsService).to receive(:configure).and_return([false, "error message"])
2017-09-10 17:25:29 +05:30
expect(subject).to redirect_to(new_project_mattermost_url(project))
2017-08-17 22:00:37 +05:30
end
end
context 'the request is succesull' do
before do
allow_any_instance_of(Mattermost::Command).to receive(:create).and_return('token')
end
it 'redirects to the new page' do
subject
service = project.services.last
2017-09-10 17:25:29 +05:30
expect(subject).to redirect_to(edit_project_service_url(project, service))
2017-08-17 22:00:37 +05:30
end
end
end
end