Commit 67d5b95d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge pull request #7383 from Razer6/fix_test_hooks_empty_project

Do not execute hooks on empty projects, fixes #6108
......@@ -24,7 +24,12 @@ def create
def test, current_user)
if !@project.empty_repo?, current_user)
flash[:notice] = 'Hook successfully executed.'
flash[:alert] = 'Hook execution failed. Ensure the project has commits.'
redirect_to :back
......@@ -19,3 +19,8 @@ Feature: Project Hooks
When I click test hook button
Then hook should be triggered
Scenario: I test a hook on empty project
Given I own empty project with hook
And I visit project hooks page
When I click test hook button
Then I should see hook error message
......@@ -8,31 +8,45 @@ class ProjectHooks < Spinach::FeatureSteps
include RSpec::Mocks::ExampleMethods
include WebMock::API
Given 'project has hook' do
step 'project has hook' do
@hook = create(:project_hook, project: current_project)
Then 'I should see project hook' do
step 'I own empty project with hook' do
@project = create(:empty_project,
name: 'Empty Project', namespace: @user.namespace)
@hook = create(:project_hook, project: current_project)
step 'I should see project hook' do
page.should have_content @hook.url
When 'I submit new hook' do
step 'I submit new hook' do
@url = Faker::Internet.uri("http")
fill_in "hook_url", with: @url
expect { click_button "Add Web Hook" }.to change(ProjectHook, :count).by(1)
Then 'I should see newly created hook' do
step 'I should see newly created hook' do
page.current_path.should == project_hooks_path(current_project)
page.should have_content(@url)
When 'I click test hook button' do
step 'I click test hook button' do
stub_request(:post, @hook.url).to_return(status: 200)
click_link 'Test Hook'
Then 'hook should be triggered' do
step 'hook should be triggered' do
page.current_path.should == project_hooks_path(current_project)
page.should have_selector '.flash-notice',
text: 'Hook successfully executed.'
step 'I should see hook error message' do
page.should have_selector '.flash-alert',
text: 'Hook execution failed. '\
'Ensure the project has commits.'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment