Welcome to mirror list, hosted at ThFree Co, Russian Federation.

redirects_spec.rb « show « projects « features « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef326b92b984e8f7298ee57bbfadf4365d38e11a (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
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Projects > Show > Redirects', feature_category: :groups_and_projects do
  let(:user) { create :user }
  let(:public_project) { create :project, :public }
  let(:private_project) { create :project, :private }

  before do
    allow(Gitlab.config.gitlab).to receive(:host).and_return('www.example.com')
  end

  it 'shows public project page' do
    visit project_path(public_project)

    page.within '.breadcrumbs .breadcrumb-item-text' do
      expect(page).to have_content(public_project.name)
    end
  end

  it 'redirects to sign in page when project is private' do
    visit project_path(private_project)

    expect(page).to have_current_path(new_user_session_path, ignore_query: true)
  end

  it 'redirects to sign in page when project does not exist' do
    visit project_path(build(:project, :public))

    expect(page).to have_current_path(new_user_session_path, ignore_query: true)
  end

  it 'redirects to public project page after signing in' do
    visit project_path(public_project)

    first(:link, 'Sign in').click

    fill_in 'user_login',    with: user.email
    fill_in 'user_password', with: user.password
    click_button 'Sign in'

    expect(status_code).to eq(200)
    expect(page).to have_current_path("/#{public_project.full_path}", ignore_query: true)
  end

  it 'redirects to private project page after sign in' do
    visit project_path(private_project)

    owner = private_project.first_owner
    fill_in 'user_login',    with: owner.email
    fill_in 'user_password', with: owner.password
    click_button 'Sign in'

    expect(status_code).to eq(200)
    expect(page).to have_current_path("/#{private_project.full_path}", ignore_query: true)
  end

  context 'when signed in' do
    before do
      sign_in(user)
    end

    it 'returns 404 status when project does not exist' do
      visit project_path(build(:project, :public))

      expect(status_code).to eq(404)
    end

    it 'returns 404 when project is private' do
      visit project_path(private_project)

      expect(status_code).to eq(404)
    end
  end
end