From fe96a1f268558526fd122a348866fbf513ac17e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 12 Jan 2018 22:39:42 +0100 Subject: Stub multiple variable controller method --- spec/controllers/projects/variables_controller_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 9fde6544215..97284909b3c 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -55,4 +55,11 @@ describe Projects::VariablesController do end end end + + describe 'POST #save_multiple' do + it 'returns a successful response' do + post :save_multiple, namespace_id: project.namespace.to_param, project_id: project + expect(response).to have_gitlab_http_status(:ok) + end + end end -- cgit v1.2.1 From 121d84d774e18b27a8a4624f173e97cfad0d7f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 13 Jan 2018 01:46:43 +0100 Subject: Implement multiple variable handling action --- .../projects/variables_controller_spec.rb | 55 ++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 97284909b3c..e0294fd4a46 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -57,9 +57,58 @@ describe Projects::VariablesController do end describe 'POST #save_multiple' do - it 'returns a successful response' do - post :save_multiple, namespace_id: project.namespace.to_param, project_id: project - expect(response).to have_gitlab_http_status(:ok) + let(:variable) { create(:ci_variable) } + + before do + project.variables << variable + end + + context 'with invalid new variable parameters' do + subject do + post :save_multiple, + namespace_id: project.namespace.to_param, project_id: project, + variables: [{ key: variable.key, value: 'other_value' }, + { key: '..?', value: 'dummy_value' }], + format: :json + end + + it 'does not update the existing variable' do + expect { subject }.not_to change { variable.reload.value } + end + + it 'does not create the new variable' do + expect { subject }.not_to change { project.variables.count } + end + + it 'returns a bad request response' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context 'with valid new variable parameters' do + subject do + post :save_multiple, + namespace_id: project.namespace.to_param, project_id: project, + variables: [{ key: variable.key, value: 'other_value' }, + { key: 'new_key', value: 'dummy_value' }], + format: :json + end + + it 'updates the existing variable' do + expect { subject }.to change { variable.reload.value }.to('other_value') + end + + it 'creates the new variable' do + expect { subject }.to change { project.variables.count }.by(1) + end + + it 'returns a successful response' do + subject + + expect(response).to have_gitlab_http_status(:ok) + end end end end -- cgit v1.2.1 From ba077841922089c0eb2bbb48947de8828f891776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 13 Jan 2018 03:36:04 +0100 Subject: Add destroy functionality to save_multiple --- .../projects/variables_controller_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index e0294fd4a46..87463f00b8f 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -110,5 +110,25 @@ describe Projects::VariablesController do expect(response).to have_gitlab_http_status(:ok) end end + + context 'with a deleted variable' do + subject do + post :save_multiple, + namespace_id: project.namespace.to_param, project_id: project, + variables: [{ key: variable.key, value: variable.value, _destroy: 'true' }], + format: :json + end + + it 'destroys the variable' do + expect { subject }.to change { project.variables.count }.by(-1) + expect { variable.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'returns a successful response' do + subject + + expect(response).to have_gitlab_http_status(:ok) + end + end end end -- cgit v1.2.1 From 5de85708ce17c1965581b8bf7563751dda77510d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 23 Jan 2018 01:17:40 +0100 Subject: Use nested attributes for updating multiple variables --- spec/controllers/projects/variables_controller_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 87463f00b8f..946110c0e64 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -67,8 +67,8 @@ describe Projects::VariablesController do subject do post :save_multiple, namespace_id: project.namespace.to_param, project_id: project, - variables: [{ key: variable.key, value: 'other_value' }, - { key: '..?', value: 'dummy_value' }], + variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, + { key: '..?', value: 'dummy_value' }], format: :json end @@ -91,8 +91,8 @@ describe Projects::VariablesController do subject do post :save_multiple, namespace_id: project.namespace.to_param, project_id: project, - variables: [{ key: variable.key, value: 'other_value' }, - { key: 'new_key', value: 'dummy_value' }], + variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, + { key: 'new_key', value: 'dummy_value' }], format: :json end @@ -115,7 +115,8 @@ describe Projects::VariablesController do subject do post :save_multiple, namespace_id: project.namespace.to_param, project_id: project, - variables: [{ key: variable.key, value: variable.value, _destroy: 'true' }], + variables_attributes: [{ id: variable.id, key: variable.key, + value: variable.value, _destroy: 'true' }], format: :json end -- cgit v1.2.1 From edbe911b04465f0e6c72e102d083d0e85848a552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 23 Jan 2018 02:09:36 +0100 Subject: Remove redundant routes in VariablesController --- .../projects/variables_controller_spec.rb | 47 ---------------------- 1 file changed, 47 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 946110c0e64..4cbc2fb443a 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -9,53 +9,6 @@ describe Projects::VariablesController do project.add_master(user) end - describe 'POST #create' do - context 'variable is valid' do - it 'shows a success flash message' do - post :create, namespace_id: project.namespace.to_param, project_id: project, - variable: { key: "one", value: "two" } - - expect(flash[:notice]).to include 'Variable was successfully created.' - expect(response).to redirect_to(project_settings_ci_cd_path(project)) - end - end - - context 'variable is invalid' do - it 'renders show' do - post :create, namespace_id: project.namespace.to_param, project_id: project, - variable: { key: "..one", value: "two" } - - expect(response).to render_template("projects/variables/show") - end - end - end - - describe 'POST #update' do - let(:variable) { create(:ci_variable) } - - context 'updating a variable with valid characters' do - before do - project.variables << variable - end - - it 'shows a success flash message' do - post :update, namespace_id: project.namespace.to_param, project_id: project, - id: variable.id, variable: { key: variable.key, value: 'two' } - - expect(flash[:notice]).to include 'Variable was successfully updated.' - expect(response).to redirect_to(project_variables_path(project)) - end - - it 'renders the action #show if the variable key is invalid' do - post :update, namespace_id: project.namespace.to_param, project_id: project, - id: variable.id, variable: { key: '?', value: variable.value } - - expect(response).to have_gitlab_http_status(200) - expect(response).to render_template :show - end - end - end - describe 'POST #save_multiple' do let(:variable) { create(:ci_variable) } -- cgit v1.2.1 From cc2bed9283039db726f42184ea635f057534205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 23 Jan 2018 19:24:55 +0100 Subject: Port #save_multiple to Groups::VariablesController --- .../groups/variables_controller_spec.rb | 79 ++++++++++++++++++++-- 1 file changed, 74 insertions(+), 5 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 8ea98cd9e8f..294e712f45d 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -29,13 +29,9 @@ describe Groups::VariablesController do end describe 'POST #update' do - let(:variable) { create(:ci_group_variable) } + let!(:variable) { create(:ci_group_variable, group: group) } context 'updating a variable with valid characters' do - before do - group.variables << variable - end - it 'shows a success flash message' do post :update, group_id: group, id: variable.id, variable: { key: variable.key, value: 'two' } @@ -53,4 +49,77 @@ describe Groups::VariablesController do end end end + + describe 'POST #save_multiple' do + let!(:variable) { create(:ci_group_variable, group: group) } + + context 'with invalid new variable parameters' do + subject do + post :save_multiple, + group_id: group, + variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, + { key: '..?', value: 'dummy_value' }], + format: :json + end + + it 'does not update the existing variable' do + expect { subject }.not_to change { variable.reload.value } + end + + it 'does not create the new variable' do + expect { subject }.not_to change { group.variables.count } + end + + it 'returns a bad request response' do + subject + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context 'with valid new variable parameters' do + subject do + post :save_multiple, + group_id: group, + variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, + { key: 'new_key', value: 'dummy_value' }], + format: :json + end + + it 'updates the existing variable' do + expect { subject }.to change { variable.reload.value }.to('other_value') + end + + it 'creates the new variable' do + expect { subject }.to change { group.variables.count }.by(1) + end + + it 'returns a successful response' do + subject + + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'with a deleted variable' do + subject do + post :save_multiple, + group_id: group, + variables_attributes: [{ id: variable.id, key: variable.key, + value: variable.value, _destroy: 'true' }], + format: :json + end + + it 'destroys the variable' do + expect { subject }.to change { group.variables.count }.by(-1) + expect { variable.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'returns a successful response' do + subject + + expect(response).to have_gitlab_http_status(:ok) + end + end + end end -- cgit v1.2.1 From dcc23530bd1e2bd1600bd523c90c040f84f8c354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 23 Jan 2018 19:34:06 +0100 Subject: Remove redundant routes in Groups::VariablesController --- .../groups/variables_controller_spec.rb | 41 ---------------------- 1 file changed, 41 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 294e712f45d..8570df15f34 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -9,47 +9,6 @@ describe Groups::VariablesController do group.add_master(user) end - describe 'POST #create' do - context 'variable is valid' do - it 'shows a success flash message' do - post :create, group_id: group, variable: { key: "one", value: "two" } - - expect(flash[:notice]).to include 'Variable was successfully created.' - expect(response).to redirect_to(group_settings_ci_cd_path(group)) - end - end - - context 'variable is invalid' do - it 'renders show' do - post :create, group_id: group, variable: { key: "..one", value: "two" } - - expect(response).to render_template("groups/variables/show") - end - end - end - - describe 'POST #update' do - let!(:variable) { create(:ci_group_variable, group: group) } - - context 'updating a variable with valid characters' do - it 'shows a success flash message' do - post :update, group_id: group, - id: variable.id, variable: { key: variable.key, value: 'two' } - - expect(flash[:notice]).to include 'Variable was successfully updated.' - expect(response).to redirect_to(group_variables_path(group)) - end - - it 'renders the action #show if the variable key is invalid' do - post :update, group_id: group, - id: variable.id, variable: { key: '?', value: variable.value } - - expect(response).to have_gitlab_http_status(200) - expect(response).to render_template :show - end - end - end - describe 'POST #save_multiple' do let!(:variable) { create(:ci_group_variable, group: group) } -- cgit v1.2.1 From 2592aec9e3a7a1b0d2689dd14cc6e0b9cea068cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 23 Jan 2018 19:53:29 +0100 Subject: Use all parameters in VariablesController specs --- spec/controllers/groups/variables_controller_spec.rb | 18 +++++++++++++----- spec/controllers/projects/variables_controller_spec.rb | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 8570df15f34..4299c3b0040 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -16,8 +16,11 @@ describe Groups::VariablesController do subject do post :save_multiple, group_id: group, - variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, - { key: '..?', value: 'dummy_value' }], + variables_attributes: [{ id: variable.id, key: variable.key, + value: 'other_value', + protected: variable.protected?.to_s }, + { key: '..?', value: 'dummy_value', + protected: 'false' }], format: :json end @@ -40,8 +43,11 @@ describe Groups::VariablesController do subject do post :save_multiple, group_id: group, - variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, - { key: 'new_key', value: 'dummy_value' }], + variables_attributes: [{ id: variable.id, key: variable.key, + value: 'other_value', + protected: variable.protected?.to_s }, + { key: 'new_key', value: 'dummy_value', + protected: 'false' }], format: :json end @@ -65,7 +71,9 @@ describe Groups::VariablesController do post :save_multiple, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, - value: variable.value, _destroy: 'true' }], + value: variable.value, + protected: variable.protected?.to_s, + _destroy: 'true' }], format: :json end diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 4cbc2fb443a..ac5c453a8ab 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -20,8 +20,11 @@ describe Projects::VariablesController do subject do post :save_multiple, namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, - { key: '..?', value: 'dummy_value' }], + variables_attributes: [{ id: variable.id, key: variable.key, + value: 'other_value', + protected: variable.protected?.to_s }, + { key: '..?', value: 'dummy_value', + protected: 'false' }], format: :json end @@ -44,8 +47,11 @@ describe Projects::VariablesController do subject do post :save_multiple, namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value' }, - { key: 'new_key', value: 'dummy_value' }], + variables_attributes: [{ id: variable.id, key: variable.key, + value: 'other_value', + protected: variable.protected?.to_s }, + { key: 'new_key', value: 'dummy_value', + protected: 'false' }], format: :json end @@ -69,7 +75,9 @@ describe Projects::VariablesController do post :save_multiple, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, - value: variable.value, _destroy: 'true' }], + value: variable.value, + protected: variable.protected?.to_s, + _destroy: 'true' }], format: :json end -- cgit v1.2.1 From 0bfcdd66bf932c080398ff264323b5c0df17d05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 29 Jan 2018 18:39:06 +0100 Subject: Use `resource` in Project Variables routing scheme --- .../projects/variables_controller_spec.rb | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index ac5c453a8ab..f6e15ee6147 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -9,7 +9,26 @@ describe Projects::VariablesController do project.add_master(user) end - describe 'POST #save_multiple' do + describe 'GET #show' do + let(:variable) { create(:ci_variable) } + + before do + project.variables << variable + end + + subject do + get :show, namespace_id: project.namespace.to_param, project_id: project, + format: :json + end + + it 'renders the ci_variable as json' do + subject + + expect(response.body).to include(variable.to_json) + end + end + + describe 'POST #update' do let(:variable) { create(:ci_variable) } before do @@ -18,7 +37,7 @@ describe Projects::VariablesController do context 'with invalid new variable parameters' do subject do - post :save_multiple, + post :update, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -45,7 +64,7 @@ describe Projects::VariablesController do context 'with valid new variable parameters' do subject do - post :save_multiple, + post :update, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -72,7 +91,7 @@ describe Projects::VariablesController do context 'with a deleted variable' do subject do - post :save_multiple, + post :update, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, value: variable.value, -- cgit v1.2.1 From a8887a0d9c4a41a0707b92189572aeff10566af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 29 Jan 2018 18:54:16 +0100 Subject: Use `resource` in Group Variables routing scheme --- .../groups/variables_controller_spec.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 4299c3b0040..96f1dc4d0ce 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -9,12 +9,26 @@ describe Groups::VariablesController do group.add_master(user) end - describe 'POST #save_multiple' do + describe 'GET #show' do + let!(:variable) { create(:ci_group_variable, group: group) } + + subject do + get :show, group_id: group, format: :json + end + + it 'renders the ci_variable as json' do + subject + + expect(response.body).to include(variable.to_json) + end + end + + describe 'POST #update' do let!(:variable) { create(:ci_group_variable, group: group) } context 'with invalid new variable parameters' do subject do - post :save_multiple, + post :update, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -41,7 +55,7 @@ describe Groups::VariablesController do context 'with valid new variable parameters' do subject do - post :save_multiple, + post :update, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -68,7 +82,7 @@ describe Groups::VariablesController do context 'with a deleted variable' do subject do - post :save_multiple, + post :update, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, value: variable.value, -- cgit v1.2.1 From 13f0e18d2f85478c1f3e6a2851701e88d6f8378c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Mon, 29 Jan 2018 19:01:21 +0100 Subject: Fix a typo in Groups::VariablesController spec --- spec/controllers/groups/variables_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 96f1dc4d0ce..72a489febdb 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -16,7 +16,7 @@ describe Groups::VariablesController do get :show, group_id: group, format: :json end - it 'renders the ci_variable as json' do + it 'renders the ci_group_variable as json' do subject expect(response.body).to include(variable.to_json) -- cgit v1.2.1 From 9eb3bb5cffbd18a744be2553ab2be7cb7843b029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 30 Jan 2018 00:29:13 +0100 Subject: Change POST to PATCH requests in the controller specs --- spec/controllers/groups/variables_controller_spec.rb | 6 +++--- spec/controllers/projects/variables_controller_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 72a489febdb..a462d64c0f5 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -28,7 +28,7 @@ describe Groups::VariablesController do context 'with invalid new variable parameters' do subject do - post :update, + patch :update, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -55,7 +55,7 @@ describe Groups::VariablesController do context 'with valid new variable parameters' do subject do - post :update, + patch :update, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -82,7 +82,7 @@ describe Groups::VariablesController do context 'with a deleted variable' do subject do - post :update, + patch :update, group_id: group, variables_attributes: [{ id: variable.id, key: variable.key, value: variable.value, diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index f6e15ee6147..ab8915c58d0 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -37,7 +37,7 @@ describe Projects::VariablesController do context 'with invalid new variable parameters' do subject do - post :update, + patch :update, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -64,7 +64,7 @@ describe Projects::VariablesController do context 'with valid new variable parameters' do subject do - post :update, + patch :update, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, value: 'other_value', @@ -91,7 +91,7 @@ describe Projects::VariablesController do context 'with a deleted variable' do subject do - post :update, + patch :update, namespace_id: project.namespace.to_param, project_id: project, variables_attributes: [{ id: variable.id, key: variable.key, value: variable.value, -- cgit v1.2.1 From b48d8c8ad0bb2874db6b4c9accb3bebd19e9f2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 30 Jan 2018 00:44:53 +0100 Subject: Return all variables after UPDATE --- spec/controllers/groups/variables_controller_spec.rb | 12 ++++++++++++ spec/controllers/projects/variables_controller_spec.rb | 12 ++++++++++++ 2 files changed, 24 insertions(+) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index a462d64c0f5..4927a9ee402 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -78,6 +78,12 @@ describe Groups::VariablesController do expect(response).to have_gitlab_http_status(:ok) end + + it 'has all variables in response' do + subject + + expect(response.body).to include(group.variables.reload.to_json) + end end context 'with a deleted variable' do @@ -101,6 +107,12 @@ describe Groups::VariablesController do expect(response).to have_gitlab_http_status(:ok) end + + it 'has all variables in response' do + subject + + expect(response.body).to include(group.variables.reload.to_json) + end end end end diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index ab8915c58d0..ddba6cd83f4 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -87,6 +87,12 @@ describe Projects::VariablesController do expect(response).to have_gitlab_http_status(:ok) end + + it 'has all variables in response' do + subject + + expect(response.body).to include(project.variables.reload.to_json) + end end context 'with a deleted variable' do @@ -110,6 +116,12 @@ describe Projects::VariablesController do expect(response).to have_gitlab_http_status(:ok) end + + it 'has all variables in response' do + subject + + expect(response.body).to include(project.variables.reload.to_json) + end end end end -- cgit v1.2.1 From 9be519c199b01d4b4b1c69ec4d74a1e99345eb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 30 Jan 2018 02:01:53 +0100 Subject: Add VariableSerializer for Ci::Variable --- spec/controllers/projects/variables_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index ddba6cd83f4..8e5d6023b79 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -24,7 +24,7 @@ describe Projects::VariablesController do it 'renders the ci_variable as json' do subject - expect(response.body).to include(variable.to_json) + expect(response).to match_response_schema('variable') end end @@ -91,7 +91,7 @@ describe Projects::VariablesController do it 'has all variables in response' do subject - expect(response.body).to include(project.variables.reload.to_json) + expect(response).to match_response_schema('variable') end end @@ -120,7 +120,7 @@ describe Projects::VariablesController do it 'has all variables in response' do subject - expect(response.body).to include(project.variables.reload.to_json) + expect(json_response['variables'].count).to eq(0) end end end -- cgit v1.2.1 From 04263b9f3be22bd97249162d9d3e27829c639d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 30 Jan 2018 02:11:17 +0100 Subject: Add GroupVariableSerializer for Ci::GroupVariable --- spec/controllers/groups/variables_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 4927a9ee402..f6bcc68f9ad 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -19,7 +19,7 @@ describe Groups::VariablesController do it 'renders the ci_group_variable as json' do subject - expect(response.body).to include(variable.to_json) + expect(response).to match_response_schema('variable') end end @@ -82,7 +82,7 @@ describe Groups::VariablesController do it 'has all variables in response' do subject - expect(response.body).to include(group.variables.reload.to_json) + expect(response).to match_response_schema('variable') end end @@ -111,7 +111,7 @@ describe Groups::VariablesController do it 'has all variables in response' do subject - expect(response.body).to include(group.variables.reload.to_json) + expect(json_response['variables'].count).to eq(0) end end end -- cgit v1.2.1 From 558057010f02fc931db08d8dedfc7cdeb6192ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 1 Feb 2018 21:58:05 +0100 Subject: Extract variable parameters in VariablesController specs --- .../groups/variables_controller_spec.rb | 28 +++++++++++----------- .../projects/variables_controller_spec.rb | 28 +++++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index f6bcc68f9ad..94d13b632cd 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -25,16 +25,22 @@ describe Groups::VariablesController do describe 'POST #update' do let!(:variable) { create(:ci_group_variable, group: group) } + let(:variable_attributes) do + { id: variable.id, key: variable.key, + value: variable.value, + protected: variable.protected?.to_s } + end + let(:new_variable_attributes) do + { key: 'new_key', value: 'dummy_value', + protected: 'false' } + end context 'with invalid new variable parameters' do subject do patch :update, group_id: group, - variables_attributes: [{ id: variable.id, key: variable.key, - value: 'other_value', - protected: variable.protected?.to_s }, - { key: '..?', value: 'dummy_value', - protected: 'false' }], + variables_attributes: [variable_attributes.merge(value: 'other_value'), + new_variable_attributes.merge(key: '..?')], format: :json end @@ -57,11 +63,8 @@ describe Groups::VariablesController do subject do patch :update, group_id: group, - variables_attributes: [{ id: variable.id, key: variable.key, - value: 'other_value', - protected: variable.protected?.to_s }, - { key: 'new_key', value: 'dummy_value', - protected: 'false' }], + variables_attributes: [variable_attributes.merge(value: 'other_value'), + new_variable_attributes], format: :json end @@ -90,10 +93,7 @@ describe Groups::VariablesController do subject do patch :update, group_id: group, - variables_attributes: [{ id: variable.id, key: variable.key, - value: variable.value, - protected: variable.protected?.to_s, - _destroy: 'true' }], + variables_attributes: [variable_attributes.merge(_destroy: 'true')], format: :json end diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 8e5d6023b79..4dbcfb125a2 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -30,6 +30,15 @@ describe Projects::VariablesController do describe 'POST #update' do let(:variable) { create(:ci_variable) } + let(:variable_attributes) do + { id: variable.id, key: variable.key, + value: variable.value, + protected: variable.protected?.to_s } + end + let(:new_variable_attributes) do + { key: 'new_key', value: 'dummy_value', + protected: 'false' } + end before do project.variables << variable @@ -39,11 +48,8 @@ describe Projects::VariablesController do subject do patch :update, namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [{ id: variable.id, key: variable.key, - value: 'other_value', - protected: variable.protected?.to_s }, - { key: '..?', value: 'dummy_value', - protected: 'false' }], + variables_attributes: [variable_attributes.merge(value: 'other_value'), + new_variable_attributes.merge(key: '..?')], format: :json end @@ -66,11 +72,8 @@ describe Projects::VariablesController do subject do patch :update, namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [{ id: variable.id, key: variable.key, - value: 'other_value', - protected: variable.protected?.to_s }, - { key: 'new_key', value: 'dummy_value', - protected: 'false' }], + variables_attributes: [variable_attributes.merge(value: 'other_value'), + new_variable_attributes], format: :json end @@ -99,10 +102,7 @@ describe Projects::VariablesController do subject do patch :update, namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [{ id: variable.id, key: variable.key, - value: variable.value, - protected: variable.protected?.to_s, - _destroy: 'true' }], + variables_attributes: [variable_attributes.merge(_destroy: 'true')], format: :json end -- cgit v1.2.1 From 18232d7efb53381dea8727c36fc7a36dd2fd9d5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Thu, 1 Feb 2018 22:35:00 +0100 Subject: Extract Variable into separate JSON Schema --- spec/controllers/groups/variables_controller_spec.rb | 6 +++--- spec/controllers/projects/variables_controller_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 94d13b632cd..80b6be39291 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -19,7 +19,7 @@ describe Groups::VariablesController do it 'renders the ci_group_variable as json' do subject - expect(response).to match_response_schema('variable') + expect(response).to match_response_schema('variables') end end @@ -85,7 +85,7 @@ describe Groups::VariablesController do it 'has all variables in response' do subject - expect(response).to match_response_schema('variable') + expect(response).to match_response_schema('variables') end end @@ -111,7 +111,7 @@ describe Groups::VariablesController do it 'has all variables in response' do subject - expect(json_response['variables'].count).to eq(0) + expect(response).to match_response_schema('variables') end end end diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 4dbcfb125a2..0082757a5c6 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -24,7 +24,7 @@ describe Projects::VariablesController do it 'renders the ci_variable as json' do subject - expect(response).to match_response_schema('variable') + expect(response).to match_response_schema('variables') end end @@ -94,7 +94,7 @@ describe Projects::VariablesController do it 'has all variables in response' do subject - expect(response).to match_response_schema('variable') + expect(response).to match_response_schema('variables') end end @@ -120,7 +120,7 @@ describe Projects::VariablesController do it 'has all variables in response' do subject - expect(json_response['variables'].count).to eq(0) + expect(response).to match_response_schema('variables') end end end -- cgit v1.2.1 From 45a14b4f584dd1102bd81c560e4d2e7c4b34aea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 2 Feb 2018 18:54:13 +0100 Subject: Refactor Variable controllers specs --- .../groups/variables_controller_spec.rb | 43 ++++++++++---------- .../projects/variables_controller_spec.rb | 46 +++++++++++----------- 2 files changed, 47 insertions(+), 42 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 80b6be39291..8abdc1cb5b1 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -25,23 +25,32 @@ describe Groups::VariablesController do describe 'POST #update' do let!(:variable) { create(:ci_group_variable, group: group) } + + subject do + patch :update, + group_id: group, + variables_attributes: variables_attributes, + format: :json + end + let(:variable_attributes) do - { id: variable.id, key: variable.key, + { id: variable.id, + key: variable.key, value: variable.value, protected: variable.protected?.to_s } end let(:new_variable_attributes) do - { key: 'new_key', value: 'dummy_value', + { key: 'new_key', + value: 'dummy_value', protected: 'false' } end context 'with invalid new variable parameters' do - subject do - patch :update, - group_id: group, - variables_attributes: [variable_attributes.merge(value: 'other_value'), - new_variable_attributes.merge(key: '..?')], - format: :json + let(:variables_attributes) do + [ + variable_attributes.merge(value: 'other_value'), + new_variable_attributes.merge(key: '...?') + ] end it 'does not update the existing variable' do @@ -60,12 +69,11 @@ describe Groups::VariablesController do end context 'with valid new variable parameters' do - subject do - patch :update, - group_id: group, - variables_attributes: [variable_attributes.merge(value: 'other_value'), - new_variable_attributes], - format: :json + let(:variables_attributes) do + [ + variable_attributes.merge(value: 'other_value'), + new_variable_attributes + ] end it 'updates the existing variable' do @@ -90,12 +98,7 @@ describe Groups::VariablesController do end context 'with a deleted variable' do - subject do - patch :update, - group_id: group, - variables_attributes: [variable_attributes.merge(_destroy: 'true')], - format: :json - end + let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] } it 'destroys the variable' do expect { subject }.to change { group.variables.count }.by(-1) diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index 0082757a5c6..d2cb3dd9453 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -17,8 +17,7 @@ describe Projects::VariablesController do end subject do - get :show, namespace_id: project.namespace.to_param, project_id: project, - format: :json + get :show, namespace_id: project.namespace.to_param, project_id: project, format: :json end it 'renders the ci_variable as json' do @@ -30,13 +29,23 @@ describe Projects::VariablesController do describe 'POST #update' do let(:variable) { create(:ci_variable) } + + subject do + patch :update, + namespace_id: project.namespace.to_param, project_id: project, + variables_attributes: variables_attributes, + format: :json + end + let(:variable_attributes) do - { id: variable.id, key: variable.key, + { id: variable.id, + key: variable.key, value: variable.value, protected: variable.protected?.to_s } end let(:new_variable_attributes) do - { key: 'new_key', value: 'dummy_value', + { key: 'new_key', + value: 'dummy_value', protected: 'false' } end @@ -45,12 +54,11 @@ describe Projects::VariablesController do end context 'with invalid new variable parameters' do - subject do - patch :update, - namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [variable_attributes.merge(value: 'other_value'), - new_variable_attributes.merge(key: '..?')], - format: :json + let(:variables_attributes) do + [ + variable_attributes.merge(value: 'other_value'), + new_variable_attributes.merge(key: '...?') + ] end it 'does not update the existing variable' do @@ -69,12 +77,11 @@ describe Projects::VariablesController do end context 'with valid new variable parameters' do - subject do - patch :update, - namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [variable_attributes.merge(value: 'other_value'), - new_variable_attributes], - format: :json + let(:variables_attributes) do + [ + variable_attributes.merge(value: 'other_value'), + new_variable_attributes + ] end it 'updates the existing variable' do @@ -99,12 +106,7 @@ describe Projects::VariablesController do end context 'with a deleted variable' do - subject do - patch :update, - namespace_id: project.namespace.to_param, project_id: project, - variables_attributes: [variable_attributes.merge(_destroy: 'true')], - format: :json - end + let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] } it 'destroys the variable' do expect { subject }.to change { project.variables.count }.by(-1) -- cgit v1.2.1 From f7ed096455c932a5ead8bafb8c937ff9cdb3070c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Fri, 2 Feb 2018 19:35:00 +0100 Subject: Extract Variables controllers specs to shared_examples --- .../groups/variables_controller_spec.rb | 94 +----------------- .../projects/variables_controller_spec.rb | 109 ++------------------- 2 files changed, 12 insertions(+), 191 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/groups/variables_controller_spec.rb b/spec/controllers/groups/variables_controller_spec.rb index 8abdc1cb5b1..39a36b92bb4 100644 --- a/spec/controllers/groups/variables_controller_spec.rb +++ b/spec/controllers/groups/variables_controller_spec.rb @@ -16,15 +16,12 @@ describe Groups::VariablesController do get :show, group_id: group, format: :json end - it 'renders the ci_group_variable as json' do - subject - - expect(response).to match_response_schema('variables') - end + include_examples 'GET #show lists all variables' end - describe 'POST #update' do + describe 'PATCH #update' do let!(:variable) { create(:ci_group_variable, group: group) } + let(:owner) { group } subject do patch :update, @@ -33,89 +30,6 @@ describe Groups::VariablesController do format: :json end - let(:variable_attributes) do - { id: variable.id, - key: variable.key, - value: variable.value, - protected: variable.protected?.to_s } - end - let(:new_variable_attributes) do - { key: 'new_key', - value: 'dummy_value', - protected: 'false' } - end - - context 'with invalid new variable parameters' do - let(:variables_attributes) do - [ - variable_attributes.merge(value: 'other_value'), - new_variable_attributes.merge(key: '...?') - ] - end - - it 'does not update the existing variable' do - expect { subject }.not_to change { variable.reload.value } - end - - it 'does not create the new variable' do - expect { subject }.not_to change { group.variables.count } - end - - it 'returns a bad request response' do - subject - - expect(response).to have_gitlab_http_status(:bad_request) - end - end - - context 'with valid new variable parameters' do - let(:variables_attributes) do - [ - variable_attributes.merge(value: 'other_value'), - new_variable_attributes - ] - end - - it 'updates the existing variable' do - expect { subject }.to change { variable.reload.value }.to('other_value') - end - - it 'creates the new variable' do - expect { subject }.to change { group.variables.count }.by(1) - end - - it 'returns a successful response' do - subject - - expect(response).to have_gitlab_http_status(:ok) - end - - it 'has all variables in response' do - subject - - expect(response).to match_response_schema('variables') - end - end - - context 'with a deleted variable' do - let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] } - - it 'destroys the variable' do - expect { subject }.to change { group.variables.count }.by(-1) - expect { variable.reload }.to raise_error ActiveRecord::RecordNotFound - end - - it 'returns a successful response' do - subject - - expect(response).to have_gitlab_http_status(:ok) - end - - it 'has all variables in response' do - subject - - expect(response).to match_response_schema('variables') - end - end + include_examples 'PATCH #update updates variables' end end diff --git a/spec/controllers/projects/variables_controller_spec.rb b/spec/controllers/projects/variables_controller_spec.rb index d2cb3dd9453..68019743be0 100644 --- a/spec/controllers/projects/variables_controller_spec.rb +++ b/spec/controllers/projects/variables_controller_spec.rb @@ -10,120 +10,27 @@ describe Projects::VariablesController do end describe 'GET #show' do - let(:variable) { create(:ci_variable) } - - before do - project.variables << variable - end + let!(:variable) { create(:ci_variable, project: project) } subject do get :show, namespace_id: project.namespace.to_param, project_id: project, format: :json end - it 'renders the ci_variable as json' do - subject - - expect(response).to match_response_schema('variables') - end + include_examples 'GET #show lists all variables' end - describe 'POST #update' do - let(:variable) { create(:ci_variable) } + describe 'PATCH #update' do + let!(:variable) { create(:ci_variable, project: project) } + let(:owner) { project } subject do patch :update, - namespace_id: project.namespace.to_param, project_id: project, + namespace_id: project.namespace.to_param, + project_id: project, variables_attributes: variables_attributes, format: :json end - let(:variable_attributes) do - { id: variable.id, - key: variable.key, - value: variable.value, - protected: variable.protected?.to_s } - end - let(:new_variable_attributes) do - { key: 'new_key', - value: 'dummy_value', - protected: 'false' } - end - - before do - project.variables << variable - end - - context 'with invalid new variable parameters' do - let(:variables_attributes) do - [ - variable_attributes.merge(value: 'other_value'), - new_variable_attributes.merge(key: '...?') - ] - end - - it 'does not update the existing variable' do - expect { subject }.not_to change { variable.reload.value } - end - - it 'does not create the new variable' do - expect { subject }.not_to change { project.variables.count } - end - - it 'returns a bad request response' do - subject - - expect(response).to have_gitlab_http_status(:bad_request) - end - end - - context 'with valid new variable parameters' do - let(:variables_attributes) do - [ - variable_attributes.merge(value: 'other_value'), - new_variable_attributes - ] - end - - it 'updates the existing variable' do - expect { subject }.to change { variable.reload.value }.to('other_value') - end - - it 'creates the new variable' do - expect { subject }.to change { project.variables.count }.by(1) - end - - it 'returns a successful response' do - subject - - expect(response).to have_gitlab_http_status(:ok) - end - - it 'has all variables in response' do - subject - - expect(response).to match_response_schema('variables') - end - end - - context 'with a deleted variable' do - let(:variables_attributes) { [variable_attributes.merge(_destroy: 'true')] } - - it 'destroys the variable' do - expect { subject }.to change { project.variables.count }.by(-1) - expect { variable.reload }.to raise_error ActiveRecord::RecordNotFound - end - - it 'returns a successful response' do - subject - - expect(response).to have_gitlab_http_status(:ok) - end - - it 'has all variables in response' do - subject - - expect(response).to match_response_schema('variables') - end - end + include_examples 'PATCH #update updates variables' end end -- cgit v1.2.1 From 6b0c6e69e1b249f14624550fcbca7f5ee6f51410 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Fri, 1 Dec 2017 13:58:49 +0000 Subject: Use hashed storage in the specs --- spec/controllers/profiles_controller_spec.rb | 40 +++++++++--- spec/controllers/projects_controller_spec.rb | 96 +++++++++++++++++----------- 2 files changed, 89 insertions(+), 47 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb index d380978b86e..03cbbb21e62 100644 --- a/spec/controllers/profiles_controller_spec.rb +++ b/spec/controllers/profiles_controller_spec.rb @@ -69,9 +69,8 @@ describe ProfilesController, :request_store do describe 'PUT update_username' do let(:namespace) { user.namespace } - let(:project) { create(:project_empty_repo, namespace: namespace) } let(:gitlab_shell) { Gitlab::Shell.new } - let(:new_username) { 'renamedtosomethingelse' } + let(:new_username) { generate(:username) } it 'allows username change' do sign_in(user) @@ -85,16 +84,39 @@ describe ProfilesController, :request_store do expect(user.username).to eq(new_username) end - it 'moves dependent projects to new namespace' do - sign_in(user) + context 'with legacy storage' do + it 'moves dependent projects to new namespace' do + project = create(:project_empty_repo, :legacy_storage, namespace: namespace) - put :update_username, - user: { username: new_username } + sign_in(user) - user.reload + put :update_username, + user: { username: new_username } - expect(response.status).to eq(302) - expect(gitlab_shell.exists?(project.repository_storage_path, "#{new_username}/#{project.path}.git")).to be_truthy + user.reload + + expect(response.status).to eq(302) + expect(gitlab_shell.exists?(project.repository_storage_path, "#{new_username}/#{project.path}.git")).to be_truthy + end + end + + context 'with hashed storage' do + it 'keeps repository location unchanged on disk' do + project = create(:project_empty_repo, namespace: namespace) + + before_disk_path = project.disk_path + + sign_in(user) + + put :update_username, + user: { username: new_username } + + user.reload + + expect(response.status).to eq(302) + expect(gitlab_shell.exists?(project.repository_storage_path, "#{project.disk_path}.git")).to be_truthy + expect(before_disk_path).to eq(project.disk_path) + end end end end diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index 5202ffdd8bb..994da3cd159 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -288,62 +288,82 @@ describe ProjectsController do render_views let(:admin) { create(:admin) } - let(:project) { create(:project, :repository) } before do sign_in(admin) end - context 'when only renaming a project path' do - it "sets the repository to the right path after a rename" do - expect { update_project path: 'renamed_path' } - .to change { project.reload.path } + shared_examples_for 'updating a project' do + context 'when only renaming a project path' do + it "sets the repository to the right path after a rename" do + original_repository_path = project.repository.path - expect(project.path).to include 'renamed_path' - expect(assigns(:repository).path).to include project.path - expect(response).to have_gitlab_http_status(302) - end - end + expect { update_project path: 'renamed_path' } + .to change { project.reload.path } + expect(project.path).to include 'renamed_path' - context 'when project has container repositories with tags' do - before do - stub_container_registry_config(enabled: true) - stub_container_registry_tags(repository: /image/, tags: %w[rc1]) - create(:container_repository, project: project, name: :image) + if project.hashed_storage?(:repository) + expect(assigns(:repository).path).to eq(original_repository_path) + else + expect(assigns(:repository).path).to include(project.path) + end + + expect(response).to have_gitlab_http_status(302) + end end - it 'does not allow to rename the project' do - expect { update_project path: 'renamed_path' } - .not_to change { project.reload.path } + context 'when project has container repositories with tags' do + before do + stub_container_registry_config(enabled: true) + stub_container_registry_tags(repository: /image/, tags: %w[rc1]) + create(:container_repository, project: project, name: :image) + end - expect(controller).to set_flash[:alert].to(/container registry tags/) - expect(response).to have_gitlab_http_status(200) + it 'does not allow to rename the project' do + expect { update_project path: 'renamed_path' } + .not_to change { project.reload.path } + + expect(controller).to set_flash[:alert].to(/container registry tags/) + expect(response).to have_gitlab_http_status(200) + end end - end - it 'updates Fast Forward Merge attributes' do - controller.instance_variable_set(:@project, project) + it 'updates Fast Forward Merge attributes' do + controller.instance_variable_set(:@project, project) - params = { - merge_method: :ff - } + params = { + merge_method: :ff + } - put :update, - namespace_id: project.namespace, - id: project.id, - project: params + put :update, + namespace_id: project.namespace, + id: project.id, + project: params - expect(response).to have_gitlab_http_status(302) - params.each do |param, value| - expect(project.public_send(param)).to eq(value) + expect(response).to have_gitlab_http_status(302) + params.each do |param, value| + expect(project.public_send(param)).to eq(value) + end + end + + def update_project(**parameters) + put :update, + namespace_id: project.namespace.path, + id: project.path, + project: parameters end end - def update_project(**parameters) - put :update, - namespace_id: project.namespace.path, - id: project.path, - project: parameters + context 'hashed storage' do + let(:project) { create(:project, :repository) } + + it_behaves_like 'updating a project' + end + + context 'legacy storage' do + let(:project) { create(:project, :repository, :legacy_storage) } + + it_behaves_like 'updating a project' end end -- cgit v1.2.1 From 3581a78f81c294a905dd5cc8731c645eeb7d2c1e Mon Sep 17 00:00:00 2001 From: Mario de la Ossa Date: Wed, 7 Feb 2018 12:05:25 -0600 Subject: Updating `HelpController` spec to use an existing image --- spec/controllers/help_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/controllers') diff --git a/spec/controllers/help_controller_spec.rb b/spec/controllers/help_controller_spec.rb index f75048f422c..21d59c62613 100644 --- a/spec/controllers/help_controller_spec.rb +++ b/spec/controllers/help_controller_spec.rb @@ -68,7 +68,7 @@ describe HelpController do context 'when requested file exists' do it 'renders the raw file' do get :show, - path: 'user/project/img/labels_filter', + path: 'user/project/img/labels_default', format: :png expect(response).to be_success expect(response.content_type).to eq 'image/png' -- cgit v1.2.1 From 71c948d63743c80f50cdd929728bb074d9deeace Mon Sep 17 00:00:00 2001 From: Clement Ho Date: Fri, 9 Feb 2018 11:14:48 +0000 Subject: Replace $.post in importer status with axios --- .../import/bitbucket_controller_spec.rb | 88 +++++++++++++++------- spec/controllers/import/gitlab_controller_spec.rb | 85 ++++++++++++++------- 2 files changed, 118 insertions(+), 55 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb index e8707760a5a..9c7a54f9ed4 100644 --- a/spec/controllers/import/bitbucket_controller_spec.rb +++ b/spec/controllers/import/bitbucket_controller_spec.rb @@ -84,20 +84,42 @@ describe Import::BitbucketController do double(slug: "vim", owner: bitbucket_username, name: 'vim') end + let(:project) { create(:project) } + before do allow_any_instance_of(Bitbucket::Client).to receive(:repo).and_return(bitbucket_repo) allow_any_instance_of(Bitbucket::Client).to receive(:user).and_return(bitbucket_user) assign_session_tokens end + it 'returns 200 response when the project is imported successfully' do + allow(Gitlab::BitbucketImport::ProjectCreator) + .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params) + .and_return(double(execute: project)) + + post :create, format: :json + + expect(response).to have_gitlab_http_status(200) + end + + it 'returns 422 response when the project could not be imported' do + allow(Gitlab::BitbucketImport::ProjectCreator) + .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params) + .and_return(double(execute: build(:project))) + + post :create, format: :json + + expect(response).to have_gitlab_http_status(422) + end + context "when the repository owner is the Bitbucket user" do context "when the Bitbucket user and GitLab user's usernames match" do it "takes the current user's namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -107,9 +129,9 @@ describe Import::BitbucketController do it "takes the current user's namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -120,7 +142,7 @@ describe Import::BitbucketController do allow(controller).to receive(:current_user).and_return(user) allow(user).to receive(:can?).and_return(false) - post :create, format: :js + post :create, format: :json end end end @@ -143,9 +165,9 @@ describe Import::BitbucketController do it "takes the existing namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, existing_namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -154,7 +176,7 @@ describe Import::BitbucketController do expect(Gitlab::BitbucketImport::ProjectCreator) .not_to receive(:new) - post :create, format: :js + post :create, format: :json end end end @@ -163,17 +185,17 @@ describe Import::BitbucketController do context "when current user can create namespaces" do it "creates the namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) - .to receive(:new).and_return(double(execute: true)) + .to receive(:new).and_return(double(execute: project)) - expect { post :create, format: :js }.to change(Namespace, :count).by(1) + expect { post :create, format: :json }.to change(Namespace, :count).by(1) end it "takes the new namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, an_instance_of(Group), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -184,17 +206,17 @@ describe Import::BitbucketController do it "doesn't create the namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) - .to receive(:new).and_return(double(execute: true)) + .to receive(:new).and_return(double(execute: project)) - expect { post :create, format: :js }.not_to change(Namespace, :count) + expect { post :create, format: :json }.not_to change(Namespace, :count) end it "takes the current user's namespace" do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, bitbucket_repo.name, user.namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end end @@ -212,9 +234,9 @@ describe Import::BitbucketController do it 'takes the selected namespace and name' do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, nested_namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: nested_namespace.full_path, new_name: test_name, format: :js } + post :create, { target_namespace: nested_namespace.full_path, new_name: test_name, format: :json } end end @@ -224,26 +246,26 @@ describe Import::BitbucketController do it 'takes the selected namespace and name' do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :js } + post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :json } end it 'creates the namespaces' do allow(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - expect { post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :js } } + expect { post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :json } } .to change { Namespace.count }.by(2) end it 'new namespace has the right parent' do allow(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :js } + post :create, { target_namespace: 'foo/bar', new_name: test_name, format: :json } expect(Namespace.find_by_path_or_name('bar').parent.path).to eq('foo') end @@ -256,19 +278,29 @@ describe Import::BitbucketController do it 'takes the selected namespace and name' do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: 'foo/foobar/bar', new_name: test_name, format: :js } + post :create, { target_namespace: 'foo/foobar/bar', new_name: test_name, format: :json } end it 'creates the namespaces' do allow(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - expect { post :create, { target_namespace: 'foo/foobar/bar', new_name: test_name, format: :js } } + expect { post :create, { target_namespace: 'foo/foobar/bar', new_name: test_name, format: :json } } .to change { Namespace.count }.by(2) end end + + context 'when user can not create projects in the chosen namespace' do + it 'returns 422 response' do + other_namespace = create(:group, name: 'other_namespace') + + post :create, { target_namespace: other_namespace.name, format: :json } + + expect(response).to have_gitlab_http_status(422) + end + end end end diff --git a/spec/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb index faf1e6f63ea..d902c6210f5 100644 --- a/spec/controllers/import/gitlab_controller_spec.rb +++ b/spec/controllers/import/gitlab_controller_spec.rb @@ -57,6 +57,7 @@ describe Import::GitlabController do end describe "POST create" do + let(:project) { create(:project) } let(:gitlab_username) { user.username } let(:gitlab_user) do { username: gitlab_username }.with_indifferent_access @@ -75,14 +76,34 @@ describe Import::GitlabController do assign_session_token end + it 'returns 200 response when the project is imported successfully' do + allow(Gitlab::GitlabImport::ProjectCreator) + .to receive(:new).with(gitlab_repo, user.namespace, user, access_params) + .and_return(double(execute: project)) + + post :create, format: :json + + expect(response).to have_gitlab_http_status(200) + end + + it 'returns 422 response when the project could not be imported' do + allow(Gitlab::GitlabImport::ProjectCreator) + .to receive(:new).with(gitlab_repo, user.namespace, user, access_params) + .and_return(double(execute: build(:project))) + + post :create, format: :json + + expect(response).to have_gitlab_http_status(422) + end + context "when the repository owner is the GitLab.com user" do context "when the GitLab.com user and GitLab server user's usernames match" do it "takes the current user's namespace" do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, user.namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -92,9 +113,9 @@ describe Import::GitlabController do it "takes the current user's namespace" do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, user.namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end end @@ -118,9 +139,9 @@ describe Import::GitlabController do it "takes the existing namespace" do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, existing_namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -129,7 +150,7 @@ describe Import::GitlabController do expect(Gitlab::GitlabImport::ProjectCreator) .not_to receive(:new) - post :create, format: :js + post :create, format: :json end end end @@ -138,17 +159,17 @@ describe Import::GitlabController do context "when current user can create namespaces" do it "creates the namespace" do expect(Gitlab::GitlabImport::ProjectCreator) - .to receive(:new).and_return(double(execute: true)) + .to receive(:new).and_return(double(execute: project)) - expect { post :create, format: :js }.to change(Namespace, :count).by(1) + expect { post :create, format: :json }.to change(Namespace, :count).by(1) end it "takes the new namespace" do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, an_instance_of(Group), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end @@ -159,17 +180,17 @@ describe Import::GitlabController do it "doesn't create the namespace" do expect(Gitlab::GitlabImport::ProjectCreator) - .to receive(:new).and_return(double(execute: true)) + .to receive(:new).and_return(double(execute: project)) - expect { post :create, format: :js }.not_to change(Namespace, :count) + expect { post :create, format: :json }.not_to change(Namespace, :count) end it "takes the current user's namespace" do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, user.namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, format: :js + post :create, format: :json end end end @@ -185,9 +206,9 @@ describe Import::GitlabController do it 'takes the selected namespace and name' do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, nested_namespace, user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: nested_namespace.full_path, format: :js } + post :create, { target_namespace: nested_namespace.full_path, format: :json } end end @@ -197,26 +218,26 @@ describe Import::GitlabController do it 'takes the selected namespace and name' do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: 'foo/bar', format: :js } + post :create, { target_namespace: 'foo/bar', format: :json } end it 'creates the namespaces' do allow(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - expect { post :create, { target_namespace: 'foo/bar', format: :js } } + expect { post :create, { target_namespace: 'foo/bar', format: :json } } .to change { Namespace.count }.by(2) end it 'new namespace has the right parent' do allow(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: 'foo/bar', format: :js } + post :create, { target_namespace: 'foo/bar', format: :json } expect(Namespace.find_by_path_or_name('bar').parent.path).to eq('foo') end @@ -229,20 +250,30 @@ describe Import::GitlabController do it 'takes the selected namespace and name' do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - post :create, { target_namespace: 'foo/foobar/bar', format: :js } + post :create, { target_namespace: 'foo/foobar/bar', format: :json } end it 'creates the namespaces' do allow(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, kind_of(Namespace), user, access_params) - .and_return(double(execute: true)) + .and_return(double(execute: project)) - expect { post :create, { target_namespace: 'foo/foobar/bar', format: :js } } + expect { post :create, { target_namespace: 'foo/foobar/bar', format: :json } } .to change { Namespace.count }.by(2) end end + + context 'when user can not create projects in the chosen namespace' do + it 'returns 422 response' do + other_namespace = create(:group, name: 'other_namespace') + + post :create, { target_namespace: other_namespace.name, format: :json } + + expect(response).to have_gitlab_http_status(422) + end + end end end end -- cgit v1.2.1 From 68e31c098ec3984c42b921c07fec8593116e77ce Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 26 Jan 2018 15:39:10 +0000 Subject: Merge branch 'fix/gh-namespace-issue' into 'security-10-4' [10.4] Fix GH namespace security issue --- spec/controllers/import/bitbucket_controller_spec.rb | 10 +++++++--- spec/controllers/import/gitlab_controller_spec.rb | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'spec/controllers') diff --git a/spec/controllers/import/bitbucket_controller_spec.rb b/spec/controllers/import/bitbucket_controller_spec.rb index 9c7a54f9ed4..2be46049aab 100644 --- a/spec/controllers/import/bitbucket_controller_spec.rb +++ b/spec/controllers/import/bitbucket_controller_spec.rb @@ -222,7 +222,7 @@ describe Import::BitbucketController do end end - context 'user has chosen an existing nested namespace and name for the project' do + context 'user has chosen an existing nested namespace and name for the project', :postgresql do let(:parent_namespace) { create(:group, name: 'foo', owner: user) } let(:nested_namespace) { create(:group, name: 'bar', parent: parent_namespace) } let(:test_name) { 'test_name' } @@ -240,7 +240,7 @@ describe Import::BitbucketController do end end - context 'user has chosen a non-existent nested namespaces and name for the project' do + context 'user has chosen a non-existent nested namespaces and name for the project', :postgresql do let(:test_name) { 'test_name' } it 'takes the selected namespace and name' do @@ -271,10 +271,14 @@ describe Import::BitbucketController do end end - context 'user has chosen existent and non-existent nested namespaces and name for the project' do + context 'user has chosen existent and non-existent nested namespaces and name for the project', :postgresql do let(:test_name) { 'test_name' } let!(:parent_namespace) { create(:group, name: 'foo', owner: user) } + before do + parent_namespace.add_owner(user) + end + it 'takes the selected namespace and name' do expect(Gitlab::BitbucketImport::ProjectCreator) .to receive(:new).with(bitbucket_repo, test_name, kind_of(Namespace), user, access_params) diff --git a/spec/controllers/import/gitlab_controller_spec.rb b/spec/controllers/import/gitlab_controller_spec.rb index d902c6210f5..e958be077c2 100644 --- a/spec/controllers/import/gitlab_controller_spec.rb +++ b/spec/controllers/import/gitlab_controller_spec.rb @@ -195,7 +195,7 @@ describe Import::GitlabController do end end - context 'user has chosen an existing nested namespace for the project' do + context 'user has chosen an existing nested namespace for the project', :postgresql do let(:parent_namespace) { create(:group, name: 'foo', owner: user) } let(:nested_namespace) { create(:group, name: 'bar', parent: parent_namespace) } @@ -212,7 +212,7 @@ describe Import::GitlabController do end end - context 'user has chosen a non-existent nested namespaces for the project' do + context 'user has chosen a non-existent nested namespaces for the project', :postgresql do let(:test_name) { 'test_name' } it 'takes the selected namespace and name' do @@ -243,10 +243,14 @@ describe Import::GitlabController do end end - context 'user has chosen existent and non-existent nested namespaces and name for the project' do + context 'user has chosen existent and non-existent nested namespaces and name for the project', :postgresql do let(:test_name) { 'test_name' } let!(:parent_namespace) { create(:group, name: 'foo', owner: user) } + before do + parent_namespace.add_owner(user) + end + it 'takes the selected namespace and name' do expect(Gitlab::GitlabImport::ProjectCreator) .to receive(:new).with(gitlab_repo, kind_of(Namespace), user, access_params) -- cgit v1.2.1