Module: GitModels::TestHelpers

Defined in:
lib/git_models/test_helpers.rb

Class Method Summary collapse

Class Method Details

.create_branch(repository_name: 'repository_name', name: 'path/branch', last_modified_date: Time.current, author_name: 'Author Name', author_email: '[email protected]') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/git_models/test_helpers.rb', line 5

def self.create_branch(repository_name: 'repository_name',
                       name: 'path/branch',
                       last_modified_date: Time.current,
                       author_name: 'Author Name',
                       author_email: '[email protected]')
  git_data = Git::TestHelpers.create_branch(
    repository_name: repository_name,
    name: name,
    last_modified_date: last_modified_date,
    author_name: author_name,
    author_email: author_email
  )
  ::Branch.create_from_git_data!(git_data)
end

.create_branches(repository_name: 'repository_name', author_name: 'Author Name', author_email: '[email protected]', count: 2) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/git_models/test_helpers.rb', line 20

def self.create_branches(repository_name: 'repository_name',
                         author_name: 'Author Name',
                         author_email: '[email protected]',
                         count: 2)
  branches = []
  (0..count - 1).each do |i|
    branches << create_branch(
      repository_name: repository_name,
      name: "path/#{author_name}/branch#{i}",
      last_modified_date: DateTime.current,
      author_name: author_name,
      author_email: author_email
    )
  end
  branches
end

.create_commit(sha: '1234567890123456789012345678901234567890', message: 'Commit message', author_name: 'Author Name', author_email: '[email protected]') ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/git_models/test_helpers.rb', line 37

def self.create_commit(sha: '1234567890123456789012345678901234567890',
                       message: 'Commit message',
                       author_name: 'Author Name',
                       author_email: '[email protected]')
  commit = ::Commit.create(sha: sha, message: message)
  commit.author = ::User.first_or_create!(name: author_name, email: author_email)
  commit.save!
  commit
end

.create_commits(author_name: 'Author Name', author_email: '[email protected]', count: 2) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/git_models/test_helpers.rb', line 47

def self.create_commits(author_name: 'Author Name', author_email: '[email protected]', count: 2)
  commits = []
  (0..count - 1).each do |i|
    commits << create_commit(
      sha: (i + 1).to_s.ljust(40, '0'),
      message: "Commit message #{i + 1}",
      author_name: author_name,
      author_email: author_email
    )
  end
  commits
end