6 let(:user) { create(:user) }
7 let(:admin) { create(:admin) }
8 let!(:hook) { create(:system_hook, url: "http://example.com") }
10 before { stub_request(:post, hook.url) }
12 describe "GET /hooks" do
13 context "when no user" do
14 it "should return authentication error" do
16 response.status.should == 401
20 context "when not an admin" do
21 it "should return forbidden error" do
22 get api("/hooks", user)
23 response.status.should == 403
27 context "when authenticated as admin" do
28 it "should return an array of hooks" do
29 get api("/hooks", admin)
30 response.status.should == 200
31 json_response.should be_an Array
32 json_response.first['url'].should == hook.url
37 describe "POST /hooks" do
38 it "should create new hook" do
40 post api("/hooks", admin), url: 'http://example.com'
41 }.to change { SystemHook.count }.by(1)
44 it "should respond with 400 if url not given" do
45 post api("/hooks", admin)
46 response.status.should == 400
49 it "should not create new hook without url" do
51 post api("/hooks", admin)
52 }.to_not change { SystemHook.count }
56 describe "GET /hooks/:id" do
57 it "should return hook by id" do
58 get api("/hooks/#{hook.id}", admin)
59 response.status.should == 200
60 json_response['event_name'].should == 'project_create'
63 it "should return 404 on failure" do
64 get api("/hooks/404", admin)
65 response.status.should == 404
69 describe "DELETE /hooks/:id" do
70 it "should delete a hook" do
72 delete api("/hooks/#{hook.id}", admin)
73 }.to change { SystemHook.count }.by(-1)
76 it "should return success if hook id not found" do
77 delete api("/hooks/12345", admin)
78 response.status.should == 200