File: snippets_spec.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (102 lines) | stat: -rw-r--r-- 2,985 bytes parent folder | download
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
97
98
99
100
101
102
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Client do
  describe '.snippets' do
    before do
      stub_get('/projects/3/snippets', 'snippets')
      @snippets = Gitlab.snippets(3)
    end

    it 'gets the correct resource' do
      expect(a_get('/projects/3/snippets')).to have_been_made
    end

    it "returns a paginated response of project's snippets" do
      expect(@snippets).to be_a Gitlab::PaginatedResponse
      expect(@snippets.first.file_name).to eq('mailer_test.rb')
    end
  end

  describe '.snippet' do
    before do
      stub_get('/projects/3/snippets/1', 'snippet')
      @snippet = Gitlab.snippet(3, 1)
    end

    it 'gets the correct resource' do
      expect(a_get('/projects/3/snippets/1')).to have_been_made
    end

    it 'returns information about a snippet' do
      expect(@snippet.file_name).to eq('mailer_test.rb')
      expect(@snippet.author.name).to eq('John Smith')
    end
  end

  describe '.create_snippet' do
    before do
      stub_post('/projects/3/snippets', 'snippet')
      @snippet = Gitlab.create_snippet(3, title: 'API', file_name: 'api.rb', code: 'code', visibility: 'public')
    end

    it 'gets the correct resource' do
      body = { title: 'API', file_name: 'api.rb', code: 'code', visibility: 'public' }
      expect(a_post('/projects/3/snippets').with(body: body)).to have_been_made
    end

    it 'returns information about a new snippet' do
      expect(@snippet.file_name).to eq('mailer_test.rb')
      expect(@snippet.author.name).to eq('John Smith')
    end
  end

  describe '.edit_snippet' do
    before do
      stub_put('/projects/3/snippets/1', 'snippet')
      @snippet = Gitlab.edit_snippet(3, 1, file_name: 'mailer_test.rb')
    end

    it 'gets the correct resource' do
      expect(a_put('/projects/3/snippets/1')
        .with(body: { file_name: 'mailer_test.rb' })).to have_been_made
    end

    it 'returns information about an edited snippet' do
      expect(@snippet.file_name).to eq('mailer_test.rb')
      expect(@snippet.author.name).to eq('John Smith')
    end
  end

  describe '.delete_snippet' do
    before do
      stub_delete('/projects/3/snippets/1', 'snippet')
      @snippet = Gitlab.delete_snippet(3, 1)
    end

    it 'gets the correct resource' do
      expect(a_delete('/projects/3/snippets/1')).to have_been_made
    end

    it 'returns information about a deleted snippet' do
      expect(@snippet.file_name).to eq('mailer_test.rb')
      expect(@snippet.author.name).to eq('John Smith')
    end
  end

  describe '.snippet_content' do
    before do
      stub_get('/projects/3/snippets/1/raw', 'snippet_content')
      @snippet_content = Gitlab.snippet_content(3, 1)
    end

    it 'gets the correct resource' do
      expect(a_get('/projects/3/snippets/1/raw')).to have_been_made
    end

    it 'returns raw content of a snippet' do
      expect(@snippet_content).to eq("#!/usr/bin/env ruby\n\nputs \"Cool snippet!\"\n")
    end
  end
end