2012-02-28 15:48:15 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Project, "Hooks" do
|
2012-11-06 04:31:55 +01:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
before do
|
|
|
|
@key = create(:key, user: project.owner)
|
2012-04-04 06:39:04 +02:00
|
|
|
@user = @key.user
|
2012-02-29 22:04:09 +01:00
|
|
|
@key_id = @key.identifier
|
|
|
|
end
|
2012-02-28 15:48:15 +01:00
|
|
|
|
2012-11-06 04:31:55 +01:00
|
|
|
describe "Post Receive Event" do
|
|
|
|
it "should create push event" do
|
2012-02-28 15:48:15 +01:00
|
|
|
oldrev, newrev, ref = '00000000000000000000000000000000', 'newrev', 'refs/heads/master'
|
2012-11-19 19:44:05 +01:00
|
|
|
data = project.post_receive_data(oldrev, newrev, ref, @user)
|
|
|
|
|
|
|
|
project.observe_push(data)
|
2012-02-28 15:48:15 +01:00
|
|
|
event = Event.last
|
|
|
|
|
|
|
|
event.should_not be_nil
|
|
|
|
event.project.should == project
|
|
|
|
event.action.should == Event::Pushed
|
2012-11-19 19:44:05 +01:00
|
|
|
event.data.should == data
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-07-15 16:36:06 +02:00
|
|
|
describe "Project hooks" do
|
2012-02-28 15:48:15 +01:00
|
|
|
context "with no web hooks" do
|
|
|
|
it "raises no errors" do
|
|
|
|
lambda {
|
2012-11-19 19:44:05 +01:00
|
|
|
project.execute_hooks({})
|
2012-02-28 15:48:15 +01:00
|
|
|
}.should_not raise_error
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with web hooks" do
|
|
|
|
before do
|
2012-11-06 04:31:55 +01:00
|
|
|
@project_hook = create(:project_hook)
|
|
|
|
@project_hook_2 = create(:project_hook)
|
2012-07-15 16:36:06 +02:00
|
|
|
project.hooks << [@project_hook, @project_hook_2]
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "executes multiple web hook" do
|
2012-07-15 16:36:06 +02:00
|
|
|
@project_hook.should_receive(:execute).once
|
|
|
|
@project_hook_2.should_receive(:execute).once
|
2012-02-28 15:48:15 +01:00
|
|
|
|
2012-11-19 19:44:05 +01:00
|
|
|
project.trigger_post_receive('oldrev', 'newrev', 'refs/heads/master', @user)
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "does not execute web hooks" do
|
|
|
|
before do
|
2012-11-06 04:31:55 +01:00
|
|
|
@project_hook = create(:project_hook)
|
2012-07-15 16:36:06 +02:00
|
|
|
project.hooks << [@project_hook]
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "when pushing a branch for the first time" do
|
2012-07-15 16:36:06 +02:00
|
|
|
@project_hook.should_not_receive(:execute)
|
2012-11-19 19:44:05 +01:00
|
|
|
project.trigger_post_receive('00000000000000000000000000000000', 'newrev', 'refs/heads/master', @user)
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "when pushing tags" do
|
2012-07-15 16:36:06 +02:00
|
|
|
@project_hook.should_not_receive(:execute)
|
2012-11-19 19:44:05 +01:00
|
|
|
project.trigger_post_receive('oldrev', 'newrev', 'refs/tags/v1.0.0', @user)
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when pushing new branches" do
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when gathering commit data" do
|
|
|
|
before do
|
|
|
|
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master'
|
|
|
|
@commit = project.fresh_commits(2).first
|
|
|
|
|
|
|
|
# Fill nil/empty attributes
|
|
|
|
project.description = "This is a description"
|
|
|
|
|
2012-04-04 06:39:04 +02:00
|
|
|
@data = project.post_receive_data(@oldrev, @newrev, @ref, @user)
|
2012-02-28 15:48:15 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { @data }
|
|
|
|
|
|
|
|
it { should include(before: @oldrev) }
|
|
|
|
it { should include(after: @newrev) }
|
|
|
|
it { should include(ref: @ref) }
|
2012-02-29 22:04:09 +01:00
|
|
|
it { should include(user_id: project.owner.id) }
|
|
|
|
it { should include(user_name: project.owner.name) }
|
2012-02-28 15:48:15 +01:00
|
|
|
|
|
|
|
context "with repository data" do
|
|
|
|
subject { @data[:repository] }
|
|
|
|
|
|
|
|
it { should include(name: project.name) }
|
|
|
|
it { should include(url: project.web_url) }
|
|
|
|
it { should include(description: project.description) }
|
|
|
|
it { should include(homepage: project.web_url) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with commits" do
|
|
|
|
subject { @data[:commits] }
|
|
|
|
|
|
|
|
it { should be_an(Array) }
|
|
|
|
it { should have(1).element }
|
|
|
|
|
|
|
|
context "the commit" do
|
|
|
|
subject { @data[:commits].first }
|
|
|
|
|
|
|
|
it { should include(id: @commit.id) }
|
|
|
|
it { should include(message: @commit.safe_message) }
|
|
|
|
it { should include(timestamp: @commit.date.xmlschema) }
|
2012-07-02 20:51:48 +02:00
|
|
|
it { should include(url: "#{Gitlab.config.url}/#{project.code}/commits/#{@commit.id}") }
|
2012-02-28 15:48:15 +01:00
|
|
|
|
|
|
|
context "with a author" do
|
|
|
|
subject { @data[:commits].first[:author] }
|
|
|
|
|
|
|
|
it { should include(name: @commit.author_name) }
|
|
|
|
it { should include(email: @commit.author_email) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|