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/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb') 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 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/projects/variables_controller_spec.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb') 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 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/projects/variables_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb') 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 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 --- .../projects/variables_controller_spec.rb | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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/projects/variables_controller_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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 --- .../projects/variables_controller_spec.rb | 46 +++++++++++----------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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 --- .../projects/variables_controller_spec.rb | 109 ++------------------- 1 file changed, 8 insertions(+), 101 deletions(-) (limited to 'spec/controllers/projects/variables_controller_spec.rb') 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