summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/projects/variables_controller.rb13
-rw-r--r--app/presenters/ci/variable_presenter.rb4
-rw-r--r--config/routes/project.rb4
-rw-r--r--spec/controllers/projects/variables_controller_spec.rb27
-rw-r--r--spec/presenters/ci/variable_presenter_spec.rb4
5 files changed, 40 insertions, 12 deletions
diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb
index 99dea65927d..2f03603bd1d 100644
--- a/app/controllers/projects/variables_controller.rb
+++ b/app/controllers/projects/variables_controller.rb
@@ -1,7 +1,18 @@
class Projects::VariablesController < Projects::ApplicationController
before_action :authorize_admin_build!
- def save_multiple
+ def show
+ respond_to do |format|
+ format.json do
+ variables = @project.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 @project.update(variables_params)
diff --git a/app/presenters/ci/variable_presenter.rb b/app/presenters/ci/variable_presenter.rb
index 2e8f069646a..96159f88c59 100644
--- a/app/presenters/ci/variable_presenter.rb
+++ b/app/presenters/ci/variable_presenter.rb
@@ -11,11 +11,11 @@ module Ci
end
def edit_path
- project_variables_save_multiple_path(project)
+ project_variables_path(project)
end
def delete_path
- project_variables_save_multiple_path(project)
+ project_variables_path(project)
end
end
end
diff --git a/config/routes/project.rb b/config/routes/project.rb
index b8d09f01ae1..1912808f9c0 100644
--- a/config/routes/project.rb
+++ b/config/routes/project.rb
@@ -156,9 +156,7 @@ constraints(ProjectUrlConstrainer.new) do
end
end
- namespace :variables do
- post :save_multiple
- end
+ resource :variables, only: [:show, :update]
resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
member do
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,
diff --git a/spec/presenters/ci/variable_presenter_spec.rb b/spec/presenters/ci/variable_presenter_spec.rb
index 35ad49817b8..e3ce88372ea 100644
--- a/spec/presenters/ci/variable_presenter_spec.rb
+++ b/spec/presenters/ci/variable_presenter_spec.rb
@@ -43,12 +43,12 @@ describe Ci::VariablePresenter do
describe '#edit_path' do
subject { described_class.new(variable).edit_path }
- it { is_expected.to eq(project_variables_save_multiple_path(project)) }
+ it { is_expected.to eq(project_variables_path(project)) }
end
describe '#delete_path' do
subject { described_class.new(variable).delete_path }
- it { is_expected.to eq(project_variables_save_multiple_path(project)) }
+ it { is_expected.to eq(project_variables_path(project)) }
end
end