Commit 8bfc62fb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Convert TestHookContext into TestHookService. Added tests

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 37ef33cb
No related merge requests found
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
end
def test
TestHookContext.new(project, current_user, params).execute
TestHookService.new.execute(hook, current_user)
redirect_to :back
end
def destroy
@hook = @project.hooks.find(params[:id])
@hook.destroy
hook.destroy
redirect_to project_hooks_path(@project)
end
private
def hook
@hook ||= @project.hooks.find(params[:id])
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