summaryrefslogtreecommitdiff
path: root/spec/frontend/fixtures/issues.rb
blob: 8bedb802242d013afb261428cbd99c487bb4fedd (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::IssuesController, '(JavaScript fixtures)', type: :controller do
  include JavaScriptFixturesHelpers

  let(:user) { create(:user, feed_token: 'feedtoken:coldfeed') }
  let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
  let(:project) { create(:project_empty_repo, namespace: namespace, path: 'issues-project') }

  render_views

  before do
    project.add_maintainer(user)
    sign_in(user)
  end

  after do
    remove_repository(project)
  end

  it 'issues/new-issue.html' do
    get :new, params: {
      namespace_id: project.namespace.to_param,
      project_id: project
    }

    expect(response).to be_successful
  end

  it 'issues/open-issue.html' do
    render_issue(create(:issue, project: project))
  end

  it 'issues/closed-issue.html' do
    render_issue(create(:closed_issue, project: project))
  end

  private

  def render_issue(issue)
    get :show, params: {
      namespace_id: project.namespace.to_param,
      project_id: project,
      id: issue.to_param
    }

    expect(response).to be_successful
  end
end

RSpec.describe API::Issues, '(JavaScript fixtures)', type: :request do
  include ApiHelpers
  include JavaScriptFixturesHelpers

  def get_related_merge_requests(project_id, issue_iid, user = nil)
    get api("/projects/#{project_id}/issues/#{issue_iid}/related_merge_requests", user)
  end

  def create_referencing_mr(user, project, issue)
    attributes = {
      author: user,
      source_project: project,
      target_project: project,
      source_branch: "master",
      target_branch: "test",
      assignee: user,
      description: "See #{issue.to_reference}"
    }
    create(:merge_request, attributes).tap do |merge_request|
      create(:note, :system, project: issue.project, noteable: issue, author: user, note: merge_request.to_reference(full: true))
    end
  end

  it 'issues/related_merge_requests.json' do
    user = create(:user)
    project = create(:project, :public, creator_id: user.id, namespace: user.namespace)
    issue_title = 'foo'
    issue_description = 'closed'
    milestone = create(:milestone, title: '1.0.0', project: project)
    issue = create :issue,
            author: user,
            assignees: [user],
            project: project,
            milestone: milestone,
            created_at: generate(:past_time),
            updated_at: 1.hour.ago,
            title: issue_title,
            description: issue_description

    project.add_reporter(user)
    create_referencing_mr(user, project, issue)

    create(:merge_request,
           :simple,
           author: user,
           source_project: project,
           target_project: project,
           description: "Some description")
    project2 = create(:project, :public, creator_id: user.id, namespace: user.namespace)
    create_referencing_mr(user, project2, issue).update!(head_pipeline: create(:ci_pipeline))

    get_related_merge_requests(project.id, issue.iid, user)

    expect(response).to be_successful
  end
end