BigW Consortium Gitlab

project.rb 8.34 KB
Newer Older
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.team << [@user, :master]
8 9
  end

10 11 12 13 14 15
  step "I own a project in some group namespace" do
    @group = create(:group, name: 'some group')
    @project = create(:project, namespace: @group)
    @project.team << [@user, :master]
  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 committed
23
    @project = Project.find_by(name: "Shop")
24
    @project ||= create(:project, :repository, name: "Shop", namespace: @user.namespace)
25
    @project.team << [@user, :master]
Nihad Abbasov committed
26
  end
27

28 29 30 31 32
  step 'I disable snippets in project' do
    @project.snippets_enabled = false
    @project.save
  end

33 34 35 36 37 38
  step 'I disable issues and merge requests in project' do
    @project.issues_enabled = false
    @project.merge_requests_enabled = false
    @project.save
  end

39 40 41 42 43 44 45
  # 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

46
  # Create another specific project called "Forum"
47
  step 'I own project "Forum"' do
skv committed
48
    @project = Project.find_by(name: "Forum")
49
    @project ||= create(:project, :repository, name: "Forum", namespace: @user.namespace, path: 'forum_project')
50 51
    @project.build_project_feature
    @project.project_feature.save
52 53 54
    @project.team << [@user, :master]
  end

55
  # Create an empty project without caring about the name
56
  step 'I own an empty project' do
57 58 59 60 61
    @project = create(:empty_project,
                      name: 'Empty Project', namespace: @user.namespace)
    @project.team << [@user, :master]
  end

62
  step 'I visit my empty project page' do
Vinnie Okada committed
63 64
    project = Project.find_by(name: 'Empty Project')
    visit namespace_project_path(project.namespace, project)
65 66
  end

67 68 69 70 71
  step 'I visit project "Shop" activity page' do
    project = Project.find_by(name: 'Shop')
    visit namespace_project_path(project.namespace, project)
  end

72
  step 'project "Shop" has push event' do
skv committed
73
    @project = Project.find_by(name: "Shop")
74 75

    data = {
76
      before: Gitlab::Git::BLANK_SHA,
77 78
      after: "6d394385cf567f80a8fd85055db1ab4c5295806f",
      ref: "refs/heads/fix",
79 80 81 82 83 84 85 86 87 88 89 90 91
      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,
92
      action: Event::PUSHED,
93 94 95 96 97
      data: data,
      author_id: @user.id
    )
  end

98
  step 'I should see project "Shop" activity feed' do
skv committed
99
    project = Project.find_by(name: "Shop")
100
    expect(page).to have_content "#{@user.name} pushed new branch fix at #{project.name_with_namespace}"
101 102
  end

103
  step 'I should see project settings' do
104 105
    expect(current_path).to eq edit_namespace_project_path(@project.namespace, @project)
    expect(page).to have_content("Project name")
Luke "Jared" Bennett committed
106
    expect(page).to have_content("Sharing & Permissions")
107 108
  end

109 110 111
  def current_project
    @project ||= Project.first
  end
112

113 114 115 116 117 118 119 120 121 122 123 124
  # ----------------------------------------
  # 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 committed
125 126 127 128 129
  # ----------------------------------------
  # Visibility of archived project
  # ----------------------------------------

  step 'archived project "Archive"' do
130
    create(:project, :archived, :public, :repository, name: 'Archive')
Artem Sidorenko committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  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

148 149 150 151 152
  # ----------------------------------------
  # Visibility level
  # ----------------------------------------

  step 'private project "Enterprise"' do
153
    create(:project, :private, :repository, name: 'Enterprise')
154 155 156
  end

  step 'I should see project "Enterprise"' do
157
    expect(page).to have_content "Enterprise"
158 159 160
  end

  step 'I should not see project "Enterprise"' do
161
    expect(page).not_to have_content "Enterprise"
162 163 164
  end

  step 'internal project "Internal"' do
165
    create(:project, :internal, :repository, name: 'Internal')
166 167 168
  end

  step 'I should see project "Internal"' do
169 170 171
    page.within '.js-projects-list-holder' do
      expect(page).to have_content "Internal"
    end
172 173 174
  end

  step 'I should not see project "Internal"' do
175 176 177
    page.within '.js-projects-list-holder' do
      expect(page).not_to have_content "Internal"
    end
178 179 180
  end

  step 'public project "Community"' do
181
    create(:project, :public, :repository, name: 'Community')
182 183 184
  end

  step 'I should see project "Community"' do
185
    expect(page).to have_content "Community"
186 187 188
  end

  step 'I should not see project "Community"' do
189
    expect(page).not_to have_content "Community"
190 191
  end

192
  step '"John Doe" owns private project "Enterprise"' do
193 194 195 196
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Enterprise'
    )
197 198
  end

199 200 201 202 203
  step '"Mary Jane" owns private project "Enterprise"' do
    user_owns_project(
      user_name: 'Mary Jane',
      project_name: 'Enterprise'
    )
204 205
  end

206 207 208 209 210 211
  step '"John Doe" owns internal project "Internal"' do
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Internal',
      visibility: :internal
    )
212
  end
Ciro Santilli committed
213

214 215 216 217 218 219
  step '"John Doe" owns public project "Community"' do
    user_owns_project(
      user_name: 'John Doe',
      project_name: 'Community',
      visibility: :public
    )
220 221
  end

Ciro Santilli committed
222
  step 'public empty project "Empty Public Project"' do
223
    create :project_empty_repo, :public, name: "Empty Public Project"
Ciro Santilli committed
224
  end
225 226 227 228 229

  step 'project "Community" has comments' do
    project = Project.find_by(name: "Community")
    2.times { create(:note_on_issue, project: project) }
  end
Dmitriy Zaporozhets committed
230

231 232 233 234
  step 'trending projects are refreshed' do
    TrendingProject.refresh!
  end

Dmitriy Zaporozhets committed
235 236 237 238 239 240
  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
241

Phil Hughes committed
242 243 244 245 246
  step 'project "Shop" has issue: "bug report"' do
    project = Project.find_by(name: "Shop")
    create(:issue, project: project, title: "bug report")
  end

247 248
  step 'project "Shop" has CI enabled' do
    project = Project.find_by(name: "Shop")
249
    project.enable_ci
250 251 252 253
  end

  step 'project "Shop" has CI build' do
    project = Project.find_by(name: "Shop")
254 255
    pipeline = create :ci_pipeline, project: project, sha: project.commit.sha, ref: 'master'
    pipeline.skip
256
  end
257 258

  step 'I should see last commit with CI status' do
259
    page.within ".blob-commit-info" do
260
      expect(page).to have_content(project.commit.sha[0..6])
261
      expect(page).to have_link("Commit: skipped")
262 263
    end
  end
264

265 266 267 268
  step 'The project is internal' do
    @project.update(visibility_level: Gitlab::VisibilityLevel::INTERNAL)
  end

269 270 271 272 273 274 275 276
  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

Luke "Jared" Bennett committed
277 278 279 280
  step 'project "Shop" has a "Bugfix MR" merge request open' do
    create(:merge_request, title: "Bugfix MR", target_project: project, source_project: project, author: project.users.first)
  end

281
  def user_owns_project(user_name:, project_name:, visibility: :private)
282
    user = user_exists(user_name, username: user_name.gsub(/\s/, '').underscore)
283 284 285 286
    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 committed
287
end