summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2017-01-16 16:43:03 -0200
committerFelipe Artur <felipefac@gmail.com>2017-02-24 15:13:42 -0300
commit0d000d351ca587ff7a6d4a14ad3cfa693238eec0 (patch)
tree9f28fd85600e2ff74867219a1f7fcf1142fb54da /spec/support
parent61e2a3eb15b2b7661523214c86c0f4f3d5ecc525 (diff)
downloadgitlab-ce-0d000d351ca587ff7a6d4a14ad3cfa693238eec0.tar.gz
Fix issuable stale object error handler for js when updating tasklistsissue_24815
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/update_invalid_issuable.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/support/update_invalid_issuable.rb b/spec/support/update_invalid_issuable.rb
new file mode 100644
index 00000000000..f984ac7bfa7
--- /dev/null
+++ b/spec/support/update_invalid_issuable.rb
@@ -0,0 +1,57 @@
+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
+
+ expect(response).to render_template(:edit)
+ expect(assigns[:conflict]).to be_truthy
+ end
+
+ it 'renders json error message when format is json' do
+ params.merge!(format: "json")
+
+ put :update, params
+
+ expect(response.status).to eq(409)
+ expect(JSON.parse(response.body)).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
+
+ expect(response).to render_template(:edit)
+ end
+ end
+end