forked_merge_requests.rb 6.34 KB
Newer Older
1
class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps
2 3 4 5
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths
6
  include Select2Helper
7

8
  step 'I am a member of project "Shop"' do
skv's avatar
skv committed
9
    @project = Project.find_by(name: "Shop")
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
10
    @project ||= create(:project, name: "Shop")
11 12 13
    @project.team << [@user, :reporter]
  end

14
  step 'I have a project forked off of "Shop" called "Forked Shop"' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
    @forked_project = Projects::ForkService.new(@project, @user).execute
16 17
  end

18
  step 'I click link "New Merge Request"' do
19 20 21
    click_link "New Merge Request"
  end

22
  step 'I should see merge request "Merge Request On Forked Project"' do
23
    expect(@project.merge_requests.size).to be >= 1
24
    @merge_request = @project.merge_requests.last
25 26 27 28 29 30 31 32 33
    expect(current_path).to eq namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
    expect(@merge_request.title).to eq "Merge Request On Forked Project"
    expect(@merge_request.source_project).to eq @forked_project
    expect(@merge_request.source_branch).to eq "fix"
    expect(@merge_request.target_branch).to eq "master"
    expect(page).to have_content @forked_project.path_with_namespace
    expect(page).to have_content @project.path_with_namespace
    expect(page).to have_content @merge_request.source_branch
    expect(page).to have_content @merge_request.target_branch
34 35
  end

36
  step 'I fill out a "Merge Request On Forked Project" merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
37 38 39 40
    select @forked_project.path_with_namespace, from: "merge_request_source_project_id"
    select @project.path_with_namespace, from: "merge_request_target_project_id"
    select "fix", from: "merge_request_source_branch"
    select "master", from: "merge_request_target_branch"
41

42
    click_button "Compare branches"
Izaak Alpert's avatar
Izaak Alpert committed
43

44
    expect(page).to have_content "New merge request"
45
    fill_in "merge_request_title", with: "Merge Request On Forked Project"
46 47
  end

48
  step 'I submit the merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
49
    click_button "Submit new merge request"
50 51
  end

52
  step 'I follow the target commit link' do
53 54 55 56
    commit = @project.repository.commit
    click_link commit.short_id(8)
  end

57
  step 'I should see the commit under the forked from project' do
58
    commit = @project.repository.commit
59
    expect(page).to have_content(commit.message)
60 61
  end

62
  step 'I click "Create Merge Request on fork" link' do
63 64 65
    click_link "Create Merge Request on fork"
  end

66
  step 'I see prefilled new Merge Request page for the forked project' do
67 68 69 70 71 72
    expect(current_path).to eq new_namespace_project_merge_request_path(@forked_project.namespace, @forked_project)
    expect(find("#merge_request_source_project_id").value).to eq @forked_project.id.to_s
    expect(find("#merge_request_target_project_id").value).to eq @project.id.to_s
    expect(find("#merge_request_source_branch").value).to have_content "new_design"
    expect(find("#merge_request_target_branch").value).to have_content "master"
    expect(find("#merge_request_title").value).to eq "New Design"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
73 74
    verify_commit_link(".mr_target_commit", @project)
    verify_commit_link(".mr_source_commit", @forked_project)
75 76
  end

77
  step 'I update the merge request title' do
78 79 80
    fill_in "merge_request_title", with: "An Edited Forked Merge Request"
  end

81
  step 'I save the merge request' do
82 83 84
    click_button "Save changes"
  end

85
  step 'I should see the edited merge request' do
86 87
    expect(page).to have_content "An Edited Forked Merge Request"
    expect(@project.merge_requests.size).to be >= 1
88
    @merge_request = @project.merge_requests.last
89 90 91 92 93 94 95 96
    expect(current_path).to eq namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
    expect(@merge_request.source_project).to eq @forked_project
    expect(@merge_request.source_branch).to eq "fix"
    expect(@merge_request.target_branch).to eq "master"
    expect(page).to have_content @forked_project.path_with_namespace
    expect(page).to have_content @project.path_with_namespace
    expect(page).to have_content @merge_request.source_branch
    expect(page).to have_content @merge_request.target_branch
97 98
  end

99
  step 'I should see last push widget' do
100 101
    expect(page).to have_content "You pushed to new_design"
    expect(page).to have_link "Create Merge Request"
102 103
  end

104
  step 'I click link edit "Merge Request On Forked Project"' do
Izaak Alpert's avatar
Izaak Alpert committed
105
    find("#edit_merge_request").click
106 107
  end

108
  step 'I see the edit page prefilled for "Merge Request On Forked Project"' do
109 110 111
    expect(current_path).to eq edit_namespace_project_merge_request_path(@project.namespace, @project, @merge_request)
    expect(page).to have_content "Edit merge request ##{@merge_request.id}"
    expect(find("#merge_request_title").value).to eq "Merge Request On Forked Project"
112 113
  end

114
  step 'I fill out an invalid "Merge Request On Forked Project" merge request' do
115
    select "Select branch", from: "merge_request_target_branch"
116 117 118 119
    expect(find(:select, "merge_request_source_project_id", {}).value).to eq @forked_project.id.to_s
    expect(find(:select, "merge_request_target_project_id", {}).value).to eq @project.id.to_s
    expect(find(:select, "merge_request_source_branch", {}).value).to eq ""
    expect(find(:select, "merge_request_target_branch", {}).value).to eq ""
120
    click_button "Compare branches"
Izaak Alpert's avatar
Izaak Alpert committed
121 122
  end

123
  step 'I should see validation errors' do
124
    expect(page).to have_content "You must select source and target branch"
125 126 127
  end

  step 'the target repository should be the original repository' do
128
    expect(page).to have_select("merge_request_target_project_id", selected: @project.path_with_namespace)
Izaak Alpert's avatar
Izaak Alpert committed
129 130
  end

131 132 133 134 135 136 137 138 139
  step 'I click "Assign to" dropdown"' do
    first('.ajax-users-select').click
  end

  step 'I should see the target project ID in the input selector' do
    expect(page).to have_selector("input[data-project-id=\"#{@project.id}\"]")
  end

  step 'I should see the users from the target project ID' do
140
    expect(page).to have_selector('.user-result', visible: true, count: 3)
141
    users = page.all('.user-name')
142
    expect(users[0].text).to eq 'Unassigned'
143 144
    expect(users[1].text).to eq current_user.name
    expect(users[2].text).to eq @project.users.first.name
145 146
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
147
  # Verify a link is generated against the correct project
Izaak Alpert's avatar
Izaak Alpert committed
148
  def verify_commit_link(container_div, container_project)
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
149
    # This should force a wait for the javascript to execute
150
    expect(find(:div,container_div).find(".commit_short_id")['href']).to have_content "#{container_project.path_with_namespace}/commit"
Izaak Alpert's avatar
Izaak Alpert committed
151
  end
152
end