Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
0cf23fde
Commit
0cf23fde
authored
Dec 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work on tests for mattermost
parent
d305d15b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
7 deletions
+56
-7
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+4
-4
lib/mattermost/client.rb
lib/mattermost/client.rb
+4
-2
lib/mattermost/session.rb
lib/mattermost/session.rb
+13
-1
spec/models/project_services/mattermost_slash_commands_service_spec.rb
...roject_services/mattermost_slash_commands_service_spec.rb
+35
-0
No files found.
app/helpers/projects_helper.rb
View file @
0cf23fde
...
@@ -150,10 +150,10 @@ module ProjectsHelper
...
@@ -150,10 +150,10 @@ module ProjectsHelper
def
mattermost_teams_options
(
teams
)
def
mattermost_teams_options
(
teams
)
teams_options
=
teams
.
map
do
|
id
,
options
|
teams_options
=
teams
.
map
do
|
id
,
options
|
return
nil
unless
id
&&
options
[
'display_name'
]
[
options
[
'display_name'
]
||
options
[
'name'
],
id
]
[
options
[
'display_name'
],
id
]
end
end
.
compact
teams_options
.
unshift
([
'Select team...'
,
'0'
])
teams_options
.
compact
.
unshift
([
'Select team...'
,
'0'
])
end
end
private
private
...
...
lib/mattermost/client.rb
View file @
0cf23fde
module
Mattermost
module
Mattermost
class
ClientError
<
Mattermost
::
Error
;
end
class
Client
class
Client
attr_reader
:user
attr_reader
:user
...
@@ -30,9 +32,9 @@ module Mattermost
...
@@ -30,9 +32,9 @@ module Mattermost
if
response
.
success?
if
response
.
success?
json_response
json_response
elsif
json_response
[
'message'
]
elsif
json_response
[
'message'
]
raise
json_response
[
'message'
]
raise
ClientError
(
json_response
[
'message'
])
else
else
raise
'Undefined error'
raise
ClientError
(
'Undefined error'
)
end
end
end
end
end
end
...
...
lib/mattermost/session.rb
View file @
0cf23fde
module
Mattermost
module
Mattermost
class
NoSessionError
<
StandardError
class
Error
<
StandardError
;
end
class
NoSessionError
<
Error
def
message
def
message
'No session could be set up, is Mattermost configured with Single Sign on?'
'No session could be set up, is Mattermost configured with Single Sign on?'
end
end
end
end
class
ConnectionError
<
Error
def
message
'Could not connect. Is Mattermost up?'
end
end
# This class' prime objective is to obtain a session token on a Mattermost
# This class' prime objective is to obtain a session token on a Mattermost
# instance with SSO configured where this GitLab instance is the provider.
# instance with SSO configured where this GitLab instance is the provider.
#
#
...
@@ -66,10 +74,14 @@ module Mattermost
...
@@ -66,10 +74,14 @@ module Mattermost
def
get
(
path
,
options
=
{})
def
get
(
path
,
options
=
{})
self
.
class
.
get
(
path
,
options
.
merge
(
headers:
@headers
))
self
.
class
.
get
(
path
,
options
.
merge
(
headers:
@headers
))
rescue
Errno
::
ECONNREFUSED
raise
ConnectionError
end
end
def
post
(
path
,
options
=
{})
def
post
(
path
,
options
=
{})
self
.
class
.
post
(
path
,
options
.
merge
(
headers:
@headers
))
self
.
class
.
post
(
path
,
options
.
merge
(
headers:
@headers
))
rescue
Errno
::
ECONNREFUSED
raise
ConnectionError
end
end
private
private
...
...
spec/models/project_services/mattermost_slash_commands_service_spec.rb
View file @
0cf23fde
...
@@ -2,4 +2,39 @@ require 'spec_helper'
...
@@ -2,4 +2,39 @@ require 'spec_helper'
describe
MattermostSlashCommandsService
,
:models
do
describe
MattermostSlashCommandsService
,
:models
do
it_behaves_like
"chat slash commands service"
it_behaves_like
"chat slash commands service"
describe
'#configure!'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:service
)
{
project
.
build_mattermost_slash_commands_service
}
let
(
:user
)
{
create
(
:user
)}
before
do
allow_any_instance_of
(
Mattermost
::
Session
).
to
receive
(
:with_session
).
and_yield
end
subject
do
service
.
configure!
(
user
,
team_id:
'abc'
,
trigger:
'gitlab'
,
url:
'http://trigger.url'
,
icon_url:
'http://icon.url/icon.png'
)
end
context
'the requests succeeds'
do
it
'saves the service'
do
expect
{
subject
}.
to
change
{
project
.
services
.
count
}.
by
(
1
)
end
it
'saves the token'
do
subject
expect
(
service
.
reload
.
token
).
to
eq
(
'mynewtoken'
)
end
end
context
'an error is received'
do
it
'shows error messages'
do
expect
(
subject
).
to
raise_error
(
"Error"
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment