Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-06 19:42:43 +0400
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-03-06 19:42:43 +0400
commit65d78253cb289091a4eb389bada11828849d434c (patch)
treee002a0c13e744407e90f14b3f3b8d92bd5bb675a /spec
parent0384ef46b8839e7d9824473952e82ec62f72081a (diff)
parent1dd712ddc238d2e6c30be09cb071c8e9b60cfcac (diff)
Merge pull request #3156 from m4tthumphrey/api-system-hooks
Added methods to manage system hooks from API
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/system_hooks_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/requests/api/system_hooks_spec.rb b/spec/requests/api/system_hooks_spec.rb
new file mode 100644
index 00000000000..9842ae91ec3
--- /dev/null
+++ b/spec/requests/api/system_hooks_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+describe Gitlab::API do
+ include ApiHelpers
+
+ let(:user) { create(:user) }
+ let(:admin) { create(:admin) }
+ let!(:hook) { create(:system_hook, url: "http://example.com") }
+
+ before { stub_request(:post, hook.url) }
+
+ describe "GET /hooks" do
+ context "when not an admin" do
+ it "should return forbidden error" do
+ get api("/hooks", user)
+ response.status.should == 403
+ end
+ end
+
+ context "when authenticated as admin" do
+ it "should return an array of hooks" do
+ get api("/hooks", admin)
+ response.status.should == 200
+ json_response.should be_an Array
+ json_response.first['url'].should == hook.url
+ end
+ end
+ end
+
+ describe "POST /hooks" do
+ it "should create new hook" do
+ expect {
+ post api("/hooks", admin), url: 'http://example.com'
+ }.to change { SystemHook.count }.by(1)
+ end
+
+ it "should respond with 404 on failure" do
+ post api("/hooks", admin)
+ response.status.should == 404
+ end
+
+ it "should not create new hook without url" do
+ expect {
+ post api("/hooks", admin)
+ }.to_not change { SystemHook.count }
+ end
+ end
+
+ describe "GET /hooks/:id" do
+ it "should return hook by id" do
+ get api("/hooks/#{hook.id}", admin)
+ response.status.should == 200
+ json_response['event_name'].should == 'project_create'
+ end
+
+ it "should return 404 on failure" do
+ get api("/hooks/404", admin)
+ response.status.should == 404
+ end
+ end
+
+ describe "DELETE /hooks/:id" do
+ it "should delete a hook" do
+ expect {
+ delete api("/hooks/#{hook.id}", admin)
+ }.to change { SystemHook.count }.by(-1)
+ end
+ end
+end \ No newline at end of file