BigW Consortium Gitlab

assign_issues_spec.rb 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
require 'rails_helper'

feature 'Merge request issue assignment', js: true, feature: true do
  let(:user) { create(:user) }
  let(:project) { create(:project, :public) }
  let(:issue1) { create(:issue, project: project) }
  let(:issue2) { create(:issue, project: project) }
  let(:merge_request) { create(:merge_request, :simple, source_project: project, author: user, description: "fixes #{issue1.to_reference} and #{issue2.to_reference}") }
  let(:service) { MergeRequests::AssignIssuesService.new(merge_request, user, user, project) }

  before do
    project.team << [user, :developer]
  end

  def visit_merge_request(current_user = nil)
    login_as(current_user || user)
    visit namespace_project_merge_request_path(project.namespace, project, merge_request)
  end

  context 'logged in as author' do
    scenario 'updates related issues' do
      visit_merge_request
      click_link "Assign yourself to these issues"

      expect(page).to have_content "2 issues have been assigned to you"
    end

    it 'returns user to the merge request' do
      visit_merge_request
      click_link "Assign yourself to these issues"

      expect(page).to have_content merge_request.description
    end

    it "doesn't display if related issues are already assigned" do
      [issue1, issue2].each { |issue| issue.update!(assignee: user) }

      visit_merge_request

      expect(page).not_to have_content "Assign yourself"
    end
  end

  context 'not MR author' do
    it "doesn't not show assignment link" do
      visit_merge_request(create(:user))

      expect(page).not_to have_content "Assign yourself"
    end
  end
end