Commit 8bfc62fb8b02bde7da97958deb8aeda63581bfce
1 parent
37ef33cb
Exists in
spb-stable
and in
3 other branches
Convert TestHookContext into TestHookService. Added tests
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
4 changed files
with
28 additions
and
10 deletions
Show diff stats
app/contexts/test_hook_context.rb
app/controllers/projects/hooks_controller.rb
| ... | ... | @@ -24,15 +24,20 @@ class Projects::HooksController < Projects::ApplicationController |
| 24 | 24 | end |
| 25 | 25 | |
| 26 | 26 | def test |
| 27 | - TestHookContext.new(project, current_user, params).execute | |
| 27 | + TestHookService.new.execute(hook, current_user) | |
| 28 | 28 | |
| 29 | 29 | redirect_to :back |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | 32 | def destroy |
| 33 | - @hook = @project.hooks.find(params[:id]) | |
| 34 | - @hook.destroy | |
| 33 | + hook.destroy | |
| 35 | 34 | |
| 36 | 35 | redirect_to project_hooks_path(@project) |
| 37 | 36 | end |
| 37 | + | |
| 38 | + private | |
| 39 | + | |
| 40 | + def hook | |
| 41 | + @hook ||= @project.hooks.find(params[:id]) | |
| 42 | + end | |
| 38 | 43 | end | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +require 'spec_helper' | |
| 2 | + | |
| 3 | +describe TestHookService do | |
| 4 | + let (:user) { create :user } | |
| 5 | + let (:project) { create :project_with_code } | |
| 6 | + let (:hook) { create :project_hook, project: project } | |
| 7 | + | |
| 8 | + describe :execute do | |
| 9 | + it "should execute successfully" do | |
| 10 | + stub_request(:post, hook.url).to_return(status: 200) | |
| 11 | + TestHookService.new.execute(hook, user).should be_true | |
| 12 | + end | |
| 13 | + end | |
| 14 | +end | ... | ... |