diff options
author | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-12-20 22:30:06 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-12-20 22:30:06 +0100 |
commit | 36eed726dcf7e4bf062265cb665ad798be774f89 (patch) | |
tree | 2078fa137dd783b6346e8a6de061b24351990aa2 /spec/controllers/projects | |
parent | 4a03fae930a58b485ee610ce9e6058a2c2dd3d6e (diff) | |
download | gitlab-ce-36eed726dcf7e4bf062265cb665ad798be774f89.tar.gz |
Add controller test
Diffstat (limited to 'spec/controllers/projects')
-rw-r--r-- | spec/controllers/projects/mattermosts_controller_spec.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/controllers/projects/mattermosts_controller_spec.rb b/spec/controllers/projects/mattermosts_controller_spec.rb new file mode 100644 index 00000000000..3f9482b0cde --- /dev/null +++ b/spec/controllers/projects/mattermosts_controller_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe Projects::MattermostsController do + let!(:project) { create(:empty_project) } + let!(:user) { create(:user) } + + before do + project.team << [user, :master] + sign_in(user) + end + + describe 'GET #new' do + before do + get(:new, + namespace_id: project.namespace.to_param, + project_id: project.to_param) + end + + it 'accepts the request' do + expect(response).to have_http_status(200) + 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.to_param, + mattermost: mattermost_params) + end + + context 'no request can be made to mattermost' do + it 'shows the error' do + expect(controller).to set_flash[:alert].to /\AFailed to open TCP connection to/ + 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 + + expect(subject).to redirect_to(edit_namespace_project_service_url(project.namespace, project, service)) + end + end + end +end |