Commit 86bd11cb authored by Valeriy Sizov's avatar Valeriy Sizov

System Hooks: rspec

parent 655418be
......@@ -28,9 +28,15 @@ class Admin::HooksController < ApplicationController
def test
@hook = @project.hooks.find(params[:id])
commits = @project.commits(@project.default_branch, nil, 3)
data = @project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{@project.default_branch}", current_user)
@hook = SystemHook.find(params[:hook_id])
data = {
event_name: "project_create",
name: "Ruby",
path: "ruby",
project_id: 1,
owner_name: "Someone",
owner_email: "example@gitlabhq.com"
}
@hook.execute(data)
redirect_to :back
......
......@@ -7,6 +7,12 @@ Factory.add(:project, Project) do |obj|
obj.code = 'LGT'
end
Factory.add(:project_without_owner, Project) do |obj|
obj.name = Faker::Internet.user_name
obj.path = 'gitlabhq'
obj.code = 'LGT'
end
Factory.add(:public_project, Project) do |obj|
obj.name = Faker::Internet.user_name
obj.path = 'gitlabhq'
......@@ -64,6 +70,10 @@ Factory.add(:project_hook, ProjectHook) do |obj|
obj.url = Faker::Internet.uri("http")
end
Factory.add(:system_hook, SystemHook) do |obj|
obj.url = Faker::Internet.uri("http")
end
Factory.add(:wiki, Wiki) do |obj|
obj.title = Faker::Lorem.sentence
obj.content = Faker::Lorem.sentence
......
require "spec_helper"
describe SystemHook do
describe "execute" do
before(:each) do
@system_hook = Factory :system_hook
WebMock.stub_request(:post, @system_hook.url)
end
it "project_create hook" do
user = Factory :user
with_resque do
project = Factory :project_without_owner, :owner => user
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_create/).once
end
it "project_destroy hook" do
project = Factory :project
with_resque do
project.destroy
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /project_destroy/).once
end
it "user_create hook" do
with_resque do
Factory :user
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_create/).once
end
it "user_destroy hook" do
user = Factory :user
with_resque do
user.destroy
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_destroy/).once
end
it "project_create hook" do
user = Factory :user
project = Factory :project
with_resque do
project.users << user
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end
it "project_destroy hook" do
user = Factory :user
project = Factory :project
project.users << user
with_resque do
project.users_projects.clear
end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_remove_from_team/).once
end
end
end
require 'spec_helper'
describe "Admin::Hooks" do
before do
@project = Factory :project,
:name => "LeGiT",
:code => "LGT"
login_as :admin
@system_hook = Factory :system_hook
end
describe "GET /admin/hooks" do
it "should be ok" do
visit admin_root_path
within ".main_menu" do
click_on "Hooks"
end
current_path.should == admin_hooks_path
end
it "should have hooks list" do
visit admin_hooks_path
page.should have_content(@system_hook.url)
end
end
describe "New Hook" do
before do
@url = Faker::Internet.uri("http")
visit admin_hooks_path
fill_in "hook_url", :with => @url
expect { click_button "Add System Hook" }.to change(SystemHook, :count).by(1)
end
it "should open new hook popup" do
page.current_path.should == admin_hooks_path
page.should have_content(@url)
end
end
describe "Test" do
before do
WebMock.stub_request(:post, @system_hook.url)
visit admin_hooks_path
click_link "Test Hook"
end
it { page.current_path.should == admin_hooks_path }
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