File: deployments_spec.rb

package info (click to toggle)
ruby-octokit 10.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,092 kB
  • sloc: ruby: 13,339; sh: 99; makefile: 7; javascript: 3
file content (96 lines) | stat: -rw-r--r-- 3,605 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# frozen_string_literal: true

describe Octokit::Client::Deployments do
  before do
    Octokit.reset!
    @client = oauth_client
  end

  after do
    Octokit.reset!
  end

  describe '.deployments', :vcr do
    it 'lists deployments' do
      deployments = @client.deployments(@test_repo)
      expect(deployments).to be_kind_of Array
      assert_requested :get, github_url("/repos/#{@test_repo}/deployments")
    end
  end # .deployments

  context 'with ref', :vcr do
    before(:each) do
      commits = @client.commits(@test_repo)
      @first_sha = commits.first.sha

      @branch_name = 'testing/deployment'
      @ref = @client.create_ref(@test_repo, "heads/#{@branch_name}", @first_sha)
    end

    after(:each) do
      @client.delete_ref(@test_repo, "heads/#{@branch_name}")
    rescue Octokit::UnprocessableEntity
    end

    describe '.create_deployment' do
      it 'creates a deployment' do
        deployment = @client.create_deployment(@test_repo, @branch_name)
        expect(deployment.sha).to eq(@ref.object.sha)
        expect(deployment.creator.login).to eq(test_github_login)
        assert_requested :post, github_url("/repos/#{@test_repo}/deployments")
      end

      it 'creates a deployment with a payload' do
        opts = { payload: { environment: 'production' } }
        deployment = @client.create_deployment(@test_repo, @branch_name, opts)
        expect(deployment.sha).to eq(@ref.object.sha)
        expect(deployment.creator.login).to eq(test_github_login)
        expect(deployment.payload.to_hash).to eq(opts[:payload])
        assert_requested :post, github_url("/repos/#{@test_repo}/deployments")
      end
    end # .create_deployment

    context 'with deployment' do
      before(:each) do
        @deployment = @client.create_deployment(@test_repo, @branch_name)
        @deployment_url = "https://api.github.com/repos/#{@test_repo}/deployments/#{@deployment.id}"
      end

      describe '.deployment' do
        it 'gets a single deployment' do
          deployment = @client.deployment(@test_repo, @deployment.id)
          expect(deployment).to be_kind_of Sawyer::Resource
          assert_requested :get, github_url("/repos/#{@test_repo}/deployments/#{@deployment.id}")
        end
      end # .deployment

      describe '.delete_deployment' do
        it 'deletes a single deployment' do
          response = @client.delete_deployment(@test_repo, @deployment.id)
          expect(response.empty?).to be true
          assert_requested :delete, github_url("/repos/#{@test_repo}/deployments/#{@deployment.id}")
        end
      end # .delete_deployment

      describe '.deployment_statuses' do
        it 'lists deployment statuses' do
          statuses = @client.deployment_statuses(@deployment_url)
          expect(statuses).to be_kind_of Array
          assert_requested :get, github_url(@deployment_url)
          assert_requested :get, github_url("#{@deployment_url}/statuses")
        end
      end # .deployment_statuses

      describe '.create_deployment_status' do
        it 'creates a deployment status' do
          status = @client.create_deployment_status(@deployment_url, 'SUCCESS', target_url: 'http://wynn.fm')
          expect(status.creator.login).to eq(test_github_login)
          expect(status.state).to eq('success')
          expect(status.rels[:target].href).to eq('http://wynn.fm')
          assert_requested :get, github_url(@deployment_url)
          assert_requested :post, github_url("#{@deployment_url}/statuses")
        end
      end # .create_deployment_status
    end # with deployment
  end # with ref
end