File: issue_spec.rb

package info (click to toggle)
ruby-jira 2.1.5-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 968 kB
  • sloc: ruby: 5,125; makefile: 12
file content (93 lines) | stat: -rw-r--r-- 3,282 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
require 'spec_helper'

describe JIRA::Resource::Issue do
  with_each_client do |site_url, client|
    let(:client) { client }
    let(:site_url) { site_url }

    let(:key) { '10002' }

    let(:expected_attributes) do
      {
        'self'   => 'http://localhost:2990/jira/rest/api/2/issue/10002',
        'key'    => 'SAMPLEPROJECT-1',
        'expand' => 'renderedFields,names,schema,transitions,editmeta,changelog'
      }
    end

    let(:attributes_for_post) do
      { 'foo' => 'bar' }
    end
    let(:expected_attributes_from_post) do
      { 'id' => '10005', 'key' => 'SAMPLEPROJECT-4' }
    end

    let(:attributes_for_put) do
      { 'foo' => 'bar' }
    end
    let(:expected_attributes_from_put) do
      { 'foo' => 'bar' }
    end
    let(:expected_collection_length) { 11 }

    it_should_behave_like 'a resource'
    it_should_behave_like 'a resource with a singular GET endpoint'
    describe 'GET all issues' do # JIRA::Resource::Issue.all uses the search endpoint
      let(:client) { client }
      let(:site_url) { site_url }

      let(:expected_attributes) do
        {
          'id' => '10014',
          'self' => 'http://localhost:2990/jira/rest/api/2/issue/10014',
          'key' => 'SAMPLEPROJECT-13'
        }
      end
      before(:each) do
        stub_request(:get, site_url + '/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=0')
          .to_return(status: 200, body: get_mock_response('issue.json'))

        stub_request(:get, site_url + '/jira/rest/api/2/search?expand=transitions.fields&maxResults=1000&startAt=11')
          .to_return(status: 200, body: get_mock_response('empty_issues.json'))
      end
      it_should_behave_like 'a resource with a collection GET endpoint'
    end
    it_should_behave_like 'a resource with a DELETE endpoint'
    it_should_behave_like 'a resource with a POST endpoint'
    it_should_behave_like 'a resource with a PUT endpoint'
    it_should_behave_like 'a resource with a PUT endpoint that rejects invalid fields'

    describe 'errors' do
      before(:each) do
        stub_request(:get,
                     site_url + '/jira/rest/api/2/issue/10002')
          .to_return(status: 200, body: get_mock_response('issue/10002.json'))
        stub_request(:put, site_url + '/jira/rest/api/2/issue/10002')
          .with(body: '{"missing":"fields and update"}')
          .to_return(status: 400, body: get_mock_response('issue/10002.put.missing_field_update.json'))
      end

      it 'fails to save when fields and update are missing' do
        subject = client.Issue.build('id' => '10002')
        subject.fetch
        expect(subject.save('missing' => 'fields and update')).to be_falsey
      end
    end

    describe 'GET jql issues' do # JIRA::Resource::Issue.jql uses the search endpoint
      jql_query_string = "PROJECT = 'SAMPLEPROJECT'"
      let(:client) { client }
      let(:site_url) { site_url }
      let(:jql_query_string) { jql_query_string }

      let(:expected_attributes) do
        {
          'id' => '10014',
          'self' => 'http://localhost:2990/jira/rest/api/2/issue/10014',
          'key' => 'SAMPLEPROJECT-13'
        }
      end
      it_should_behave_like 'a resource with JQL inputs and a collection GET endpoint'
    end
  end
end