BigW Consortium Gitlab

Convert TestHookContext into TestHookService. Added tests

parent 37ef33cb
class TestHookContext < BaseContext
def execute
hook = project.hooks.find(params[:id])
data = GitPushService.new.sample_data(project, current_user)
hook.execute(data)
end
end
...@@ -24,15 +24,20 @@ class Projects::HooksController < Projects::ApplicationController ...@@ -24,15 +24,20 @@ class Projects::HooksController < Projects::ApplicationController
end end
def test def test
TestHookContext.new(project, current_user, params).execute TestHookService.new.execute(hook, current_user)
redirect_to :back redirect_to :back
end end
def destroy def destroy
@hook = @project.hooks.find(params[:id]) hook.destroy
@hook.destroy
redirect_to project_hooks_path(@project) redirect_to project_hooks_path(@project)
end end
private
def hook
@hook ||= @project.hooks.find(params[:id])
end
end end
class TestHookService
def execute(hook, current_user)
data = GitPushService.new.sample_data(hook.project, current_user)
hook.execute(data)
end
end
require 'spec_helper'
describe TestHookService do
let (:user) { create :user }
let (:project) { create :project_with_code }
let (:hook) { create :project_hook, project: project }
describe :execute do
it "should execute successfully" do
stub_request(:post, hook.url).to_return(status: 200)
TestHookService.new.execute(hook, user).should be_true
end
end
end
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