Skip to content
Snippets Groups Projects
Verified Commit 8bfc62fb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Convert TestHookContext into TestHookService. Added tests

parent 37ef33cb
No related branches found
No related tags found
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
Loading
Loading
@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment