project.rb 7.63 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
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
6
    @project = create(:project, namespace: @user.namespace)
7
    @project.team << [@user, :master]
8 9
  end

10 11 12 13 14
  step "project exists in some group namespace" do
    @group = create(:group, name: 'some group')
    @project = create(:project, namespace: @group)
  end

15
  # Create a specific project called "Shop"
16
  step 'I own project "Shop"' do
skv's avatar
skv committed
17
    @project = Project.find_by(name: "Shop")
18
    @project ||= create(:project, name: "Shop", namespace: @user.namespace)
19
    @project.team << [@user, :master]
Nihad Abbasov's avatar
Nihad Abbasov committed
20
  end
21

22 23 24 25 26
  step 'I disable snippets in project' do
    @project.snippets_enabled = false
    @project.save
  end

27 28 29 30 31 32
  step 'I disable issues and merge requests in project' do
    @project.issues_enabled = false
    @project.merge_requests_enabled = false
    @project.save
  end

33 34 35 36 37 38 39
  # Add another user to project "Shop"
  step 'I add a user to project "Shop"' do
    @project = Project.find_by(name: "Shop")
    other_user = create(:user, name: 'Alpha')
    @project.team << [other_user, :master]
  end

40
  # Create another specific project called "Forum"
41
  step 'I own project "Forum"' do
skv's avatar
skv committed
42
    @project = Project.find_by(name: "Forum")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
43
    @project ||= create(:project, name: "Forum", namespace: @user.namespace, path: 'forum_project')
44 45
    @project.build_project_feature
    @project.project_feature.save
46 47 48
    @project.team << [@user, :master]
  end

49
  # Create an empty project without caring about the name
50
  step 'I own an empty project' do
51 52 53 54 55
    @project = create(:empty_project,
                      name: 'Empty Project', namespace: @user.namespace)
    @project.team << [@user, :master]
  end

56
  step 'I visit my empty project page' do
Vinnie Okada's avatar
Vinnie Okada committed
57 58
    project = Project.find_by(name: 'Empty Project')
    visit namespace_project_path(project.namespace, project)
59 60
  end

61 62 63 64 65
  step 'I visit project "Shop" activity page' do
    project = Project.find_by(name: 'Shop')
    visit namespace_project_path(project.namespace, project)
  end

66
  step 'project "Shop" has push event' do
skv's avatar
skv committed
67
    @project = Project.find_by(name: "Shop")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
68 69

    data = {
70
      before: Gitlab::Git::BLANK_SHA,
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
71 72
      after: "6d394385cf567f80a8fd85055db1ab4c5295806f",
      ref: "refs/heads/fix",
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
73 74 75 76 77 78 79 80 81 82 83 84 85
      user_id: @user.id,
      user_name: @user.name,
      repository: {
        name: @project.name,
        url: "localhost/rubinius",
        description: "",
        homepage: "localhost/rubinius",
        private: true
      }
    }

    @event = Event.create(
      project: @project,
86
      action: Event::PUSHED,
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
87 88 89 90 91
      data: data,
      author_id: @user.id
    )
  end

92
  step 'I should see project "Shop" activity feed' do
skv's avatar
skv committed
93
    project = Project.find_by(name: "Shop")
94
    expect(page).to have_content "#{@user.name} pushed new branch fix at #{project.name_with_namespace}"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
95 96
  end

97
  step 'I should see project settings' do
98 99
    expect(current_path).to eq edit_namespace_project_path(@project.namespace, @project)
    expect(page).to have_content("Project name")
100
    expect(page).to have_content("Feature Visibility")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
101 102
  end

103 104 105
  def current_project
    @project ||= Project.first
  end
106

107 108 109 110 111 112 113 114 115 116 117 118
  # ----------------------------------------
  # Project permissions
  # ----------------------------------------

  step 'I am member of a project with a guest role' do
    @project.team << [@user, Gitlab::Access::GUEST]
  end

  step 'I am member of a project with a reporter role' do
    @project.team << [@user, Gitlab::Access::REPORTER]
  end

Artem Sidorenko's avatar
Artem Sidorenko committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
  # ----------------------------------------
  # Visibility of archived project
  # ----------------------------------------

  step 'archived project "Archive"' do
    create :project, :public, archived: true, name: 'Archive'
  end

  step 'I should not see project "Archive"' do
    project = Project.find_by(name: "Archive")
    expect(page).not_to have_content project.name_with_namespace
  end

  step 'I should see project "Archive"' do
    project = Project.find_by(name: "Archive")
    expect(page).to have_content project.name_with_namespace
  end

  step 'project "Archive" has comments' do
    project = Project.find_by(name: "Archive")
    2.times { create(:note_on_issue, project: project) }
  end

142 143 144 145 146 147 148 149 150
  # ----------------------------------------
  # Visibility level
  # ----------------------------------------

  step 'private project "Enterprise"' do
    create :project, name: 'Enterprise'
  end

  step 'I should see project "Enterprise"' do
151
    expect(page).to have_content "Enterprise"
152 153 154
  end

  step 'I should not see project "Enterprise"' do
155
    expect(page).not_to have_content "Enterprise"
156 157 158
  end

  step 'internal project "Internal"' do
159
    create :project, :internal, name: 'Internal'
160 161 162
  end

  step 'I should see project "Internal"' do
163
    expect(page).to have_content "Internal"
164 165 166
  end

  step 'I should not see project "Internal"' do
167
    expect(page).not_to have_content "Internal"
168 169 170
  end

  step 'public project "Community"' do
171
    create :project, :public, name: 'Community'
172 173 174
  end

  step 'I should see project "Community"' do
175
    expect(page).to have_content "Community"
176 177 178
  end

  step 'I should not see project "Community"' do
179
    expect(page).not_to have_content "Community"
180 181
  end

182
  step '"John Doe" owns private project "Enterprise"' do
183 184 185 186
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Enterprise'
    )
187 188
  end

189 190 191 192 193
  step '"Mary Jane" owns private project "Enterprise"' do
    user_owns_project(
      user_name: 'Mary Jane',
      project_name: 'Enterprise'
    )
194 195
  end

196 197 198 199 200 201
  step '"John Doe" owns internal project "Internal"' do
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Internal',
      visibility: :internal
    )
202
  end
Ciro Santilli's avatar
Ciro Santilli committed
203

204 205 206 207 208 209
  step '"John Doe" owns public project "Community"' do
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Community',
      visibility: :public
    )
210 211
  end

Ciro Santilli's avatar
Ciro Santilli committed
212
  step 'public empty project "Empty Public Project"' do
213
    create :project_empty_repo, :public, name: "Empty Public Project"
Ciro Santilli's avatar
Ciro Santilli committed
214
  end
215 216 217 218 219

  step 'project "Community" has comments' do
    project = Project.find_by(name: "Community")
    2.times { create(:note_on_issue, project: project) }
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
220 221 222 223 224 225 226

  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
227

Phil Hughes's avatar
Phil Hughes committed
228 229 230 231 232
  step 'project "Shop" has issue: "bug report"' do
    project = Project.find_by(name: "Shop")
    create(:issue, project: project, title: "bug report")
  end

233 234
  step 'project "Shop" has CI enabled' do
    project = Project.find_by(name: "Shop")
235
    project.enable_ci
236 237 238 239
  end

  step 'project "Shop" has CI build' do
    project = Project.find_by(name: "Shop")
240
    create :ci_pipeline, project: project, sha: project.commit.sha, ref: 'master', status: 'skipped'
241
  end
242 243 244 245 246 247 248

  step 'I should see last commit with CI status' do
    page.within ".project-last-commit" do
      expect(page).to have_content(project.commit.sha[0..6])
      expect(page).to have_content("skipped")
    end
  end
249

250 251 252 253
  step 'The project is internal' do
    @project.update(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
  end

254 255 256 257 258 259 260 261
  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

262
  def user_owns_project(user_name:, project_name:, visibility: :private)
263
    user = user_exists(user_name, username: user_name.gsub(/\s/, '').underscore)
264 265 266 267
    project = Project.find_by(name: project_name)
    project ||= create(:empty_project, visibility, name: project_name, namespace: user.namespace)
    project.team << [user, :master]
  end
Nihad Abbasov's avatar
Nihad Abbasov committed
268
end