-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommits_controller_spec.rb
More file actions
56 lines (49 loc) · 2.52 KB
/
commits_controller_spec.rb
File metadata and controls
56 lines (49 loc) · 2.52 KB
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
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe V1::Repositories::CommitsController, type: :controller do
let(:user) { FactoryBot.create(:user, otp_required_for_login: true) }
let(:organization) { FactoryBot.create(:organization) }
let(:repository) { FactoryBot.create(:repository, created_by: user.id, owner_id: organization.id, owner_type: 'Organization', server_type: 'perforce') }
let!(:repository_permission) { FactoryBot.create(:repository_permission, repository: repository, user: user) }
let(:branch_ref) { FactoryBot.create(:ref, name: 'BranchRef', repository: repository, type: :branch) }
let!(:commit) { FactoryBot.create(:commit, ref: branch_ref, repository: repository, user: user) }
before do
sign_in(user)
end
describe 'GET index' do
it 'returns commits for specified ref and repository' do
get :index, params: { repository_id: repository.id, branch: branch_ref.name }
expect(response).to be_successful
expect(response.body).to eq(JSON.dump(
[
{
id: commit.id,
message: commit.message,
committed_at: commit.committed_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ'),
sha: "#{branch_ref.name}@#{commit.sha}",
author: {
name: user.name,
email: user.email,
},
},
]
))
end
end
describe 'GET show' do
it 'returns specified branch from specified repository' do
get :show, params: { repository_id: repository.id, branch: branch_ref.name, id: commit.sha }
expect(response).to be_successful
expect(response.body).to eq(JSON.dump(
id: commit.id,
message: commit.message,
committed_at: commit.committed_at.strftime('%Y-%m-%dT%H:%M:%S.%LZ'),
sha: "#{branch_ref.name}@#{commit.sha}",
author: {
name: user.name,
email: user.email,
}
))
end
end
end