BigW Consortium Gitlab

projects.rb 3.51 KB
Newer Older
Dmitriy Zaporozhets committed
1
FactoryGirl.define do
2 3 4
  # Project without repository
  #
  # Project does not have bare repository.
5
  # Use this factory if you don't need repository in tests
Dmitriy Zaporozhets committed
6 7 8 9 10 11
  factory :empty_project, class: 'Project' do
    sequence(:name) { |n| "project#{n}" }
    path { name.downcase.gsub(/\s/, '_') }
    namespace
    creator

12 13 14
    # Behaves differently to nil due to cache_has_external_issue_tracker
    has_external_issue_tracker false

Dmitriy Zaporozhets committed
15 16 17 18 19 20 21 22 23 24 25
    trait :public do
      visibility_level Gitlab::VisibilityLevel::PUBLIC
    end

    trait :internal do
      visibility_level Gitlab::VisibilityLevel::INTERNAL
    end

    trait :private do
      visibility_level Gitlab::VisibilityLevel::PRIVATE
    end
26 27 28 29 30 31

    trait :empty_repo do
      after(:create) do |project|
        project.create_repository
      end
    end
32

33 34 35 36 37 38 39 40
    trait :broken_repo do
      after(:create) do |project|
        project.create_repository

        FileUtils.rm_r(File.join(project.repository_storage_path, "#{project.path_with_namespace}.git", 'refs'))
      end
    end

41 42 43 44 45 46 47
    # Nest Project Feature attributes
    transient do
      wiki_access_level ProjectFeature::ENABLED
      builds_access_level ProjectFeature::ENABLED
      snippets_access_level ProjectFeature::ENABLED
      issues_access_level ProjectFeature::ENABLED
      merge_requests_access_level ProjectFeature::ENABLED
48
      repository_access_level ProjectFeature::ENABLED
49 50 51 52 53 54 55 56 57 58
    end

    after(:create) do |project, evaluator|
      project.project_feature.
        update_attributes(
          wiki_access_level: evaluator.wiki_access_level,
          builds_access_level: evaluator.builds_access_level,
          snippets_access_level: evaluator.snippets_access_level,
          issues_access_level: evaluator.issues_access_level,
          merge_requests_access_level: evaluator.merge_requests_access_level,
59
          repository_access_level: evaluator.repository_access_level
60 61
        )
    end
Dmitriy Zaporozhets committed
62 63
  end

64 65 66 67 68
  # Project with empty repository
  #
  # This is a case when you just created a project
  # but not pushed any code there yet
  factory :project_empty_repo, parent: :empty_project do
69
    empty_repo
70 71
  end

72 73 74 75 76 77 78
  # Project with broken repository
  #
  # Project with an invalid repository state
  factory :project_broken_repo, parent: :empty_project do
    broken_repo
  end

79 80 81 82
  # Project with test repository
  #
  # Test repository source can be found at
  # https://gitlab.com/gitlab-org/gitlab-test
Dmitriy Zaporozhets committed
83 84 85 86 87 88 89 90
  factory :project, parent: :empty_project do
    path { 'gitlabhq' }

    after :create do |project|
      TestEnv.copy_repo(project)
    end
  end

91 92 93 94 95 96 97 98
  factory :forked_project_with_submodules, parent: :empty_project do
    path { 'forked-gitlabhq' }

    after :create do |project|
      TestEnv.copy_forked_repo_with_submodules(project)
    end
  end

Dmitriy Zaporozhets committed
99
  factory :redmine_project, parent: :project do
100 101
    has_external_issue_tracker true

102 103 104 105
    after :create do |project|
      project.create_redmine_service(
        active: true,
        properties: {
106 107 108
          'project_url' => 'http://redmine/projects/project_name_in_redmine',
          'issues_url' => "http://redmine/#{project.id}/project_name_in_redmine/:id",
          'new_issue_url' => 'http://redmine/projects/project_name_in_redmine/issues/new'
109 110 111
        }
      )
    end
Dmitriy Zaporozhets committed
112
  end
113 114

  factory :jira_project, parent: :project do
115 116
    has_external_issue_tracker true

117 118 119 120
    after :create do |project|
      project.create_jira_service(
        active: true,
        properties: {
121 122 123
          title: 'JIRA tracker',
          url: 'http://jira.example.net',
          project_key: 'JIRA'
124 125 126 127
        }
      )
    end
  end
Dmitriy Zaporozhets committed
128
end