2012-07-24 08:19:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2014-04-11 15:45:56 -04:00
|
|
|
describe API::API, api: true do
|
2012-08-25 13:31:50 -04:00
|
|
|
include ApiHelpers
|
2013-09-17 09:12:10 -04:00
|
|
|
before(:each) { ActiveRecord::Base.observers.enable(:user_observer) }
|
|
|
|
after(:each) { ActiveRecord::Base.observers.disable(:user_observer) }
|
2012-08-25 13:31:50 -04:00
|
|
|
|
2012-11-05 22:31:55 -05:00
|
|
|
let(:user) { create(:user) }
|
2013-01-02 12:32:34 -05:00
|
|
|
let!(:project) { create(:project, namespace: user.namespace ) }
|
2012-11-05 22:31:55 -05:00
|
|
|
let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
|
2013-01-04 11:50:31 -05:00
|
|
|
before { project.team << [user, :reporter] }
|
2012-07-24 08:19:51 -04:00
|
|
|
|
|
|
|
describe "GET /issues" do
|
2012-09-12 08:11:56 -04:00
|
|
|
context "when unauthenticated" do
|
|
|
|
it "should return authentication error" do
|
|
|
|
get api("/issues")
|
|
|
|
response.status.should == 401
|
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
2012-09-12 08:11:56 -04:00
|
|
|
context "when authenticated" do
|
2012-07-24 08:19:51 -04:00
|
|
|
it "should return an array of issues" do
|
2012-08-25 13:43:55 -04:00
|
|
|
get api("/issues", user)
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 200
|
|
|
|
json_response.should be_an Array
|
|
|
|
json_response.first['title'].should == issue.title
|
|
|
|
end
|
2013-10-29 05:41:20 -04:00
|
|
|
|
|
|
|
it "should add pagination headers" do
|
|
|
|
get api("/issues?per_page=3", user)
|
|
|
|
response.headers['Link'].should ==
|
|
|
|
'<http://www.example.com/api/v3/issues?page=1&per_page=3>; rel="first", <http://www.example.com/api/v3/issues?page=1&per_page=3>; rel="last"'
|
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/issues" do
|
|
|
|
it "should return project issues" do
|
2013-01-02 12:46:06 -05:00
|
|
|
get api("/projects/#{project.id}/issues", user)
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 200
|
|
|
|
json_response.should be_an Array
|
|
|
|
json_response.first['title'].should == issue.title
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/issues/:issue_id" do
|
|
|
|
it "should return a project issue by id" do
|
2013-01-02 12:46:06 -05:00
|
|
|
get api("/projects/#{project.id}/issues/#{issue.id}", user)
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 200
|
|
|
|
json_response['title'].should == issue.title
|
2013-10-14 09:39:54 -04:00
|
|
|
json_response['iid'].should == issue.iid
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
2013-02-27 08:36:20 -05:00
|
|
|
|
|
|
|
it "should return 404 if issue id not found" do
|
|
|
|
get api("/projects/#{project.id}/issues/54321", user)
|
|
|
|
response.status.should == 404
|
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/issues" do
|
|
|
|
it "should create a new project issue" do
|
2013-01-02 12:46:06 -05:00
|
|
|
post api("/projects/#{project.id}/issues", user),
|
2012-08-10 18:07:50 -04:00
|
|
|
title: 'new issue', labels: 'label, label2'
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 201
|
|
|
|
json_response['title'].should == 'new issue'
|
|
|
|
json_response['description'].should be_nil
|
|
|
|
json_response['labels'].should == ['label', 'label2']
|
|
|
|
end
|
2013-02-27 08:36:20 -05:00
|
|
|
|
|
|
|
it "should return a 400 bad request if title not given" do
|
|
|
|
post api("/projects/#{project.id}/issues", user), labels: 'label, label2'
|
|
|
|
response.status.should == 400
|
|
|
|
end
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
|
2013-02-18 04:10:58 -05:00
|
|
|
describe "PUT /projects/:id/issues/:issue_id to update only title" do
|
2012-07-24 08:19:51 -04:00
|
|
|
it "should update a project issue" do
|
2013-01-02 12:46:06 -05:00
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
2013-02-18 04:10:58 -05:00
|
|
|
title: 'updated title'
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 200
|
2013-02-18 04:10:58 -05:00
|
|
|
|
2012-07-24 08:19:51 -04:00
|
|
|
json_response['title'].should == 'updated title'
|
2013-02-18 04:10:58 -05:00
|
|
|
end
|
2013-02-27 08:36:20 -05:00
|
|
|
|
|
|
|
it "should return 404 error if issue id not found" do
|
|
|
|
put api("/projects/#{project.id}/issues/44444", user),
|
|
|
|
title: 'updated title'
|
|
|
|
response.status.should == 404
|
|
|
|
end
|
2013-02-18 04:10:58 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/issues/:issue_id to update state and label" do
|
|
|
|
it "should update a project issue" do
|
|
|
|
put api("/projects/#{project.id}/issues/#{issue.id}", user),
|
|
|
|
labels: 'label2', state_event: "close"
|
|
|
|
response.status.should == 200
|
|
|
|
|
2012-07-24 08:19:51 -04:00
|
|
|
json_response['labels'].should == ['label2']
|
2013-02-18 04:10:58 -05:00
|
|
|
json_response['state'].should eq "closed"
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "DELETE /projects/:id/issues/:issue_id" do
|
|
|
|
it "should delete a project issue" do
|
2013-01-02 12:46:06 -05:00
|
|
|
delete api("/projects/#{project.id}/issues/#{issue.id}", user)
|
2012-08-22 13:26:09 -04:00
|
|
|
response.status.should == 405
|
2012-07-24 08:19:51 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|