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
Tatuya Kamada
gitlab-ce
Commits
86bd11cb
Commit
86bd11cb
authored
Jul 19, 2012
by
Valeriy Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System Hooks: rspec
parent
655418be
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
133 additions
and
3 deletions
+133
-3
app/controllers/admin/hooks_controller.rb
app/controllers/admin/hooks_controller.rb
+9
-3
spec/factories.rb
spec/factories.rb
+10
-0
spec/models/system_hook_spec.rb
spec/models/system_hook_spec.rb
+61
-0
spec/requests/admin/admin_hooks_spec.rb
spec/requests/admin/admin_hooks_spec.rb
+53
-0
No files found.
app/controllers/admin/hooks_controller.rb
View file @
86bd11cb
...
...
@@ -28,9 +28,15 @@ class Admin::HooksController < ApplicationController
def
test
@hook
=
@project
.
hooks
.
find
(
params
[
:id
])
commits
=
@project
.
commits
(
@project
.
default_branch
,
nil
,
3
)
data
=
@project
.
post_receive_data
(
commits
.
last
.
id
,
commits
.
first
.
id
,
"refs/heads/
#{
@project
.
default_branch
}
"
,
current_user
)
@hook
=
SystemHook
.
find
(
params
[
:hook_id
])
data
=
{
event_name:
"project_create"
,
name:
"Ruby"
,
path:
"ruby"
,
project_id:
1
,
owner_name:
"Someone"
,
owner_email:
"example@gitlabhq.com"
}
@hook
.
execute
(
data
)
redirect_to
:back
...
...
spec/factories.rb
View file @
86bd11cb
...
...
@@ -7,6 +7,12 @@ Factory.add(:project, Project) do |obj|
obj
.
code
=
'LGT'
end
Factory
.
add
(
:project_without_owner
,
Project
)
do
|
obj
|
obj
.
name
=
Faker
::
Internet
.
user_name
obj
.
path
=
'gitlabhq'
obj
.
code
=
'LGT'
end
Factory
.
add
(
:public_project
,
Project
)
do
|
obj
|
obj
.
name
=
Faker
::
Internet
.
user_name
obj
.
path
=
'gitlabhq'
...
...
@@ -64,6 +70,10 @@ Factory.add(:project_hook, ProjectHook) do |obj|
obj
.
url
=
Faker
::
Internet
.
uri
(
"http"
)
end
Factory
.
add
(
:system_hook
,
SystemHook
)
do
|
obj
|
obj
.
url
=
Faker
::
Internet
.
uri
(
"http"
)
end
Factory
.
add
(
:wiki
,
Wiki
)
do
|
obj
|
obj
.
title
=
Faker
::
Lorem
.
sentence
obj
.
content
=
Faker
::
Lorem
.
sentence
...
...
spec/models/system_hook_spec.rb
0 → 100644
View file @
86bd11cb
require
"spec_helper"
describe
SystemHook
do
describe
"execute"
do
before
(
:each
)
do
@system_hook
=
Factory
:system_hook
WebMock
.
stub_request
(
:post
,
@system_hook
.
url
)
end
it
"project_create hook"
do
user
=
Factory
:user
with_resque
do
project
=
Factory
:project_without_owner
,
:owner
=>
user
end
WebMock
.
should
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/project_create/
).
once
end
it
"project_destroy hook"
do
project
=
Factory
:project
with_resque
do
project
.
destroy
end
WebMock
.
should
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/project_destroy/
).
once
end
it
"user_create hook"
do
with_resque
do
Factory
:user
end
WebMock
.
should
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/user_create/
).
once
end
it
"user_destroy hook"
do
user
=
Factory
:user
with_resque
do
user
.
destroy
end
WebMock
.
should
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/user_destroy/
).
once
end
it
"project_create hook"
do
user
=
Factory
:user
project
=
Factory
:project
with_resque
do
project
.
users
<<
user
end
WebMock
.
should
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/user_add_to_team/
).
once
end
it
"project_destroy hook"
do
user
=
Factory
:user
project
=
Factory
:project
project
.
users
<<
user
with_resque
do
project
.
users_projects
.
clear
end
WebMock
.
should
have_requested
(
:post
,
@system_hook
.
url
).
with
(
body:
/user_remove_from_team/
).
once
end
end
end
spec/requests/admin/admin_hooks_spec.rb
0 → 100644
View file @
86bd11cb
require
'spec_helper'
describe
"Admin::Hooks"
do
before
do
@project
=
Factory
:project
,
:name
=>
"LeGiT"
,
:code
=>
"LGT"
login_as
:admin
@system_hook
=
Factory
:system_hook
end
describe
"GET /admin/hooks"
do
it
"should be ok"
do
visit
admin_root_path
within
".main_menu"
do
click_on
"Hooks"
end
current_path
.
should
==
admin_hooks_path
end
it
"should have hooks list"
do
visit
admin_hooks_path
page
.
should
have_content
(
@system_hook
.
url
)
end
end
describe
"New Hook"
do
before
do
@url
=
Faker
::
Internet
.
uri
(
"http"
)
visit
admin_hooks_path
fill_in
"hook_url"
,
:with
=>
@url
expect
{
click_button
"Add System Hook"
}.
to
change
(
SystemHook
,
:count
).
by
(
1
)
end
it
"should open new hook popup"
do
page
.
current_path
.
should
==
admin_hooks_path
page
.
should
have_content
(
@url
)
end
end
describe
"Test"
do
before
do
WebMock
.
stub_request
(
:post
,
@system_hook
.
url
)
visit
admin_hooks_path
click_link
"Test Hook"
end
it
{
page
.
current_path
.
should
==
admin_hooks_path
}
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