summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValeriy Sizov <vsv2711@gmail.com>2012-07-15 17:36:06 +0300
committerValeriy Sizov <vsv2711@gmail.com>2012-07-19 00:25:10 +0300
commit655418bed2f81651c54988963713769f85d8b5da (patch)
treeb6cf82c648c1a5bcacdd7f763e1da1fc2b4d136a
parentf5908cef19a3cd2c44be02b453fecb568b2c6c8e (diff)
downloadgitlab-ce-655418bed2f81651c54988963713769f85d8b5da.tar.gz
System hooks: fix broken tests
-rw-r--r--app/roles/git_push.rb6
-rw-r--r--spec/factories.rb2
-rw-r--r--spec/models/project_hooks_spec.rb28
-rw-r--r--spec/models/project_spec.rb2
-rw-r--r--spec/models/web_hook_spec.rb20
-rw-r--r--spec/requests/admin/security_spec.rb8
-rw-r--r--spec/requests/hooks_spec.rb7
-rw-r--r--spec/workers/post_receive_spec.rb4
8 files changed, 39 insertions, 38 deletions
diff --git a/app/roles/git_push.rb b/app/roles/git_push.rb
index d0267b59b6d..4ee7e62a69e 100644
--- a/app/roles/git_push.rb
+++ b/app/roles/git_push.rb
@@ -27,7 +27,7 @@ module GitPush
true
end
- def execute_web_hooks(oldrev, newrev, ref, user)
+ def execute_hooks(oldrev, newrev, ref, user)
ref_parts = ref.split('/')
# Return if this is not a push to a branch (e.g. new commits)
@@ -35,7 +35,7 @@ module GitPush
data = post_receive_data(oldrev, newrev, ref, user)
- hooks.each { |web_hook| web_hook.execute(data) }
+ hooks.each { |hook| hook.execute(data) }
end
def post_receive_data(oldrev, newrev, ref, user)
@@ -97,7 +97,7 @@ module GitPush
self.update_merge_requests(oldrev, newrev, ref, user)
# Execute web hooks
- self.execute_web_hooks(oldrev, newrev, ref, user)
+ self.execute_hooks(oldrev, newrev, ref, user)
# Create satellite
self.satellite.create unless self.satellite.exists?
diff --git a/spec/factories.rb b/spec/factories.rb
index ea8c7aef0e2..d6570551803 100644
--- a/spec/factories.rb
+++ b/spec/factories.rb
@@ -60,7 +60,7 @@ 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
diff --git a/spec/models/project_hooks_spec.rb b/spec/models/project_hooks_spec.rb
index fcc969ceba5..5544c5a8683 100644
--- a/spec/models/project_hooks_spec.rb
+++ b/spec/models/project_hooks_spec.rb
@@ -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
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 381fe7592c9..351f5748b4d 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -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
diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb
index 9971bd5819d..885947614d7 100644
--- a/spec/models/web_hook_spec.rb
+++ b/spec/models/web_hook_spec.rb
@@ -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
diff --git a/spec/requests/admin/security_spec.rb b/spec/requests/admin/security_spec.rb
index 0b0edb85a37..0c369740cff 100644
--- a/spec/requests/admin/security_spec.rb
+++ b/spec/requests/admin/security_spec.rb
@@ -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
diff --git a/spec/requests/hooks_spec.rb b/spec/requests/hooks_spec.rb
index a508e5ea517..05432f13f3c 100644
--- a/spec/requests/hooks_spec.rb
+++ b/spec/requests/hooks_spec.rb
@@ -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
diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb
index c70b2f6cebb..5f3b6d3daec 100644
--- a/spec/workers/post_receive_spec.rb
+++ b/spec/workers/post_receive_spec.rb
@@ -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