summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2017-01-31 11:40:27 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2017-01-31 11:40:27 +0000
commite4bcdddfa79d855e7f320a8d91e79e17d2e1bf5f (patch)
tree773ec4112b83aed98c1c4faefd1b0f60e2640d7c
parent223f1f3d2dd95d6b87a485ce0df6f4fef77eb522 (diff)
parentbd5245dba67b4aa4fccce819e4491259d568240b (diff)
downloadgitlab-ce-e4bcdddfa79d855e7f320a8d91e79e17d2e1bf5f.tar.gz
Merge branch 'zj-display-error-team-fetch' into 'master'
Fix inconsistent return type Closes #27150 See merge request !8290
-rw-r--r--app/controllers/projects/mattermosts_controller.rb2
-rw-r--r--app/models/project_services/mattermost_slash_commands_service.rb4
-rw-r--r--app/views/projects/mattermosts/_no_teams.html.haml4
-rw-r--r--spec/controllers/projects/mattermosts_controller_spec.rb4
-rw-r--r--spec/features/projects/services/mattermost_slash_command_spec.rb9
-rw-r--r--spec/models/project_services/mattermost_slash_commands_service_spec.rb5
6 files changed, 19 insertions, 9 deletions
diff --git a/app/controllers/projects/mattermosts_controller.rb b/app/controllers/projects/mattermosts_controller.rb
index 01d99c7df35..38f7e6eb5e9 100644
--- a/app/controllers/projects/mattermosts_controller.rb
+++ b/app/controllers/projects/mattermosts_controller.rb
@@ -34,7 +34,7 @@ class Projects::MattermostsController < Projects::ApplicationController
end
def teams
- @teams ||= @service.list_teams(current_user)
+ @teams, @teams_error_message = @service.list_teams(current_user)
end
def service
diff --git a/app/models/project_services/mattermost_slash_commands_service.rb b/app/models/project_services/mattermost_slash_commands_service.rb
index 50a011db74e..b0f7a42f9a3 100644
--- a/app/models/project_services/mattermost_slash_commands_service.rb
+++ b/app/models/project_services/mattermost_slash_commands_service.rb
@@ -28,8 +28,8 @@ class MattermostSlashCommandsService < ChatSlashCommandsService
[false, e.message]
end
- def list_teams(user)
- Mattermost::Team.new(user).all
+ def list_teams(current_user)
+ [Mattermost::Team.new(current_user).all, nil]
rescue Mattermost::Error => e
[[], e.message]
end
diff --git a/app/views/projects/mattermosts/_no_teams.html.haml b/app/views/projects/mattermosts/_no_teams.html.haml
index 605c7f61dee..aac74a25b75 100644
--- a/app/views/projects/mattermosts/_no_teams.html.haml
+++ b/app/views/projects/mattermosts/_no_teams.html.haml
@@ -1,3 +1,7 @@
+- if @teams_error_message
+ = content_for :flash_message do
+ .alert.alert-danger= @teams_error_message
+
%p
You aren’t a member of any team on the Mattermost instance at
%strong= Gitlab.config.mattermost.host
diff --git a/spec/controllers/projects/mattermosts_controller_spec.rb b/spec/controllers/projects/mattermosts_controller_spec.rb
index 2ae635a1244..cae733f0cfb 100644
--- a/spec/controllers/projects/mattermosts_controller_spec.rb
+++ b/spec/controllers/projects/mattermosts_controller_spec.rb
@@ -13,13 +13,13 @@ describe Projects::MattermostsController do
before do
allow_any_instance_of(MattermostSlashCommandsService).
to receive(:list_teams).and_return([])
+ end
+ it 'accepts the request' 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
diff --git a/spec/features/projects/services/mattermost_slash_command_spec.rb b/spec/features/projects/services/mattermost_slash_command_spec.rb
index 86a07b2c679..042a1ccab51 100644
--- a/spec/features/projects/services/mattermost_slash_command_spec.rb
+++ b/spec/features/projects/services/mattermost_slash_command_spec.rb
@@ -99,6 +99,15 @@ feature 'Setup Mattermost slash commands', feature: true do
expect(select_element.all('option').count).to eq(3)
end
+ it 'shows an error alert with the error message if there is an error requesting teams' do
+ allow_any_instance_of(MattermostSlashCommandsService).to receive(:list_teams) { [[], 'test mattermost error message'] }
+
+ click_link 'Add to Mattermost'
+
+ expect(page).to have_selector('.alert')
+ expect(page).to have_content('test mattermost error message')
+ end
+
def stub_teams(count: 0)
teams = create_teams(count)
diff --git a/spec/models/project_services/mattermost_slash_commands_service_spec.rb b/spec/models/project_services/mattermost_slash_commands_service_spec.rb
index c879edddfdd..98f3d420c8a 100644
--- a/spec/models/project_services/mattermost_slash_commands_service_spec.rb
+++ b/spec/models/project_services/mattermost_slash_commands_service_spec.rb
@@ -113,10 +113,7 @@ describe MattermostSlashCommandsService, :models do
end
it 'shows error messages' do
- teams, message = subject
-
- expect(teams).to be_empty
- expect(message).to eq('Failed to get team list.')
+ expect(subject).to eq([[], "Failed to get team list."])
end
end
end