2012-07-24 08:19:51 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::API do
|
2012-08-25 13:31:50 -04:00
|
|
|
include ApiHelpers
|
|
|
|
|
2012-07-24 08:19:51 -04:00
|
|
|
let(:user) { Factory :user }
|
2012-08-10 18:07:50 -04:00
|
|
|
let!(:project) { Factory :project, owner: user }
|
|
|
|
let!(:issue) { Factory :issue, author: user, assignee: user, project: project }
|
2012-07-24 08:19:51 -04:00
|
|
|
before { project.add_access(user, :read) }
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "GET /projects/:id/issues" do
|
|
|
|
it "should return project issues" do
|
2012-08-25 13:43:55 -04:00
|
|
|
get api("/projects/#{project.code}/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
|
2012-08-25 13:43:55 -04:00
|
|
|
get api("/projects/#{project.code}/issues/#{issue.id}", user)
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 200
|
|
|
|
json_response['title'].should == issue.title
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "POST /projects/:id/issues" do
|
|
|
|
it "should create a new project issue" do
|
2012-08-25 13:43:55 -04:00
|
|
|
post api("/projects/#{project.code}/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
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "PUT /projects/:id/issues/:issue_id" do
|
|
|
|
it "should update a project issue" do
|
2012-08-25 13:43:55 -04:00
|
|
|
put api("/projects/#{project.code}/issues/#{issue.id}", user),
|
2012-08-10 18:07:50 -04:00
|
|
|
title: 'updated title', labels: 'label2', closed: 1
|
2012-07-24 08:19:51 -04:00
|
|
|
response.status.should == 200
|
|
|
|
json_response['title'].should == 'updated title'
|
|
|
|
json_response['labels'].should == ['label2']
|
|
|
|
json_response['closed'].should be_true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "DELETE /projects/:id/issues/:issue_id" do
|
|
|
|
it "should delete a project issue" do
|
2012-08-29 11:58:33 -04:00
|
|
|
delete api("/projects/#{project.code}/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
|