issues_spec.rb 2.3 KB
Newer Older
N
Nihad Abbasov 已提交
1 2 3
require 'spec_helper'

describe Gitlab::API do
4 5
  include ApiHelpers

6
  let(:user) { create(:user) }
7
  let!(:project) { create(:project, namespace: user.namespace ) }
8
  let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
N
Nihad Abbasov 已提交
9 10 11
  before { project.add_access(user, :read) }

  describe "GET /issues" do
12 13 14 15 16
    context "when unauthenticated" do
      it "should return authentication error" do
        get api("/issues")
        response.status.should == 401
      end
N
Nihad Abbasov 已提交
17 18
    end

19
    context "when authenticated" do
N
Nihad Abbasov 已提交
20
      it "should return an array of issues" do
R
Robert Speicher 已提交
21
        get api("/issues", user)
N
Nihad Abbasov 已提交
22 23 24 25 26 27 28 29 30
        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
31
      get api("/projects/#{project.id}/issues", user)
N
Nihad Abbasov 已提交
32 33 34 35 36 37 38 39
      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
40
      get api("/projects/#{project.id}/issues/#{issue.id}", user)
N
Nihad Abbasov 已提交
41 42 43 44 45 46 47
      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
48
      post api("/projects/#{project.id}/issues", user),
49
        title: 'new issue', labels: 'label, label2'
N
Nihad Abbasov 已提交
50 51 52 53 54 55 56 57 58
      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
59
      put api("/projects/#{project.id}/issues/#{issue.id}", user),
60
        title: 'updated title', labels: 'label2', closed: 1
N
Nihad Abbasov 已提交
61 62 63 64 65 66 67 68 69
      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
70
      delete api("/projects/#{project.id}/issues/#{issue.id}", user)
71
      response.status.should == 405
N
Nihad Abbasov 已提交
72 73 74
    end
  end
end