summaryrefslogtreecommitdiff
path: root/spec/factories/commits.rb
blob: 4a411eea2ede1a908af7114fc8777a510d7aa035 (plain)
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
# == Schema Information
#
# Table name: commits
#
#  id          :integer          not null, primary key
#  project_id  :integer
#  ref         :string(255)
#  sha         :string(255)
#  before_sha  :string(255)
#  push_data   :text
#  created_at  :datetime
#  updated_at  :datetime
#  tag         :boolean          default(FALSE)
#  yaml_errors :text
#

# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
  factory :commit do
    ref 'master'
    before_sha '76de212e80737a608d939f648d959671fb0a0142'
    sha '97de212e80737a608d939f648d959671fb0a0142'
    push_data do
      {
        ref: 'refs/heads/master',
        before: '76de212e80737a608d939f648d959671fb0a0142',
        after: '97de212e80737a608d939f648d959671fb0a0142',
        user_name: 'Git User',
        user_email: 'git@example.com',
        repository: {
          name: 'test-data',
          url: 'ssh://git@gitlab.com/test/test-data.git',
          description: '',
          homepage: 'http://gitlab.com/test/test-data'
        },
        commits: [
          {
            id: '97de212e80737a608d939f648d959671fb0a0142',
            message: 'Test commit message',
            timestamp: '2014-09-23T13:12:25+02:00',
            url: 'https://gitlab.com/test/test-data/commit/97de212e80737a608d939f648d959671fb0a0142',
            author: {
              name: 'Git User',
              email: 'git@user.com'
            }
          }
        ],
        total_commits_count: 1,
        ci_yaml_file: File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
      }
    end

    factory :commit_with_one_job do
      after(:create) do |commit, evaluator|
        commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }})
      end
    end

    factory :commit_with_two_jobs do
      after(:create) do |commit, evaluator|
        commit.push_data[:ci_yaml_file] = YAML.dump({rspec: { script: "ls" }, spinach: { script: "ls" }})
      end
    end
  end
end