Merge branch 'master' into api
This commit is contained in:
commit
eca823c1c7
124 changed files with 1743 additions and 657 deletions
|
@ -78,7 +78,7 @@ describe Gitlab::API do
|
|||
end
|
||||
|
||||
describe "DELETE /projects/:id/snippets/:snippet_id" do
|
||||
it "should create a new project snippet" do
|
||||
it "should delete existing project snippet" do
|
||||
expect {
|
||||
delete "#{api_prefix}/projects/#{project.code}/snippets/#{snippet.id}?private_token=#{user.private_token}"
|
||||
}.should change { Snippet.count }.by(-1)
|
||||
|
|
|
@ -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'
|
||||
|
@ -60,7 +66,11 @@ Factory.add(:key, Key) do |obj|
|
|||
obj.key = File.read(File.join(Rails.root, "db", "pkey.example"))
|
||||
end
|
||||
|
||||
Factory.add(:web_hook, WebHook) do |obj|
|
||||
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
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ describe MergeRequest do
|
|||
it { should validate_presence_of(:title) }
|
||||
it { should validate_presence_of(:author_id) }
|
||||
it { should validate_presence_of(:project_id) }
|
||||
it { should validate_presence_of(:assignee_id) }
|
||||
end
|
||||
|
||||
describe "Scope" do
|
||||
|
|
|
@ -21,44 +21,44 @@ describe Project, "Hooks" do
|
|||
end
|
||||
end
|
||||
|
||||
describe "Web hooks" do
|
||||
describe "Project hooks" do
|
||||
context "with no web hooks" do
|
||||
it "raises no errors" do
|
||||
lambda {
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'ref', @user)
|
||||
project.execute_hooks('oldrev', 'newrev', 'ref', @user)
|
||||
}.should_not raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "with web hooks" do
|
||||
before do
|
||||
@webhook = Factory(:web_hook)
|
||||
@webhook_2 = Factory(:web_hook)
|
||||
project.web_hooks << [@webhook, @webhook_2]
|
||||
@project_hook = Factory(:project_hook)
|
||||
@project_hook_2 = Factory(:project_hook)
|
||||
project.hooks << [@project_hook, @project_hook_2]
|
||||
end
|
||||
|
||||
it "executes multiple web hook" do
|
||||
@webhook.should_receive(:execute).once
|
||||
@webhook_2.should_receive(:execute).once
|
||||
@project_hook.should_receive(:execute).once
|
||||
@project_hook_2.should_receive(:execute).once
|
||||
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'refs/heads/master', @user)
|
||||
project.execute_hooks('oldrev', 'newrev', 'refs/heads/master', @user)
|
||||
end
|
||||
end
|
||||
|
||||
context "does not execute web hooks" do
|
||||
before do
|
||||
@webhook = Factory(:web_hook)
|
||||
project.web_hooks << [@webhook]
|
||||
@project_hook = Factory(:project_hook)
|
||||
project.hooks << [@project_hook]
|
||||
end
|
||||
|
||||
it "when pushing a branch for the first time" do
|
||||
@webhook.should_not_receive(:execute)
|
||||
project.execute_web_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master', @user)
|
||||
@project_hook.should_not_receive(:execute)
|
||||
project.execute_hooks('00000000000000000000000000000000', 'newrev', 'refs/heads/master', @user)
|
||||
end
|
||||
|
||||
it "when pushing tags" do
|
||||
@webhook.should_not_receive(:execute)
|
||||
project.execute_web_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0', @user)
|
||||
@project_hook.should_not_receive(:execute)
|
||||
project.execute_hooks('oldrev', 'newrev', 'refs/tags/v1.0.0', @user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ describe Project do
|
|||
it { should have_many(:issues).dependent(:destroy) }
|
||||
it { should have_many(:notes).dependent(:destroy) }
|
||||
it { should have_many(:snippets).dependent(:destroy) }
|
||||
it { should have_many(:web_hooks).dependent(:destroy) }
|
||||
it { should have_many(:hooks).dependent(:destroy) }
|
||||
it { should have_many(:deploy_keys).dependent(:destroy) }
|
||||
end
|
||||
|
||||
|
|
63
spec/models/system_hook_spec.rb
Normal file
63
spec/models/system_hook_spec.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
require "spec_helper"
|
||||
|
||||
describe SystemHook do
|
||||
describe "execute" do
|
||||
before(:each) { ActiveRecord::Base.observers.enable(:all) }
|
||||
|
||||
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
|
|
@ -1,6 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe WebHook do
|
||||
describe ProjectHook do
|
||||
describe "Associations" do
|
||||
it { should belong_to :project }
|
||||
end
|
||||
|
@ -23,32 +23,32 @@ describe WebHook do
|
|||
|
||||
describe "execute" do
|
||||
before(:each) do
|
||||
@webhook = Factory :web_hook
|
||||
@project_hook = Factory :project_hook
|
||||
@project = Factory :project
|
||||
@project.web_hooks << [@webhook]
|
||||
@project.hooks << [@project_hook]
|
||||
@data = { before: 'oldrev', after: 'newrev', ref: 'ref'}
|
||||
|
||||
WebMock.stub_request(:post, @webhook.url)
|
||||
WebMock.stub_request(:post, @project_hook.url)
|
||||
end
|
||||
|
||||
it "POSTs to the web hook URL" do
|
||||
@webhook.execute(@data)
|
||||
WebMock.should have_requested(:post, @webhook.url).once
|
||||
@project_hook.execute(@data)
|
||||
WebMock.should have_requested(:post, @project_hook.url).once
|
||||
end
|
||||
|
||||
it "POSTs the data as JSON" do
|
||||
json = @data.to_json
|
||||
|
||||
@webhook.execute(@data)
|
||||
WebMock.should have_requested(:post, @webhook.url).with(body: json).once
|
||||
@project_hook.execute(@data)
|
||||
WebMock.should have_requested(:post, @project_hook.url).with(body: json).once
|
||||
end
|
||||
|
||||
it "catches exceptions" do
|
||||
WebHook.should_receive(:post).and_raise("Some HTTP Post error")
|
||||
|
||||
lambda {
|
||||
@webhook.execute(@data)
|
||||
}.should_not raise_error
|
||||
@project_hook.execute(@data)
|
||||
}.should raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
53
spec/requests/admin/admin_hooks_spec.rb
Normal file
53
spec/requests/admin/admin_hooks_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
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
|
|
@ -13,9 +13,9 @@ describe "Admin::Projects" do
|
|||
it { admin_users_path.should be_denied_for :visitor }
|
||||
end
|
||||
|
||||
describe "GET /admin/emails" do
|
||||
it { admin_emails_path.should be_allowed_for :admin }
|
||||
it { admin_emails_path.should be_denied_for :user }
|
||||
it { admin_emails_path.should be_denied_for :visitor }
|
||||
describe "GET /admin/hooks" do
|
||||
it { admin_hooks_path.should be_allowed_for :admin }
|
||||
it { admin_hooks_path.should be_denied_for :user }
|
||||
it { admin_hooks_path.should be_denied_for :visitor }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe "Hooks" do
|
|||
|
||||
describe "GET index" do
|
||||
it "should be available" do
|
||||
@hook = Factory :web_hook, :project => @project
|
||||
@hook = Factory :project_hook, :project => @project
|
||||
visit project_hooks_path(@project)
|
||||
page.should have_content "Hooks"
|
||||
page.should have_content @hook.url
|
||||
|
@ -21,7 +21,7 @@ describe "Hooks" do
|
|||
@url = Faker::Internet.uri("http")
|
||||
visit project_hooks_path(@project)
|
||||
fill_in "hook_url", :with => @url
|
||||
expect { click_button "Add Web Hook" }.to change(WebHook, :count).by(1)
|
||||
expect { click_button "Add Web Hook" }.to change(ProjectHook, :count).by(1)
|
||||
end
|
||||
|
||||
it "should open new team member popup" do
|
||||
|
@ -32,7 +32,8 @@ describe "Hooks" do
|
|||
|
||||
describe "Test" do
|
||||
before do
|
||||
@hook = Factory :web_hook, :project => @project
|
||||
@hook = Factory :project_hook, :project => @project
|
||||
stub_request(:post, @hook.url)
|
||||
visit project_hooks_path(@project)
|
||||
click_link "Test Hook"
|
||||
end
|
||||
|
|
|
@ -22,14 +22,14 @@ describe PostReceive do
|
|||
Key.stub(find_by_identifier: nil)
|
||||
|
||||
project.should_not_receive(:observe_push)
|
||||
project.should_not_receive(:execute_web_hooks)
|
||||
project.should_not_receive(:execute_hooks)
|
||||
|
||||
PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', key_id).should be_false
|
||||
end
|
||||
|
||||
it "asks the project to execute web hooks" do
|
||||
Project.stub(find_by_path: project)
|
||||
project.should_receive(:execute_web_hooks).with('sha-old', 'sha-new', 'refs/heads/master', project.owner)
|
||||
project.should_receive(:execute_hooks).with('sha-old', 'sha-new', 'refs/heads/master', project.owner)
|
||||
|
||||
PostReceive.perform(project.path, 'sha-old', 'sha-new', 'refs/heads/master', key_id)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue