project_merge_requests.rb 6.06 KB
Newer Older
1
class ProjectMergeRequests < Spinach::FeatureSteps
Nihad Abbasov's avatar
Nihad Abbasov committed
2 3 4 5 6
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths

7
  step 'I click link "New Merge Request"' do
8
    click_link "New Merge Request"
9 10
  end

11
  step 'I click link "Bug NS-04"' do
12 13 14
    click_link "Bug NS-04"
  end

15
  step 'I click link "All"' do
16
    click_link "All"
17 18
  end

19
  step 'I click link "Closed"' do
20 21 22
    click_link "Closed"
  end

23
  step 'I should see merge request "Wiki Feature"' do
24 25 26
    within '.merge-request' do
      page.should have_content "Wiki Feature"
    end
27 28
  end

29
  step 'I should see closed merge request "Bug NS-04"' do
30 31
    merge_request = MergeRequest.find_by_title!("Bug NS-04")
    merge_request.closed?.should be_true
32
    page.should have_content "Closed by"
33 34
  end

35
  step 'I should see merge request "Bug NS-04"' do
36
    page.should have_content "Bug NS-04"
37 38
  end

39
  step 'I should see "Bug NS-04" in merge requests' do
40
    page.should have_content "Bug NS-04"
41 42
  end

43
  step 'I should see "Feature NS-03" in merge requests' do
44
    page.should have_content "Feature NS-03"
45 46
  end

47
  step 'I should not see "Feature NS-03" in merge requests' do
48
    page.should_not have_content "Feature NS-03"
49 50
  end

51

52
  step 'I should not see "Bug NS-04" in merge requests' do
53
    page.should_not have_content "Bug NS-04"
54 55
  end

56
  step 'I click link "Close"' do
57
    click_link "Close"
58 59
  end

60
  step 'I submit new merge request "Wiki Feature"' do
61 62 63 64 65 66 67
    fill_in "merge_request_title", with: "Wiki Feature"

    # this must come first, so that the target branch is set
    # by the time the "select" for "notes_refactoring" is executed
    select project.path_with_namespace, from: "merge_request_target_project_id"
    select "master", from: "merge_request_source_branch"

Izaak Alpert's avatar
Izaak Alpert committed
68 69 70
    find(:select, "merge_request_target_project_id", {}).value.should == project.id.to_s
    find(:select, "merge_request_source_project_id", {}).value.should == project.id.to_s

71 72
    # using "notes_refactoring" because "Bug NS-04" uses master/stable,
    # this will fail merge_request validation if the branches are the same
Izaak Alpert's avatar
Izaak Alpert committed
73
    find(:select, "merge_request_target_branch", {}).find(:option, "notes_refactoring", {}).value.should == "notes_refactoring"
74
    select "notes_refactoring", from: "merge_request_target_branch"
Izaak Alpert's avatar
Izaak Alpert committed
75

76
    click_button "Submit merge request"
77 78
  end

79
  step 'project "Shop" have "Bug NS-04" open merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
80
    create(:merge_request,
81
           title: "Bug NS-04",
82 83
           source_project: project,
           target_project: project,
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
84 85
           source_branch: 'stable',
           target_branch: 'master',
86 87 88
           author: project.users.first)
  end

89
  step 'project "Shop" have "Bug NS-05" open merge request with diffs inside' do
90 91
    create(:merge_request_with_diffs,
           title: "Bug NS-05",
92 93
           source_project: project,
           target_project: project,
94
           author: project.users.first)
95 96
  end

97
  step 'project "Shop" have "Feature NS-03" closed merge request' do
Andrew8xx8's avatar
Andrew8xx8 committed
98
    create(:closed_merge_request,
99
           title: "Feature NS-03",
100 101
           source_project: project,
           target_project: project,
Andrew8xx8's avatar
Andrew8xx8 committed
102
           author: project.users.first)
103 104
  end

105
  step 'I switch to the diff tab' do
106
    visit diffs_project_merge_request_path(project, merge_request)
107 108
  end

109
  step 'I switch to the merge request\'s comments tab' do
110
    visit project_merge_request_path(project, merge_request)
111 112
  end

113
  step 'I click on the first commit in the merge request' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
114 115 116
    within '.first-commits' do
      click_link merge_request.commits.first.short_id(8)
    end
117 118
  end

119
  step 'I leave a comment on the diff page' do
120
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
121 122
    leave_comment "One comment to rule them all"
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
123

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
124 125 126
  step 'I leave a comment on the diff page in commit' do
    find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
    leave_comment "One comment to rule them all"
127 128
  end

129
  step 'I leave a comment like "Line is wrong" on line 185 of the first file' do
130
    init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
131 132
    leave_comment "Line is wrong"
  end
133

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
134 135 136
  step 'I leave a comment like "Line is wrong" on line 185 of the first file in commit' do
    find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_185_185"]').click
    leave_comment "Line is wrong"
137 138
  end

139
  step 'I should see a discussion has started on line 185' do
140
    page.should have_content "#{current_user.name} started a discussion on this merge request diff"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
141
    page.should have_content "app/assets/stylesheets/tree.scss:L185"
142 143 144
    page.should have_content "Line is wrong"
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
145
  step 'I should see a discussion has started on commit b1e6a9dbf1:L185' do
146
    page.should have_content "#{current_user.name} started a discussion on commit"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
147
    page.should have_content "app/assets/stylesheets/tree.scss:L185"
148 149 150
    page.should have_content "Line is wrong"
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
151 152
  step 'I should see a discussion has started on commit b1e6a9dbf1' do
    page.should have_content "#{current_user.name} started a discussion on commit"
153
    page.should have_content "One comment to rule them all"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
154
    page.should have_content "app/assets/stylesheets/tree.scss:L185"
155
  end
156

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
  step 'merge request is mergeable' do
    page.should have_content 'You can accept this request automatically'
  end

  step 'I modify merge commit message' do
    find('.modify-merge-commit-link').click
    fill_in 'merge_commit_message', with: "wow such merge"
  end

  step 'merge request "Bug NS-05" is mergeable' do
    merge_request.mark_as_mergeable
  end

  step 'I accept this merge request' do
    click_button "Accept Merge Request"
  end

  step 'I should see merged request' do
    within '.page-title' do
      page.should have_content "Merged"
    end
  end

180 181 182 183 184 185 186
  def project
    @project ||= Project.find_by_name!("Shop")
  end

  def merge_request
    @merge_request ||= MergeRequest.find_by_title!("Bug NS-05")
  end
187 188

  def init_diff_note
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
189 190 191 192 193 194 195 196 197 198 199 200
    find('a[data-line-code="4735dfc552ad7bf15ca468adc3cad9d05b624490_172_185"]').click
  end

  def leave_comment(message)
    within(".js-discussion-note-form") do
      fill_in "note_note", with: message
      click_button "Add Comment"
    end

    within ".note-text" do
      page.should have_content message
    end
201
  end
202
end