diff --git a/app/controllers/projects/hooks_controller.rb b/app/controllers/projects/hooks_controller.rb index c8269ed99cecd856d9beb59630bd8b20568676e8..cab8fd76e6c4f8b56096bcafba03c7f3ad6de633 100644 --- a/app/controllers/projects/hooks_controller.rb +++ b/app/controllers/projects/hooks_controller.rb @@ -25,8 +25,13 @@ class Projects::HooksController < Projects::ApplicationController def test if !@project.empty_repo? - TestHookService.new.execute(hook, current_user) - flash[:notice] = 'Hook successfully executed.' + status = TestHookService.new.execute(hook, current_user) + if status + flash[:notice] = 'Hook successfully executed.' + else + flash[:alert] = 'Hook execution failed. '\ + 'Ensure hook URL is correct and service is up.' + end else flash[:alert] = 'Hook execution failed. Ensure the project has commits.' end diff --git a/app/services/test_hook_service.rb b/app/services/test_hook_service.rb index 17d86a7a274d2b4d44212e5e8c73b1f4a29d05c1..b6b1ef29b51840cc4038c9681d07be6381652d71 100644 --- a/app/services/test_hook_service.rb +++ b/app/services/test_hook_service.rb @@ -2,5 +2,8 @@ class TestHookService def execute(hook, current_user) data = GitPushService.new.sample_data(hook.project, current_user) hook.execute(data) + true + rescue SocketError + false end end diff --git a/features/project/hooks.feature b/features/project/hooks.feature index 52e02a890ddf1e1e6276a44e8abf82116f659052..1a60846a23e6eb79e020324699fbb6c9c76709d1 100644 --- a/features/project/hooks.feature +++ b/features/project/hooks.feature @@ -24,3 +24,9 @@ Feature: Project Hooks And I visit project hooks page When I click test hook button Then I should see hook error message + + Scenario: I test a hook on down URL + Given project has hook + And I visit project hooks page + When I click test hook button with invalid URL + Then I should see hook service down error message diff --git a/features/steps/project/hooks.rb b/features/steps/project/hooks.rb index 30da589260d3ca1d47816c18531fdb4803dac8d0..2bd383676e738bc17da6c9de4e42f67ecbf53e77 100644 --- a/features/steps/project/hooks.rb +++ b/features/steps/project/hooks.rb @@ -38,6 +38,11 @@ class ProjectHooks < Spinach::FeatureSteps click_link 'Test Hook' end + step 'I click test hook button with invalid URL' do + stub_request(:post, @hook.url).to_raise(SocketError) + click_link 'Test Hook' + end + step 'hook should be triggered' do page.current_path.should == project_hooks_path(current_project) page.should have_selector '.flash-notice', @@ -49,4 +54,11 @@ class ProjectHooks < Spinach::FeatureSteps text: 'Hook execution failed. '\ 'Ensure the project has commits.' end + + step 'I should see hook service down error message' do + page.should have_selector '.flash-alert', + text: 'Hook execution failed. '\ + 'Ensure hook URL is correct and '\ + 'service is up.' + end end