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

3
feature 'Create New Merge Request', :js do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project, :public, :repository) }
6 7

  before do
8
    project.add_master(user)
9

10
    sign_in user
11 12
  end

13
  it 'selects the source branch sha when a tag with the same name exists' do
14
    visit project_merge_requests_path(project)
15

16 17 18
    page.within '.content' do
      click_link 'New merge request'
    end
19 20 21 22
    expect(page).to have_content('Source branch')
    expect(page).to have_content('Target branch')

    first('.js-source-branch').click
23
    find('.dropdown-source-branch .dropdown-content a', match: :first).click
24 25 26 27 28

    expect(page).to have_content "b83d6e3"
  end

  it 'selects the target branch sha when a tag with the same name exists' do
29
    visit project_merge_requests_path(project)
Luke "Jared" Bennett's avatar
Luke "Jared" Bennett committed
30

31 32 33
    page.within '.content' do
      click_link 'New merge request'
    end
34 35 36 37 38

    expect(page).to have_content('Source branch')
    expect(page).to have_content('Target branch')

    first('.js-target-branch').click
39
    find('.dropdown-target-branch .dropdown-content a', text: 'v1.1.0', match: :first).click
40 41 42 43

    expect(page).to have_content "b83d6e3"
  end

44
  it 'generates a diff for an orphaned branch' do
45
    visit project_merge_requests_path(project)
46

47 48 49
    page.within '.content' do
      click_link 'New merge request'
    end
Phil Hughes's avatar
Phil Hughes committed
50 51
    expect(page).to have_content('Source branch')
    expect(page).to have_content('Target branch')
Phil Hughes's avatar
Phil Hughes committed
52

53 54
    find('.js-source-branch', match: :first).click
    find('.dropdown-source-branch .dropdown-content a', text: 'orphaned-branch', match: :first).click
Phil Hughes's avatar
Phil Hughes committed
55

56
    click_button "Compare branches"
Phil Hughes's avatar
Phil Hughes committed
57
    click_link "Changes"
58 59 60 61 62 63 64

    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
65 66
    click_link "Check out branch"

67 68
    expect(page).to have_content 'git checkout -b orphaned-branch origin/orphaned-branch'
  end
69

70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
  it 'allows filtering multiple dropdowns' do
    visit project_new_merge_request_path(project)

    first('.js-source-branch').click

    input = find('.dropdown-source-branch .dropdown-input-field')
    input.click
    input.send_keys('orphaned-branch')

    find('.dropdown-source-branch .dropdown-content li', match: :first)
    source_items = all('.dropdown-source-branch .dropdown-content li')

    expect(source_items.count).to eq(1)

    first('.js-target-branch').click

    find('.dropdown-target-branch .dropdown-content li', match: :first)
    target_items = all('.dropdown-target-branch .dropdown-content li')

    expect(target_items.count).to be > 1
  end

92 93
  context 'when approvals are disabled for the target project' do
    it 'does not show approval settings' do
94
      visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'feature_conflict' })
95 96 97 98 99 100

      expect(page).not_to have_content('Approvers')
    end
  end

  context 'when approvals are enabled for the target project' do
101 102
    before do
      project.update_attributes(approvals_before_merge: 1)
103

104
      visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'feature_conflict' })
105
    end
106

107
    it 'shows approval settings' do
108 109
      expect(page).to have_content('Approvers')
    end
110 111 112 113 114 115 116 117 118

    context 'saving the MR' do
      it 'shows the saved MR' do
        fill_in 'merge_request_title', with: 'Test'
        click_button 'Submit merge request'

        expect(page).to have_link('Close merge request')
      end
    end
119 120
  end

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

125
      visit project_new_merge_request_path(project, merge_request: { target_project_id: private_project.id })
126

127 128
      expect(page).not_to have_content private_project.full_path
      expect(page).to have_content project.full_path
129 130 131 132 133
    end
  end

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

136
      visit project_new_merge_request_path(project, merge_request: { source_project_id: private_project.id })
137

138 139
      expect(page).not_to have_content private_project.full_path
      expect(page).to have_content project.full_path
140 141
    end
  end
142

143
  it 'populates source branch button' do
144
    visit project_new_merge_request_path(project, change_branches: true, merge_request: { target_branch: 'master', source_branch: 'fix' })
145 146 147 148

    expect(find('.js-source-branch')).to have_content('fix')
  end

149
  it 'allows to change the diff view' do
150
    visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'fix' })
151 152 153

    click_link 'Changes'

154 155
    expect(page).to have_css('a.btn.active', text: 'Inline')
    expect(page).not_to have_css('a.btn.active', text: 'Side-by-side')
156 157 158

    click_link 'Side-by-side'

Alfredo Sumaran's avatar
Alfredo Sumaran committed
159 160 161 162
    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
163
  end
164 165

  it 'does not allow non-existing branches' do
166
    visit project_new_merge_request_path(project, merge_request: { target_branch: 'non-exist-target', source_branch: 'non-exist-source' })
167 168 169 170 171

    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
172 173 174

  context 'when a branch contains commits that both delete and add the same image' do
    it 'renders the diff successfully' do
175
      visit project_new_merge_request_path(project, merge_request: { target_branch: 'master', source_branch: 'deleted-image-test' })
176 177 178 179 180 181

      click_link "Changes"

      expect(page).to have_content "6049019_460s.jpg"
    end
  end
182 183 184

  # Isolates a regression (see #24627)
  it 'does not show error messages on initial form' do
185
    visit project_new_merge_request_path(project)
186 187 188
    expect(page).not_to have_selector('#error_explanation')
    expect(page).not_to have_content('The form contains the following error')
  end
189 190 191 192 193 194 195 196 197

  context 'when a new merge request has a pipeline' do
    let!(:pipeline) do
      create(:ci_pipeline, sha: project.commit('fix').id,
                           ref: 'fix',
                           project: project)
    end

    it 'shows pipelines for a new merge request' do
198 199
      visit project_new_merge_request_path(
        project,
200 201 202 203
        merge_request: { target_branch: 'master', source_branch: 'fix' })

      page.within('.merge-request') do
        click_link 'Pipelines'
204
        wait_for_requests
205 206 207 208 209

        expect(page).to have_content "##{pipeline.id}"
      end
    end
  end
210
end