Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update_invalid_issuable_shared_examples.rb « controllers « shared_examples « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a0d5b755dbd05f67b0a66ffff0e5e31801b933f (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
# frozen_string_literal: true

RSpec.shared_examples 'update invalid issuable' do |klass|
  let(:params) do
    {
      namespace_id: project.namespace.path,
      project_id: project.path,
      id: issuable.iid
    }
  end

  let(:issuable) do
    klass == Issue ? issue : merge_request
  end

  before do
    if klass == Issue
      params.merge!(issue: { title: "any" })
    else
      params.merge!(merge_request: { title: "any" })
    end
  end

  context 'when updating causes conflicts' do
    before do
      allow_any_instance_of(issuable.class).to receive(:save)
        .and_raise(ActiveRecord::StaleObjectError.new(issuable, :save))
    end

    it 'renders edit when format is html' do
      put :update, params: params

      expect(response).to render_template(:edit)
      expect(assigns[:conflict]).to be_truthy
    end

    it 'renders json error message when format is json' do
      params[:format] = "json"

      put :update, params: params

      expect(response).to have_gitlab_http_status(:conflict)
      expect(json_response).to have_key('errors')
    end
  end

  context 'when updating an invalid issuable' do
    before do
      key = klass == Issue ? :issue : :merge_request
      params[key][:title] = ""
    end

    it 'renders edit when merge request is invalid' do
      put :update, params: params

      expect(response).to render_template(:edit)
    end
  end
end