Remove redundant routes in VariablesController
This commit is contained in:
parent
5de85708ce
commit
edbe911b04
|
@ -1,37 +1,6 @@
|
||||||
class Projects::VariablesController < Projects::ApplicationController
|
class Projects::VariablesController < Projects::ApplicationController
|
||||||
before_action :variable, only: [:show, :update, :destroy]
|
|
||||||
before_action :authorize_admin_build!
|
before_action :authorize_admin_build!
|
||||||
|
|
||||||
layout 'project_settings'
|
|
||||||
|
|
||||||
def index
|
|
||||||
redirect_to project_settings_ci_cd_path(@project)
|
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
if variable.update(variable_params)
|
|
||||||
redirect_to project_variables_path(project),
|
|
||||||
notice: 'Variable was successfully updated.'
|
|
||||||
else
|
|
||||||
render "show"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def create
|
|
||||||
@variable = project.variables.create(variable_params)
|
|
||||||
.present(current_user: current_user)
|
|
||||||
|
|
||||||
if @variable.persisted?
|
|
||||||
redirect_to project_settings_ci_cd_path(project),
|
|
||||||
notice: 'Variable was successfully created.'
|
|
||||||
else
|
|
||||||
render "show"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def save_multiple
|
def save_multiple
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
|
@ -42,24 +11,8 @@ class Projects::VariablesController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
|
||||||
if variable.destroy
|
|
||||||
redirect_to project_settings_ci_cd_path(project),
|
|
||||||
status: 302,
|
|
||||||
notice: 'Variable was successfully removed.'
|
|
||||||
else
|
|
||||||
redirect_to project_settings_ci_cd_path(project),
|
|
||||||
status: 302,
|
|
||||||
notice: 'Failed to remove the variable.'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def variable_params
|
|
||||||
params.require(:variable).permit(*variable_params_attributes)
|
|
||||||
end
|
|
||||||
|
|
||||||
def variables_params
|
def variables_params
|
||||||
params.permit(variables_attributes: [*variable_params_attributes])
|
params.permit(variables_attributes: [*variable_params_attributes])
|
||||||
end
|
end
|
||||||
|
@ -67,8 +20,4 @@ class Projects::VariablesController < Projects::ApplicationController
|
||||||
def variable_params_attributes
|
def variable_params_attributes
|
||||||
%i[id key value protected _destroy]
|
%i[id key value protected _destroy]
|
||||||
end
|
end
|
||||||
|
|
||||||
def variable
|
|
||||||
@variable ||= project.variables.find(params[:id]).present(current_user: current_user)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -156,10 +156,8 @@ constraints(ProjectUrlConstrainer.new) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :variables, only: [:index, :show, :update, :create, :destroy] do
|
namespace :variables do
|
||||||
collection do
|
post :save_multiple
|
||||||
post :save_multiple
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
|
resources :triggers, only: [:index, :create, :edit, :update, :destroy] do
|
||||||
|
|
|
@ -9,53 +9,6 @@ describe Projects::VariablesController do
|
||||||
project.add_master(user)
|
project.add_master(user)
|
||||||
end
|
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
|
describe 'POST #save_multiple' do
|
||||||
let(:variable) { create(:ci_variable) }
|
let(:variable) { create(:ci_variable) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue