2019-07-25 05:27:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-16 18:43:03 +00:00
|
|
|
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
|
2017-06-21 13:48:12 +00:00
|
|
|
allow_any_instance_of(issuable.class).to receive(:save)
|
|
|
|
.and_raise(ActiveRecord::StaleObjectError.new(issuable, :save))
|
2017-01-16 18:43:03 +00:00
|
|
|
end
|
|
|
|
|
2017-10-26 11:04:07 +00:00
|
|
|
it 'renders edit when format is html' do
|
2018-12-17 22:52:17 +00:00
|
|
|
put :update, params: params
|
2017-01-16 18:43:03 +00:00
|
|
|
|
2017-10-26 11:04:07 +00:00
|
|
|
expect(response).to render_template(:edit)
|
|
|
|
expect(assigns[:conflict]).to be_truthy
|
2017-01-16 18:43:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders json error message when format is json' do
|
2017-02-27 15:57:04 +00:00
|
|
|
params[:format] = "json"
|
2017-01-16 18:43:03 +00:00
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
put :update, params: params
|
2017-01-16 18:43:03 +00:00
|
|
|
|
|
|
|
expect(response.status).to eq(409)
|
2019-07-16 08:03:49 +00:00
|
|
|
expect(json_response).to have_key('errors')
|
2017-01-16 18:43:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-26 11:04:07 +00:00
|
|
|
context 'when updating an invalid issuable' do
|
|
|
|
before do
|
|
|
|
key = klass == Issue ? :issue : :merge_request
|
|
|
|
params[key][:title] = ""
|
|
|
|
end
|
2017-01-16 18:43:03 +00:00
|
|
|
|
2017-10-26 11:04:07 +00:00
|
|
|
it 'renders edit when merge request is invalid' do
|
2018-12-17 22:52:17 +00:00
|
|
|
put :update, params: params
|
2017-01-16 18:43:03 +00:00
|
|
|
|
2017-10-26 11:04:07 +00:00
|
|
|
expect(response).to render_template(:edit)
|
2017-01-16 18:43:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|