debian-mirror-gitlab/spec/support/shared_examples/controllers/update_invalid_issuable_shared_examples.rb

60 lines
1.4 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2020-03-13 15:44:24 +05:30
RSpec.shared_examples 'update invalid issuable' do |klass|
2017-08-17 22:00:37 +05:30
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
2017-09-10 17:25:29 +05:30
allow_any_instance_of(issuable.class).to receive(:save)
.and_raise(ActiveRecord::StaleObjectError.new(issuable, :save))
2017-08-17 22:00:37 +05:30
end
it 'renders edit when format is html' do
2019-02-15 15:39:39 +05:30
put :update, params: params
2017-08-17 22:00:37 +05:30
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"
2019-02-15 15:39:39 +05:30
put :update, params: params
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
expect(response).to have_gitlab_http_status(:conflict)
2019-09-30 21:07:59 +05:30
expect(json_response).to have_key('errors')
2017-08-17 22:00:37 +05:30
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
2019-02-15 15:39:39 +05:30
put :update, params: params
2017-08-17 22:00:37 +05:30
expect(response).to render_template(:edit)
end
end
end