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
Jérome Perrin
gitlab-ce
Commits
655418be
Commit
655418be
authored
Jul 15, 2012
by
Valeriy Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System hooks: fix broken tests
parent
f5908cef
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
39 additions
and
38 deletions
+39
-38
app/roles/git_push.rb
app/roles/git_push.rb
+3
-3
spec/factories.rb
spec/factories.rb
+1
-1
spec/models/project_hooks_spec.rb
spec/models/project_hooks_spec.rb
+14
-14
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-1
spec/models/web_hook_spec.rb
spec/models/web_hook_spec.rb
+10
-10
spec/requests/admin/security_spec.rb
spec/requests/admin/security_spec.rb
+4
-4
spec/requests/hooks_spec.rb
spec/requests/hooks_spec.rb
+4
-3
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+2
-2
No files found.
app/roles/git_push.rb
View file @
655418be
...
@@ -27,7 +27,7 @@ module GitPush
...
@@ -27,7 +27,7 @@ module GitPush
true
true
end
end
def
execute_
web_
hooks
(
oldrev
,
newrev
,
ref
,
user
)
def
execute_hooks
(
oldrev
,
newrev
,
ref
,
user
)
ref_parts
=
ref
.
split
(
'/'
)
ref_parts
=
ref
.
split
(
'/'
)
# Return if this is not a push to a branch (e.g. new commits)
# Return if this is not a push to a branch (e.g. new commits)
...
@@ -35,7 +35,7 @@ module GitPush
...
@@ -35,7 +35,7 @@ module GitPush
data
=
post_receive_data
(
oldrev
,
newrev
,
ref
,
user
)
data
=
post_receive_data
(
oldrev
,
newrev
,
ref
,
user
)
hooks
.
each
{
|
web_hook
|
web_
hook
.
execute
(
data
)
}
hooks
.
each
{
|
hook
|
hook
.
execute
(
data
)
}
end
end
def
post_receive_data
(
oldrev
,
newrev
,
ref
,
user
)
def
post_receive_data
(
oldrev
,
newrev
,
ref
,
user
)
...
@@ -97,7 +97,7 @@ module GitPush
...
@@ -97,7 +97,7 @@ module GitPush
self
.
update_merge_requests
(
oldrev
,
newrev
,
ref
,
user
)
self
.
update_merge_requests
(
oldrev
,
newrev
,
ref
,
user
)
# Execute web hooks
# Execute web hooks
self
.
execute_
web_
hooks
(
oldrev
,
newrev
,
ref
,
user
)
self
.
execute_hooks
(
oldrev
,
newrev
,
ref
,
user
)
# Create satellite
# Create satellite
self
.
satellite
.
create
unless
self
.
satellite
.
exists?
self
.
satellite
.
create
unless
self
.
satellite
.
exists?
...
...
spec/factories.rb
View file @
655418be
...
@@ -60,7 +60,7 @@ Factory.add(:key, Key) do |obj|
...
@@ -60,7 +60,7 @@ Factory.add(:key, Key) do |obj|
obj
.
key
=
File
.
read
(
File
.
join
(
Rails
.
root
,
"db"
,
"pkey.example"
))
obj
.
key
=
File
.
read
(
File
.
join
(
Rails
.
root
,
"db"
,
"pkey.example"
))
end
end
Factory
.
add
(
:
web_hook
,
Web
Hook
)
do
|
obj
|
Factory
.
add
(
:
project_hook
,
Project
Hook
)
do
|
obj
|
obj
.
url
=
Faker
::
Internet
.
uri
(
"http"
)
obj
.
url
=
Faker
::
Internet
.
uri
(
"http"
)
end
end
...
...
spec/models/project_hooks_spec.rb
View file @
655418be
...
@@ -21,44 +21,44 @@ describe Project, "Hooks" do
...
@@ -21,44 +21,44 @@ describe Project, "Hooks" do
end
end
end
end
describe
"
Web
hooks"
do
describe
"
Project
hooks"
do
context
"with no web hooks"
do
context
"with no web hooks"
do
it
"raises no errors"
do
it
"raises no errors"
do
lambda
{
lambda
{
project
.
execute_
web_
hooks
(
'oldrev'
,
'newrev'
,
'ref'
,
@user
)
project
.
execute_hooks
(
'oldrev'
,
'newrev'
,
'ref'
,
@user
)
}.
should_not
raise_error
}.
should_not
raise_error
end
end
end
end
context
"with web hooks"
do
context
"with web hooks"
do
before
do
before
do
@
webhook
=
Factory
(
:web
_hook
)
@
project_hook
=
Factory
(
:project
_hook
)
@
webhook_2
=
Factory
(
:web
_hook
)
@
project_hook_2
=
Factory
(
:project
_hook
)
project
.
web_hooks
<<
[
@webhook
,
@web
hook_2
]
project
.
hooks
<<
[
@project_hook
,
@project_
hook_2
]
end
end
it
"executes multiple web hook"
do
it
"executes multiple web hook"
do
@
web
hook
.
should_receive
(
:execute
).
once
@
project_
hook
.
should_receive
(
:execute
).
once
@
web
hook_2
.
should_receive
(
:execute
).
once
@
project_
hook_2
.
should_receive
(
:execute
).
once
project
.
execute_
web_
hooks
(
'oldrev'
,
'newrev'
,
'refs/heads/master'
,
@user
)
project
.
execute_hooks
(
'oldrev'
,
'newrev'
,
'refs/heads/master'
,
@user
)
end
end
end
end
context
"does not execute web hooks"
do
context
"does not execute web hooks"
do
before
do
before
do
@
webhook
=
Factory
(
:web
_hook
)
@
project_hook
=
Factory
(
:project
_hook
)
project
.
web_hooks
<<
[
@web
hook
]
project
.
hooks
<<
[
@project_
hook
]
end
end
it
"when pushing a branch for the first time"
do
it
"when pushing a branch for the first time"
do
@
web
hook
.
should_not_receive
(
:execute
)
@
project_
hook
.
should_not_receive
(
:execute
)
project
.
execute_
web_
hooks
(
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
,
@user
)
project
.
execute_hooks
(
'00000000000000000000000000000000'
,
'newrev'
,
'refs/heads/master'
,
@user
)
end
end
it
"when pushing tags"
do
it
"when pushing tags"
do
@
web
hook
.
should_not_receive
(
:execute
)
@
project_
hook
.
should_not_receive
(
:execute
)
project
.
execute_
web_
hooks
(
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
,
@user
)
project
.
execute_hooks
(
'oldrev'
,
'newrev'
,
'refs/tags/v1.0.0'
,
@user
)
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
655418be
...
@@ -11,7 +11,7 @@ describe Project do
...
@@ -11,7 +11,7 @@ describe Project do
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:issues
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:notes
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:snippets
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:
web_
hooks
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:hooks
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
it
{
should
have_many
(
:deploy_keys
).
dependent
(
:destroy
)
}
end
end
...
...
spec/models/web_hook_spec.rb
View file @
655418be
require
'spec_helper'
require
'spec_helper'
describe
Web
Hook
do
describe
Project
Hook
do
describe
"Associations"
do
describe
"Associations"
do
it
{
should
belong_to
:project
}
it
{
should
belong_to
:project
}
end
end
...
@@ -23,32 +23,32 @@ describe WebHook do
...
@@ -23,32 +23,32 @@ describe WebHook do
describe
"execute"
do
describe
"execute"
do
before
(
:each
)
do
before
(
:each
)
do
@
webhook
=
Factory
:web
_hook
@
project_hook
=
Factory
:project
_hook
@project
=
Factory
:project
@project
=
Factory
:project
@project
.
web_hooks
<<
[
@web
hook
]
@project
.
hooks
<<
[
@project_
hook
]
@data
=
{
before:
'oldrev'
,
after:
'newrev'
,
ref:
'ref'
}
@data
=
{
before:
'oldrev'
,
after:
'newrev'
,
ref:
'ref'
}
WebMock
.
stub_request
(
:post
,
@
web
hook
.
url
)
WebMock
.
stub_request
(
:post
,
@
project_
hook
.
url
)
end
end
it
"POSTs to the web hook URL"
do
it
"POSTs to the web hook URL"
do
@
web
hook
.
execute
(
@data
)
@
project_
hook
.
execute
(
@data
)
WebMock
.
should
have_requested
(
:post
,
@
web
hook
.
url
).
once
WebMock
.
should
have_requested
(
:post
,
@
project_
hook
.
url
).
once
end
end
it
"POSTs the data as JSON"
do
it
"POSTs the data as JSON"
do
json
=
@data
.
to_json
json
=
@data
.
to_json
@
web
hook
.
execute
(
@data
)
@
project_
hook
.
execute
(
@data
)
WebMock
.
should
have_requested
(
:post
,
@
web
hook
.
url
).
with
(
body:
json
).
once
WebMock
.
should
have_requested
(
:post
,
@
project_
hook
.
url
).
with
(
body:
json
).
once
end
end
it
"catches exceptions"
do
it
"catches exceptions"
do
WebHook
.
should_receive
(
:post
).
and_raise
(
"Some HTTP Post error"
)
WebHook
.
should_receive
(
:post
).
and_raise
(
"Some HTTP Post error"
)
lambda
{
lambda
{
@
web
hook
.
execute
(
@data
)
@
project_
hook
.
execute
(
@data
)
}.
should
_not
raise_error
}.
should
raise_error
end
end
end
end
end
end
...
...
spec/requests/admin/security_spec.rb
View file @
655418be
...
@@ -13,9 +13,9 @@ describe "Admin::Projects" do
...
@@ -13,9 +13,9 @@ describe "Admin::Projects" do
it
{
admin_users_path
.
should
be_denied_for
:visitor
}
it
{
admin_users_path
.
should
be_denied_for
:visitor
}
end
end
describe
"GET /admin/
email
s"
do
describe
"GET /admin/
hook
s"
do
it
{
admin_
email
s_path
.
should
be_allowed_for
:admin
}
it
{
admin_
hook
s_path
.
should
be_allowed_for
:admin
}
it
{
admin_
email
s_path
.
should
be_denied_for
:user
}
it
{
admin_
hook
s_path
.
should
be_denied_for
:user
}
it
{
admin_
email
s_path
.
should
be_denied_for
:visitor
}
it
{
admin_
hook
s_path
.
should
be_denied_for
:visitor
}
end
end
end
end
spec/requests/hooks_spec.rb
View file @
655418be
...
@@ -9,7 +9,7 @@ describe "Hooks" do
...
@@ -9,7 +9,7 @@ describe "Hooks" do
describe
"GET index"
do
describe
"GET index"
do
it
"should be available"
do
it
"should be available"
do
@hook
=
Factory
:
web
_hook
,
:project
=>
@project
@hook
=
Factory
:
project
_hook
,
:project
=>
@project
visit
project_hooks_path
(
@project
)
visit
project_hooks_path
(
@project
)
page
.
should
have_content
"Hooks"
page
.
should
have_content
"Hooks"
page
.
should
have_content
@hook
.
url
page
.
should
have_content
@hook
.
url
...
@@ -21,7 +21,7 @@ describe "Hooks" do
...
@@ -21,7 +21,7 @@ describe "Hooks" do
@url
=
Faker
::
Internet
.
uri
(
"http"
)
@url
=
Faker
::
Internet
.
uri
(
"http"
)
visit
project_hooks_path
(
@project
)
visit
project_hooks_path
(
@project
)
fill_in
"hook_url"
,
:with
=>
@url
fill_in
"hook_url"
,
:with
=>
@url
expect
{
click_button
"Add Web Hook"
}.
to
change
(
Web
Hook
,
:count
).
by
(
1
)
expect
{
click_button
"Add Web Hook"
}.
to
change
(
Project
Hook
,
:count
).
by
(
1
)
end
end
it
"should open new team member popup"
do
it
"should open new team member popup"
do
...
@@ -32,7 +32,8 @@ describe "Hooks" do
...
@@ -32,7 +32,8 @@ describe "Hooks" do
describe
"Test"
do
describe
"Test"
do
before
do
before
do
@hook
=
Factory
:web_hook
,
:project
=>
@project
@hook
=
Factory
:project_hook
,
:project
=>
@project
stub_request
(
:post
,
@hook
.
url
)
visit
project_hooks_path
(
@project
)
visit
project_hooks_path
(
@project
)
click_link
"Test Hook"
click_link
"Test Hook"
end
end
...
...
spec/workers/post_receive_spec.rb
View file @
655418be
...
@@ -22,14 +22,14 @@ describe PostReceive do
...
@@ -22,14 +22,14 @@ describe PostReceive do
Key
.
stub
(
find_by_identifier:
nil
)
Key
.
stub
(
find_by_identifier:
nil
)
project
.
should_not_receive
(
:observe_push
)
project
.
should_not_receive
(
:observe_push
)
project
.
should_not_receive
(
:execute_
web_
hooks
)
project
.
should_not_receive
(
:execute_hooks
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
key_id
).
should
be_false
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
key_id
).
should
be_false
end
end
it
"asks the project to execute web hooks"
do
it
"asks the project to execute web hooks"
do
Project
.
stub
(
find_by_path:
project
)
Project
.
stub
(
find_by_path:
project
)
project
.
should_receive
(
:execute_
web_
hooks
).
with
(
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
project
.
owner
)
project
.
should_receive
(
:execute_hooks
).
with
(
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
project
.
owner
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
key_id
)
PostReceive
.
perform
(
project
.
path
,
'sha-old'
,
'sha-new'
,
'refs/heads/master'
,
key_id
)
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