Read about our upcoming Code of Conduct on this issue

create_new_mr_spec.rb 3.09 KB
Newer Older
1
2
require 'spec_helper'

Phil Hughes's avatar
Phil Hughes committed
3
feature 'Create New Merge Request', feature: true, js: true do
4
5
6
7
8
9
10
11
12
13
  let(:user) { create(:user) }
  let(:project) { create(:project, :public) }

  before do
    project.team << [user, :master]

    login_as user
  end

  it 'generates a diff for an orphaned branch' do
14
15
    visit namespace_project_merge_requests_path(project.namespace, project)

16
    click_link 'New Merge Request'
Phil Hughes's avatar
Phil Hughes committed
17
18
    expect(page).to have_content('Source branch')
    expect(page).to have_content('Target branch')
Phil Hughes's avatar
Phil Hughes committed
19
20
21
22

    first('.js-source-branch').click
    first('.dropdown-source-branch .dropdown-content a', text: 'orphaned-branch').click

23
    click_button "Compare branches"
Phil Hughes's avatar
Phil Hughes committed
24
    click_link "Changes"
25
26
27
28
29
30
31

    expect(page).to have_content "README.md"
    expect(page).to have_content "wm.png"

    fill_in "merge_request_title", with: "Orphaned MR test"
    click_button "Submit merge request"

Phil Hughes's avatar
Phil Hughes committed
32
33
    click_link "Check out branch"

34
35
    expect(page).to have_content 'git checkout -b orphaned-branch origin/orphaned-branch'
  end
36
37
38
39
40
41
42

  context 'when target project cannot be viewed by the current user' do
    it 'does not leak the private project name & namespace' do
      private_project = create(:project, :private)

      visit new_namespace_project_merge_request_path(project.namespace, project, merge_request: { target_project_id: private_project.id })

43
      expect(page).not_to have_content private_project.path_with_namespace
44
45
    end
  end
46
47
48
49
50
51

  it 'allows to change the diff view' do
    visit new_namespace_project_merge_request_path(project.namespace, project, merge_request: { target_branch: 'master', source_branch: 'fix' })

    click_link 'Changes'

52
53
    expect(page).to have_css('a.btn.active', text: 'Inline')
    expect(page).not_to have_css('a.btn.active', text: 'Side-by-side')
54
55
56

    click_link 'Side-by-side'

Alfredo Sumaran's avatar
Alfredo Sumaran committed
57
58
59
60
    within '.merge-request' do
      expect(page).not_to have_css('a.btn.active', text: 'Inline')
      expect(page).to have_css('a.btn.active', text: 'Side-by-side')
    end
61
  end
62
63
64
65
66
67
68
69

  it 'does not allow non-existing branches' do
    visit new_namespace_project_merge_request_path(project.namespace, project, merge_request: { target_branch: 'non-exist-target', source_branch: 'non-exist-source' })

    expect(page).to have_content('The form contains the following errors')
    expect(page).to have_content('Source branch "non-exist-source" does not exist')
    expect(page).to have_content('Target branch "non-exist-target" does not exist')
  end
70
71
72
73
74
75
76
77
78
79

  context 'when a branch contains commits that both delete and add the same image' do
    it 'renders the diff successfully' do
      visit new_namespace_project_merge_request_path(project.namespace, project, merge_request: { target_branch: 'master', source_branch: 'deleted-image-test' })

      click_link "Changes"

      expect(page).to have_content "6049019_460s.jpg"
    end
  end
80
81
82
83
84
85
86

  # Isolates a regression (see #24627)
  it 'does not show error messages on initial form' do
    visit new_namespace_project_merge_request_path(project.namespace, project)
    expect(page).not_to have_selector('#error_explanation')
    expect(page).not_to have_content('The form contains the following error')
  end
87
end