Commit 44bb70c8 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Improved code styling on the variables_controller_spec

Also updated the #update action inside the variables controller as
to render the show and not redirect back to the settings route
parent f3aaf906
...@@ -12,11 +12,11 @@ class Projects::TriggersController < Projects::ApplicationController ...@@ -12,11 +12,11 @@ class Projects::TriggersController < Projects::ApplicationController
@trigger.save @trigger.save
if @trigger.valid? if @trigger.valid?
flash[:notice] = "Trigger has been created successfully" redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Trigger was created successfully.'
else else
@triggers = project.triggers.select(&:persisted?) @triggers = project.triggers.select(&:persisted?)
render action: "show"
end end
redirect_to namespace_project_settings_ci_cd_path(@project.namespace, @project)
end end
def destroy def destroy
......
...@@ -15,11 +15,10 @@ class Projects::VariablesController < Projects::ApplicationController ...@@ -15,11 +15,10 @@ class Projects::VariablesController < Projects::ApplicationController
@variable = @project.variables.find(params[:id]) @variable = @project.variables.find(params[:id])
if @variable.update_attributes(project_params) if @variable.update_attributes(project_params)
flash[:notice] = 'Variables were successfully updated.' redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Variable was successfully updated.'
else else
flash[:alert] = @variable.errors.full_messages.join(',').html_safe render action: "show"
end end
redirect_to namespace_project_settings_ci_cd_path(project.namespace, project)
end end
def create def create
......
...@@ -14,6 +14,7 @@ describe Projects::VariablesController do ...@@ -14,6 +14,7 @@ describe Projects::VariablesController do
it 'shows a success flash message' do it 'shows a success flash message' do
post :create, namespace_id: project.namespace.to_param, project_id: project.to_param, post :create, namespace_id: project.namespace.to_param, project_id: project.to_param,
variable: { key: "one", value: "two" } variable: { key: "one", value: "two" }
expect(flash[:notice]).to include 'Variables were successfully updated.' expect(flash[:notice]).to include 'Variables were successfully updated.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project)) expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project))
end end
...@@ -23,6 +24,7 @@ describe Projects::VariablesController do ...@@ -23,6 +24,7 @@ describe Projects::VariablesController do
it 'shows an alert flash message' do it 'shows an alert flash message' do
post :create, namespace_id: project.namespace.to_param, project_id: project.to_param, post :create, namespace_id: project.namespace.to_param, project_id: project.to_param,
variable: { key: "..one", value: "two" } variable: { key: "..one", value: "two" }
expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.' expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project)) expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project))
end end
...@@ -41,15 +43,17 @@ describe Projects::VariablesController do ...@@ -41,15 +43,17 @@ describe Projects::VariablesController do
it 'shows a success flash message' do it 'shows a success flash message' do
post :update, namespace_id: project.namespace.to_param, project_id: project.to_param, post :update, namespace_id: project.namespace.to_param, project_id: project.to_param,
id: variable.id, variable: { key: variable.key, value: 'two' } id: variable.id, variable: { key: variable.key, value: 'two' }
expect(flash[:notice]).to include 'Variables were successfully updated.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project)) expect(flash[:notice]).to include 'Variable was successfully updated.'
expect(response).to redirect_to(namespace_project_variables_path(project.namespace, project))
end end
it 'shows an alert flash message' do it 'renders the action #show if the variable key is invalid' do
post :update, namespace_id: project.namespace.to_param, project_id: project.to_param, post :update, namespace_id: project.namespace.to_param, project_id: project.to_param,
id: variable.id, variable: { key: '?', value: variable.value } id: variable.id, variable: { key: '?', value: variable.value }
expect(flash[:alert]).to include 'Key can contain only letters, digits and \'_\'.'
expect(response).to redirect_to(namespace_project_settings_ci_cd_path(project.namespace, project)) expect(response).to have_http_status(200)
expect(response).to render_template :show
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment