BigW Consortium Gitlab

milestones_spec.rb 3.39 KB
Newer Older
Robert Speicher committed
1 2
require 'spec_helper'

3
describe API::API, api: true  do
4
  include ApiHelpers
5
  let(:user) { create(:user) }
6
  let!(:project) { create(:project, namespace: user.namespace ) }
7
  let!(:milestone) { create(:milestone, project: project) }
Robert Speicher committed
8

Dmitriy Zaporozhets committed
9
  before { project.team << [user, :developer] }
Robert Speicher committed
10 11 12

  describe "GET /projects/:id/milestones" do
    it "should return project milestones" do
13
      get api("/projects/#{project.id}/milestones", user)
Robert Speicher committed
14 15 16 17
      response.status.should == 200
      json_response.should be_an Array
      json_response.first['title'].should == milestone.title
    end
18 19 20 21 22

    it "should return a 401 error if user not authenticated" do
      get api("/projects/#{project.id}/milestones")
      response.status.should == 401
    end
Robert Speicher committed
23 24 25 26
  end

  describe "GET /projects/:id/milestones/:milestone_id" do
    it "should return a project milestone by id" do
27
      get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
Robert Speicher committed
28 29
      response.status.should == 200
      json_response['title'].should == milestone.title
30
      json_response['iid'].should == milestone.iid
Robert Speicher committed
31
    end
32

33 34 35 36 37
    it "should return 401 error if user not authenticated" do
      get api("/projects/#{project.id}/milestones/#{milestone.id}")
      response.status.should == 401
    end

38 39 40 41
    it "should return a 404 error if milestone id not found" do
      get api("/projects/#{project.id}/milestones/1234", user)
      response.status.should == 404
    end
Robert Speicher committed
42 43 44 45
  end

  describe "POST /projects/:id/milestones" do
    it "should create a new project milestone" do
46
      post api("/projects/#{project.id}/milestones", user), title: 'new milestone'
Robert Speicher committed
47 48 49 50
      response.status.should == 201
      json_response['title'].should == 'new milestone'
      json_response['description'].should be_nil
    end
51 52 53 54 55 56 57 58 59 60 61 62 63

    it "should create a new project milestone with description and due date" do
      post api("/projects/#{project.id}/milestones", user),
        title: 'new milestone', description: 'release', due_date: '2013-03-02'
      response.status.should == 201
      json_response['description'].should == 'release'
      json_response['due_date'].should == '2013-03-02'
    end

    it "should return a 400 error if title is missing" do
      post api("/projects/#{project.id}/milestones", user)
      response.status.should == 400
    end
Robert Speicher committed
64 65 66 67
  end

  describe "PUT /projects/:id/milestones/:milestone_id" do
    it "should update a project milestone" do
68
      put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
Robert Speicher committed
69 70 71 72
        title: 'updated title'
      response.status.should == 200
      json_response['title'].should == 'updated title'
    end
73

74
    it "should return a 404 error if milestone id not found" do
75 76 77 78
      put api("/projects/#{project.id}/milestones/1234", user),
        title: 'updated title'
      response.status.should == 404
    end
Robert Speicher committed
79
  end
80 81 82 83 84 85 86 87 88 89

  describe "PUT /projects/:id/milestones/:milestone_id to close milestone" do
    it "should update a project milestone" do
      put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
        state_event: 'close'
      response.status.should == 200

      json_response['state'].should == 'closed'
    end
  end
90 91 92 93 94 95 96 97 98

  describe "PUT /projects/:id/milestones/:milestone_id to test observer on close" do
    it "should create an activity event when an milestone is closed" do
      Event.should_receive(:create)

      put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
          state_event: 'close'
    end
  end
Robert Speicher committed
99
end