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
Léo-Paul Géneau
gitlab-ce
Commits
4a03fae9
Commit
4a03fae9
authored
Dec 20, 2016
by
Z.J. van de Weg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix rspec tests due to different API
[ci skip]
parent
0bd8669f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
36 deletions
+33
-36
lib/mattermost/session.rb
lib/mattermost/session.rb
+2
-2
spec/features/projects/services/mattermost_slash_command_spec.rb
...atures/projects/services/mattermost_slash_command_spec.rb
+4
-8
spec/lib/mattermost/command_spec.rb
spec/lib/mattermost/command_spec.rb
+10
-5
spec/lib/mattermost/team_spec.rb
spec/lib/mattermost/team_spec.rb
+5
-12
spec/models/project_services/mattermost_slash_commands_service_spec.rb
...roject_services/mattermost_slash_commands_service_spec.rb
+12
-9
No files found.
lib/mattermost/session.rb
View file @
4a03fae9
...
@@ -75,9 +75,9 @@ module Mattermost
...
@@ -75,9 +75,9 @@ 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
HTTParty
::
Error
=>
e
rescue
HTTParty
::
Error
=>
e
raise
ConnectionError
(
e
.
message
)
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
rescue
Errno
::
ECONNREFUSED
=>
e
rescue
Errno
::
ECONNREFUSED
=>
e
raise
ConnectionError
(
e
.
message
)
raise
Mattermost
::
ConnectionError
.
new
(
e
.
message
)
end
end
def
post
(
path
,
options
=
{})
def
post
(
path
,
options
=
{})
...
...
spec/features/projects/services/mattermost_slash_command_spec.rb
View file @
4a03fae9
...
@@ -4,10 +4,12 @@ feature 'Setup Mattermost slash commands', feature: true do
...
@@ -4,10 +4,12 @@ feature 'Setup Mattermost slash commands', feature: true do
include
WaitForAjax
include
WaitForAjax
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:
empty_
project
)
}
let
(
:service
)
{
project
.
create_mattermost_slash_commands_service
}
let
(
:service
)
{
project
.
create_mattermost_slash_commands_service
}
let
(
:mattermost_enabled
)
{
true
}
before
do
before
do
Settings
.
mattermost
[
'enabled'
]
=
mattermost_enabled
project
.
team
<<
[
user
,
:master
]
project
.
team
<<
[
user
,
:master
]
login_as
(
user
)
login_as
(
user
)
visit
edit_namespace_project_service_path
(
project
.
namespace
,
project
,
service
)
visit
edit_namespace_project_service_path
(
project
.
namespace
,
project
,
service
)
...
@@ -32,19 +34,13 @@ feature 'Setup Mattermost slash commands', feature: true do
...
@@ -32,19 +34,13 @@ feature 'Setup Mattermost slash commands', feature: true do
end
end
describe
'mattermost service is enabled'
do
describe
'mattermost service is enabled'
do
before
do
allow
(
Gitlab
.
config
.
mattermost
).
to
receive
(
:enabled
).
and_return
(
true
)
end
it
'shows the add to mattermost button'
do
it
'shows the add to mattermost button'
do
expect
(
page
).
to
have_link
'Add to Mattermost'
expect
(
page
).
to
have_link
'Add to Mattermost'
end
end
end
end
describe
'mattermost service is not enabled'
do
describe
'mattermost service is not enabled'
do
before
do
let
(
:mattermost_enabled
)
{
false
}
allow
(
Gitlab
.
config
.
mattermost
).
to
receive
(
:enabled
).
and_return
(
false
)
end
it
'shows the correct trigger url'
do
it
'shows the correct trigger url'
do
value
=
find_field
(
'request_url'
).
value
value
=
find_field
(
'request_url'
).
value
...
...
spec/lib/mattermost/command_spec.rb
View file @
4a03fae9
require
'spec_helper'
require
'spec_helper'
describe
Mattermost
::
Command
do
describe
Mattermost
::
Command
do
let
(
:
hash
)
{
{
'token'
=>
'token
'
}
}
let
(
:
params
)
{
{
'token'
=>
'token'
,
team_id:
'abc
'
}
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
build
(
:user
)
}
before
do
before
do
Mattermost
::
Session
.
base_uri
(
"http://mattermost.example.com"
)
Mattermost
::
Session
.
base_uri
(
"http://mattermost.example.com"
)
end
end
subject
{
described_class
.
new
(
user
)
}
describe
'#create'
do
describe
'#create'
do
it
'creates a command'
do
it
'interpolates the team id'
do
described_class
.
new
(
user
).
allow
(
subject
).
to
receive
(
:json_post
).
create
(
team_id:
'abc'
,
url:
'http://trigger.com'
)
with
(
'/api/v3/teams/abc/commands/create'
,
body:
params
.
to_json
).
and_return
(
'token'
=>
'token'
)
subject
.
create
(
params
)
end
end
end
end
end
end
spec/lib/mattermost/team_spec.rb
View file @
4a03fae9
...
@@ -2,7 +2,9 @@ require 'spec_helper'
...
@@ -2,7 +2,9 @@ require 'spec_helper'
describe
Mattermost
::
Team
do
describe
Mattermost
::
Team
do
describe
'#all'
do
describe
'#all'
do
let
(
:session
)
{
double
(
"session"
)
}
let
(
:user
)
{
build
(
:user
)
}
subject
{
described_class
.
new
(
user
)
}
let
(
:response
)
do
let
(
:response
)
do
[{
[{
...
@@ -20,22 +22,13 @@ describe Mattermost::Team do
...
@@ -20,22 +22,13 @@ describe Mattermost::Team do
"allow_open_invite"
=>
false
}]
"allow_open_invite"
=>
false
}]
end
end
let
(
:json
)
{
nil
}
before
do
before
do
allow
(
session
).
to
receive
(
:get
).
with
(
'/api/v3/teams/all'
).
allow
(
subject
).
to
receive
(
:json_get
).
and_return
(
response
)
and_return
(
json
)
allow
(
json
).
to
receive
(
:parsed_response
).
and_return
(
response
)
end
end
it
'gets the teams'
do
it
'gets the teams'
do
expect
(
described_class
.
all
(
session
).
count
).
to
be
(
1
)
expect
(
subject
.
all
.
count
).
to
be
(
1
)
end
it
'filters on being team admin'
do
ids
=
described_class
.
all
(
session
).
map
{
|
team
|
team
[
'id'
]
}
expect
(
ids
).
to
include
(
"xiyro8huptfhdndadpz8r3wnbo"
)
end
end
end
end
end
end
spec/models/project_services/mattermost_slash_commands_service_spec.rb
View file @
4a03fae9
...
@@ -3,23 +3,23 @@ require 'spec_helper'
...
@@ -3,23 +3,23 @@ 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
describe
'#configure'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:service
)
{
project
.
build_mattermost_slash_commands_service
}
let
(
:service
)
{
project
.
build_mattermost_slash_commands_service
}
let
(
:user
)
{
create
(
:user
)}
let
(
:user
)
{
create
(
:user
)}
before
do
allow_any_instance_of
(
Mattermost
::
Session
).
to
receive
(
:with_session
).
and_yield
end
subject
do
subject
do
service
.
configure
!
(
user
,
team_id:
'abc'
,
service
.
configure
(
user
,
team_id:
'abc'
,
trigger:
'gitlab'
,
url:
'http://trigger.url'
,
trigger:
'gitlab'
,
url:
'http://trigger.url'
,
icon_url:
'http://icon.url/icon.png'
)
icon_url:
'http://icon.url/icon.png'
)
end
end
context
'the requests succeeds'
do
context
'the requests succeeds'
do
before
do
allow_any_instance_of
(
Mattermost
::
Command
).
to
receive
(
:json_post
).
and_return
(
'token'
=>
'token'
)
end
it
'saves the service'
do
it
'saves the service'
do
expect
{
subject
}.
to
change
{
project
.
services
.
count
}.
by
(
1
)
expect
{
subject
}.
to
change
{
project
.
services
.
count
}.
by
(
1
)
end
end
...
@@ -27,13 +27,16 @@ describe MattermostSlashCommandsService, :models do
...
@@ -27,13 +27,16 @@ describe MattermostSlashCommandsService, :models do
it
'saves the token'
do
it
'saves the token'
do
subject
subject
expect
(
service
.
reload
.
token
).
to
eq
(
'
mynew
token'
)
expect
(
service
.
reload
.
token
).
to
eq
(
'token'
)
end
end
end
end
context
'an error is received'
do
context
'an error is received'
do
it
'shows error messages'
do
it
'shows error messages'
do
expect
(
subject
).
to
raise_error
(
"Error"
)
succeeded
,
message
=
subject
expect
(
succeeded
).
to
be
(
false
)
expect
(
message
).
to
start_with
(
"Failed to open TCP connection to"
)
end
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