project.rb 4.46 KB
Newer Older
Nihad Abbasov's avatar
Nihad Abbasov committed
1 2 3
module SharedProject
  include Spinach::DSL

4
  # Create a project without caring about what it's called
5
  step "I own a project" do
6
    @project = create(:project, :repository, namespace: @user.namespace)
7
    @project.add_master(@user)
8 9
  end

10 11
  step "I own a project in some group namespace" do
    @group = create(:group, name: 'some group')
12
    @project = create(:project, namespace: @group)
13
    @project.add_master(@user)
14 15
  end

16 17
  step "project exists in some group namespace" do
    @group = create(:group, name: 'some group')
18
    @project = create(:project, :repository, namespace: @group, public_builds: false)
19 20
  end

21
  # Create a specific project called "Shop"
22
  step 'I own project "Shop"' do
skv's avatar
skv committed
23
    @project = Project.find_by(name: "Shop")
24
    @project ||= create(:project, :repository, name: "Shop", namespace: @user.namespace)
25
    @project.add_master(@user)
Nihad Abbasov's avatar
Nihad Abbasov committed
26
  end
27 28 29 30

  def current_project
    @project ||= Project.first
  end
31

32 33 34 35 36
  # ----------------------------------------
  # Project permissions
  # ----------------------------------------

  step 'I am member of a project with a guest role' do
37
    @project.add_guest(@user)
38 39 40
  end

  step 'I am member of a project with a reporter role' do
41
    @project.add_reporter(@user)
42 43
  end

Artem Sidorenko's avatar
Artem Sidorenko committed
44 45 46 47 48 49
  # ----------------------------------------
  # Visibility of archived project
  # ----------------------------------------

  step 'I should not see project "Archive"' do
    project = Project.find_by(name: "Archive")
50
    expect(page).not_to have_content project.full_name
Artem Sidorenko's avatar
Artem Sidorenko committed
51 52 53 54
  end

  step 'I should see project "Archive"' do
    project = Project.find_by(name: "Archive")
55
    expect(page).to have_content project.full_name
Artem Sidorenko's avatar
Artem Sidorenko committed
56 57
  end

58 59 60 61 62
  # ----------------------------------------
  # Visibility level
  # ----------------------------------------

  step 'private project "Enterprise"' do
63
    create(:project, :private, :repository, name: 'Enterprise')
64 65 66
  end

  step 'I should see project "Enterprise"' do
67
    expect(page).to have_content "Enterprise"
68 69 70
  end

  step 'I should not see project "Enterprise"' do
71
    expect(page).not_to have_content "Enterprise"
72 73 74
  end

  step 'internal project "Internal"' do
75
    create(:project, :internal, :repository, name: 'Internal')
76 77 78
  end

  step 'I should see project "Internal"' do
79 80 81
    page.within '.js-projects-list-holder' do
      expect(page).to have_content "Internal"
    end
82 83 84
  end

  step 'I should not see project "Internal"' do
85 86 87
    page.within '.js-projects-list-holder' do
      expect(page).not_to have_content "Internal"
    end
88 89 90
  end

  step 'public project "Community"' do
91
    create(:project, :public, :repository, name: 'Community')
92 93 94
  end

  step 'I should see project "Community"' do
95
    expect(page).to have_content "Community"
96 97 98
  end

  step 'I should not see project "Community"' do
99
    expect(page).not_to have_content "Community"
100 101
  end

102
  step '"John Doe" owns private project "Enterprise"' do
103 104 105 106
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Enterprise'
    )
107 108
  end

109 110 111 112 113
  step '"Mary Jane" owns private project "Enterprise"' do
    user_owns_project(
      user_name: 'Mary Jane',
      project_name: 'Enterprise'
    )
114 115
  end

116 117 118 119 120 121
  step '"John Doe" owns internal project "Internal"' do
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Internal',
      visibility: :internal
    )
122
  end
Ciro Santilli's avatar
Ciro Santilli committed
123

124 125 126 127 128 129
  step '"John Doe" owns public project "Community"' do
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Community',
      visibility: :public
    )
130 131
  end

Ciro Santilli's avatar
Ciro Santilli committed
132
  step 'public empty project "Empty Public Project"' do
133
    create :project_empty_repo, :public, name: "Empty Public Project"
Ciro Santilli's avatar
Ciro Santilli committed
134
  end
135

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
136 137 138 139 140 141
  step 'project "Shop" has labels: "bug", "feature", "enhancement"' do
    project = Project.find_by(name: "Shop")
    create(:label, project: project, title: 'bug')
    create(:label, project: project, title: 'feature')
    create(:label, project: project, title: 'enhancement')
  end
142

143 144 145 146
  step 'The project is internal' do
    @project.update(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
  end

147 148 149 150 151 152 153 154
  step 'public access for builds is enabled' do
    @project.update(public_builds: true)
  end

  step 'public access for builds is disabled' do
    @project.update(public_builds: false)
  end

155
  def user_owns_project(user_name:, project_name:, visibility: :private)
156
    user = user_exists(user_name, username: user_name.gsub(/\s/, '').underscore)
157
    project = Project.find_by(name: project_name)
158
    project ||= create(:project, visibility, name: project_name, namespace: user.namespace)
159
    project.add_master(user)
160
  end
Nihad Abbasov's avatar
Nihad Abbasov committed
161
end