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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Client do
describe '.file_contents' do
before do
stub_get('/projects/3/repository/files/Gemfile/raw?ref=master', 'raw_file.txt')
@file_contents = Gitlab.file_contents(3, 'Gemfile')
end
it 'gets the correct resource' do
expect(a_get('/projects/3/repository/files/Gemfile/raw?ref=master')).to have_been_made
end
it 'returns file contents' do
expect(@file_contents).to eq("source 'https://rubygems.org'\ngem 'rails', '4.1.2'\n")
end
end
describe '.get_file_blame' do
before do
stub_get('/projects/3/repository/files/README%2Emd/blame?ref=master', 'get_file_blame')
@blames = Gitlab.get_file_blame(3, 'README.md', 'master')
end
it 'gets the correct resource' do
expect(a_get('/projects/3/repository/files/README%2Emd/blame?ref=master')).to have_been_made
end
it 'returns the blame info of the file' do
expect(@blames.first.commit.id).to eq('d42409d56517157c48bf3bd97d3f75974dde19fb')
end
end
describe '.get_file' do
before do
stub_get('/projects/3/repository/files/README%2Emd?ref=master', 'get_repository_file')
@file = Gitlab.get_file(3, 'README.md', 'master')
end
it 'gets the correct resource' do
expect(a_get('/projects/3/repository/files/README%2Emd?ref=master')).to have_been_made
end
it 'returns the base64 encoded file' do
expect(@file.file_path).to eq 'README.md'
expect(@file.ref).to eq 'master'
expect(@file.content).to eq "VGhpcyBpcyBhICpSRUFETUUqIQ==\n"
end
end
describe '.create_file' do
let(:api_path) { '/projects/3/repository/files/path' }
before do
stub_post(api_path, 'repository_file')
@file = Gitlab.create_file(3, 'path', 'branch', 'content', 'commit message', author_name: 'joe')
end
it 'creates the correct resource' do
expected_parameters = {
author_name: 'joe',
branch: 'branch',
commit_message: 'commit message'
}
expect(a_post(api_path).with(body: hash_including(expected_parameters))).to have_been_made
end
it 'returns information about the new file' do
expect(@file.file_path).to eq 'path'
expect(@file.branch_name).to eq 'branch'
end
end
describe '.edit_file' do
let(:api_path) { '/projects/3/repository/files/path' }
before do
stub_put(api_path, 'repository_file')
@file = Gitlab.edit_file(3, 'path', 'branch', 'content', 'commit message', author_name: 'joe')
end
it 'updates the correct resource' do
expected_parameters = {
author_name: 'joe',
branch: 'branch',
commit_message: 'commit message'
}
expect(a_put(api_path).with(body: hash_including(expected_parameters))).to have_been_made
end
it 'returns information about the new file' do
expect(@file.file_path).to eq 'path'
expect(@file.branch_name).to eq 'branch'
end
end
describe '.remove_file' do
let(:api_path) { '/projects/3/repository/files/path' }
before do
stub_delete(api_path, 'repository_file')
@file = Gitlab.remove_file(3, 'path', 'branch', 'commit message', author_name: 'joe')
end
it 'updates the correct resource' do
expected_parameters = {
author_name: 'joe',
branch: 'branch',
commit_message: 'commit message'
}
expect(a_delete(api_path).with(body: hash_including(expected_parameters))).to have_been_made
end
it 'returns information about the new file' do
expect(@file.file_path).to eq 'path'
expect(@file.branch_name).to eq 'branch'
end
end
end
|