diff options
-rw-r--r-- | app/controllers/groups/variables_controller.rb | 13 | ||||
-rw-r--r-- | app/presenters/ci/group_variable_presenter.rb | 4 | ||||
-rw-r--r-- | config/routes/group.rb | 4 | ||||
-rw-r--r-- | spec/controllers/groups/variables_controller_spec.rb | 22 | ||||
-rw-r--r-- | spec/presenters/ci/group_variable_presenter_spec.rb | 4 |
5 files changed, 35 insertions, 12 deletions
diff --git a/app/controllers/groups/variables_controller.rb b/app/controllers/groups/variables_controller.rb index 2f7058e95ea..c0eff63da18 100644 --- a/app/controllers/groups/variables_controller.rb +++ b/app/controllers/groups/variables_controller.rb @@ -2,7 +2,18 @@ module Groups class VariablesController < Groups::ApplicationController before_action :authorize_admin_build! - def save_multiple + def show + respond_to do |format| + format.json do + variables = @group.variables + .map { |variable| variable.present(current_user: current_user) } + + render status: :ok, json: { variables: variables } + end + end + end + + def update respond_to do |format| format.json do return head :ok if @group.update(variables_params) diff --git a/app/presenters/ci/group_variable_presenter.rb b/app/presenters/ci/group_variable_presenter.rb index fb6dfcc1e4d..98d68bc7a83 100644 --- a/app/presenters/ci/group_variable_presenter.rb +++ b/app/presenters/ci/group_variable_presenter.rb @@ -11,11 +11,11 @@ module Ci end def edit_path - group_variables_save_multiple_path(group) + group_variables_path(group) end def delete_path - group_variables_save_multiple_path(group) + group_variables_path(group) end end end diff --git a/config/routes/group.rb b/config/routes/group.rb index b3afbb4152f..ac22b636372 100644 --- a/config/routes/group.rb +++ b/config/routes/group.rb @@ -27,9 +27,7 @@ constraints(GroupUrlConstrainer.new) do resource :ci_cd, only: [:show], controller: 'ci_cd' end - namespace :variables do - post :save_multiple - end + resource :variables, only: [:show, :update] resources :children, only: [:index] 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, diff --git a/spec/presenters/ci/group_variable_presenter_spec.rb b/spec/presenters/ci/group_variable_presenter_spec.rb index d20fae47939..cb58a757564 100644 --- a/spec/presenters/ci/group_variable_presenter_spec.rb +++ b/spec/presenters/ci/group_variable_presenter_spec.rb @@ -43,12 +43,12 @@ describe Ci::GroupVariablePresenter do describe '#edit_path' do subject { described_class.new(variable).edit_path } - it { is_expected.to eq(group_variables_save_multiple_path(group)) } + it { is_expected.to eq(group_variables_path(group)) } end describe '#delete_path' do subject { described_class.new(variable).delete_path } - it { is_expected.to eq(group_variables_save_multiple_path(group)) } + it { is_expected.to eq(group_variables_path(group)) } end end |