project_merge_requests.rb 6.1 KB
Newer Older
1
class ProjectMergeRequests < Spinach::FeatureSteps
N
Nihad Abbasov 已提交
2 3 4 5 6
  include SharedAuthentication
  include SharedProject
  include SharedNote
  include SharedPaths

7
  step 'I click link "New Merge Request"' do
R
Riyad Preukschas 已提交
8
    click_link "New Merge Request"
9 10
  end

11
  step 'I click link "Bug NS-04"' do
R
Riyad Preukschas 已提交
12 13 14
    click_link "Bug NS-04"
  end

15
  step 'I click link "All"' do
R
Riyad Preukschas 已提交
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
S
skv 已提交
30
    merge_request = MergeRequest.find_by!(title: "Bug NS-04")
31
    merge_request.closed?.should be_true
R
Riyad Preukschas 已提交
32
    page.should have_content "Closed by"
33 34
  end

35
  step 'I should see merge request "Bug NS-04"' do
R
Riyad Preukschas 已提交
36
    page.should have_content "Bug NS-04"
37 38
  end

39
  step 'I should see "Bug NS-04" in merge requests' do
R
Riyad Preukschas 已提交
40
    page.should have_content "Bug NS-04"
41 42
  end

43
  step 'I should see "Feature NS-03" in merge requests' do
R
Riyad Preukschas 已提交
44
    page.should have_content "Feature NS-03"
45 46
  end

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

R
Riyad Preukschas 已提交
51

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

56
  step 'I click link "Close"' do
R
Riyad Preukschas 已提交
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"

I
Izaak Alpert 已提交
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
I
Izaak Alpert 已提交
73
    find(:select, "merge_request_target_branch", {}).find(:option, "notes_refactoring", {}).value.should == "notes_refactoring"
74
    select "notes_refactoring", from: "merge_request_target_branch"
I
Izaak Alpert 已提交
75

76
    click_button "Submit merge request"
77 78
  end

79
  step 'project "Shop" have "Bug NS-04" open merge request' do
A
Andrew8xx8 已提交
80
    create(:merge_request,
R
Riyad Preukschas 已提交
81
           title: "Bug NS-04",
I
Izaak Alpert 已提交
82 83
           source_project: project,
           target_project: project,
D
Dmitriy Zaporozhets 已提交
84 85
           source_branch: 'stable',
           target_branch: 'master',
R
Riyad Preukschas 已提交
86 87 88
           author: project.users.first)
  end

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

97
  step 'project "Shop" have "Feature NS-03" closed merge request' do
A
Andrew8xx8 已提交
98
    create(:closed_merge_request,
R
Riyad Preukschas 已提交
99
           title: "Feature NS-03",
I
Izaak Alpert 已提交
100 101
           source_project: project,
           target_project: project,
A
Andrew8xx8 已提交
102
           author: project.users.first)
R
Riyad Preukschas 已提交
103 104
  end

105
  step 'I switch to the diff tab' do
106
    visit diffs_project_merge_request_path(project, merge_request)
R
Riyad Preukschas 已提交
107 108
  end

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

113
  step 'I click on the first commit in the merge request' do
D
Dmitriy Zaporozhets 已提交
114 115 116
    within '.first-commits' do
      click_link merge_request.commits.first.short_id(8)
    end
R
Riyad Preukschas 已提交
117 118
  end

119
  step 'I leave a comment on the diff page' do
120
    init_diff_note
D
Dmitriy Zaporozhets 已提交
121 122
    leave_comment "One comment to rule them all"
  end
D
Dmitriy Zaporozhets 已提交
123

D
Dmitriy Zaporozhets 已提交
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"
R
Riyad Preukschas 已提交
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
D
Dmitriy Zaporozhets 已提交
131 132
    leave_comment "Line is wrong"
  end
R
Riyad Preukschas 已提交
133

D
Dmitriy Zaporozhets 已提交
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"
R
Riyad Preukschas 已提交
137 138
  end

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

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

D
Dmitriy Zaporozhets 已提交
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"
R
Riyad Preukschas 已提交
153
    page.should have_content "One comment to rule them all"
D
Dmitriy Zaporozhets 已提交
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
  def project
S
skv 已提交
181
    @project ||= Project.find_by!(name: "Shop")
182 183 184
  end

  def merge_request
S
skv 已提交
185
    @merge_request ||= MergeRequest.find_by!(title: "Bug NS-05")
186
  end
187 188

  def init_diff_note
D
Dmitriy Zaporozhets 已提交
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