OSDN Git Service

Refactor API classes. So api classes like Gitlab::Issues become API::Issues
[wvm/gitlab.git] / spec / requests / api / issues_spec.rb
1 require 'spec_helper'
2
3 describe API::API do
4   include ApiHelpers
5
6   let(:user) { create(:user) }
7   let!(:project) { create(:project, namespace: user.namespace ) }
8   let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
9   before { project.team << [user, :reporter] }
10
11   describe "GET /issues" do
12     context "when unauthenticated" do
13       it "should return authentication error" do
14         get api("/issues")
15         response.status.should == 401
16       end
17     end
18
19     context "when authenticated" do
20       it "should return an array of issues" do
21         get api("/issues", user)
22         response.status.should == 200
23         json_response.should be_an Array
24         json_response.first['title'].should == issue.title
25       end
26     end
27   end
28
29   describe "GET /projects/:id/issues" do
30     it "should return project issues" do
31       get api("/projects/#{project.id}/issues", user)
32       response.status.should == 200
33       json_response.should be_an Array
34       json_response.first['title'].should == issue.title
35     end
36   end
37
38   describe "GET /projects/:id/issues/:issue_id" do
39     it "should return a project issue by id" do
40       get api("/projects/#{project.id}/issues/#{issue.id}", user)
41       response.status.should == 200
42       json_response['title'].should == issue.title
43     end
44
45     it "should return 404 if issue id not found" do
46       get api("/projects/#{project.id}/issues/54321", user)
47       response.status.should == 404
48     end
49   end
50
51   describe "POST /projects/:id/issues" do
52     it "should create a new project issue" do
53       post api("/projects/#{project.id}/issues", user),
54         title: 'new issue', labels: 'label, label2'
55       response.status.should == 201
56       json_response['title'].should == 'new issue'
57       json_response['description'].should be_nil
58       json_response['labels'].should == ['label', 'label2']
59     end
60
61     it "should return a 400 bad request if title not given" do
62       post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
63       response.status.should == 400
64     end
65   end
66
67   describe "PUT /projects/:id/issues/:issue_id to update only title" do
68     it "should update a project issue" do
69       put api("/projects/#{project.id}/issues/#{issue.id}", user),
70         title: 'updated title'
71       response.status.should == 200
72
73       json_response['title'].should == 'updated title'
74     end
75
76     it "should return 404 error if issue id not found" do
77       put api("/projects/#{project.id}/issues/44444", user),
78         title: 'updated title'
79       response.status.should == 404
80     end
81   end
82
83   describe "PUT /projects/:id/issues/:issue_id to update state and label" do
84     it "should update a project issue" do
85       put api("/projects/#{project.id}/issues/#{issue.id}", user),
86         labels: 'label2', state_event: "close"
87       response.status.should == 200
88
89       json_response['labels'].should == ['label2']
90       json_response['state'].should eq "closed"
91     end
92   end
93
94   describe "DELETE /projects/:id/issues/:issue_id" do
95     it "should delete a project issue" do
96       delete api("/projects/#{project.id}/issues/#{issue.id}", user)
97       response.status.should == 405
98     end
99   end
100 end